19 if(SDL_Init(SDL_INIT_AUDIO) == -1)
24 extern void mixaudio(
void *unused, Uint8 *stream,
int len);
29 fmt.format = AUDIO_S16;
35 if ( SDL_OpenAudio(&fmt, NULL) < 0 ) {
36 fprintf(stderr,
"Unable to open audio: %s\n", SDL_GetError());
42 int Audio::LoadAudio(std::string name,
string location,
bool play_on_start,
int play_count)
64 if ( index == SOUND_CAP )
68 if ( SDL_LoadWAV(location.c_str(), &wave, &data, &dlen) == NULL ) {
69 fprintf(stderr,
"Couldn't load %s: %s\n", location.c_str(), SDL_GetError());
72 SDL_BuildAudioCVT(&cvt, wave.format, wave.channels, wave.freq,
75 cvt.buf = (Uint8*) malloc(dlen*cvt.len_mult);
76 memcpy(cvt.buf, data, dlen);
78 SDL_ConvertAudio(&cvt);
81 if (
sounds[index].data ) {
99 if (
sounds[index].data ) {
126 static double angle = 0.0 ;
128 fprintf( stderr,
"Filling %d\n", len ) ;
130 *stream++ = 255*cos(angle) ;
131 angle += 3.14159/100 ;
132 if( angle > 2.0*3.14159 ) {
133 angle -= 2.0*3.14159 ;
145 SDL_AudioSpec *desired, *obtained;
146 SDL_AudioSpec *hardware_spec;
148 desired = (SDL_AudioSpec*)malloc(
sizeof(SDL_AudioSpec));
149 obtained = (SDL_AudioSpec*)malloc(
sizeof(SDL_AudioSpec));
153 desired->format=AUDIO_S16LSB;
155 desired->samples=8192;
157 desired->userdata=NULL;
159 SDL_Init(SDL_INIT_AUDIO);
165 void mixaudio(
void *unused, Uint8 *stream,
int len)
172 if ( amount > len ) {
175 SDL_MixAudio(stream, &
sounds[i].data[
sounds[i].dpos], amount, SDL_MIX_MAXVOLUME);