[SDL] Using secondary screen

Chris Nystrom cnystrom at gmail.com
Mon Nov 21 05:45:17 PST 2005


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20051101/8745b88e/attachment-0008.pgp>


More information about the SDL mailing list