Skip to content

Commit 3cb4001

Browse files
committed
Implement support for SDL_sound
1 parent 35272dd commit 3cb4001

File tree

22 files changed

+1090
-75
lines changed

22 files changed

+1090
-75
lines changed

include.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<define name="lime-opengl" if="desktop" unless="html5" />
2424
<define name="lime-opengles" if="emscripten || mobile" />
2525
<define name="lime-vorbis" if="native" />
26+
<define name="lime-sdlsound" if="native"/>
2627
<define name="lime-webgl" if="html5" />
2728

2829
<define name="no-typedarray-inline" if="cs" />

project/Build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@
284284
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/sdl_sound/src/" />
285285

286286
<file name="src/media/decoders/SDL_sound.cpp" />
287+
<file name="src/media/decoders/SDL_soundBindings.cpp" />
287288

288289
</section>
289290

project/BuildHashlink.xml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,20 @@
5555
<file name="${HASHLINK_PATH}/src/std/ucs2.c" />
5656

5757
<!-- PCRE2 -->
58-
<file name="${HASHLINK_PATH}/include/pcre/pcre16_ord2utf16.c" />
58+
<file name="${HASHLINK_PATH}/include/pcre/pcre2_ord2utf.c" />
5959
<compilerflag value="-DHAVE_CONFIG_H" />
60-
<file name="${HASHLINK_PATH}/include/pcre/pcre_globals.c" />
6160
<compilerflag value="-DPCRE2_CODE_UNIT_WIDTH=16" />
62-
<file name="${HASHLINK_PATH}/include/pcre/pcre16_valid_utf16.c" />
61+
<file name="${HASHLINK_PATH}/include/pcre/pcre2_valid_utf.c" />
6362
<file name="${HASHLINK_PATH}/include/pcre/pcre2_auto_possess.c" />
64-
<file name="${HASHLINK_PATH}/include/pcre/pcre_newline.c" />
6563
<file name="${HASHLINK_PATH}/include/pcre/pcre2_chartables.c" />
66-
<file name="${HASHLINK_PATH}/include/pcre/pcre_chartables.c" />
6764
<file name="${HASHLINK_PATH}/include/pcre/pcre2_compile.c" />
68-
<file name="${HASHLINK_PATH}/include/pcre/pcre_string_utils.c" />
6965
<file name="${HASHLINK_PATH}/include/pcre/pcre2_config.c" />
70-
<file name="${HASHLINK_PATH}/include/pcre/pcre_compile.c" />
7166
<file name="${HASHLINK_PATH}/include/pcre/pcre2_context.c" />
72-
<file name="${HASHLINK_PATH}/include/pcre/pcre_tables.c" />
7367
<file name="${HASHLINK_PATH}/include/pcre/pcre2_convert.c" />
74-
<file name="${HASHLINK_PATH}/include/pcre/pcre_dfa_exec.c" />
7568
<file name="${HASHLINK_PATH}/include/pcre/pcre2_dfa_match.c" />
76-
<file name="${HASHLINK_PATH}/include/pcre/pcre_ucd.c" />
7769
<file name="${HASHLINK_PATH}/include/pcre/pcre2_error.c" />
78-
<file name="${HASHLINK_PATH}/include/pcre/pcre_exec.c" />
7970
<file name="${HASHLINK_PATH}/include/pcre/pcre2_extuni.c" />
80-
<file name="${HASHLINK_PATH}/include/pcre/pcre_xclass.c" />
8171
<file name="${HASHLINK_PATH}/include/pcre/pcre2_find_bracket.c" />
82-
<file name="${HASHLINK_PATH}/include/pcre/pcre_fullinfo.c" />
8372
<file name="${HASHLINK_PATH}/include/pcre/pcre2_jit_compile.c" />
8473
<file name="${HASHLINK_PATH}/include/pcre/pcre2_maketables.c" />
8574
<file name="${HASHLINK_PATH}/include/pcre/pcre2_match_data.c" />

project/include/media/AudioBuffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace lime {
3636
int channels;
3737
ArrayBufferView* data;
3838
int sampleRate;
39+
int dataFormat;
3940

4041
vdynamic* __srcAudio;
4142
vdynamic* __srcBuffer;

project/include/media/decoders/SDL_sound.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <media/AudioBuffer.h>
66
#include <utils/Resource.h>
7+
#include <SDL_sound.h>
78

89

910
namespace lime {
@@ -14,6 +15,8 @@ namespace lime {
1415

1516
public:
1617

18+
static Sound_Sample* FromBytes (Bytes* bytes);
19+
static Sound_Sample* FromFile (const char* path);
1720
static bool Decode (Resource *resource, AudioBuffer *audioBuffer);
1821

1922

project/src/ExternalInterface.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4219,11 +4219,12 @@ namespace lime {
42194219
#define _TTOUCH_EVENT _OBJ (_I32 _F64 _F64 _I32 _F64 _I32 _F64 _F64)
42204220
#define _TVECTOR2 _OBJ (_F64 _F64)
42214221
#define _TVORBISFILE _OBJ (_I32 _DYN)
4222+
#define _TSDL_SOUNDSAMPLE _OBJ (_I32 _DYN)
42224223
#define _TWINDOW_EVENT _OBJ (_I32 _I32 _I32 _I32 _I32 _I32)
42234224

42244225
#define _TARRAYBUFFER _TBYTES
42254226
#define _TARRAYBUFFERVIEW _OBJ (_I32 _TARRAYBUFFER _I32 _I32 _I32 _I32)
4226-
#define _TAUDIOBUFFER _OBJ (_I32 _I32 _TARRAYBUFFERVIEW _I32 _DYN _DYN _DYN _DYN _DYN _TVORBISFILE)
4227+
#define _TAUDIOBUFFER _OBJ (_I32 _I32 _TARRAYBUFFERVIEW _I32 _I32 _DYN _DYN _DYN _DYN _DYN _TVORBISFILE _TSDL_SOUNDSAMPLE)
42274228
#define _TIMAGEBUFFER _OBJ (_I32 _TARRAYBUFFERVIEW _I32 _I32 _BOOL _BOOL _I32 _DYN _DYN _DYN _DYN _DYN _DYN)
42284229
#define _TIMAGE _OBJ (_TIMAGEBUFFER _BOOL _I32 _I32 _I32 _TRECTANGLE _ENUM _I32 _I32 _F64 _F64)
42294230

@@ -4431,6 +4432,12 @@ extern "C" int lime_vorbis_register_prims ();
44314432
extern "C" int lime_vorbis_register_prims () { return 0; }
44324433
#endif
44334434

4435+
#ifdef LIME_SDL_SOUND
4436+
extern "C" int lime_sdl_sound_register_prims ();
4437+
#else
4438+
extern "C" int lime_sdl_sound_register_prims () { return 0; }
4439+
#endif
4440+
44344441

44354442
extern "C" int lime_register_prims () {
44364443

@@ -4440,6 +4447,7 @@ extern "C" int lime_register_prims () {
44404447
lime_openal_register_prims ();
44414448
lime_opengl_register_prims ();
44424449
lime_vorbis_register_prims ();
4450+
lime_sdl_sound_register_prims ();
44434451

44444452
return 0;
44454453

project/src/media/AudioBuffer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace lime {
88
static int id_channels;
99
static int id_data;
1010
static int id_sampleRate;
11+
static int id_dataFormat;
1112
static bool init = false;
1213

1314

@@ -19,6 +20,7 @@ namespace lime {
1920
id_channels = val_id ("channels");
2021
id_data = val_id ("data");
2122
id_sampleRate = val_id ("sampleRate");
23+
id_dataFormat = val_id ("dataFormat");
2224
init = true;
2325

2426
}
@@ -29,13 +31,15 @@ namespace lime {
2931
channels = val_int (val_field (audioBuffer, id_channels));
3032
data = new ArrayBufferView (val_field (audioBuffer, id_data));
3133
sampleRate = val_int (val_field (audioBuffer, id_sampleRate));
34+
dataFormat = val_int (val_field (audioBuffer, id_dataFormat));
3235

3336
} else {
3437

3538
bitsPerSample = 0;
3639
channels = 0;
3740
// data = new ArrayBufferView ();
3841
sampleRate = 0;
42+
dataFormat = 0;
3943

4044
}
4145

@@ -70,6 +74,7 @@ namespace lime {
7074
id_channels = val_id ("channels");
7175
id_data = val_id ("data");
7276
id_sampleRate = val_id ("sampleRate");
77+
id_dataFormat = val_id ("dataFormat");
7378
init = true;
7479

7580
}
@@ -78,6 +83,8 @@ namespace lime {
7883
alloc_field (audioBuffer, id_channels, alloc_int (channels));
7984
alloc_field (audioBuffer, id_data, data ? data->Value (val_field (audioBuffer, id_data)) : alloc_null ());
8085
alloc_field (audioBuffer, id_sampleRate, alloc_int (sampleRate));
86+
alloc_field (audioBuffer, id_dataFormat, alloc_int (dataFormat));
87+
8188
return audioBuffer;
8289

8390
}

project/src/media/containers/OGG.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace lime {
5555
audioBuffer->sampleRate = pInfo->rate;
5656

5757
audioBuffer->bitsPerSample = 16;
58+
audioBuffer->dataFormat = 1;
5859

5960
int dataLength = ov_pcm_total (oggFile, -1) * audioBuffer->channels * audioBuffer->bitsPerSample / 8;
6061
audioBuffer->data->Resize (dataLength);

project/src/media/containers/WAV.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ namespace lime {
204204
audioBuffer->sampleRate = (int)wave_format.sampleRate;
205205
audioBuffer->channels = wave_format.numChannels;
206206
audioBuffer->bitsPerSample = wave_format.bitsPerSample;
207+
audioBuffer->dataFormat = wave_format.audioFormat;
207208

208209
return true;
209210

0 commit comments

Comments
 (0)