hello
When i play a wave file with sdl_mixer, I hear is a staticy noise. but when
i used the sdl directly, it sound well.
i test the player with Ubuntu and fedora 8, both sound badly.
Thank you in advance.
my player source code as follows, it use sdl_mixer library
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
static int play_over = 0;
void channel_finished(int channel)
{
play_over = 1;
}
int main(int argc, char* argv[])
{
SDL_Surface* screen = NULL;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
struct
{
SDL_AudioSpec spec;
Uint8 *sound; /* Pointer to wave data */
Uint32 soundlen; /* Length of wave data */
int soundpos; /* Current play position */
}wave;
SDL_LoadWAV("sample.wav", &wave.spec, &wave.sound, &wave.soundlen);
SDL_FreeWAV(wave.sound);
if(Mix_OpenAudio(wave.spec.freq, wave.spec.format, wave.spec.channels,
wave.spec.samples))
{
printf(“Unable to open audio!\n”);
exit(1);
}
int freq, format, channels;
Mix_QuerySpec(&freq, (unsigned short int*)&format, &channels);
fprintf(stderr, "<freq: %d vs %d>|<format: %d vs %d>|<channels: %d vs
%d>",
wave.spec.freq, freq, wave.spec.format, format,
wave.spec.channels, channels);
Mix_AllocateChannels(1);
Mix_ChannelFinished(channel_finished);
/* Pre-load sound effects */
Mix_Chunk* mixChunk = Mix_LoadWAV("sample.wav");
mixChunk->volume = 64;
screen = SDL_SetVideoMode(320, 240, 0, 0);
char name[32];
printf("Using audio driver: %s\n", SDL_AudioDriverName(name, 32));
Mix_PlayChannel(0, mixChunk, 2); // you can change 2 to any times
while(play_over == 0)
{
usleep(20 * 1000);
}
Mix_FreeChunk(mixChunk);
Mix_CloseAudio();
SDL_Quit();
return 0;
}
gcc -g -o sMixer sMixer.c -lSDL -lSDL_mixer