c - SDL Callback is repeating non stop? -
we have called our callback function in sdl audio following setup.
struct { sdl_audiospec spec; /* sdl audio spec structure */ uint8 *sound; /* pointer 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) { // here } sdl_memcpy(process_buf, waveptr, waveleft); /* processing here, e.g. */ /* processing audio samples in process_buf[*] */ // play processed audio samples sdl_memcpy(stream, process_buf, waveleft); stream += waveleft; len -= waveleft; // ready repeat play 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 size represent in kb or mb ? secondly not want keep repeating , need take sample , mix other clips. in main have codes.
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 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);
Comments
Post a Comment