Skip to content

Commit 7389eb0

Browse files
Add SDL_sound streaming support and CFFI bindings
Expose SDL_sound streaming to the engine and update related plumbing. - Add SDLSound streaming API (SDLSoundStreamInfo / SDLSoundStream) and functions: GetStreamInfo, OpenStream, ReadStream, RewindStream, SeekStream, CloseStream. - Implement robust SDL_sound handling in SDLSound.cpp: sample creation, buffer alignment, prepare/resize logic, better error reporting, and streaming decode paths. - Add SDLSoundBindings.cpp: CFFI/Haxe/HL bindings to work with SDL_sound streams (get info, open stream from bytes/file, read, seek, rewind, clear). - Register new native CFFI functions in NativeCFFI.hx (regular and HL variants) and add CFFI callables. - Extend AudioBuffer with fields for SDL sound sources and new helpers: fromBytesStream / fromFileStream and internal SDLSound metadata handling. - Enhance NativeAudioSource to support SDL_sound streaming: open/reset/clear stream, buffer alignment, queue management, reading stream data and seeking; integrate with existing Vorbis streaming logic. - Add TryResize API to Bytes and ArrayBufferView and update usages to avoid unnecessary allocations and handle OOM safely. - Add SDLSoundBindings.cpp to project Build.xml and check Sound_Init() result during SDL init. These changes enable streamed playback of compressed audio via SDL_sound (bytes or file), improve memory handling during decoding, and expose the required native bindings to Haxe/HL runtimes.
1 parent ec6d491 commit 7389eb0

File tree

14 files changed

+1677
-122
lines changed

14 files changed

+1677
-122
lines changed

project/Build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@
300300
<compilerflag value="-DHAVE_STDIO_H" unless="windows" />
301301
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/sdl_sound/src/" />
302302

303+
<file name="src/media/SDLSoundBindings.cpp" />
303304
<file name="src/media/SDLSound.cpp" />
304305

305306
</section>

project/include/media/SDLSound.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,48 @@
22
#define LIME_MEDIA_DECODERS_SDL_SOUND_H
33

44

5+
#include "SDL_sound.h"
56
#include <media/AudioBuffer.h>
67
#include <utils/Resource.h>
78

89

910
namespace lime {
1011

1112

13+
struct SDLSoundStreamInfo {
14+
15+
int bitsPerSample;
16+
bool canSeek;
17+
int channels;
18+
int duration;
19+
int sampleRate;
20+
21+
SDLSoundStreamInfo () : bitsPerSample (0), canSeek (false), channels (0), duration (0), sampleRate (0) {}
22+
23+
};
24+
25+
26+
struct SDLSoundStream {
27+
28+
Sound_Sample* sample;
29+
30+
SDLSoundStream () : sample (NULL) {}
31+
32+
};
33+
34+
1235
class SDLSound {
1336

1437

1538
public:
1639

1740
static bool Decode (Resource *resource, AudioBuffer *audioBuffer);
41+
static bool GetStreamInfo (Resource *resource, SDLSoundStreamInfo *streamInfo);
42+
static SDLSoundStream* OpenStream (Resource *resource);
43+
static int ReadStream (SDLSoundStream *stream, unsigned char *buffer, int length);
44+
static bool RewindStream (SDLSoundStream *stream);
45+
static bool SeekStream (SDLSoundStream *stream, int ms);
46+
static void CloseStream (SDLSoundStream *stream);
1847

1948

2049
};
@@ -23,4 +52,4 @@ namespace lime {
2352
}
2453

2554

26-
#endif
55+
#endif

project/include/utils/ArrayBufferView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace lime {
2222
ArrayBufferView (value arrayBufferView);
2323
~ArrayBufferView ();
2424

25+
bool TryResize (int size);
2526
void Resize (int size);
2627
void Set (value bytes);
2728
void Set (const QuickVec<unsigned char> data);
@@ -34,4 +35,4 @@ namespace lime {
3435
}
3536

3637

37-
#endif
38+
#endif

project/include/utils/Bytes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace lime {
2020
~Bytes ();
2121

2222
void ReadFile (const char* path);
23+
bool TryResize (int size);
2324
void Resize (int size);
2425
void Set (value bytes);
2526
void Set (const QuickVec<unsigned char> data);
@@ -32,4 +33,4 @@ namespace lime {
3233
}
3334

3435

35-
#endif
36+
#endif

project/src/backend/sdl/SDLApplication.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ namespace lime {
4343
}
4444

4545
#ifdef LIME_SDL_SOUND
46-
Sound_Init();
46+
if (!Sound_Init ()) {
47+
48+
printf ("Could not initialize SDL_sound: %s.\n", Sound_GetError ());
49+
50+
}
4751
#endif
4852

4953
SDL_LogSetPriority (SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN);

0 commit comments

Comments
 (0)