Migrate audio pipeline to float from 16-bit integer (#2873)
Co-authored-by: Cameron Gutman <aicommander@gmail.com>
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "third-party/TPCircularBuffer/TPCircularBuffer.h"
|
||||
|
||||
#define kBufferLength 2048
|
||||
#define kBufferLength 4096
|
||||
|
||||
@interface AVAudio: NSObject <AVCaptureAudioDataOutputSampleBufferDelegate> {
|
||||
@public
|
||||
|
||||
@@ -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
|
||||
}];
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user