bjorn преди 7 години
родител
ревизия
74445b5380
променени са 4 файла, в които са добавени 115 реда и са изтрити 11 реда
  1. 73 5
      api/init.lua
  2. 21 0
      api/lovr/audio/SourceType.lua
  3. 18 6
      api/lovr/audio/newSource.lua
  4. 3 0
      api/lovr/data/newSoundData.lua

+ 73 - 5
api/init.lua

@@ -649,6 +649,23 @@ return {
         }
         }
       },
       },
       enums = {
       enums = {
+        {
+          name = "SourceType",
+          summary = "Different ways to handle audio data for Source objects.",
+          description = "When you create a Source, you can either decode audio data gradually over time or you can decode it all at once.  Streaming it over time will use less memory but cause higher processing overhead because audio is continuously being decoded.  On the other hand, decoding a sound all at once means it will take more time to load and use more memory, but after it's loaded there is virtually no processing overhead.  It's recommended to use the 'static' mode for short sound effects and the 'stream' mode for longer music tracks.",
+          key = "SourceType",
+          module = "audio",
+          values = {
+            {
+              name = "static",
+              description = "Decode the entire sound file up front."
+            },
+            {
+              name = "stream",
+              description = "Decode the sound gradually over time."
+            }
+          }
+        },
         {
         {
           name = "TimeUnit",
           name = "TimeUnit",
           summary = "Time units for sound samples.",
           summary = "Time units for sound samples.",
@@ -845,9 +862,20 @@ return {
                   name = "filename",
                   name = "filename",
                   type = "string",
                   type = "string",
                   description = "The filename of the sound to load."
                   description = "The filename of the sound to load."
+                },
+                {
+                  name = "type",
+                  type = "SourceType",
+                  description = "How to stream in audio data."
                 }
                 }
               },
               },
-              returns = {}
+              returns = {
+                {
+                  name = "source",
+                  type = "Source",
+                  description = "The new Source."
+                }
+              }
             },
             },
             {
             {
               arguments = {
               arguments = {
@@ -855,9 +883,20 @@ return {
                   name = "blob",
                   name = "blob",
                   type = "Blob",
                   type = "Blob",
                   description = "The Blob containing the Source data."
                   description = "The Blob containing the Source data."
+                },
+                {
+                  name = "type",
+                  type = "SourceType",
+                  description = "How to stream in audio data."
                 }
                 }
               },
               },
-              returns = {}
+              returns = {
+                {
+                  name = "source",
+                  type = "Source",
+                  description = "The new Source."
+                }
+              }
             },
             },
             {
             {
               arguments = {
               arguments = {
@@ -865,9 +904,36 @@ return {
                   name = "stream",
                   name = "stream",
                   type = "AudioStream",
                   type = "AudioStream",
                   description = "The AudioStream used to stream audio data to the Source."
                   description = "The AudioStream used to stream audio data to the Source."
+                },
+                {
+                  name = "type",
+                  type = "SourceType",
+                  description = "How to stream in audio data."
                 }
                 }
               },
               },
-              returns = {}
+              returns = {
+                {
+                  name = "source",
+                  type = "Source",
+                  description = "The new Source."
+                }
+              }
+            },
+            {
+              arguments = {
+                {
+                  name = "soundData",
+                  type = "SoundData",
+                  description = "The SoundData containing raw audio samples to play."
+                }
+              },
+              returns = {
+                {
+                  name = "source",
+                  type = "Source",
+                  description = "The new Source."
+                }
+              }
             }
             }
           }
           }
         },
         },
@@ -2135,12 +2201,14 @@ return {
                 {
                 {
                   name = "sampleRate",
                   name = "sampleRate",
                   type = "number",
                   type = "number",
-                  description = "The number of samples per second."
+                  description = "The number of samples per second.",
+                  default = "44100"
                 },
                 },
                 {
                 {
                   name = "bitDepth",
                   name = "bitDepth",
                   type = "number",
                   type = "number",
-                  description = "The number of bits stored for each sample."
+                  description = "The number of bits stored for each sample.",
+                  default = "16"
                 }
                 }
               },
               },
               returns = {
               returns = {

+ 21 - 0
api/lovr/audio/SourceType.lua

@@ -0,0 +1,21 @@
+return {
+  summary = 'Different ways to handle audio data for Source objects.',
+  description = [[
+    When you create a Source, you can either decode audio data gradually over time or you can decode
+    it all at once.  Streaming it over time will use less memory but cause higher processing
+    overhead because audio is continuously being decoded.  On the other hand, decoding a sound all
+    at once means it will take more time to load and use more memory, but after it's loaded there is
+    virtually no processing overhead.  It's recommended to use the 'static' mode for short sound
+    effects and the 'stream' mode for longer music tracks.
+  ]],
+  values = {
+    {
+      name = 'static',
+      description = 'Decode the entire sound file up front.'
+    },
+    {
+      name = 'stream',
+      description = 'Decode the sound gradually over time.'
+    }
+  }
+}

+ 18 - 6
api/lovr/audio/newSource.lua

@@ -14,6 +14,14 @@ return {
     stream = {
     stream = {
       type = 'AudioStream',
       type = 'AudioStream',
       description = 'The AudioStream used to stream audio data to the Source.'
       description = 'The AudioStream used to stream audio data to the Source.'
+    },
+    soundData = {
+      type = 'SoundData',
+      description = 'The SoundData containing raw audio samples to play.'
+    },
+    type = {
+      type = 'SourceType',
+      description = 'How to stream in audio data.'
     }
     }
   },
   },
   returns = {
   returns = {
@@ -24,16 +32,20 @@ return {
   },
   },
   variants = {
   variants = {
     {
     {
-      arguments = { 'filename' },
-      returns = { 'source '}
+      arguments = { 'filename', 'type' },
+      returns = { 'source' }
+    },
+    {
+      arguments = { 'blob', 'type' },
+      returns = { 'source' }
     },
     },
     {
     {
-      arguments = { 'blob' },
-      returns = { 'source '}
+      arguments = { 'stream', 'type' },
+      returns = { 'source' }
     },
     },
     {
     {
-      arguments = { 'stream' },
-      returns = { 'source '}
+      arguments = { 'soundData' },
+      returns = { 'source' }
     }
     }
   }
   }
 }
 }

+ 3 - 0
api/lovr/data/newSoundData.lua

@@ -12,14 +12,17 @@ return {
     },
     },
     sampleRate = {
     sampleRate = {
       type = 'number',
       type = 'number',
+      default = '44100',
       description = 'The number of samples per second.'
       description = 'The number of samples per second.'
     },
     },
     bitDepth = {
     bitDepth = {
       type = 'number',
       type = 'number',
+      default = '16',
       description = 'The number of bits stored for each sample.'
       description = 'The number of bits stored for each sample.'
     },
     },
     channels = {
     channels = {
       type = 'number',
       type = 'number',
+      default = '2',
       description = 'The number of channels in the sound (1 for mono, 2 for stereo).'
       description = 'The number of channels in the sound (1 for mono, 2 for stereo).'
     },
     },
     filename = {
     filename = {