SDL回拨重复不停止?
我们已经使用以下设置成功地在SDL Audio中调用了我们的回调函数。
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;
}
它继续打印:8343在kb或mb中代表什么大小? 其次我们不希望它继续重复,我们现在需要采取一些样本并与其他剪辑混合。 在我的主要我有这个代码。
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/5795.html
上一篇: SDL Callback is repeating non stop?
下一篇: c++