cubeb_sink: Hold last available value instead of writing zeros
This reduces clicking in output audio should we underrun.
This commit is contained in:
parent
6d9dd1dc6d
commit
7e697ab7ff
@ -89,6 +89,10 @@ public:
|
|||||||
return num_channels;
|
return num_channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 GetNumChannelsInQueue() const {
|
||||||
|
return num_channels == 1 ? 1 : 2;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> device_list;
|
std::vector<std::string> device_list;
|
||||||
|
|
||||||
@ -98,6 +102,7 @@ private:
|
|||||||
bool is_6_channel{};
|
bool is_6_channel{};
|
||||||
|
|
||||||
Common::RingBuffer<s16, 0x10000> queue;
|
Common::RingBuffer<s16, 0x10000> queue;
|
||||||
|
std::array<s16, 2> last_frame;
|
||||||
|
|
||||||
static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer,
|
static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer,
|
||||||
void* output_buffer, long num_frames);
|
void* output_buffer, long num_frames);
|
||||||
@ -156,13 +161,18 @@ long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t max_samples_to_write = impl->GetNumChannels() * num_frames;
|
const size_t num_channels = impl->GetNumChannelsInQueue();
|
||||||
|
const size_t max_samples_to_write = num_channels * num_frames;
|
||||||
const size_t samples_written = impl->queue.Pop(buffer, max_samples_to_write);
|
const size_t samples_written = impl->queue.Pop(buffer, max_samples_to_write);
|
||||||
|
|
||||||
if (samples_written < max_samples_to_write) {
|
if (samples_written >= num_channels) {
|
||||||
// Fill the rest of the frames with silence
|
std::memcpy(&impl->last_frame[0], buffer + (samples_written - num_channels) * sizeof(s16),
|
||||||
std::memset(buffer + samples_written * sizeof(s16), 0,
|
num_channels * sizeof(s16));
|
||||||
(max_samples_to_write - samples_written) * sizeof(s16));
|
}
|
||||||
|
|
||||||
|
// Fill the rest of the frames with last_frame
|
||||||
|
for (size_t i = samples_written; i < max_samples_to_write; i += num_channels) {
|
||||||
|
std::memcpy(buffer + i * sizeof(s16), &impl->last_frame[0], num_channels * sizeof(s16));
|
||||||
}
|
}
|
||||||
|
|
||||||
return num_frames;
|
return num_frames;
|
||||||
|
Loading…
Reference in New Issue
Block a user