diff --git a/reSID.cpp b/reSID.cpp index 5d8f468..79ee813 100644 --- a/reSID.cpp +++ b/reSID.cpp @@ -27,17 +27,23 @@ #include "reSID.h" #include -#define SAMPLERATE 44118 -#define CLOCKFREQ (22.5 * SAMPLERATE) //nearest int to 985248 + +#define SAMPLERATE AUDIO_SAMPLE_RATE_EXACT +#define CLOCKFREQ 985248 void AudioPlaySID::begin(void) { sidptr = &sid; this->reset(); - sid.set_sampling_parameters(CLOCKFREQ, SAMPLE_FAST, SAMPLERATE); + setSampleParameters(CLOCKFREQ, SAMPLERATE); playing = true; } +void AudioPlaySID::setSampleParameters(unsigned clockfreq, unsigned samplerate) { + sid.set_sampling_parameters(clockfreq, SAMPLE_FAST, samplerate); + csdelta = round((float)clockfreq / ((float)samplerate / AUDIO_BLOCK_SAMPLES)); +} + void AudioPlaySID::reset(void) { sid.reset(); @@ -59,9 +65,9 @@ void AudioPlaySID::update(void) { // allocate the audio blocks to transmit block = allocate(); if (block == NULL) return; - - //I'm not 100% if this is correct: - cycle_count delta_t = CLOCKFREQ / (SAMPLERATE / AUDIO_BLOCK_SAMPLES); + + //cycle_count delta_t = CLOCKFREQ / (SAMPLERATE / AUDIO_BLOCK_SAMPLES); + cycle_count delta_t = csdelta; sidptr->clock(delta_t, (short int*)block->data, AUDIO_BLOCK_SAMPLES); diff --git a/reSID.h b/reSID.h index b9c0e05..56eda49 100644 --- a/reSID.h +++ b/reSID.h @@ -36,11 +36,14 @@ class AudioPlaySID : public AudioStream public: AudioPlaySID(void) : AudioStream(0, NULL) { begin(); } void begin(void); + void setSampleParameters(unsigned clockfreq, unsigned samplerate); inline void setreg(int ofs, int val) { sid.write(ofs, val); } + inline uint8_t getreg(int ofs) { return sid.read(ofs); } void reset(void); void stop(void); inline bool isPlaying(void) { return playing; } private: + cycle_count csdelta; volatile bool playing; virtual void update(void); SID sid; diff --git a/reSID/wave.h b/reSID/wave.h index 0a26126..376960d 100644 --- a/reSID/wave.h +++ b/reSID/wave.h @@ -267,7 +267,7 @@ reg12 WaveformGenerator::output___T() { reg24 msb = (ring_mod ? accumulator ^ sync_source->accumulator : accumulator) & 0x800000; - return ((msb ? ~accumulator : accumulator) >> 11) & 0xfff; + return ((msb ? ~accumulator : accumulator) >> 11) & 0xffe; } // Sawtooth: