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, 321024);
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;
}