Migrate audio pipeline to float from 16-bit integer (#2873)

Co-authored-by: Cameron Gutman <aicommander@gmail.com>
This commit is contained in:
ns6089
2024-07-26 04:01:43 +03:00
committed by GitHub
parent aa2cf8e5a9
commit f4dda21248
9 changed files with 435 additions and 298 deletions

View File

@@ -8,7 +8,7 @@
#include "third-party/TPCircularBuffer/TPCircularBuffer.h"
#define kBufferLength 2048
#define kBufferLength 4096
@interface AVAudio: NSObject <AVCaptureAudioDataOutputSampleBufferDelegate> {
@public

View File

@@ -87,8 +87,8 @@
(NSString *) AVFormatIDKey: [NSNumber numberWithUnsignedInt:kAudioFormatLinearPCM],
(NSString *) AVSampleRateKey: [NSNumber numberWithUnsignedInt:sampleRate],
(NSString *) AVNumberOfChannelsKey: [NSNumber numberWithUnsignedInt:channels],
(NSString *) AVLinearPCMBitDepthKey: [NSNumber numberWithUnsignedInt:16],
(NSString *) AVLinearPCMIsFloatKey: @NO,
(NSString *) AVLinearPCMBitDepthKey: [NSNumber numberWithUnsignedInt:32],
(NSString *) AVLinearPCMIsFloatKey: @YES,
(NSString *) AVLinearPCMIsNonInterleaved: @NO
}];

View File

@@ -19,23 +19,23 @@ namespace platf {
}
capture_e
sample(std::vector<std::int16_t> &sample_in) override {
sample(std::vector<float> &sample_in) override {
auto sample_size = sample_in.size();
uint32_t length = 0;
void *byteSampleBuffer = TPCircularBufferTail(&av_audio_capture->audioSampleBuffer, &length);
while (length < sample_size * sizeof(std::int16_t)) {
while (length < sample_size * sizeof(float)) {
[av_audio_capture.samplesArrivedSignal wait];
byteSampleBuffer = TPCircularBufferTail(&av_audio_capture->audioSampleBuffer, &length);
}
const int16_t *sampleBuffer = (int16_t *) byteSampleBuffer;
std::vector<int16_t> vectorBuffer(sampleBuffer, sampleBuffer + sample_size);
const float *sampleBuffer = (float *) byteSampleBuffer;
std::vector<float> vectorBuffer(sampleBuffer, sampleBuffer + sample_size);
std::copy_n(std::begin(vectorBuffer), sample_size, std::begin(sample_in));
TPCircularBufferConsume(&av_audio_capture->audioSampleBuffer, sample_size * sizeof(std::int16_t));
TPCircularBufferConsume(&av_audio_capture->audioSampleBuffer, sample_size * sizeof(float));
return capture_e::ok;
}