2009-01-05 10:43:37 +01:00
|
|
|
/*
|
|
|
|
* SID_linux.i - 6581 emulation, Linux specific stuff
|
|
|
|
*
|
|
|
|
* Frodo (C) 1994-1997,2002 Christian Bauer
|
|
|
|
* Linux sound stuff by Bernd Schmidt
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gcaudio.h"
|
|
|
|
|
|
|
|
#include "VIC.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DigitalRenderer::init_sound(void)
|
|
|
|
{
|
2009-01-05 14:10:04 +01:00
|
|
|
this->sndbufsize = 512;
|
2009-01-05 10:43:37 +01:00
|
|
|
|
|
|
|
ready = false;
|
|
|
|
InitialiseAudio();
|
|
|
|
ResetAudio();
|
|
|
|
|
|
|
|
this->sound_buffer = new int16[this->sndbufsize];
|
2009-01-05 14:10:04 +01:00
|
|
|
memset(this->sound_buffer, 0, sizeof(int16) * this->sndbufsize);
|
2009-01-05 10:43:37 +01:00
|
|
|
ready = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
|
|
|
|
DigitalRenderer::~DigitalRenderer()
|
|
|
|
{
|
|
|
|
StopAudio();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pause sound output
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DigitalRenderer::Pause(void)
|
|
|
|
{
|
|
|
|
StopAudio();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resume sound output
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DigitalRenderer::Resume(void)
|
|
|
|
{
|
|
|
|
/* Done by PlayAudio() */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill buffer, sample volume (for sampled voice)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DigitalRenderer::EmulateLine(void)
|
|
|
|
{
|
|
|
|
static int divisor = 0;
|
|
|
|
static int to_output = 0;
|
|
|
|
|
|
|
|
if (!ready)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sample_buf[sample_in_ptr] = volume;
|
|
|
|
sample_in_ptr = (sample_in_ptr + 1) % SAMPLE_BUF_SIZE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now see how many samples have to be added for this line
|
|
|
|
*/
|
|
|
|
divisor += SAMPLE_FREQ;
|
|
|
|
while (divisor >= 0)
|
|
|
|
divisor -= TOTAL_RASTERS*SCREEN_FREQ, to_output++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the sound data only when we have enough to fill
|
|
|
|
* the buffer entirely.
|
|
|
|
*/
|
2009-01-05 14:10:04 +01:00
|
|
|
if (to_output >= sndbufsize) {
|
|
|
|
int datalen = sndbufsize;
|
2009-01-05 10:43:37 +01:00
|
|
|
to_output -= datalen;
|
2009-01-05 14:10:04 +01:00
|
|
|
calc_buffer(sound_buffer, datalen * 2);
|
|
|
|
|
|
|
|
PlaySound(sound_buffer, datalen);
|
2009-01-05 10:43:37 +01:00
|
|
|
}
|
|
|
|
}
|