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