Hello,
i can’t solve a following (newbie) problem. I have callback function for
SDL_AudioSpec, and SDL_OpenAudio is inicializated with some userdata value.
Then i need to change the userdata with another value, but in callback still remain
old value. How i can to reinicialize it? Pleas see the source below for more details.
Many thanks you for help!
BruXy
/*********************************************************************/
#include “SDL.h”
#include <stdio.h>
#include <math.h>
#define SAMPLE_RATE 8000.0
void my_play(void* userdata, Uint8 *stream, int len) {
static int gpos = 0;
int pos = 0;
double freq = *(double *)userdata;
printf(“Freq: %f\n”, freq);
while(len > 0)
{
*(stream + pos) = (127 * sin( gpos * 2.0 * M_PI * freq / SAMPLE_RATE ) + 128 );
len -= 1;
pos += 1;
gpos++;
}
}
int main(int argc, char *argv[]) {
SDL_AudioSpec audioSpec;
int i;
double freq1 = 440.0;
double freq2 = 800.0;
SDL_Init(SDL_INIT_AUDIO);
audioSpec.freq = SAMPLE_RATE;
audioSpec.format = AUDIO_U8;
audioSpec.channels = 1;
audioSpec.samples = 1024;
audioSpec.callback = my_play;
audioSpec.userdata = &freq1;
SDL_OpenAudio(&audioSpec, NULL);
SDL_PauseAudio(0);
puts(“1.”);
SDL_Delay(1000);
/* SDL_CloseAudio(); */
SDL_LockAudio();
audioSpec.userdata = &freq2;
SDL_UnlockAudio();
/* SDL_PauseAudio(0);*/
puts(“2.”);
/* SDL_OpenAudio(&audioSpec, NULL); */
SDL_Delay(1000);
SDL_CloseAudio();
SDL_Quit();
}–
PGPKey: http://bruxy.regnet.cz/bruxy-gpg.key
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020719/00cd9e0d/attachment.pgp