quote:
Original post by Scet
and it doesn''t even come with sound you need to download an extra mixer library.
YOUR BRAIN IS RUNNING WHEN YOU WRITE ???
DO YOU KNOW WHAT THE HELL YOU ARE TALKING ABOUT ???
I THINK YOU HAVE NEVER READ CHAP 10 OF SDL
Chapter 10. Audio
Table of Contents
SDL_AudioSpec — Audio Specification Structure
SDL_OpenAudio — Opens the audio device with the desired parameters.
SDL_PauseAudio — Pauses and unpauses the audio callback processing
SDL_GetAudioStatus — Get the current audio state
SDL_LoadWAV — Load a WAVE file
SDL_FreeWAV — Frees previously opened WAV data
SDL_AudioCVT — Audio Conversion Structure
SDL_BuildAudioCVT — Initializes a SDL_AudioCVT structure for conversion
SDL_ConvertAudio — Convert audio data to a desired audio format.
SDL_MixAudio — Mix audio data
SDL_LockAudio — Lock out the callback function
SDL_UnlockAudio — Unlock the callback function
SDL_CloseAudio — Shuts down audio processing and closes the audio device.
Sound on the computer is translated from waves that you hear into a series of values, or samples, each representing the amplitude of the wave. When these samples are sent in a stream to a sound card, an approximation of the original wave can be recreated. The more bits used to represent the amplitude, and the greater frequency these samples are gathered, the closer the approximated sound is to the original, and the better the quality of sound.
This library supports both 8 and 16 bit signed and unsigned sound samples, at frequencies ranging from 11025 Hz to 44100 Hz, depending on the underlying hardware. If the hardware doesn''t support the desired audio format or frequency, it can be emulated if desired (See SDL_OpenAudio())
A commonly supported audio format is 16 bits per sample at 22050 Hz.
/***************************************/
the extra library you mean is SDL_MIXER(always sdl)
NOW here ALL ( i say ALL ) the code you need to play background music with SDL_MIXER
it work with files:
-wav
-mod
-it
-s3m
-XM
and others that i dont imagine
void musica ( Mix_Music *music,char *song )
{
int audio_rate=22050;
Uint16 audio_format=MIX_DEFAULT_FORMAT;
int audio_channels=1;
int audio_buffers=8192;
Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers);
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
Mix_SetMusicCMD(getenv("MUSIC_CMD"));
music = Mix_LoadMUS(song);
Mix_VolumeMusic(MIX_MAX_VOLUME );
Mix_PlayMusic(music, -1);
}
void stop_musica ( Mix_Music *music )
{
Mix_HaltMusic();
Mix_FreeMusic(music);
music = NULL;
}