Răsfoiți Sursa

More audio stuff;

bjorn 7 ani în urmă
părinte
comite
74445b5380
4 a modificat fișierele cu 115 adăugiri și 11 ștergeri
  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 = {
+        {
+          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",
           summary = "Time units for sound samples.",
@@ -845,9 +862,20 @@ return {
                   name = "filename",
                   type = "string",
                   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 = {
@@ -855,9 +883,20 @@ return {
                   name = "blob",
                   type = "Blob",
                   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 = {
@@ -865,9 +904,36 @@ return {
                   name = "stream",
                   type = "AudioStream",
                   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",
                   type = "number",
-                  description = "The number of samples per second."
+                  description = "The number of samples per second.",
+                  default = "44100"
                 },
                 {
                   name = "bitDepth",
                   type = "number",
-                  description = "The number of bits stored for each sample."
+                  description = "The number of bits stored for each sample.",
+                  default = "16"
                 }
               },
               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 = {
       type = 'AudioStream',
       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 = {
@@ -24,16 +32,20 @@ return {
   },
   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 = {
       type = 'number',
+      default = '44100',
       description = 'The number of samples per second.'
     },
     bitDepth = {
       type = 'number',
+      default = '16',
       description = 'The number of bits stored for each sample.'
     },
     channels = {
       type = 'number',
+      default = '2',
       description = 'The number of channels in the sound (1 for mono, 2 for stereo).'
     },
     filename = {