~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/sdl_audio_quickload.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <SDL/SDL.h>
 
4
#include <SDL/SDL_mixer.h>
 
5
#include <assert.h>
 
6
#include <limits.h>
 
7
#include <emscripten.h>
 
8
 
 
9
Mix_Chunk *sound;
 
10
 
 
11
void play() {
 
12
  int channel = Mix_PlayChannel(-1, sound, 1);
 
13
  assert(channel == 0);
 
14
 
 
15
  int result = 1;
 
16
  REPORT_RESULT();
 
17
}
 
18
 
 
19
int main(int argc, char **argv) {
 
20
  SDL_Init(SDL_INIT_AUDIO);
 
21
 
 
22
  int ret = Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
 
23
  assert(ret == 0);
 
24
 
 
25
  Uint16* buffer = (Uint16*)malloc(10*44100*sizeof(Uint16));
 
26
  for (Uint32 i = 0; i < 10*44100; ++i) {
 
27
    buffer[i] = (i * 5) % UINT32_MAX;
 
28
  }
 
29
  sound = Mix_QuickLoad_RAW((Uint8*) buffer, 10*44100*sizeof(Uint16));
 
30
  assert(sound);
 
31
 
 
32
  play();
 
33
 
 
34
  emscripten_run_script("element = document.createElement('input');"
 
35
                        "element.setAttribute('type', 'button');"
 
36
                        "element.setAttribute('value', 'replay!');"
 
37
                        "element.setAttribute('onclick', 'Module[\"_play\"]()');"
 
38
                        "document.body.appendChild(element);");
 
39
 
 
40
  printf("you should one sounds. press the button to replay!\n");
 
41
 
 
42
  return 0;
 
43
}
 
44