0

我们已经通过以下设置成功地在 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: %s\n", "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: %s\n", SDL_GetError());
                SDL_FreeWAV(wave.sound);
                //quit(2);
     }*/
     // start playing
     SDL_PauseAudio(0);
4

0 回答 0