9 #define deg2rad(a) (((a)/180)*PI)
12 SDL_AudioSpec
*desired
, *obtained
;
13 SDL_AudioSpec
*hardware_spec
;
16 void my_audio_callback(void *userdata
, Uint8
*stream
, int len
) {
17 int sampl_freq
= desired
->freq
;
20 double sine_freq
= 50;
21 static double i
,j
; // = 0;
23 short int *u
; u
= (short int *)stream
;
24 //for(;len>0;len--) *(u++) = random();
25 while( (void *)u
<(void *)(stream
+len
) ) {
28 i
+= (2*PI
*sine_freq
)/sampl_freq
30 // *(u++) = sin(deg2rad(j+=8))*1280000;
39 int main(int argc
, char *argv
[]) {
41 /* Allocate a desired SDL_AudioSpec */
42 desired
=(SDL_AudioSpec
*)malloc(sizeof(SDL_AudioSpec
));
44 /* Allocate space for the obtained SDL_AudioSpec */
45 obtained
=(SDL_AudioSpec
*)malloc(sizeof(SDL_AudioSpec
));
47 /* 22050Hz - FM Radio quality */
51 /* 16-bit signed audio */
52 desired
->format
=AUDIO_S16LSB
;
53 //desired->format=AUDIO_S8;
55 desired
->channels
=2; //0,1,2 = autodetect,mono,stereo
57 /* Large audio buffer reduces risk of dropouts but increases response time */
58 desired
->samples
=65530;
60 /* Our callback function */
61 desired
->callback
=my_audio_callback
;
63 desired
->userdata
=NULL
;
64 desired
->userdata
=&desired
->freq
;
66 /* Open the audio device */
67 if ( SDL_OpenAudio(desired
, obtained
) < 0 ){
68 fprintf(stderr
, "Couldn't open audio: %s", SDL_GetError());
71 /* desired spec is no longer needed */
73 hardware_spec
=obtained
;
75 /* Prepare callback for playing */
This page took 1.694628 seconds and 4 git commands to generate.