Skip to content

Commit a86fa4a

Browse files
committed
Remove PCM16 read since unprocessed might fix it...
1 parent 6715e72 commit a86fa4a

1 file changed

Lines changed: 5 additions & 28 deletions

File tree

VoiceCraft.Client/VoiceCraft.Client.Android/Audio/AndroidMiniAudioEngine.cs

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77
using Android.Media;
8-
using Android.OS;
98
using SoundFlow.Abstracts;
109
using SoundFlow.Abstracts.Devices;
1110
using SoundFlow.Backends.MiniAudio.Devices;
1211
using SoundFlow.Backends.MiniAudio.Enums;
1312
using SoundFlow.Enums;
14-
using VoiceCraft.Core.Audio;
1513

1614
namespace VoiceCraft.Client.Android.Audio;
1715

@@ -168,8 +166,6 @@ internal sealed class AndroidAudioCaptureDevice : AudioCaptureDevice
168166
private readonly Lock _lock = new();
169167
private readonly AudioRecord _nativeRecorder;
170168
private readonly float[] _buffer;
171-
private readonly short[] _pcm16Buffer;
172-
private readonly bool _readPcm16;
173169

174170
public AndroidAudioCaptureDevice(
175171
AudioManager audioManager,
@@ -204,15 +200,13 @@ public AndroidAudioCaptureDevice(
204200
var periods = deviceConfig?.Periods > 0 ? deviceConfig.Periods : 3;
205201
var bufferSize = periodFrames * format.Channels;
206202
_buffer = new float[bufferSize];
207-
_readPcm16 = IsGoogleDevice();
208-
_pcm16Buffer = _readPcm16 ? new short[bufferSize] : [];
209203

210204
_nativeRecorder = new AudioRecord(
211205
source,
212206
format.SampleRate,
213207
channelMask,
214-
_readPcm16 ? Encoding.Pcm16bit : Encoding.PcmFloat,
215-
(int)(bufferSize * (_readPcm16 ? sizeof(short) : sizeof(float)) * periods));
208+
Encoding.PcmFloat,
209+
(int)(bufferSize * sizeof(float) * periods));
216210
var device = audioManager.GetDevices(GetDevicesTargets.Inputs)
217211
?.FirstOrDefault(device => device.Id == deviceInfo?.Id);
218212
_nativeRecorder.SetPreferredDevice(device);
@@ -266,16 +260,7 @@ private void RecordingLogic()
266260
{
267261
lock (_lock)
268262
{
269-
if (_readPcm16)
270-
{
271-
read = _nativeRecorder.Read(_pcm16Buffer, 0, _pcm16Buffer.Length, 0);
272-
if (read > 0)
273-
Sample16ToFloat.Read(_pcm16Buffer.AsSpan(0, read), _buffer.AsSpan(0, read));
274-
}
275-
else
276-
{
277-
read = _nativeRecorder.Read(_buffer, 0, _buffer.Length, 0);
278-
}
263+
read = _nativeRecorder.Read(_buffer, 0, _buffer.Length, 0);
279264
}
280265
}
281266
catch (Exception)
@@ -285,20 +270,12 @@ private void RecordingLogic()
285270

286271
if (read <= 0)
287272
continue;
288-
273+
289274
InvokeOnAudioProcessed(_buffer);
290275
}
291276

292277
Stop();
293278
}
294-
295-
private static bool IsGoogleDevice()
296-
{
297-
var manufacturer = Build.Manufacturer ?? string.Empty;
298-
var brand = Build.Brand ?? string.Empty;
299-
return manufacturer.Equals("Google", StringComparison.OrdinalIgnoreCase) ||
300-
brand.Equals("google", StringComparison.OrdinalIgnoreCase);
301-
}
302279
}
303280

304281
internal sealed class AndroidAudioPlaybackDevice : AudioPlaybackDevice
@@ -459,4 +436,4 @@ private static SoundComponentProcessDelegate BuildProcessDelegate()
459436
? throw new InvalidOperationException("SoundFlow process method not found.")
460437
: method.CreateDelegate<SoundComponentProcessDelegate>();
461438
}
462-
}
439+
}

0 commit comments

Comments
 (0)