Mercurial > almixer_isolated
comparison EXAMPLES/playsound.c @ 4:26aec5629f68
Added example programs.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Wed, 27 Oct 2010 21:41:31 -0700 |
parents | |
children | ee50db043251 |
comparison
equal
deleted
inserted
replaced
3:a929285e1db0 | 4:26aec5629f68 |
---|---|
1 #include "ALmixer.h" | |
2 #include <stdio.h> | |
3 | |
4 #ifdef ALMIXER_COMPILE_WITHOUT_SDL | |
5 #if defined(_WIN32) | |
6 #define WIN32_LEAN_AND_MEAN | |
7 #include <windows.h> | |
8 #else | |
9 #include <unistd.h> | |
10 #endif | |
11 | |
12 static void Internal_Delay(ALuint milliseconds_delay) | |
13 { | |
14 #if defined(_WIN32) | |
15 Sleep(milliseconds_delay); | |
16 #else | |
17 usleep(milliseconds_delay); | |
18 #endif | |
19 } | |
20 #else | |
21 #include "SDL.h" | |
22 #define Internal_Delay SDL_Delay | |
23 #endif | |
24 #define MAX_SOURCES 16 | |
25 | |
26 ALboolean g_PlayingAudio[MAX_SOURCES]; | |
27 | |
28 void Internal_SoundFinished_CallbackIntercept(ALint which_channel, ALuint al_source, ALmixer_Data* almixer_data, ALboolean finished_naturally, void* user_data) | |
29 { | |
30 fprintf(stderr, "Channel %d finished\n", which_channel); | |
31 g_PlayingAudio[which_channel] = AL_FALSE; | |
32 } | |
33 | |
34 int main(int argc, char* argv[]) | |
35 { | |
36 if(argc < 1) | |
37 { | |
38 printf("Pass a sound file (or files) as a parameter\n"); | |
39 } | |
40 else if(argc-1 > MAX_SOURCES) | |
41 { | |
42 printf("Maximum supported files is %d\n", MAX_SOURCES); | |
43 } | |
44 size_t i; | |
45 ALboolean still_playing = AL_TRUE; | |
46 | |
47 ALmixer_Data* audio_data[MAX_SOURCES]; | |
48 ALmixer_Init(22050, 0, 0); | |
49 | |
50 for(i=1; i<argc; i++) | |
51 { | |
52 if(!(audio_data[i-1]=ALmixer_LoadAll( argv[i], AL_TRUE) )) | |
53 { | |
54 printf("%s. Quiting program.\n", ALmixer_GetError()); | |
55 exit(0); | |
56 } | |
57 } | |
58 | |
59 ALmixer_SetPlaybackFinishedCallback(Internal_SoundFinished_CallbackIntercept, NULL); | |
60 | |
61 for(i=1; i<argc; i++) | |
62 { | |
63 g_PlayingAudio[i-1] = AL_TRUE; | |
64 ALmixer_PlayChannel(i-1, audio_data[i-1], 0); | |
65 } | |
66 | |
67 while(still_playing) | |
68 { | |
69 still_playing = AL_FALSE; | |
70 for(i=1; i<argc; i++) | |
71 { | |
72 still_playing |= g_PlayingAudio[i-1]; | |
73 } | |
74 ALmixer_Update(); | |
75 Internal_Delay(10); | |
76 } | |
77 | |
78 for(i=1; i<argc; i++) | |
79 { | |
80 ALmixer_FreeData(audio_data[i-1]); | |
81 } | |
82 | |
83 ALmixer_Quit(); | |
84 | |
85 return 0; | |
86 } | |
87 |