1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-07 23:29:06 +00:00

It turns out that the Vic has a 1.6Khz low-pass filter. So added that.

This commit is contained in:
Thomas Harte 2016-08-21 12:13:41 -04:00
parent 8d839c5278
commit c783090980
3 changed files with 27 additions and 4 deletions

View File

@ -15,7 +15,11 @@ Speaker::Speaker() :
_control_registers{0, 0, 0, 0},
_shift_registers{0, 0, 0, 0},
_counters{2, 1, 0, 0} // create a slight phase offset for the three channels
{}
{
// The Vic has a 1.6Khz low-pass filter;
// TODO: this is part of the Vic-20, not part of the 6560. So relocate it.
set_high_frequency_cut_off(1600);
}
void Speaker::set_volume(uint8_t volume)
{

View File

@ -72,7 +72,7 @@ template <class T> class MOS6560 {
void set_clock_rate(double clock_rate)
{
_speaker->set_input_rate(clock_rate / 4.0);
_speaker->set_input_rate((float)(clock_rate / 4.0));
}
std::shared_ptr<Outputs::CRT::CRT> get_crt() { return _crt; }

View File

@ -109,12 +109,20 @@ class Speaker {
*/
template <class T> class Filter: public Speaker {
public:
Filter() : _high_frequency_cut_off(-1.0) {}
void set_high_frequency_cut_off(float high_frequency)
{
_high_frequency_cut_off = high_frequency;
set_needs_updated_filter_coefficients();
}
void run_for_cycles(unsigned int input_cycles)
{
if(_coefficients_are_dirty) update_filter_coefficients();
// if input and output rates exactly match, just accumulate results and pass on
if(_input_cycles_per_second == _output_cycles_per_second)
if(_input_cycles_per_second == _output_cycles_per_second && _high_frequency_cut_off < 0.0)
{
while(input_cycles)
{
@ -196,6 +204,7 @@ template <class T> class Filter: public Speaker {
std::unique_ptr<int16_t> _input_buffer;
int _input_buffer_depth;
float _high_frequency_cut_off;
void update_filter_coefficients()
{
@ -215,7 +224,17 @@ template <class T> class Filter: public Speaker {
_buffer_in_progress_pointer = 0;
_stepper.reset(new SignalProcessing::Stepper((uint64_t)_input_cycles_per_second, (uint64_t)_output_cycles_per_second));
_filter.reset(new SignalProcessing::FIRFilter((unsigned int)_number_of_taps, (float)_input_cycles_per_second, 0.0, (float)_output_cycles_per_second / 2.0f, SignalProcessing::FIRFilter::DefaultAttenuation));
float high_pass_frequency;
if(_high_frequency_cut_off > 0.0)
{
high_pass_frequency = std::min((float)_output_cycles_per_second / 2.0f, _high_frequency_cut_off);
}
else
{
high_pass_frequency = (float)_output_cycles_per_second / 2.0f;
}
_filter.reset(new SignalProcessing::FIRFilter((unsigned int)_number_of_taps, (float)_input_cycles_per_second, 0.0, high_pass_frequency, SignalProcessing::FIRFilter::DefaultAttenuation));
_input_buffer.reset(new int16_t[_number_of_taps]);
_input_buffer_depth = 0;