diff --git a/project/include/media/AudioBuffer.h b/project/include/media/AudioBuffer.h index 3a60eb9023..7a989b402f 100644 --- a/project/include/media/AudioBuffer.h +++ b/project/include/media/AudioBuffer.h @@ -35,6 +35,7 @@ namespace lime { int bitsPerSample; int channels; ArrayBufferView* data; + int dataFormat; int sampleRate; vdynamic* __srcAudio; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index d213c61e74..507957fb49 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -4098,7 +4098,7 @@ namespace lime { #define _TARRAYBUFFER _TBYTES #define _TARRAYBUFFERVIEW _OBJ (_I32 _TARRAYBUFFER _I32 _I32 _I32 _I32) - #define _TAUDIOBUFFER _OBJ (_I32 _I32 _TARRAYBUFFERVIEW _I32 _DYN _DYN _DYN _DYN _DYN _TVORBISFILE) + #define _TAUDIOBUFFER _OBJ (_I32 _I32 _TARRAYBUFFERVIEW _I32 _I32 _DYN _DYN _DYN _DYN _DYN _TVORBISFILE) #define _TIMAGEBUFFER _OBJ (_I32 _TARRAYBUFFERVIEW _I32 _I32 _BOOL _BOOL _I32 _DYN _DYN _DYN _DYN _DYN _DYN) #define _TIMAGE _OBJ (_TIMAGEBUFFER _BOOL _I32 _I32 _I32 _TRECTANGLE _ENUM _I32 _I32 _F64 _F64) diff --git a/project/src/media/AudioBuffer.cpp b/project/src/media/AudioBuffer.cpp index 3c1e7318e2..f295ea62dc 100644 --- a/project/src/media/AudioBuffer.cpp +++ b/project/src/media/AudioBuffer.cpp @@ -7,6 +7,7 @@ namespace lime { static int id_bitsPerSample; static int id_channels; static int id_data; + static int id_dataFormat; static int id_sampleRate; static bool init = false; @@ -18,6 +19,7 @@ namespace lime { id_bitsPerSample = val_id ("bitsPerSample"); id_channels = val_id ("channels"); id_data = val_id ("data"); + id_dataFormat = val_id ("dataFormat"); id_sampleRate = val_id ("sampleRate"); init = true; @@ -28,6 +30,7 @@ namespace lime { bitsPerSample = val_int (val_field (audioBuffer, id_bitsPerSample)); channels = val_int (val_field (audioBuffer, id_channels)); data = new ArrayBufferView (val_field (audioBuffer, id_data)); + dataFormat = val_int (val_field (audioBuffer, id_dataFormat)); sampleRate = val_int (val_field (audioBuffer, id_sampleRate)); } else { @@ -35,6 +38,7 @@ namespace lime { bitsPerSample = 0; channels = 0; // data = new ArrayBufferView (); + dataFormat = 0; sampleRate = 0; } @@ -69,6 +73,7 @@ namespace lime { id_bitsPerSample = val_id ("bitsPerSample"); id_channels = val_id ("channels"); id_data = val_id ("data"); + id_dataFormat = val_id ("dataFormat"); id_sampleRate = val_id ("sampleRate"); init = true; @@ -77,6 +82,7 @@ namespace lime { alloc_field (audioBuffer, id_bitsPerSample, alloc_int (bitsPerSample)); alloc_field (audioBuffer, id_channels, alloc_int (channels)); alloc_field (audioBuffer, id_data, data ? data->Value (val_field (audioBuffer, id_data)) : alloc_null ()); + alloc_field (audioBuffer, id_dataFormat, alloc_int (dataFormat)); alloc_field (audioBuffer, id_sampleRate, alloc_int (sampleRate)); return audioBuffer; diff --git a/project/src/media/containers/OGG.cpp b/project/src/media/containers/OGG.cpp index 4dc363e91c..b045d56b31 100644 --- a/project/src/media/containers/OGG.cpp +++ b/project/src/media/containers/OGG.cpp @@ -55,6 +55,7 @@ namespace lime { audioBuffer->sampleRate = pInfo->rate; audioBuffer->bitsPerSample = 16; + audioBuffer->dataFormat = 1; int dataLength = ov_pcm_total (oggFile, -1) * audioBuffer->channels * audioBuffer->bitsPerSample / 8; audioBuffer->data->Resize (dataLength); diff --git a/project/src/media/containers/WAV.cpp b/project/src/media/containers/WAV.cpp index 1f88d03344..1723e7bf5d 100644 --- a/project/src/media/containers/WAV.cpp +++ b/project/src/media/containers/WAV.cpp @@ -204,6 +204,7 @@ namespace lime { audioBuffer->sampleRate = (int)wave_format.sampleRate; audioBuffer->channels = wave_format.numChannels; audioBuffer->bitsPerSample = wave_format.bitsPerSample; + audioBuffer->dataFormat = wave_format.audioFormat; return true; diff --git a/src/lime/media/AudioBuffer.hx b/src/lime/media/AudioBuffer.hx index e74b531ec3..fadd067062 100644 --- a/src/lime/media/AudioBuffer.hx +++ b/src/lime/media/AudioBuffer.hx @@ -33,10 +33,10 @@ import flash.net.URLRequest; #end /** - The `AudioBuffer` class represents a buffer of audio data that can be played back using an `AudioSource`. + The `AudioBuffer` class represents a buffer of audio data that can be played back using an `AudioSource`. It supports a variety of audio formats and platforms, providing a consistent API for loading and managing audio data. - Depending on the platform, the audio backend may differ, but the class provides a unified interface for accessing + Depending on the platform, the audio backend may differ, but the class provides a unified interface for accessing audio data, whether it's stored in memory, loaded from a file, or streamed. @see lime.media.AudioSource @@ -58,6 +58,11 @@ class AudioBuffer **/ public var data:UInt8Array; + /** + The format the raw audio data is stored in. + **/ + public var dataFormat:AudioBufferDataFormat; + /** The sample rate of the audio data, in Hz. **/ @@ -144,6 +149,7 @@ class AudioBuffer audioBuffer.bitsPerSample = data.bitsPerSample; audioBuffer.channels = data.channels; audioBuffer.data = new UInt8Array(@:privateAccess new Bytes(data.data.length, data.data.b)); + audioBuffer.dataFormat = data.dataFormat; audioBuffer.sampleRate = data.sampleRate; return audioBuffer; } @@ -183,6 +189,7 @@ class AudioBuffer audioBuffer.bitsPerSample = data.bitsPerSample; audioBuffer.channels = data.channels; audioBuffer.data = new UInt8Array(@:privateAccess new Bytes(data.data.length, data.data.b)); + audioBuffer.dataFormat = data.dataFormat; audioBuffer.sampleRate = data.sampleRate; return audioBuffer; } @@ -238,6 +245,7 @@ class AudioBuffer audioBuffer.bitsPerSample = data.bitsPerSample; audioBuffer.channels = data.channels; audioBuffer.data = new UInt8Array(@:privateAccess new Bytes(data.data.length, data.data.b)); + audioBuffer.dataFormat = data.dataFormat; audioBuffer.sampleRate = data.sampleRate; return audioBuffer; } @@ -287,7 +295,7 @@ class AudioBuffer @return An `AudioBuffer` instance with the decoded audio data. **/ #if lime_vorbis - + public static function fromVorbisFile(vorbisFile:VorbisFile):AudioBuffer { if (vorbisFile == null) return null; @@ -298,6 +306,7 @@ class AudioBuffer audioBuffer.channels = info.channels; audioBuffer.sampleRate = info.rate; audioBuffer.bitsPerSample = 16; + audioBuffer.dataFormat = PCM; audioBuffer.__srcVorbisFile = vorbisFile; return audioBuffer; diff --git a/src/lime/media/AudioBufferDataFormat.hx b/src/lime/media/AudioBufferDataFormat.hx new file mode 100644 index 0000000000..07e747ce43 --- /dev/null +++ b/src/lime/media/AudioBufferDataFormat.hx @@ -0,0 +1,7 @@ +package lime.media; + +#if (haxe_ver >= 4.0) enum #else @:enum #end abstract AudioBufferDataFormat(Int) from Int to Int +{ + var PCM = 1; + var IEEEFloat = 3; +}