c - SDL audio call back not working? -


i have following snippet of codes. need audio samples , play them accordingly.

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; 

here call function.

void fillerup(void *unused, uint8 *stream, int len) { uint8 *waveptr; int waveleft=0; printf("in fillerup"); 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);       } } 

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; 

i have commented codes whenever ope gives me error couldnt open audio. top loadwav gives me not error , check wav file exist.

/*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); 

what problem not callback ?

if never open actual audio output device sdl_openaudio(), there isn't trying play audio, of course there's nothing calls buffer-filling callback.

if opening audio device fails, that's problem need solve. sdl_loadwav() calls doesn't open device, fills in spec can hand sdl_openaudio().


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -