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

« back to all changes in this revision

Viewing changes to tests/sdl_audio_mix.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
static Mix_Chunk *sound = NULL;
 
8
static Mix_Music *music = NULL;
 
9
 
 
10
static int soundChannel = 0;
 
11
 
 
12
void one_iter();
 
13
void one_iter() {
 
14
  static int frames = 0;
 
15
  frames++;
 
16
  
 
17
  switch( frames ) {
 
18
    case 1:
 
19
      soundChannel = Mix_PlayChannel(-1, sound, 0);
 
20
      printf("channel = %d", soundChannel);
 
21
      assert(soundChannel != -1 && soundChannel != 0);
 
22
      break;
 
23
    case 2:
 
24
      printf("channel %d is playing = %d", soundChannel, Mix_Playing(soundChannel));
 
25
      assert(Mix_Playing(soundChannel));
 
26
      break;
 
27
    case 30:
 
28
      Mix_Pause(soundChannel);
 
29
      Mix_PlayMusic(music, 1);
 
30
      break;
 
31
    case 31:
 
32
      assert(Mix_Paused(soundChannel));
 
33
      assert(Mix_PlayingMusic());
 
34
      break;
 
35
    case 60:
 
36
      Mix_Resume(soundChannel);
 
37
      Mix_PauseMusic();
 
38
      break;
 
39
    case 61:
 
40
      assert(Mix_Playing(soundChannel));
 
41
      assert(Mix_PausedMusic());
 
42
      break;
 
43
    case 90:
 
44
      Mix_ResumeMusic();
 
45
      break;
 
46
    case 91:
 
47
      assert(Mix_PlayingMusic());
 
48
      break;
 
49
    case 120:
 
50
      Mix_HaltChannel(soundChannel);
 
51
      Mix_HaltMusic();
 
52
      int result = 1;
 
53
      REPORT_RESULT();
 
54
      break;
 
55
  };
 
56
}
 
57
 
 
58
 
 
59
int main(int argc, char **argv) {
 
60
  SDL_Init(SDL_INIT_AUDIO);
 
61
  Mix_Init(MIX_INIT_OGG);
 
62
  
 
63
  // This reserves channel 0 for other purposes.
 
64
  // We are just going to verify that we are not
 
65
  // allocated channel 0 when we call Mix_PlayChannel(-1, ...)
 
66
  Mix_ReserveChannels(1);
 
67
  
 
68
  int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these..
 
69
  assert(ret == 0);
 
70
 
 
71
  sound = Mix_LoadWAV("sound.ogg");
 
72
  assert(sound);
 
73
  music = Mix_LoadMUS("music.ogg");
 
74
  assert(music);
 
75
 
 
76
  emscripten_set_main_loop(one_iter, 30, 0);
 
77
 
 
78
  // force a quit
 
79
  while(Mix_Init(0))
 
80
    Mix_Quit();
 
81
  Mix_CloseAudio();
 
82
 
 
83
  return 0;
 
84
}
 
85