--- Frodo4/Src/SID.cpp 2003/07/01 17:09:43 1.1 +++ Frodo4/Src/SID.cpp 2010/04/22 09:09:28 1.10 @@ -1,7 +1,7 @@ /* * SID.cpp - 6581 emulation * - * Frodo (C) 1994-1997,2002 Christian Bauer + * Frodo Copyright (C) Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,7 +23,6 @@ * ------------------ * * - Lots of empirically determined constants in the filter calculations - * - Voice 3 cannot be muted */ #include "sysdeps.h" @@ -33,7 +32,7 @@ #include "Prefs.h" #ifdef __BEOS__ -#include +#include #endif #ifdef AMIGA @@ -349,16 +348,13 @@ struct DRVoice { // The following bit is set for the modulating // voice, not for the modulated one (as the SID bits) bool sync; // Sync modulation bit + bool mute; // Voice muted (voice 3 only) }; // Renderer class class DigitalRenderer : public SIDRenderer { public: -#if defined(__BEOS__) || defined(__riscos__) DigitalRenderer(C64 *c64); -#else - DigitalRenderer(); -#endif virtual ~DigitalRenderer(); virtual void Reset(void); @@ -377,9 +373,10 @@ private: void calc_buffer(int16 *buf, long count); #endif + C64 *the_c64; // Pointer to C64 object + bool ready; // Flag: Renderer has initialized and is ready uint8 volume; // Master volume - bool v3_mute; // Voice 3 muted static uint16 TriTable[0x1000*2]; // Tables for certain waveforms static const uint16 TriSawTable[0x100]; @@ -418,11 +415,9 @@ private: int sample_in_ptr; // Index in sample_buf for writing #ifdef __BEOS__ - static bool stream_func(void *arg, char *buf, size_t count, void *header); - C64 *the_c64; // Pointer to C64 object - BDACStream *the_stream; // Pointer to stream - BSubscriber *the_sub; // Pointer to subscriber - bool in_stream; // Flag: Subscriber has entered stream + static void buffer_proc(void *cookie, void *buffer, size_t size, const media_raw_audio_format &format); + BSoundPlayer *the_player; // Pointer to sound player + bool player_stopped; // Flag: player stopped #endif #ifdef AMIGA @@ -442,24 +437,32 @@ private: int play_buf; // Number of buffer currently playing #endif -#ifdef __linux__ + +#ifdef HAVE_SDL + static void buffer_proc(void *cookie, uint8 *buffer, int size); +#else + +# ifdef __linux__ int devfd, sndbufsize, buffer_rate; int16 *sound_buffer; -#endif +# endif -#ifdef SUN +# ifdef SUN int fd; audio_info status; uint_t sent_samples,delta_samples; - WORD *sound_calc_buf; -#endif + int16 *sound_calc_buf; +# endif -#ifdef __hpux +# ifdef __hpux int fd; audio_status status; - int16 * sound_calc_buf; + int16 *sound_calc_buf; int linecnt; -#endif +# endif + +#endif // ndef HAVE_SDL + #ifdef __mac__ SndChannelPtr chan1; @@ -493,7 +496,6 @@ private: #ifdef __riscos__ int linecnt, sndbufsize; uint8 *sound_buffer; - C64 *the_c64; #endif }; @@ -824,11 +826,7 @@ const int16 DigitalRenderer::SampleTab[1 * Constructor */ -#if defined(__BEOS__) || defined(__riscos__) DigitalRenderer::DigitalRenderer(C64 *c64) : the_c64(c64) -#else -DigitalRenderer::DigitalRenderer() -#endif { // Link voices together voice[0].mod_by = &voice[2]; @@ -877,7 +875,6 @@ DigitalRenderer::DigitalRenderer() void DigitalRenderer::Reset(void) { volume = 0; - v3_mute = false; for (int v=0; v<3; v++) { voice[v].wave = WAVE_NONE; @@ -887,7 +884,7 @@ void DigitalRenderer::Reset(void) voice[v].eg_level = voice[v].s_level = 0; voice[v].a_add = voice[v].d_sub = voice[v].r_sub = EGTable[0]; voice[v].gate = voice[v].ring = voice[v].test = false; - voice[v].filter = voice[v].sync = false; + voice[v].filter = voice[v].sync = voice[v].mute = false; } f_type = FILT_NONE; @@ -966,7 +963,7 @@ void DigitalRenderer::WriteRegister(uint voice[v].gate = byte & 1; voice[v].mod_by->sync = byte & 2; voice[v].ring = byte & 4; - if ((voice[v].test = byte & 8)) + if ((voice[v].test = byte & 8) != 0) voice[v].count = 0; break; @@ -1005,7 +1002,7 @@ void DigitalRenderer::WriteRegister(uint case 24: volume = byte & 0xf; - v3_mute = byte & 0x80; + voice[2].mute = byte & 0x80; if (((byte >> 4) & 7) != f_type) { f_type = (byte >> 4) & 7; #ifdef USE_FIXPOINT_MATHS @@ -1201,21 +1198,15 @@ void DigitalRenderer::calc_buffer(int16 #ifdef __riscos__ // on RISC OS we have 8 bit logarithmic sound DigitalRenderer_GetTables(&LinToLog, &LogScale); // get translation tables #else -#ifdef __BEOS__ - count >>= 2; // 16 bit stereo output, count is in bytes -#else count >>= 1; // 16 bit mono output, count is in bytes #endif -#endif while (count--) { - int32 sum_output; - int32 sum_output_filter = 0; - // Get current master volume from sample buffer, // calculate sampled voice uint8 master_volume = sample_buf[(sample_count >> 16) % SAMPLE_BUF_SIZE]; sample_count += ((0x138 * 50) << 16) / SAMPLE_FREQ; - sum_output = SampleTab[master_volume] << 8; + int32 sum_output = SampleTab[master_volume] << 8; + int32 sum_output_filter = 0; // Loop for all three voices for (int j=0; j<3; j++) { @@ -1255,6 +1246,8 @@ void DigitalRenderer::calc_buffer(int16 envelope = (v->eg_level * master_volume) >> 20; // Waveform generator + if (v->mute) + continue; uint16 output; if (!v->test) @@ -1335,21 +1328,7 @@ void DigitalRenderer::calc_buffer(int16 } // Write to buffer -#ifdef __BEOS__ - int16 audio_data = (sum_output + sum_output_filter) >> 10; - int val = *buf + audio_data; - if (val > 32767) - val = 32767; - if (val < -32768) - val = -32768; - *buf++ = val; - val = *buf + audio_data; - if (val > 32767) - val = 32767; - if (val < -32768) - val = -32768; - *buf++ = val; -#elif defined(__riscos__) // lookup in 8k (13bit) translation table +#if defined(__riscos__) // lookup in 8k (13bit) translation table *buf++ = LinToLog[((sum_output + sum_output_filter) >> 13) & 0x1fff]; #else *buf++ = (sum_output + sum_output_filter) >> 10; @@ -1365,8 +1344,15 @@ void DigitalRenderer::calc_buffer(int16 #elif defined(AMIGA) #include "SID_Amiga.h" +#elif defined(HAVE_SDL) +#include "SID_SDL.h" +# if defined(__linux__) +# include "SID_catweasel.h" +# endif + #elif defined(__linux__) #include "SID_linux.h" +#include "SID_catweasel.h" #elif defined(SUN) #include "SID_sun.h" @@ -1405,18 +1391,19 @@ void MOS6581::open_close_renderer(int ol delete the_renderer; // Create new renderer - if (new_type == SIDTYPE_DIGITAL) -#if defined(__BEOS__) || defined(__riscos__) + if (new_type == SIDTYPE_DIGITAL) { the_renderer = new DigitalRenderer(the_c64); -#else - the_renderer = new DigitalRenderer(); -#endif #ifdef AMIGA - else if (new_type == SIDTYPE_SIDCARD) - the_renderer = new SIDCardRenderer(); + } else if (new_type == SIDTYPE_SIDCARD) { + the_renderer = new SIDCardRenderer; #endif - else +#ifdef __linux__ + } else if (new_type == SIDTYPE_SIDCARD) { + the_renderer = new CatweaselRenderer; +#endif + } else { the_renderer = NULL; + } // Stuff the current register values into the new renderer if (the_renderer != NULL)