Skip to content

Commit 02ae39f

Browse files
[MERGE_TO_IOS] Minor optimizations, style nits.
1 parent cd02e86 commit 02ae39f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/voicerecorder.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,16 @@ void VoiceRecorder::handleAudioInputDeviceReadyRead()
153153
if (p + frame_bytes <= AudioBuffer.size()) {
154154
QVarLengthArray<int16_t, 1024>audio_data_16bit(frame_length);
155155

156-
for (int i = 0; i < frame_length; i++) {
157-
if (sample_type == QAudioFormat::UnSignedInt && sample_size == 8) {
156+
if (sample_type == QAudioFormat::UnSignedInt && sample_size == 8) {
157+
for (int i = 0; i < frame_length; i++) {
158158
audio_data_16bit[i] = (static_cast<quint8>(AudioBuffer[p + i]) - 128) * 256;
159-
} else if (sample_type == QAudioFormat::SignedInt && sample_size == 16) {
159+
}
160+
} else if (sample_type == QAudioFormat::SignedInt && sample_size == 16) {
161+
for (int i = 0; i < frame_length; i++) {
160162
audio_data_16bit[i] = static_cast<int16_t>((static_cast<quint16>(AudioBuffer[p + i * 2 + 1]) * 256) + static_cast<quint8>(AudioBuffer[p + i * 2]));
161-
} else {
163+
}
164+
} else {
165+
for (int i = 0; i < frame_length; i++) {
162166
audio_data_16bit[i] = 0;
163167
}
164168
}
@@ -168,7 +172,7 @@ void VoiceRecorder::handleAudioInputDeviceReadyRead()
168172

169173
SilenceLength = 0;
170174

171-
if (VoiceBuffer.size() > (sample_rate / 1000) * MinVoiceDuration && !VoiceDetected) {
175+
if (!VoiceDetected && VoiceBuffer.size() > (sample_rate / 1000) * MinVoiceDuration) {
172176
VoiceDetected = true;
173177

174178
emit voiceFound();

0 commit comments

Comments
 (0)