a9ed36945b8410fe590e5f842913772f2a391e8a
1 // g++ -std=c99 -lm $(sdl-config --cflags --libs) synth.cpp -o synth
7 #include <SDL/SDL_audio.h>
18 //Do all the init stuff
21 if (SDL_Init (SDL_INIT_VIDEO
|SDL_INIT_AUDIO
) < 0)
24 screen
= SDL_SetVideoMode (640, 480, 16, SDL_HWSURFACE
);
29 //Creates the sine wave. To supress ripple, the wave runs continuously by using an incemental counter
30 void Callback (void *userdata
, Uint8
*stream
, int len
)
40 for (int z
= 0; z
< 512 ; z
++)
43 sound_buffer
[z
] = (Uint8
) A
*sin(F
*(double)counter
);
46 //Do the sound loop...
47 if (sound_pos
+ len
> sound_len
)
52 waveptr
= sound_buffer
+ sound_pos
;
53 SDL_MixAudio(stream
, waveptr
, len
, SDL_MIX_MAXVOLUME
);
55 //stream = waveptr; //Replacing the mixer gives nothing but silence...!?!
62 sound_buffer
= new Uint8
[512];
65 spec
.format
= AUDIO_S16SYS
;
73 spec
.callback
= Callback
;
74 if (SDL_OpenAudio (&spec
, NULL
) < 0)
76 printf ("Kann audio nicht öffnen: %s\n", SDL_GetError ());
82 int main(int argc
, char* argv
[])
This page took 0.527509 seconds and 5 git commands to generate.