1 |
|
/* |
2 |
|
* SID_linux.h - 6581 emulation, Linux specific stuff |
3 |
|
* |
4 |
< |
* Frodo (C) 1994-1997,2002-2004 Christian Bauer |
4 |
> |
* Frodo (C) 1994-1997,2002-2005 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 |
44 |
|
|
45 |
|
void DigitalRenderer::init_sound(void) |
46 |
|
{ |
47 |
< |
int tmp; |
48 |
< |
unsigned long format; |
47 |
> |
int arg; |
48 |
> |
unsigned long format; |
49 |
|
|
50 |
< |
ready = false; |
51 |
< |
devfd = open("/dev/dsp", O_WRONLY); |
52 |
< |
if (devfd < 0) |
53 |
< |
return; |
54 |
< |
|
55 |
< |
ioctl(devfd, SNDCTL_DSP_GETFMTS, &format); |
56 |
< |
if (!(format & AFMT_S16_LE)) |
57 |
< |
return; |
58 |
< |
format = AFMT_S16_LE; |
59 |
< |
ioctl(devfd, SNDCTL_DSP_SETFMT, &format); |
60 |
< |
|
61 |
< |
/* |
62 |
< |
* Buffer size: 2^9 == 512 bytes. Note that too large buffers will not work |
63 |
< |
* very well: The speed of the C64 is slowed down to an average speed of |
64 |
< |
* 100% by the blocking write() call in EmulateLine(). If you use a buffer |
65 |
< |
* of, say 4096 bytes, that will happen only about every 4 frames, which |
66 |
< |
* means that the emulation runs much faster in some frames, and much |
67 |
< |
* slower in others. |
68 |
< |
* On really fast machines, it might make sense to use an even smaller |
69 |
< |
* buffer size. |
70 |
< |
*/ |
71 |
< |
tmp = 0x00100009; |
72 |
< |
ioctl(devfd, SNDCTL_DSP_SETFRAGMENT, &tmp); |
73 |
< |
tmp = 0; |
74 |
< |
ioctl(devfd, SNDCTL_DSP_STEREO, &tmp); |
75 |
< |
tmp = 44100; |
76 |
< |
ioctl(devfd, SNDCTL_DSP_SPEED, &tmp); |
77 |
< |
ioctl(devfd, SOUND_PCM_READ_RATE, &tmp); |
78 |
< |
if (tmp < 43000 || tmp > 45000) |
79 |
< |
return; |
80 |
< |
|
81 |
< |
ioctl(devfd, SNDCTL_DSP_GETBLKSIZE, &sndbufsize); |
82 |
< |
sound_buffer = new int16[sndbufsize]; |
83 |
< |
ready = true; |
50 |
> |
ready = false; |
51 |
> |
devfd = open("/dev/dsp", O_WRONLY); |
52 |
> |
if (devfd < 0) |
53 |
> |
return; |
54 |
> |
|
55 |
> |
ioctl(devfd, SNDCTL_DSP_GETFMTS, &format); |
56 |
> |
if (!(format & AFMT_S16_LE)) |
57 |
> |
return; |
58 |
> |
format = AFMT_S16_LE; |
59 |
> |
ioctl(devfd, SNDCTL_DSP_SETFMT, &format); |
60 |
> |
|
61 |
> |
// Buffer size: 2^9 == 512 bytes. Note that too large buffers will not work |
62 |
> |
// very well: The speed of the C64 is slowed down to an average speed of |
63 |
> |
// 100% by the blocking write() call in EmulateLine(). If you use a buffer |
64 |
> |
// of, say 4096 bytes, that will happen only about every 4 frames, which |
65 |
> |
// means that the emulation runs much faster in some frames, and much |
66 |
> |
// slower in others. |
67 |
> |
// On really fast machines, it might make sense to use an even smaller |
68 |
> |
// buffer size. |
69 |
> |
arg = 0x00100009; |
70 |
> |
ioctl(devfd, SNDCTL_DSP_SETFRAGMENT, &arg); |
71 |
> |
arg = 0; |
72 |
> |
ioctl(devfd, SNDCTL_DSP_STEREO, &arg); |
73 |
> |
arg = 44100; |
74 |
> |
ioctl(devfd, SNDCTL_DSP_SPEED, &arg); |
75 |
> |
ioctl(devfd, SOUND_PCM_READ_RATE, &arg); |
76 |
> |
if (arg < 43000 || arg > 45000) |
77 |
> |
return; |
78 |
> |
|
79 |
> |
ioctl(devfd, SNDCTL_DSP_GETBLKSIZE, &sndbufsize); |
80 |
> |
sound_buffer = new int16[sndbufsize]; |
81 |
> |
ready = true; |
82 |
|
} |
83 |
|
|
84 |
|
|
88 |
|
|
89 |
|
DigitalRenderer::~DigitalRenderer() |
90 |
|
{ |
91 |
< |
if (devfd >= 0) |
92 |
< |
close(devfd); |
91 |
> |
if (devfd >= 0) |
92 |
> |
close(devfd); |
93 |
|
} |
94 |
|
|
95 |
|
|
117 |
|
|
118 |
|
void DigitalRenderer::EmulateLine(void) |
119 |
|
{ |
120 |
< |
static int divisor = 0; |
121 |
< |
static int to_output = 0; |
122 |
< |
static int buffer_pos = 0; |
120 |
> |
static int divisor = 0; |
121 |
> |
static int to_output = 0; |
122 |
> |
static int buffer_pos = 0; |
123 |
|
|
124 |
< |
if (!ready) |
125 |
< |
return; |
124 |
> |
if (!ready) |
125 |
> |
return; |
126 |
|
|
127 |
|
sample_buf[sample_in_ptr] = volume; |
128 |
|
sample_in_ptr = (sample_in_ptr + 1) % SAMPLE_BUF_SIZE; |
129 |
|
|
130 |
< |
/* |
131 |
< |
* Now see how many samples have to be added for this line |
132 |
< |
*/ |
133 |
< |
divisor += SAMPLE_FREQ; |
134 |
< |
while (divisor >= 0) |
135 |
< |
divisor -= TOTAL_RASTERS*SCREEN_FREQ, to_output++; |
136 |
< |
|
137 |
< |
/* |
138 |
< |
* Calculate the sound data only when we have enough to fill |
139 |
< |
* the buffer entirely. |
140 |
< |
*/ |
141 |
< |
if ((buffer_pos + to_output) >= sndbufsize) { |
142 |
< |
int datalen = sndbufsize - buffer_pos; |
143 |
< |
to_output -= datalen; |
146 |
< |
calc_buffer(sound_buffer + buffer_pos, datalen*2); |
147 |
< |
write(devfd, sound_buffer, sndbufsize*2); |
148 |
< |
buffer_pos = 0; |
149 |
< |
} |
130 |
> |
// Now see how many samples have to be added for this line |
131 |
> |
divisor += SAMPLE_FREQ; |
132 |
> |
while (divisor >= 0) |
133 |
> |
divisor -= TOTAL_RASTERS*SCREEN_FREQ, to_output++; |
134 |
> |
|
135 |
> |
// Calculate the sound data only when we have enough to fill |
136 |
> |
// the buffer entirely |
137 |
> |
if ((buffer_pos + to_output) >= sndbufsize) { |
138 |
> |
int datalen = sndbufsize - buffer_pos; |
139 |
> |
to_output -= datalen; |
140 |
> |
calc_buffer(sound_buffer + buffer_pos, datalen*2); |
141 |
> |
write(devfd, sound_buffer, sndbufsize*2); |
142 |
> |
buffer_pos = 0; |
143 |
> |
} |
144 |
|
} |
145 |
|
|
146 |
|
|
148 |
|
* Renderer for Catweasel card |
149 |
|
*/ |
150 |
|
|
151 |
< |
// Rendere class |
151 |
> |
// Renderer class |
152 |
|
class CatweaselRenderer : public SIDRenderer { |
153 |
|
public: |
154 |
|
CatweaselRenderer(); |