2 Cantaveria - action adventure platform game
3 Copyright (C) 2009 2010 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
34 void audio_callback(void *userdata
, Uint8
*stream
, int bytes
){
36 Sint16
* out
= (Sint16
*)stream
;
37 int buflen
= bytes
/ 2; /* Sint16 = 2 bytes */
38 int samples
= buflen
/ 2; /* 2 channels */
40 synth_generate(lout
, rout
, samples
);
42 for(i
=0, j
=0; i
<samples
; i
++){
43 out
[j
] = (Sint16
)(lout
[i
]*32767); j
++;
44 out
[j
] = (Sint16
)(rout
[i
]*32767); j
++;
54 want
.freq
= SAMPLE_RATE
;
55 want
.format
= AUDIO_S16
;
57 want
.samples
= BUFFER_SIZE
;
58 want
.callback
= audio_callback
;
61 if(SDL_OpenAudio(&want
, &got
)<0){
62 report_error("sdl: cannot open audio (%s)\n", SDL_GetError());
67 printf(" sample rate = %d\n", got
.freq
);
68 printf(" channels = %d\n", got
.channels
);
69 printf(" samples = %d\n", got
.samples
);
70 printf(" format = %d\n", got
.format
);
72 if(got
.format
!= AUDIO_S16
){
73 printf(" WARNING: audio format not AUDIO_S16 :(\n");
77 lout
= xmalloc(got
.samples
*sizeof(float));
78 rout
= xmalloc(got
.samples
*sizeof(float));
80 printf(" sound on\n");