Created
March 26, 2015 05:41
-
-
Save jonbro/a2cff8aa1238af31bec8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void fill_audio(void *udata, Uint8 *stream, int len) | |
| { | |
| int fLen = len/sizeof(float); | |
| /* Mix as much data as possible */ | |
| // copy the output to the stream | |
| for(int i=0;i<fLen;i+=2){ | |
| // ======================= | |
| // | |
| // my c code goes here | |
| // ======================= | |
| ((float*)stream)[i] = 0; | |
| ((float*)stream)[i+1] = 0; | |
| } | |
| } | |
| int main(int argc, char **argv){ | |
| SDL_AudioSpec wanted; | |
| /* Set the audio format */ | |
| wanted.freq = 44100; | |
| wanted.format = AUDIO_F32; | |
| wanted.channels = 2; /* 1 = mono, 2 = stereo */ | |
| wanted.samples = 2048; /* Good low-latency value for callback */ | |
| wanted.callback = &fill_audio; | |
| wanted.userdata = NULL; | |
| output = new float[2048*2]; | |
| /* Open the audio device, forcing the desired format */ | |
| if ( SDL_OpenAudio(&wanted, NULL) < 0 ) { | |
| fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); | |
| return(-1); | |
| } | |
| SDL_PauseAudio(0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment