This commit is contained in:
2026-01-22 13:47:34 +08:00
parent 06a572c08a
commit edc25c159d
10 changed files with 2308 additions and 7 deletions

View File

@@ -179,6 +179,11 @@ static const float kAudioSoftwareGain = 2.5f;
}
// Int16
if (!outputBuffer.int16ChannelData) {
NSLog(@"[AudioCaptureManager] Int16 channel data is null");
return;
}
int16_t *samples = (int16_t *)outputBuffer.int16ChannelData[0];
NSUInteger sampleCount = outputBuffer.frameLength;
NSUInteger byteCount = sampleCount * sizeof(int16_t);
@@ -189,13 +194,20 @@ static const float kAudioSoftwareGain = 2.5f;
[self calculateAndReportRMS:samples sampleCount:sampleCount];
[self logAudioStatsIfNeeded:samples sampleCount:sampleCount];
if (byteCount == 0) {
return;
}
NSData *pcmData = [NSData dataWithBytes:samples length:byteCount];
// ring buffer
dispatch_async(self.audioQueue, ^{
[self appendToRingBuffer:samples byteCount:byteCount];
[self appendToRingBuffer:(const uint8_t *)pcmData.bytes
byteCount:pcmData.length];
});
}
- (void)appendToRingBuffer:(int16_t *)samples byteCount:(NSUInteger)byteCount {
- (void)appendToRingBuffer:(const uint8_t *)bytes byteCount:(NSUInteger)byteCount {
// ring buffer
uint8_t *ringBufferBytes = (uint8_t *)self.ringBuffer.mutableBytes;
NSUInteger ringBufferLength = self.ringBuffer.length;
@@ -208,7 +220,7 @@ static const float kAudioSoftwareGain = 2.5f;
NSUInteger copySize = MIN(bytesToCopy, spaceAvailable);
memcpy(ringBufferBytes + self.ringBufferWriteIndex,
(uint8_t *)samples + sourceOffset, copySize);
bytes + sourceOffset, copySize);
self.ringBufferWriteIndex += copySize;
sourceOffset += copySize;
bytesToCopy -= copySize;