ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/SID_SDL.h
Revision: 1.1
Committed: 2010-04-22T15:07:43Z (13 years, 11 months ago) by cebix
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
sound output via SDL

File Contents

# Content
1 /*
2 * SID_SDL.h - 6581 emulation, SDL specific stuff
3 *
4 * Frodo Copyright (C) Christian Bauer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <SDL/SDL_audio.h>
22
23
24 /*
25 * Initialization
26 */
27
28 void DigitalRenderer::init_sound(void)
29 {
30 SDL_AudioSpec spec;
31 spec.freq = SAMPLE_FREQ;
32 spec.format = AUDIO_S16SYS;
33 spec.channels = 1;
34 spec.samples = 512;
35 spec.callback = buffer_proc;
36 spec.userdata = this;
37
38 if (SDL_OpenAudio(&spec, NULL) < 0) {
39 fprintf(stderr, "WARNING: Cannot open audio: %s\n", SDL_GetError());
40 return;
41 }
42
43 SDL_PauseAudio(0);
44 ready = true;
45 }
46
47
48 /*
49 * Destructor
50 */
51
52 DigitalRenderer::~DigitalRenderer()
53 {
54 SDL_CloseAudio();
55 }
56
57
58 /*
59 * Sample volume (for sampled voice)
60 */
61
62 void DigitalRenderer::EmulateLine(void)
63 {
64 sample_buf[sample_in_ptr] = volume;
65 sample_in_ptr = (sample_in_ptr + 1) % SAMPLE_BUF_SIZE;
66 }
67
68
69 /*
70 * Pause sound output
71 */
72
73 void DigitalRenderer::Pause(void)
74 {
75 SDL_PauseAudio(1);
76 }
77
78
79 /*
80 * Resume sound output
81 */
82
83 void DigitalRenderer::Resume(void)
84 {
85 SDL_PauseAudio(0);
86 }
87
88
89 /*
90 * Callback function
91 */
92
93 void DigitalRenderer::buffer_proc(void *cookie, uint8 *buffer, int size)
94 {
95 DigitalRenderer * renderer = (DigitalRenderer *) cookie;
96 renderer->calc_buffer((int16 *) buffer, size);
97 }