[SDL] Persistent surfaces

Jeremy Kronuz kronuz at hotmail.com
Mon Nov 21 20:09:00 PST 2005


On Tue, Nov 01, 2005 at 12:10:44PM -0500, Timm Murray wrote:
> I have a simple program for playing wav files:
> 
> ----
> #include <stdio.h>
> #include <SDL.h>
> #include <SDL_mixer.h>
> 
> 
> int main(int argc, char **argv)
> {
>  char *file = argv[1];
>  int done = 0;
>  Mix_Chunk *wav;
>  int ret;
> 
>  SDL_Init( SDL_INIT_AUDIO );
>  
>  ret = Mix_OpenAudio( 44100, AUDIO_S16SYS, 2, 4096 );
>  if( 0 > ret ) {
>   printf( "Error opening audio: %s\n", Mix_GetError() );
>   exit(1);
>  }
> 
>  printf( "Playing file: %s\n", file );
>  wav = Mix_LoadWAV( file );
>  ret = Mix_PlayChannel( -1, wav, -1 );
>  if( 0 > ret ) {
>   printf( "Error playing audio: %s\n", Mix_GetError() );
>  }
>  else {
>   printf( "Played on channel %i\n", ret );
>  }
>  SDL_Delay( 50 );
> 
>  Mix_FreeChunk( wav );
>  Mix_CloseAudio();
>  SDL_Quit();
>  return 0;
> }
> ----
> 
> This is compiled with "gcc `sdl-config --libs` -lSDL_mixer -I/usr/include/SDL 
> -o play_sound play_sound_mixer.c".  'sdl-config --libs' gives 
> "-L/usr/local/lib -Wl,-rpath,/usr/local/lib -lSDL -lpthread".  On running, it 
> shows:
> 
> ----
> $ ./play_sound ../data/sound/explosion.wav 
> Playing file: ../data/sound/explosion.wav
> Played on channel 0
> ----
> 
> However, nothing comes out of the speakers.  I hear the sound when using 
> wavplay, so sound works fine on my system.  This is on Linux w/ALSA, running 
> SDL 1.2.6 and SDL_mixer 1.2.6.

Hi,

SDL_Delay()'s argument is in milliseconds, so you are playing the first
0.05 seconds of the file,

cheers,
John.


> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl





More information about the SDL mailing list