Mercurial > almixer_isolated
view EXAMPLES/playsound.c @ 62:7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Instead of trying to backport my Tremor decoder which originated from the SDL_sound Vorbis decoder, I told Johnson it would be better to just start at the source and avoid all the original gotchas I hit in the subtle differences between Tremor and Vorbis.
Since this derives directly from Ryan Gordon's SDL_sound implementation, I am putting this under the LGPL subdirectory.
Johnson Lin < arch . jslin - at - gmail . com >
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Tue, 19 Jun 2012 00:31:12 -0700 |
parents | b1e13d5688d1 |
children |
line wrap: on
line source
#include "ALmixer.h" #include <stdio.h> #ifdef ALMIXER_COMPILE_WITHOUT_SDL #if defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include <windows.h> #else #include <unistd.h> #endif static void Internal_Delay(ALuint milliseconds_delay) { #if defined(_WIN32) Sleep(milliseconds_delay); #else usleep(milliseconds_delay*1000); #endif } #else #include "SDL.h" #define Internal_Delay SDL_Delay #endif #define MAX_SOURCES 16 ALboolean g_PlayingAudio[MAX_SOURCES]; void Internal_SoundFinished_CallbackIntercept(ALint which_channel, ALuint al_source, ALmixer_Data* almixer_data, ALboolean finished_naturally, void* user_data) { fprintf(stderr, "Channel %d finished\n", which_channel); g_PlayingAudio[which_channel] = AL_FALSE; } int main(int argc, char* argv[]) { ALint i; ALboolean still_playing = AL_TRUE; ALmixer_Data* audio_data[MAX_SOURCES]; if(argc < 1) { printf("Pass a sound file (or files) as a parameter\n"); } else if(argc-1 > MAX_SOURCES) { printf("Maximum supported files is %d\n", MAX_SOURCES); } ALmixer_Init(22050, 0, 0); for(i=1; i<argc; i++) { if(!(audio_data[i-1]=ALmixer_LoadAll( argv[i], AL_FALSE) )) { printf("%s. Quiting program.\n", ALmixer_GetError()); exit(0); } } ALmixer_SetPlaybackFinishedCallback(Internal_SoundFinished_CallbackIntercept, NULL); for(i=1; i<argc; i++) { g_PlayingAudio[i-1] = AL_TRUE; ALmixer_PlayChannel(i-1, audio_data[i-1], 0); } while(still_playing) { still_playing = AL_FALSE; for(i=1; i<argc; i++) { still_playing |= g_PlayingAudio[i-1]; } ALmixer_Update(); Internal_Delay(10); } for(i=1; i<argc; i++) { ALmixer_FreeData(audio_data[i-1]); } ALmixer_Quit(); return 0; }