2017-12-18 02:26:06 +00:00
|
|
|
//
|
|
|
|
// Speaker.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 12/01/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2017-12-18 02:26:06 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Speaker_hpp
|
|
|
|
#define Speaker_hpp
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Outputs {
|
|
|
|
namespace Speaker {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Provides a communication point for sound; machines that have a speaker provide an
|
|
|
|
audio output.
|
|
|
|
*/
|
|
|
|
class Speaker {
|
|
|
|
public:
|
|
|
|
virtual ~Speaker() {}
|
|
|
|
|
|
|
|
virtual float get_ideal_clock_rate_in_range(float minimum, float maximum) = 0;
|
|
|
|
virtual void set_output_rate(float cycles_per_second, int buffer_size) = 0;
|
|
|
|
|
2020-01-20 21:08:21 +00:00
|
|
|
int completed_sample_sets() const { return completed_sample_sets_; }
|
2020-01-20 17:12:23 +00:00
|
|
|
|
2017-12-18 02:26:06 +00:00
|
|
|
struct Delegate {
|
|
|
|
virtual void speaker_did_complete_samples(Speaker *speaker, const std::vector<int16_t> &buffer) = 0;
|
2018-03-22 13:23:01 +00:00
|
|
|
virtual void speaker_did_change_input_clock(Speaker *speaker) {}
|
2017-12-18 02:26:06 +00:00
|
|
|
};
|
2018-02-18 20:23:15 +00:00
|
|
|
virtual void set_delegate(Delegate *delegate) {
|
2017-12-18 02:26:06 +00:00
|
|
|
delegate_ = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2020-01-20 17:12:23 +00:00
|
|
|
void did_complete_samples(Speaker *speaker, const std::vector<int16_t> &buffer) {
|
|
|
|
++completed_sample_sets_;
|
|
|
|
delegate_->speaker_did_complete_samples(this, buffer);
|
|
|
|
}
|
2017-12-18 02:26:06 +00:00
|
|
|
Delegate *delegate_ = nullptr;
|
2020-01-20 17:12:23 +00:00
|
|
|
int completed_sample_sets_ = 0;
|
2017-12-18 02:26:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Speaker_hpp */
|