|
12 | 12 |
|
13 | 13 | #include <iostream> |
14 | 14 | #import "TIoTPCMXEchoRecord.h" |
15 | | -#import <SoundTouchiOS/ijksoundtouch_wrap.h> |
| 15 | +//#import <SoundTouchiOS/ijksoundtouch_wrap.h> |
| 16 | +#import <SoundTouchiOS/TRAESoundTouch.h> |
16 | 17 |
|
17 | 18 | __weak static TIoTAVCaptionFLV *tAVCaptionFLV = nil; |
18 | 19 | static flv_muxer_t* flvMuxer = nullptr; |
19 | 20 | dispatch_queue_t muxerQueue; |
20 | 21 | //NSFileHandle *_fileHandle; |
21 | | - |
| 22 | +//NSFileHandle *_originfileHandle; |
22 | 23 | @interface TIoTAVCaptionFLV ()<AVCaptureVideoDataOutputSampleBufferDelegate,AVCaptureAudioDataOutputSampleBufferDelegate,H264EncoderDelegate,TIoTAACEncoderDelegate> |
23 | 24 | // 负责输如何输出设备之间的数据传递 |
24 | 25 | @property (nonatomic, strong) AVCaptureSession *session; |
@@ -349,35 +350,35 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM |
349 | 350 |
|
350 | 351 | #pragma mark - PCM XEcho record_callback |
351 | 352 | void *ijk_soundtouch_handle = NULL; |
| 353 | +//trae_voice_changer_t *trae_voice_handle = NULL; |
352 | 354 | - (void)setPitch:(int)pitch { |
353 | | - _pitch = ((pitch >= -12) && (pitch <= 12 ))?pitch:-6; |
| 355 | + _pitch = ((pitch >= 0) && (pitch <= 3 ))?pitch:2; //0 NONE 2萝莉,3 大叔 |
354 | 356 | NSLog(@"设置变调参数:%d<===>修正为:%d",pitch, _pitch); |
355 | 357 | int tmpChannel = _channel; |
356 | | - |
357 | | - if (ijk_soundtouch_handle != NULL) { |
358 | | - ijk_soundtouch_destroy(ijk_soundtouch_handle); |
359 | | - } |
360 | | - ijk_soundtouch_handle = ijk_soundtouch_create(1.0, _pitch, tmpChannel, 16000); |
| 358 | + |
| 359 | + [TRAESoundTouch voice_handle_open:_pitch channels:tmpChannel]; |
361 | 360 | } |
362 | 361 |
|
| 362 | +static uint8_t trae_pcm_buffer[640]; |
363 | 363 | static void record_callback(uint8_t *buffer, int size, void *u) |
364 | 364 | { |
365 | | -// printf("pcm_size_callback: %d\n", size); |
366 | | - int ret_len = size; |
367 | | - // Sets pitch change in semi-tones compared to the original pitch |
368 | | - // (-12 .. +12) |
| 365 | +// NSData *oridata = [NSData dataWithBytes:buffer length:size]; |
| 366 | +// [_originfileHandle writeData:oridata]; |
| 367 | + |
369 | 368 | TIoTAVCaptionFLV *vc = (__bridge TIoTAVCaptionFLV *)(u); |
| 369 | + memset(trae_pcm_buffer, 0, 640); |
| 370 | + UInt32 len = [vc.pcmRecord getData:trae_pcm_buffer :640]; |
| 371 | + if (len < 640) { |
| 372 | + return; |
| 373 | + } |
370 | 374 | if (vc.pitch != 0) { |
371 | 375 | static int tmpChannel = vc.pcmRecord.pcmStreamDescription.mChannelsPerFrame; |
372 | | - ret_len = ijk_soundtouch_translate(ijk_soundtouch_handle, (short *)buffer, size/2, 2, tmpChannel); |
373 | | - if (ret_len<1) { |
374 | | - return; |
375 | | - } |
| 376 | +// int put_n_sample = (size/2) / tmpChannel; |
| 377 | +// [TRAESoundTouch voice_handle_process:(short *)buffer output:(short *)trae_pcm_buffer frames:320]; |
| 378 | + [TRAESoundTouch voice_handle_process:(short *)trae_pcm_buffer output:(short *)trae_pcm_buffer frames:320]; |
376 | 379 | } |
377 | | -// printf("pcm_size_callback_translate: %d\n", ret_len); |
378 | | - |
379 | 380 |
|
380 | | - NSData *data = [NSData dataWithBytes:buffer length:ret_len]; |
| 381 | + NSData *data = [NSData dataWithBytes:trae_pcm_buffer length:640]; |
381 | 382 | // [_fileHandle writeData:data]; |
382 | 383 | [vc.aacEncoder encodePCMData:data]; |
383 | 384 | } |
@@ -510,11 +511,17 @@ -(BOOL) startCapture { |
510 | 511 | // NSFileManager *fileManager = [NSFileManager defaultManager]; |
511 | 512 | // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
512 | 513 | // NSString *documentsDirectory = [paths firstObject]; |
513 | | - |
514 | | -// NSString *h264File = [documentsDirectory stringByAppendingPathComponent:@"lyh.pcm"]; |
| 514 | +// |
| 515 | +// NSString *h264File = [documentsDirectory stringByAppendingPathComponent:@"out.pcm"]; |
515 | 516 | // [fileManager removeItemAtPath:h264File error:nil]; |
516 | 517 | // [fileManager createFileAtPath:h264File contents:nil attributes:nil]; |
517 | 518 | // _fileHandle = [NSFileHandle fileHandleForWritingAtPath:h264File]; |
| 519 | +// |
| 520 | +// |
| 521 | +// NSString *originFile = [documentsDirectory stringByAppendingPathComponent:@"origin.pcm"]; |
| 522 | +// [fileManager removeItemAtPath:originFile error:nil]; |
| 523 | +// [fileManager createFileAtPath:originFile contents:nil attributes:nil]; |
| 524 | +// _originfileHandle = [NSFileHandle fileHandleForWritingAtPath:originFile]; |
518 | 525 |
|
519 | 526 | flv_init_load(); |
520 | 527 |
|
|
0 commit comments