SDL Callback is repeating non stop?
We have successfully called our callback function in SDL Audio with the following setup.
struct {
SDL_AudioSpec spec; /* SDL Audio Spec Structure */
Uint8 *sound; /* Pointer to wave data */
Uint32 soundlen; /* Length of wave data */
int soundpos; /* Current play position */
} wave;
void fillerup(void *unused, Uint8 *stream, int len)
{
Uint8 *waveptr;
int waveleft=0;
printf("in fillerup:%d",wave.soundlen);
waveptr = wave.sound + wave.soundpos;
waveleft = wave.soundlen - wave.soundpos;
while ( waveleft <= len ) {
/* Process samples */
Uint8 *process_buf = (Uint8 *)malloc(waveleft * sizeof(Uint8));
if(process_buf == 0) {
// do something here
}
SDL_memcpy(process_buf, waveptr, waveleft);
/* do processing here, e.g. */
/* processing the audio samples in process_buf[*] */
// play the processed audio samples
SDL_memcpy(stream, process_buf, waveleft);
stream += waveleft;
len -= waveleft;
// ready to repeat play the audio
waveptr = wave.sound;
waveleft = wave.soundlen;
wave.soundpos = 0;
free(process_buf);
}
Uint8 process_buf[len];
SDL_memcpy(process_buf, waveptr, len);
SDL_memcpy(stream, process_buf, len);
wave.soundpos += len;
}
It keep printing in fillerup:8343 what size does it represent in kb or mb ? Secondly we do not want it to keep repeating and we need to now take some sample and mix with other clips. In my main I have this codes.
if ( SDL_LoadWAV("file1.wav",&wave.spec, &wave.sound, &wave.soundlen) == NULL ) {
fprintf(stderr, "Couldn't load %s: %sn", "file1.wav", SDL_GetError());
//quit(1);
}
// set up the callback function
wave.spec.callback = fillerup;
if ( SDL_OpenAudio(&wave.spec, NULL) < 0 ) {
fprintf(stderr, "Couldn't open audio: %sn", SDL_GetError());
SDL_FreeWAV(wave.sound);
//quit(2);
}*/
// start playing
SDL_PauseAudio(0);
链接地址: http://www.djcxy.com/p/5796.html
上一篇: 将时间顺序写入Android AudioTrack
下一篇: SDL回拨重复不停止?