mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-13 07:30:21 +00:00
Adds is_silent
to SampleSource
plus shortcut processing to CompoundSource
.
This commit is contained in:
parent
772c320d5a
commit
3e1d8ea082
@ -31,19 +31,22 @@ template <typename... T> class CompoundSource: public Outputs::Speaker::SampleSo
|
|||||||
A CompoundSource adds together the sound generated by multiple individual SampleSources.
|
A CompoundSource adds together the sound generated by multiple individual SampleSources.
|
||||||
It's an instance of template metaprogramming; this is the recursive case.
|
It's an instance of template metaprogramming; this is the recursive case.
|
||||||
*/
|
*/
|
||||||
template <typename T, typename... R> class CompoundSource<T, R...>: public Outputs::Speaker::SampleSource {
|
template <typename T, typename... R> class CompoundSource<T, R...>:
|
||||||
|
public Outputs::Speaker::SampleSource {
|
||||||
public:
|
public:
|
||||||
CompoundSource(T &source, R &...next) : source_(source), next_source_(next...) {}
|
CompoundSource(T &source, R &...next) : source_(source), next_source_(next...) {}
|
||||||
|
|
||||||
void get_samples(std::size_t number_of_samples, std::int16_t *target) {
|
void get_samples(std::size_t number_of_samples, std::int16_t *target) {
|
||||||
// This is an ugly solution: get whatever the next source supplies and add the local
|
if(source_.is_silent()) {
|
||||||
// results to it, with the degenerate case performing a memset to supply an array of 0.
|
source_.skip_samples(number_of_samples);
|
||||||
// TODO: do better. Might need some alteration of SampleSource.
|
next_source_.get_samples(number_of_samples, target);
|
||||||
int16_t next_samples[number_of_samples];
|
} else {
|
||||||
next_source_.get_samples(number_of_samples, next_samples);
|
int16_t next_samples[number_of_samples];
|
||||||
source_.get_samples(number_of_samples, target);
|
next_source_.get_samples(number_of_samples, next_samples);
|
||||||
while(number_of_samples--) {
|
source_.get_samples(number_of_samples, target);
|
||||||
target[number_of_samples] += next_samples[number_of_samples];
|
while(number_of_samples--) {
|
||||||
|
target[number_of_samples] += next_samples[number_of_samples];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +56,7 @@ template <typename T, typename... R> class CompoundSource<T, R...>: public Outpu
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool is_sleeping_ = false;
|
||||||
T &source_;
|
T &source_;
|
||||||
CompoundSource<R...> next_source_;
|
CompoundSource<R...> next_source_;
|
||||||
};
|
};
|
||||||
|
@ -37,6 +37,15 @@ class SampleSource {
|
|||||||
std::int16_t scratch_pad[number_of_samples];
|
std::int16_t scratch_pad[number_of_samples];
|
||||||
get_samples(number_of_samples, scratch_pad);
|
get_samples(number_of_samples, scratch_pad);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@returns @c true if it is trivially true that a call to get_samples would just
|
||||||
|
fill the target with zeroes; @c false if a call might return all zeroes or
|
||||||
|
might not.
|
||||||
|
*/
|
||||||
|
bool is_silent() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user