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

« back to all changes in this revision

Viewing changes to tests/sdl_audio.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 <SDL/SDL.h>
 
3
#include <SDL/SDL_mixer.h>
 
4
#include <assert.h>
 
5
#include <emscripten.h>
 
6
 
 
7
Mix_Chunk *sound, *sound2;
 
8
 
 
9
int play2();
 
10
 
 
11
int play() {
 
12
  int channel = Mix_PlayChannel(-1, sound, 1);
 
13
  assert(channel == 0);
 
14
 
 
15
  emscripten_run_script("setTimeout(Module['_play2'], 500)");
 
16
  return channel;
 
17
}
 
18
 
 
19
void done(int channel) {
 
20
  assert(channel == 1);
 
21
 
 
22
  int result = 1;
 
23
  REPORT_RESULT();
 
24
}
 
25
 
 
26
int play2() {
 
27
  Mix_ChannelFinished(done);
 
28
 
 
29
  int channel2 = Mix_PlayChannel(-1, sound2, 1);
 
30
  assert(channel2 == 1);
 
31
  return channel2;
 
32
}
 
33
 
 
34
int main(int argc, char **argv) {
 
35
  SDL_Init(SDL_INIT_AUDIO);
 
36
 
 
37
  int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these..
 
38
  assert(ret == 0);
 
39
 
 
40
  sound = Mix_LoadWAV("sound.ogg");
 
41
  assert(sound);
 
42
  sound2 = Mix_LoadWAV("sound2.wav");
 
43
  assert(sound);
 
44
 
 
45
  int channel = play();
 
46
  printf( "Pausing Channel %d", channel );
 
47
  Mix_Pause(channel);
 
48
  int paused = Mix_Paused(channel);
 
49
  printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" );
 
50
  assert(paused);
 
51
  Mix_Resume(channel);
 
52
  paused = Mix_Paused(channel);
 
53
  printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" );
 
54
  assert(paused == 0);
 
55
 
 
56
  if (argc == 12121) play2(); // keep it alive
 
57
 
 
58
  emscripten_run_script("element = document.createElement('input');"
 
59
                        "element.setAttribute('type', 'button');"
 
60
                        "element.setAttribute('value', 'replay!');"
 
61
                        "element.setAttribute('onclick', 'Module[\"_play\"]()');"
 
62
                        "document.body.appendChild(element);");
 
63
 
 
64
  printf("you should hear two sounds. press the button to replay!\n");
 
65
 
 
66
  return 0;
 
67
}
 
68