No Sound Output

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.pgp

You only gives your program 50 millisecs to play the sound before you quit.
Try with a while(Mix_Playing(-1) > 0); instead of the delay and see
what happens.On 11/1/05, 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;
}

[snip]
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.


Regards,
Rasmus Neckelmann

> ?ret = Mix_PlayChannel( -1, wav, -1 ); > ?SDL_Delay( 50 ); > > ?Mix_FreeChunk( wav ); > ?Mix_CloseAudio(); > ?SDL_Quit(); > ?return 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.

Uh, you don’t give it much time (50ms) to play before quitting.
Maybe you should wait until it’s done playing? :slight_smile:

Of course, in case it does turn out to be some other issue, do other
SDL-based apps play sound properly?

-bill!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.On Tue, Nov 01, 2005 at 12:10:44PM -0500, Timm Murray wrote:


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

50 ms is not very long. You might want to give yourself more time to hear it.

ChrisOn 11/1/05, Timm Murray wrote:

SDL_Delay( 50 );


E-Mail: Chris Nystrom
Business: http://www.shaklee.net/austin
Blog: http://conversazione.blogspot.com/
AIM: nystromchris

Also, does this tutorial code work for you?

http://gpwiki.org/index.php/C:Playing_a_WAV_Sound_File_With_SDL_mixer

If so, then you know you have a code problem, if not then it is
probably a sysem setup problem.

ChrisOn 11/1/05, Timm Murray wrote:

I have a simple program for playing wav files:


E-Mail: Chris Nystrom
Business: http://www.shaklee.net/austin
Blog: http://conversazione.blogspot.com/
AIM: nystromchris

<>

SDL_Delay( 50 );
<>
You only gives your program 50 millisecs to play the sound before you quit.
Try with a while(Mix_Playing(-1) > 0); instead of the delay and see
what happens.

I’ve replaced the SDL_Delay line with the while loop above. I’m now getting:On Tuesday 01 November 2005 01:30 pm, Rasmus Neckelmann wrote:


$ ./play_sound …/data/sound/explosion.wav
Playing file: …/data/sound/explosion.wav
Played on channel 0
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

There are a few seconds between the ‘Played on channel’ line and the segfault,
so it’s probably happening after the while loop.
-------------- 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/a24dd704/attachment.pgp

The code opens a blank window for a few seconds, closes it, then segfaults.
No sound is played.
-------------- 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/82c4afd5/attachment.pgpOn Tuesday 01 November 2005 02:30 pm, Chris Nystrom wrote:

On 11/1/05, Timm Murray <@Timm_Murray> wrote:

I have a simple program for playing wav files:

Also, does this tutorial code work for you?

http://gpwiki.org/index.php/C:Playing_a_WAV_Sound_File_With_SDL_mixer

If so, then you know you have a code problem, if not then it is
probably a sysem setup problem.

How did you compile it? On linux I used:

$ gcc SDL_PlaySound.c -o SDL_PlaySound sdl-config --cflags --libs -lSDL_mixer

It compiles fine for me. When I run it, it starts up and opens a blank
window, and plays a sound, and then exits.

If you can not get this known good code to work, then I believe you
have a setup issue.

ChrisOn 11/1/05, Timm Murray wrote:

Also, does this tutorial code work for you?
http://gpwiki.org/index.php/C:Playing_a_WAV_Sound_File_With_SDL_mixer

If so, then you know you have a code problem, if not then it is
probably a sysem setup problem.

The code opens a blank window for a few seconds, closes it, then segfaults.
No sound is played.


E-Mail: Chris Nystrom
Business: http://www.shaklee.net/austin
Blog: http://conversazione.blogspot.com/
AIM: nystromchris

Also, does this tutorial code work for you?
http://gpwiki.org/index.php/C:Playing_a_WAV_Sound_File_With_SDL_mixer

If so, then you know you have a code problem, if not then it is
probably a sysem setup problem.

The code opens a blank window for a few seconds, closes it, then
segfaults. No sound is played.

How did you compile it? On linux I used:

$ gcc SDL_PlaySound.c -o SDL_PlaySound sdl-config --cflags --libs
-lSDL_mixer

Yes, that’s how I compiled it.

It compiles fine for me. When I run it, it starts up and opens a blank
window, and plays a sound, and then exits.

If you can not get this known good code to work, then I believe you
have a setup issue.

Probably. Where should I start looking?
-------------- 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/2725a536/attachment.pgpOn Tuesday 01 November 2005 08:43 pm, Chris Nystrom wrote:

On 11/1/05, Timm Murray <@Timm_Murray> wrote:

Do regular non-SDL_mixer apps work? I assume yes.

You might try un-installing SDL_mixer and the developer RPM and
re-installing them.

ChrisOn 11/1/05, Timm Murray wrote:

If you can not get this known good code to work, then I believe you
have a setup issue.

Probably. Where should I start looking?


E-Mail: Chris Nystrom
Business: http://www.shaklee.net/austin
Blog: http://conversazione.blogspot.com/
AIM: nystromchris

If you can not get this known good code to work, then I believe you
have a setup issue.

Probably. Where should I start looking?

Do regular non-SDL_mixer apps work? I assume yes.

Yup.

You might try un-installing SDL_mixer and the developer RPM and
re-installing them.

I’m on Gentoo. I emerged SDL_mixer again, but it still segfaults.
-------------- 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/20051102/3aa97f60/attachment.pgpOn Wednesday 02 November 2005 12:35 am, Chris Nystrom wrote:

On 11/1/05, Timm Murray <@Timm_Murray> wrote:

Hello

I wonder if there exists any tutorial for installing SDL on Windows,
compiling it, etc.

Thanks!

What does your code look like now? Before, you had:

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() );

Are you sure the sound file loaded? (You don’t check if “wav == NULL”)

-bill!On Wed, Nov 02, 2005 at 11:32:14AM -0500, Timm Murray wrote:

I’m on Gentoo. I emerged SDL_mixer again, but it still segfaults.

Does the FAQ cover it?

http://www.libsdl.org/faq.php?action=listentries&category=4

-bill!On Wed, Nov 02, 2005 at 07:23:00PM +0100, Sauc Jedi wrote:

Hello

I wonder if there exists any tutorial for installing SDL on Windows,
compiling it, etc.

Something like this?

http://gpwiki.org/index.php/SDL:Tutorials:Setup

ChrisOn 11/2/05, Sauc Jedi wrote:

Hello

I wonder if there exists any tutorial for installing SDL on Windows,
compiling it, etc.


E-Mail: Chris Nystrom
Business: http://www.shaklee.net/austin
Blog: http://conversazione.blogspot.com/
AIM: nystromchris

Hello

I have seen people mention this topic before on here about how you
cannot run SDL_PollEvent() in a thread separate from the one that
created the window. I am wondering if you guys will ever change it so
you can have input separate from video?

-Tom

IIRC its a limitation of the Operating Systems SDL wants to run under.

windows i think specifically.On 11/2/05, Tom Daranchuc wrote:

Hello

I have seen people mention this topic before on here about how you
cannot run SDL_PollEvent() in a thread separate from the one that
created the window. I am wondering if you guys will ever change it so
you can have input separate from video?

-Tom


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

I’m on Gentoo. I emerged SDL_mixer again, but it still segfaults.

What does your code look like now? Before, you had:

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() );On Wednesday 02 November 2005 01:20 pm, Bill Kendrick wrote:
On Wed, Nov 02, 2005 at 11:32:14AM -0500, Timm Murray wrote:


    printf( "Playing file: %s\n", file );
    wav = Mix_LoadWAV( file );
    if(! wav) {
            printf( "Can't load wav file: %s\n", Mix_GetError() );
            exit(1);
    }
    
    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 );
    }
    while(Mix_Playing(-1) > 0);

Compiled with: gcc sdl-config --libs --cflags -lSDL_mixer -o play_sound
play_sound_mixer.c

Gives:


$ ./play_sound …/data/sound/plasma.wav
Playing file: …/data/sound/plasma.wav
Played on channel 0
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

The ‘wavplay’ program on my system plays the sound successfully.
-------------- 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/20051102/6445c831/attachment.pgp

I’m on Gentoo. I emerged SDL_mixer again, but it still segfaults.

What does your code look like now? Before, you had:

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() );


    printf( "Playing file: %s\n", file );
    wav = Mix_LoadWAV( file );
    if(! wav) {
            printf( "Can't load wav file: %s\n", Mix_GetError() );
            exit(1);
    }
    
    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 );
    }
    while(Mix_Playing(-1) > 0);

Compiled with: gcc sdl-config --libs --cflags -lSDL_mixer -o play_sound
play_sound_mixer.c

Gives:


$ ./play_sound …/data/sound/plasma.wav
Playing file: …/data/sound/plasma.wav
Played on channel 0
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

The ‘wavplay’ program on my system plays the sound successfully.
Hi,

I’m on Gentoo. Your program builds and works here. It doesn’t handle
bad/missing file paths well, but it does play. I’d recommend checking the
return value from SDL_Init(). Something like this:

ret = SDL_Init(SDL_INIT_AUDIO);
if ( 0 > ret ) {
    printf("Error initialising SDL: %s\n", SDL_GetError());
    exit(1);
}

What do you get if you do:

ldd ./play_sound
linux-gate.so.1 => (0xffffe000)
libSDL-1.2.so.0 => /usr/lib/libSDL-1.2.so.0 (0xb7f69000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb7f31000)
libSDL_mixer-1.2.so.0 => /usr/lib/libSDL_mixer-1.2.so.0 (0xb7ece000)
libc.so.6 => /lib/libc.so.6 (0xb7d9d000)
libstdc++.so.5 => //usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.5-20050130/libstdc++.so.5 (0xb7ce3000)
libm.so.6 => /lib/libm.so.6 (0xb7cbe000)
libdl.so.2 => /lib/libdl.so.2 (0xb7cb9000)
libX11.so.6 => /usr/lib/libX11.so.6 (0xb7bed000)
libXext.so.6 => /usr/lib/libXext.so.6 (0xb7bdf000)
libvga.so.1 => /usr/lib/libvga.so.1 (0xb7b71000)
libaa.so.1 => /usr/lib/libaa.so.1 (0xb7b56000)
/lib/ld-linux.so.2 (0xb7fe9000)
libvorbisfile.so.3 => /usr/lib/libvorbisfile.so.3 (0xb7b4f000)
libvorbis.so.0 => /usr/lib/libvorbis.so.0 (0xb7b26000)
libogg.so.0 => /usr/lib/libogg.so.0 (0xb7b21000)
libsmpeg-0.4.so.0 => /usr/lib/libsmpeg-0.4.so.0 (0xb7ac9000)
libgcc_s.so.1 => /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.5-20050130/libgcc_s.so.1 (0xb7ac1000)
libslang.so.1 => /usr/lib/libslang.so.1 (0xb7a4d000)

What about if you do ldd on the fullpath to libSDL_mixer? I get:

ldd /usr/lib/libSDL_mixer-1.2.so.0
linux-gate.so.1 => (0xffffe000)
libvorbisfile.so.3 => /usr/lib/libvorbisfile.so.3 (0xb7f96000)
libvorbis.so.0 => /usr/lib/libvorbis.so.0 (0xb7f6d000)
libogg.so.0 => /usr/lib/libogg.so.0 (0xb7f68000)
libsmpeg-0.4.so.0 => /usr/lib/libsmpeg-0.4.so.0 (0xb7f10000)
libSDL-1.2.so.0 => /usr/lib/libSDL-1.2.so.0 (0xb7e90000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb7e59000)
libc.so.6 => /lib/libc.so.6 (0xb7d28000)
libm.so.6 => /lib/libm.so.6 (0xb7d02000)
libstdc++.so.5 => /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.5-20050130/libstdc++.so.5 (0xb7c48000)
libdl.so.2 => /lib/libdl.so.2 (0xb7c44000)
libX11.so.6 => /usr/lib/libX11.so.6 (0xb7b78000)
libXext.so.6 => /usr/lib/libXext.so.6 (0xb7b6a000)
libvga.so.1 => /usr/lib/libvga.so.1 (0xb7afb000)
libaa.so.1 => /usr/lib/libaa.so.1 (0xb7ae0000)
/lib/ld-linux.so.2 (0x80000000)
libgcc_s.so.1 => /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.5-20050130/libgcc_s.so.1 (0xb7ad8000)
libslang.so.1 => /usr/lib/libslang.so.1 (0xb7a64000)

I had a problem with SDL_Mixer and using an external libmikmod (the default on
Gentoo). It kept trying to create files (‘music.raw’?) on the hardrive, and if
it couldn’t then SDL audio initialisation failed. I manually rebuilt SDL_mixer
whilst disabling use of an external libmikmod.

Hope that helps,

cheers,
John.On Wed, Nov 02, 2005 at 05:38:32PM -0500, Timm Murray wrote:

On Wednesday 02 November 2005 01:20 pm, Bill Kendrick wrote:

On Wed, Nov 02, 2005 at 11:32:14AM -0500, Timm Murray wrote:


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