aboutsummaryrefslogtreecommitdiff
path: root/tests/sdl_audio_quickload.c
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-06-25 20:41:56 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-06-25 20:41:56 -0700
commit6c4cc9b0b8e1f6451fc4d376ef8260979f169c05 (patch)
treec3bdbb2d2da8a91c8678a295f8326b6477f89c20 /tests/sdl_audio_quickload.c
parentd1b22871c34dc9b0d5ea88f991602666d9143011 (diff)
parent5940f3189736ba5a935b35485feac1d0ec00f7fc (diff)
Merge pull request #490 from ehsan/audio
Implement Mix_QuickLoad_RAW
Diffstat (limited to 'tests/sdl_audio_quickload.c')
-rw-r--r--tests/sdl_audio_quickload.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/sdl_audio_quickload.c b/tests/sdl_audio_quickload.c
new file mode 100644
index 00000000..1525d048
--- /dev/null
+++ b/tests/sdl_audio_quickload.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_mixer.h>
+#include <assert.h>
+#include <limits.h>
+#include <emscripten.h>
+
+Mix_Chunk *sound;
+
+void play() {
+ int channel = Mix_PlayChannel(-1, sound, 1);
+ assert(channel == 0);
+
+ int result = 1;
+ REPORT_RESULT();
+}
+
+int main(int argc, char **argv) {
+ SDL_Init(SDL_INIT_AUDIO);
+
+ int ret = Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
+ assert(ret == 0);
+
+ Uint16* buffer = (Uint16*)malloc(10*44100*sizeof(Uint16));
+ for (Uint32 i = 0; i < 10*44100; ++i) {
+ buffer[i] = (i * 5) % UINT32_MAX;
+ }
+ sound = Mix_QuickLoad_RAW((Uint8*) buffer, 10*44100*sizeof(Uint16));
+ assert(sound);
+
+ play();
+
+ emscripten_run_script("element = document.createElement('input');"
+ "element.setAttribute('type', 'button');"
+ "element.setAttribute('value', 'replay!');"
+ "element.setAttribute('onclick', 'Module[\"_play\"]()');"
+ "document.body.appendChild(element);");
+
+ printf("you should one sounds. press the button to replay!\n");
+
+ return 0;
+}
+