1
0
Fork 0
forked from suyu/suyu

sink: Change EnqueueSamples to take a pointer to a buffer instead of a std::vector

This commit is contained in:
MerryMage 2016-08-31 16:55:10 +01:00
parent 87893e6d68
commit 0ef4185644
5 changed files with 9 additions and 9 deletions

View file

@ -90,7 +90,8 @@ static AudioCore::TimeStretcher time_stretcher;
static void OutputCurrentFrame(const StereoFrame16& frame) { static void OutputCurrentFrame(const StereoFrame16& frame) {
time_stretcher.AddSamples(&frame[0][0], frame.size()); time_stretcher.AddSamples(&frame[0][0], frame.size());
sink->EnqueueSamples(time_stretcher.Process(sink->SamplesInQueue())); std::vector<s16> stretched_samples = time_stretcher.Process(sink->SamplesInQueue());
sink->EnqueueSamples(stretched_samples.data(), stretched_samples.size() / 2);
} }
// Public Interface // Public Interface

View file

@ -19,7 +19,7 @@ public:
return native_sample_rate; return native_sample_rate;
} }
void EnqueueSamples(const std::vector<s16>&) override {} void EnqueueSamples(const s16*, size_t) override {}
size_t SamplesInQueue() const override { size_t SamplesInQueue() const override {
return 0; return 0;

View file

@ -71,14 +71,12 @@ unsigned int SDL2Sink::GetNativeSampleRate() const {
return impl->sample_rate; return impl->sample_rate;
} }
void SDL2Sink::EnqueueSamples(const std::vector<s16>& samples) { void SDL2Sink::EnqueueSamples(const s16* samples, size_t sample_count) {
if (impl->audio_device_id <= 0) if (impl->audio_device_id <= 0)
return; return;
ASSERT_MSG(samples.size() % 2 == 0, "Samples must be in interleaved stereo PCM16 format (size must be a multiple of two)");
SDL_LockAudioDevice(impl->audio_device_id); SDL_LockAudioDevice(impl->audio_device_id);
impl->queue.emplace_back(samples); impl->queue.emplace_back(samples, samples + sample_count * 2);
SDL_UnlockAudioDevice(impl->audio_device_id); SDL_UnlockAudioDevice(impl->audio_device_id);
} }

View file

@ -18,7 +18,7 @@ public:
unsigned int GetNativeSampleRate() const override; unsigned int GetNativeSampleRate() const override;
void EnqueueSamples(const std::vector<s16>& samples) override; void EnqueueSamples(const s16* samples, size_t sample_count) override;
size_t SamplesInQueue() const override; size_t SamplesInQueue() const override;

View file

@ -23,9 +23,10 @@ public:
/** /**
* Feed stereo samples to sink. * Feed stereo samples to sink.
* @param samples Samples in interleaved stereo PCM16 format. Size of vector must be multiple of two. * @param samples Samples in interleaved stereo PCM16 format.
* @param sample_count Number of samples.
*/ */
virtual void EnqueueSamples(const std::vector<s16>& samples) = 0; virtual void EnqueueSamples(const s16* samples, size_t sample_count) = 0;
/// Samples enqueued that have not been played yet. /// Samples enqueued that have not been played yet.
virtual std::size_t SamplesInQueue() const = 0; virtual std::size_t SamplesInQueue() const = 0;