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