|
12 | 12 |
|
13 | 13 | #include <iostream> |
14 | 14 | #import "TIoTPCMXEchoRecord.h" |
| 15 | +#include "ijksoundtouch_wrap.h" |
15 | 16 |
|
16 | 17 | __weak static TIoTAVCaptionFLV *tAVCaptionFLV = nil; |
17 | 18 | static flv_muxer_t* flvMuxer = nullptr; |
@@ -48,6 +49,7 @@ -(instancetype) initWithAudioConfig:(TIoTAVCaptionFLVAudioType)audioSampleRate c |
48 | 49 | _audioRate = audioSampleRate; |
49 | 50 | _channel = channel; |
50 | 51 | _isEchoCancel = NO; |
| 52 | + _pitch = 0; |
51 | 53 | _devicePosition = AVCaptureDevicePositionBack; |
52 | 54 | [self onInit]; |
53 | 55 | } |
@@ -320,9 +322,25 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM |
320 | 322 | #pragma mark - PCM XEcho record_callback |
321 | 323 | static void record_callback(uint8_t *buffer, int size, void *u) |
322 | 324 | { |
| 325 | +// printf("pcm_size_callback: %d\n", size); |
| 326 | + int ret_len = size; |
| 327 | + // Sets pitch change in semi-tones compared to the original pitch |
| 328 | + // (-12 .. +12) |
323 | 329 | TIoTAVCaptionFLV *vc = (__bridge TIoTAVCaptionFLV *)(u); |
| 330 | + if (vc.pitch != 0) { |
| 331 | + static int tmpChannel = vc.pcmRecord.pcmStreamDescription.mChannelsPerFrame; |
| 332 | + static int pitch = ((vc.pitch >= -12) && (vc.pitch <= 12 ))?vc.pitch:-6; |
| 333 | + static void *ijk_soundtouch_handle = ijk_soundtouch_create(1.0, pitch, tmpChannel, 16000); |
| 334 | + ret_len = ijk_soundtouch_translate(ijk_soundtouch_handle, (short *)buffer, size/2, 2, tmpChannel); |
| 335 | + if (ret_len<1) { |
| 336 | + return; |
| 337 | + } |
| 338 | + } |
| 339 | +// printf("pcm_size_callback_translate: %d\n", ret_len); |
324 | 340 |
|
325 | | - NSData *data = [NSData dataWithBytes:buffer length:size]; |
| 341 | + |
| 342 | + NSData *data = [NSData dataWithBytes:buffer length:ret_len]; |
| 343 | +// [_fileHandle writeData:data]; |
326 | 344 | [vc.aacEncoder encodePCMData:data]; |
327 | 345 | } |
328 | 346 |
|
@@ -455,7 +473,7 @@ -(BOOL) startCapture { |
455 | 473 | // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
456 | 474 | // NSString *documentsDirectory = [paths firstObject]; |
457 | 475 |
|
458 | | -// NSString *h264File = [documentsDirectory stringByAppendingPathComponent:@"lyh.aac"]; |
| 476 | +// NSString *h264File = [documentsDirectory stringByAppendingPathComponent:@"lyh.pcm"]; |
459 | 477 | // [fileManager removeItemAtPath:h264File error:nil]; |
460 | 478 | // [fileManager createFileAtPath:h264File contents:nil attributes:nil]; |
461 | 479 | // _fileHandle = [NSFileHandle fileHandleForWritingAtPath:h264File]; |
|
0 commit comments