Created
December 18, 2010 22:05
-
-
Save AZiCoDec/746919 to your computer and use it in GitHub Desktop.
Minimal code for callback function on SDL audio
This file contains 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
#include <SDL/SDL.h> | |
#include <stdio.h> | |
using namespace std; | |
void func_callback(void *unused, Uint8 *stream, int len) { | |
for (int i=0;i<len;i++) { | |
stream[i] = i; | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
if( SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO ) <0 ) { | |
SDL_WM_SetCaption( "Something busy..", NULL ); | |
return 1; | |
} | |
SDL_AudioSpec as; | |
as.freq = 22000; | |
as.format = AUDIO_U8; | |
as.samples = 1024; | |
as.callback=func_callback; | |
as.userdata=NULL; | |
as.channels = 1; | |
if ( SDL_OpenAudio(&as, NULL) < 0 ) { | |
SDL_WM_SetCaption( "Unable to open audio..", NULL ); | |
return 1; | |
} | |
SDL_Surface *screen = SDL_SetVideoMode(200,200, 16, SDL_SWSURFACE); | |
SDL_PauseAudio(0); | |
SDL_Delay(3000); | |
fclose(file); | |
SDL_Quit(); | |
return 0; | |
} |
hello, do you know how to change the parameters of the callback function?
I want to change the parameter "len" smaller.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anyone is maintaining this page, perhaps it should be updated to use SDL2 ? also, several of the functions called seems to be outdated.. or am I missing something? :) Cheers