1 |
/* |
2 |
* SID_Acorn.h - 6581 emulation, RISC OS specific stuff |
3 |
* |
4 |
* Frodo (C) 1994-1997,2002 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 "C64.h" |
22 |
|
23 |
|
24 |
void DigitalRenderer::init_sound(void) |
25 |
{ |
26 |
_kernel_oserror *err; |
27 |
|
28 |
ready = false; sound_buffer = NULL; |
29 |
if ((DigitalRenderer_ReadState() & DRState_Active) != 0) |
30 |
{ |
31 |
_kernel_oserror dra; |
32 |
|
33 |
dra.errnum = 0; sprintf(dra.errmess,"Can't claim sound system -- already active!"); |
34 |
Wimp_ReportError(&dra,1,TASKNAME); return; |
35 |
} |
36 |
// Try starting up the renderer |
37 |
sndbufsize = 2*224; linecnt = 0; |
38 |
if ((err = DigitalRenderer_Activate(1,sndbufsize,1000000/SAMPLE_FREQ)) != NULL) |
39 |
{ |
40 |
Wimp_ReportError(err,1,TASKNAME); return; |
41 |
} |
42 |
sound_buffer = new uint8[sndbufsize]; |
43 |
ready = true; |
44 |
} |
45 |
|
46 |
|
47 |
|
48 |
|
49 |
DigitalRenderer::~DigitalRenderer() |
50 |
{ |
51 |
if (ready) |
52 |
{ |
53 |
_kernel_oserror *err; |
54 |
|
55 |
delete sound_buffer; |
56 |
if ((err = DigitalRenderer_Deactivate()) != NULL) |
57 |
{ |
58 |
Wimp_ReportError(err,1,TASKNAME); |
59 |
} |
60 |
} |
61 |
} |
62 |
|
63 |
|
64 |
|
65 |
|
66 |
void DigitalRenderer::EmulateLine(void) |
67 |
{ |
68 |
if (ready) |
69 |
{ |
70 |
sample_buf[sample_in_ptr++] = volume; |
71 |
// faster than modulo; usually there shouldn't be a loop (while)... |
72 |
while (sample_in_ptr >= SAMPLE_BUF_SIZE) {sample_in_ptr -= SAMPLE_BUF_SIZE;} |
73 |
|
74 |
// A similar approach to the HP variant: check every <number> of lines if |
75 |
// new sample needed. |
76 |
if (--linecnt < 0) |
77 |
{ |
78 |
int status; |
79 |
|
80 |
linecnt = the_c64->PollSoundAfter; |
81 |
if ((status = DigitalRenderer_ReadState()) > 0) |
82 |
{ |
83 |
if ((status & DRState_NeedData) != 0) |
84 |
{ |
85 |
calc_buffer(sound_buffer, sndbufsize); |
86 |
DigitalRenderer_NewSample(sound_buffer); |
87 |
} |
88 |
} |
89 |
} |
90 |
} |
91 |
} |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
void DigitalRenderer::Pause(void) |
97 |
{ |
98 |
if (ready) {DigitalRenderer_Pause();} |
99 |
} |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
void DigitalRenderer::Resume(void) |
105 |
{ |
106 |
if (ready) {DigitalRenderer_Resume();} |
107 |
} |