diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h index c91487b7f..332328f1c 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h @@ -14,8 +14,8 @@ - (void)runForNumberOfCycles:(int)numberOfCycles; -- (int)idealSamplingRateFromRange:(NSRange)range; -- (void)setAudioSamplingRate:(int)samplingRate; +- (float)idealSamplingRateFromRange:(NSRange)range; +- (void)setAudioSamplingRate:(float)samplingRate; - (void)setView:(CSOpenGLView *)view aspectRatio:(float)aspectRatio; - (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty; diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm index e3ba9ada8..188abe561 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm @@ -36,25 +36,25 @@ struct SpeakerDelegate: public Outputs::Speaker::Delegate { }]; } -- (int)idealSamplingRateFromRange:(NSRange)range { +- (float)idealSamplingRateFromRange:(NSRange)range { @synchronized(self) { Outputs::Speaker *speaker = self.machine->get_speaker(); if(speaker) { - return speaker->get_ideal_clock_rate_in_range((int)range.location, (int)(range.location + range.length)); + return speaker->get_ideal_clock_rate_in_range((float)range.location, (float)(range.location + range.length)); } return 0; } } -- (void)setAudioSamplingRate:(int)samplingRate { +- (void)setAudioSamplingRate:(float)samplingRate { @synchronized(self) { _speakerDelegate.machine = self; [self setSpeakerDelegate:&_speakerDelegate sampleRate:samplingRate]; } } -- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(int)sampleRate { +- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(float)sampleRate { @synchronized(self) { Outputs::Speaker *speaker = self.machine->get_speaker(); if(speaker) diff --git a/Outputs/Speaker.hpp b/Outputs/Speaker.hpp index 9742e86df..6cfd434a2 100644 --- a/Outputs/Speaker.hpp +++ b/Outputs/Speaker.hpp @@ -24,7 +24,7 @@ class Speaker { virtual void speaker_did_complete_samples(Speaker *speaker, const int16_t *buffer, int buffer_size) = 0; }; - int get_ideal_clock_rate_in_range(int minimum, int maximum) + float get_ideal_clock_rate_in_range(float minimum, float maximum) { // return exactly the input rate if possible if(_input_cycles_per_second >= minimum && _input_cycles_per_second <= maximum) return _input_cycles_per_second; @@ -36,7 +36,7 @@ class Speaker { return maximum; } - void set_output_rate(int cycles_per_second, int buffer_size) + void set_output_rate(float cycles_per_second, int buffer_size) { _output_cycles_per_second = cycles_per_second; if(_buffer_size != buffer_size) @@ -58,7 +58,7 @@ class Speaker { _delegate = delegate; } - void set_input_rate(int cycles_per_second) + void set_input_rate(float cycles_per_second) { _input_cycles_per_second = cycles_per_second; set_needs_updated_filter_coefficients(); @@ -74,7 +74,7 @@ class Speaker { bool _coefficients_are_dirty; Delegate *_delegate; - int _input_cycles_per_second, _output_cycles_per_second; + float _input_cycles_per_second, _output_cycles_per_second; void set_needs_updated_filter_coefficients() { @@ -181,7 +181,7 @@ template class Filter: public Speaker { } else { - _number_of_taps = (_input_cycles_per_second + _output_cycles_per_second) / _output_cycles_per_second; + _number_of_taps = (int)ceilf((_input_cycles_per_second + _output_cycles_per_second) / _output_cycles_per_second); _number_of_taps *= 2; _number_of_taps |= 1; } @@ -190,7 +190,7 @@ template class Filter: public Speaker { _buffer_in_progress_pointer = 0; _stepper = std::unique_ptr(new SignalProcessing::Stepper((uint64_t)_input_cycles_per_second, (uint64_t)_output_cycles_per_second)); - _filter = std::unique_ptr(new SignalProcessing::FIRFilter((unsigned int)_number_of_taps, (unsigned int)_input_cycles_per_second, 0.0, (float)_output_cycles_per_second / 2.0f, SignalProcessing::FIRFilter::DefaultAttenuation)); + _filter = std::unique_ptr(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)); _input_buffer = std::unique_ptr(new int16_t[_number_of_taps]); _input_buffer_depth = 0;