From 9ee239a073dc7aa1f0e82695694df332a8634547 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 25 Aug 2016 09:37:36 +0200 Subject: [PATCH] Fix a small theoretical inefficiency; does not actually matter in practice, just cleaner. --- audio_mixer.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/audio_mixer.cpp b/audio_mixer.cpp index 59b5a70..13eed33 100644 --- a/audio_mixer.cpp +++ b/audio_mixer.cpp @@ -264,8 +264,7 @@ bool AudioMixer::add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned assert(num_channels > 0); // Convert the audio to fp32. - vector audio; - audio.resize(num_samples * num_channels); + unique_ptr audio(new float[num_samples * num_channels]); unsigned channel_index = 0; for (auto channel_it = device->interesting_channels.cbegin(); channel_it != device->interesting_channels.end(); ++channel_it, ++channel_index) { switch (audio_format.bits_per_sample) { @@ -273,13 +272,13 @@ bool AudioMixer::add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned assert(num_samples == 0); break; case 16: - convert_fixed16_to_fp32(&audio[0], channel_index, num_channels, data, *channel_it, audio_format.num_channels, num_samples); + convert_fixed16_to_fp32(audio.get(), channel_index, num_channels, data, *channel_it, audio_format.num_channels, num_samples); break; case 24: - convert_fixed24_to_fp32(&audio[0], channel_index, num_channels, data, *channel_it, audio_format.num_channels, num_samples); + convert_fixed24_to_fp32(audio.get(), channel_index, num_channels, data, *channel_it, audio_format.num_channels, num_samples); break; case 32: - convert_fixed32_to_fp32(&audio[0], channel_index, num_channels, data, *channel_it, audio_format.num_channels, num_samples); + convert_fixed32_to_fp32(audio.get(), channel_index, num_channels, data, *channel_it, audio_format.num_channels, num_samples); break; default: fprintf(stderr, "Cannot handle audio with %u bits per sample\n", audio_format.bits_per_sample); @@ -289,7 +288,7 @@ bool AudioMixer::add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned // Now add it. int64_t local_pts = device->next_local_pts; - device->resampling_queue->add_input_samples(local_pts / double(TIMEBASE), audio.data(), num_samples); + device->resampling_queue->add_input_samples(local_pts / double(TIMEBASE), audio.get(), num_samples); device->next_local_pts = local_pts + frame_length; return true; } -- 2.39.2