Fixed audio clipping on WASAPI by fixing argument order on AudioClient

Initialize method ensuring a larger capture buffer and adding bounds
to the capture and stream.
This commit is contained in:
Saracen 2018-07-27 03:47:22 +01:00
parent 7142e1d3f7
commit aca6e291d6
3 changed files with 34 additions and 14 deletions

View file

@ -135,19 +135,31 @@ void AudioStreamPlaybackMicrophone::_mix_internal(AudioFrame *p_buffer, int p_fr
AudioDriver::get_singleton()->lock();
Vector<int32_t> buf = AudioDriver::get_singleton()->get_audio_input_buffer();
unsigned int audio_input_size = AudioDriver::get_singleton()->get_audio_input_size();
for (int i = 0; i < p_frames; i++) {
float l = (buf[input_ofs++] >> 16) / 32768.f;
if (input_ofs >= buf.size()) {
input_ofs = 0;
}
float r = (buf[input_ofs++] >> 16) / 32768.f;
if (input_ofs >= buf.size()) {
input_ofs = 0;
// p_frames is multipled by two since an AudioFrame is stereo
if ((p_frames * 2) > audio_input_size) {
for (int i = 0; i < p_frames; i++) {
p_buffer[i] = AudioFrame(0.0f, 0.0f);
}
input_ofs = 0;
} else {
for (int i = 0; i < p_frames; i++) {
if (audio_input_size >= input_ofs) {
float l = (buf[input_ofs++] >> 16) / 32768.f;
if (input_ofs >= buf.size()) {
input_ofs = 0;
}
float r = (buf[input_ofs++] >> 16) / 32768.f;
if (input_ofs >= buf.size()) {
input_ofs = 0;
}
p_buffer[i] = AudioFrame(l, r);
p_buffer[i] = AudioFrame(l, r);
} else {
p_buffer[i] = AudioFrame(0.0f, 0.0f);
}
}
}
AudioDriver::get_singleton()->unlock();

View file

@ -55,6 +55,7 @@ class AudioDriver {
protected:
Vector<int32_t> audio_input_buffer;
unsigned int audio_input_position;
unsigned int audio_input_size;
void audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time = true);
void update_mix_time(int p_frames);
@ -109,6 +110,7 @@ public:
Vector<int32_t> get_audio_input_buffer() { return audio_input_buffer; }
unsigned int get_audio_input_position() { return audio_input_position; }
unsigned int get_audio_input_size() { return audio_input_size; }
#ifdef DEBUG_ENABLED
uint64_t get_profiling_time() const { return prof_time; }