SDL_mixer plays bad quality, linux play is good quality

I am using a small SDL program to play a wav file using SDL_mixer library on a
Linux PC. What I am seeing is SDL program is playing a very bad quality sound (I
have tried all combinations of frequency, format etc).

But when I just type

play abc.wav,

I get excellent quality sound!!!

That tells me linux play command is using a different sound driver then
SDL_mixer, is there a way to tweek the SDL_mixer dirver?

Let me know if you know any way of tackling this problem.

Regards,
Laeeq_M_Khan at hotmail.com

Laeeq Khan wrote:

I am using a small SDL program to play a wav file using SDL_mixer library on a
Linux PC. What I am seeing is SDL program is playing a very bad quality sound (I
have tried all combinations of frequency, format etc).

But when I just type

play abc.wav,

I get excellent quality sound!!!

That tells me linux play command is using a different sound driver then
SDL_mixer, is there a way to tweek the SDL_mixer dirver?

Let me know if you know any way of tackling this problem.

Regards,
Laeeq_M_Khan at hotmail.com

Try increasing the buffer size, that should fix your problem. Or try the
example programs that are included in SDL_mixer.

Laeeq Khan wrote:

I am using a small SDL program to play a wav file using SDL_mixer library on a
Linux PC. What I am seeing is SDL program is playing a very bad quality sound (I
have tried all combinations of frequency, format etc).

But when I just type

play abc.wav,

I get excellent quality sound!!!

That tells me linux play command is using a different sound driver then
SDL_mixer, is there a way to tweek the SDL_mixer dirver?

Let me know if you know any way of tackling this problem.

What’s your audio hardware and what SDL version are you using ? If
that’s some AC97 card and your version of SDL is 1.2.7 or older, you
might want to set the SDL_DSP_NOSELECT environment variable. However, it
has been removed in later SDL versions so there is no solution if you
run 1.2.8 or higher (short of patching SDL of course).

Stephane

Simon Parzer <s_parz yahoo.de> writes:

Laeeq Khan wrote:

I am using a small SDL program to play a wav file using SDL_mixer library
on a

Linux PC. What I am seeing is SDL program is playing a very bad
quality sound (I

have tried all combinations of frequency, format etc).

But when I just type

play abc.wav,

I get excellent quality sound!!!

That tells me linux play command is using a different sound driver then
SDL_mixer, is there a way to tweek the SDL_mixer dirver?

Let me know if you know any way of tackling this problem.

Regards,
Laeeq_M_Khan hotmail.com

Try increasing the buffer size, that should fix your problem. Or try the
example programs that are included in SDL_mixer.

I have experimented with buffer size in Mix_OpenAudio() call. In fact after a
certain size the quality begins to deteriorate. Where to get example
programs, I
am using test programs from the book “Focus on SDL”, they look very
straight
forward.

#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <stdlib.h>
#include <unistd.h>

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
SDL_Surface *screen = NULL;
Mix_Chunk *aChunk;

int rslt;

void audioCB(int x)
{
printf(“Inside audioCB()…\n”);
}

int main()
{
if(SDL_Init(SDL_INIT_VIDEO) == -1)
{
fprintf(stderr, “%s:%u SDL initialization failure\n”, FILE, LINE);
exit(EXIT_FAILURE);
}
else
{
fprintf(stderr, “%s:%u SDL initialized properly\n”, FILE, LINE);
atexit(SDL_Quit);
}

screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
if(screen == NULL)
{
fprintf(stderr, “%s:%u Unable to set video mode\n”, FILE, LINE);
exit(EXIT_FAILURE);
}

// rslt = Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 1, 321024);
x_OpenAudiorslt = Mix_OpenAudio(11025, AUDIO_S16, 1, 32
1024);
if(rslt == -1)
{
fprintf(stderr, “%s:%u Mix_OpenAudio() failure\n”, FILE, LINE);
exit(EXIT_FAILURE);
}
// aChunk = Mix_LoadWAV("/home/laeeq/wav_files/Intro1_base_sound.wav");
aChunk = Mix_LoadWAV(“song.wav”);
if(aChunk == NULL)
{
fprintf(stderr, “%s:%u Mix_LoadWAV() failure\n”, FILE, LINE);
exit(EXIT_FAILURE);
}

Mix_AllocateChannels(1);

// Mix_PlayChannel(-1, aChunk, 0); // Play once on ANY free channel.
Mix_PlayChannel(0, aChunk, 0);
// Mix_ChannelFinished(audioCB);

for( ; ; )
{
fprintf(stderr, “Monitoring …\n”);
rslt = Mix_Playing(0);
if(rslt == 1)
printf("++++++++ P L A Y I N G ++++++++++\n");
else if(rslt == 0)
{
printf("-------- S T O P P E D ----------\n");
break;
}
else
printf(">>>>>>>>>> ERROR \n");

sleep(2);

}

sleep(1);

// fprintf(stderr, “Halting …\n”);
// Mix_HaltChannel(-1); // Halt all channels.

fprintf(stderr, “Exiting …\n”);
Mix_AllocateChannels(0); // Free channels.

Mix_FreeChunk(aChunk);
Mix_CloseAudio();
fprintf(stderr, “… Finally Exiting …\n”);

return 0;
}

What’s your audio hardware and what SDL version are you using ? If
that’s some AC97 card and your version of SDL is 1.2.7 or older, you
might want to set the SDL_DSP_NOSELECT environment variable. However, it
has been removed in later SDL versions so there is no solution if you
run 1.2.8 or higher (short of patching SDL of course).

Stephane

That’s right, my SDL version is 1.2.5-4, and according to Linux hardware
browser, my sound Device is "82801DB (ICH4) AC’97 Audio controller. And driver
is snd-intel8x0.

I set the variable you mentioned by

export SDL_DSP_NOSELECT=1
When I played the program again, I still have bad quality sound with SDL.

The same program works without problem on a faster processor, with same sound
card & driver. My setup where I am having problem has 2.8 GHz Intel processor
with 400MHz front side bus.

I am surprised that Linux “play” command plays the sound flawlessly, it is
only SDL_mixer which is problematic.

=Laeeq