Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions project/include/media/AudioBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace lime {
int bitsPerSample;
int channels;
ArrayBufferView* data;
int dataFormat;
int sampleRate;

vdynamic* __srcAudio;
Expand Down
2 changes: 1 addition & 1 deletion project/src/ExternalInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions project/src/media/AudioBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -28,13 +30,15 @@ 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 {

bitsPerSample = 0;
channels = 0;
// data = new ArrayBufferView ();
dataFormat = 0;
sampleRate = 0;

}
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions project/src/media/containers/OGG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions project/src/media/containers/WAV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 12 additions & 3 deletions src/lime/media/AudioBuffer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
**/
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/lime/media/AudioBufferDataFormat.hx
Original file line number Diff line number Diff line change
@@ -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;
}
Loading