Skip to content

Commit fbb9538

Browse files
tonychanchenoldcodefarmer
authored andcommitted
添加pcm变调操作
Change-Id: Iea7f102eea7283b82709bf607e8a311171561492 (cherry picked from commit f3b184c)
1 parent de3c48c commit fbb9538

File tree

7 files changed

+38
-5
lines changed

7 files changed

+38
-5
lines changed

Podfile.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ PODS:
3131
- YYModel (= 1.0.4)
3232
- TIoTLinkKit_FLV (2.2.3)
3333
- TIoTLinkKit_IJKPlayer (2.0.7)
34+
- TIoTLinkKit_SoundTouch (0.0.3)
3435
- TIoTLinkKit_TPNS (1.0.1)
3536
- TIoTLinkKit_WechatOpenSDK (1.0.1)
3637
- TIoTLinkKit_XP2P (2.4.27)
3738
- TIoTLinkVideo (1.0.0):
3839
- CocoaAsyncSocket (= 7.6.5)
3940
- TIoTLinkKit_FLV (= 2.2.3)
41+
- TIoTLinkKit_SoundTouch (= 0.0.3)
4042
- TIoTLinkKit_XP2P (= 2.4.27)
4143
- TrueTime (5.0.3)
4244
- TXLiteAVSDK_TRTC (8.0.9644)
@@ -87,6 +89,7 @@ SPEC REPOS:
8789
- Tencent-MapSDK
8890
- TIoTLinkKit_FLV
8991
- TIoTLinkKit_IJKPlayer
92+
- TIoTLinkKit_SoundTouch
9093
- TIoTLinkKit_TPNS
9194
- TIoTLinkKit_WechatOpenSDK
9295
- TIoTLinkKit_XP2P
@@ -120,10 +123,11 @@ SPEC CHECKSUMS:
120123
TIoTLinkKit: 0386fb583c61765a02ad5cca810c7661d5a0bc53
121124
TIoTLinkKit_FLV: aec2b2ec9664990ec6c5b9f760fc1a9043d5a9a5
122125
TIoTLinkKit_IJKPlayer: 69e819379a5bbbf2eb956e20fec20249d0497ecd
126+
TIoTLinkKit_SoundTouch: 56caa7c7f60e3b98eecc26f003cf7b770c37bd15
123127
TIoTLinkKit_TPNS: 7cea4fc1d20ef6c4c11c4f0b66bbb10ecf4ed968
124128
TIoTLinkKit_WechatOpenSDK: 7822d68cc5c46edf3f6020422202e7b65ea87614
125129
TIoTLinkKit_XP2P: 645a54568e9ecd9915c392a2bd07413a5a79c72f
126-
TIoTLinkVideo: 2be39eb99a6c39e21a390302b50d4b36e1fcd4e3
130+
TIoTLinkVideo: c75b476428d71dab49f368faeaa57faa98017d90
127131
TrueTime: b49551ffafb28a9dee04e51b226f42a416010842
128132
TXLiteAVSDK_TRTC: e3383a81565e8bb2aaaaab4bd099ad5239cd5b2d
129133
TZImagePickerController: bf4c57b98d8707fce41ea6be872414a71c7a8c9d

Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoPreviewDeviceVC.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ - (void)viewDidLoad {
107107
// [TIoTCoreXP2PBridge sharedInstance].logEnable = NO;
108108
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
109109

110-
self.qualityString = quality_high;
110+
self.qualityString = quality_standard;
111111
self.screenRect = [UIApplication sharedApplication].delegate.window.frame;
112112

113113
if (self.isNVR == NO) {
@@ -261,7 +261,8 @@ - (void)getDeviceStatusWithType:(NSString *)singleType qualityType:(NSString *)q
261261
TIoTCoreAudioConfig *audio_config = [TIoTCoreAudioConfig new];
262262
audio_config.sampleRate = TIoTAVCaptionFLVAudio_8;
263263
audio_config.channels = 1;
264-
audio_config.isEchoCancel = NO;
264+
audio_config.isEchoCancel = YES;
265+
audio_config.pitch = -6; //声音会变粗一点
265266

266267
TIoTCoreVideoConfig *video_config = [TIoTCoreVideoConfig new];
267268
video_config.localView = nil;

Source/SDK/LinkVideo/FLV/TIoTAVCaptionFLV.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@property (nonatomic, weak) id<TIoTAVCaptionFLVDelegate> delegate;
1313
@property (nonatomic, assign)UIView *videoLocalView;
1414
@property (nonatomic, assign)BOOL isEchoCancel;
15+
@property (nonatomic, assign)int pitch;
1516
@property (nonatomic, assign)AVCaptureDevicePosition devicePosition;
1617
-(instancetype) initWithAudioConfig:(TIoTAVCaptionFLVAudioType)audioSampleRate channel:(int)channel;
1718

Source/SDK/LinkVideo/FLV/TIoTAVCaptionFLV.mm

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <iostream>
1414
#import "TIoTPCMXEchoRecord.h"
15+
#include "ijksoundtouch_wrap.h"
1516

1617
__weak static TIoTAVCaptionFLV *tAVCaptionFLV = nil;
1718
static flv_muxer_t* flvMuxer = nullptr;
@@ -48,6 +49,7 @@ -(instancetype) initWithAudioConfig:(TIoTAVCaptionFLVAudioType)audioSampleRate c
4849
_audioRate = audioSampleRate;
4950
_channel = channel;
5051
_isEchoCancel = NO;
52+
_pitch = 0;
5153
_devicePosition = AVCaptureDevicePositionBack;
5254
[self onInit];
5355
}
@@ -320,9 +322,25 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM
320322
#pragma mark - PCM XEcho record_callback
321323
static void record_callback(uint8_t *buffer, int size, void *u)
322324
{
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)
323329
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);
324340

325-
NSData *data = [NSData dataWithBytes:buffer length:size];
341+
342+
NSData *data = [NSData dataWithBytes:buffer length:ret_len];
343+
// [_fileHandle writeData:data];
326344
[vc.aacEncoder encodePCMData:data];
327345
}
328346

@@ -455,7 +473,7 @@ -(BOOL) startCapture {
455473
// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
456474
// NSString *documentsDirectory = [paths firstObject];
457475

458-
// NSString *h264File = [documentsDirectory stringByAppendingPathComponent:@"lyh.aac"];
476+
// NSString *h264File = [documentsDirectory stringByAppendingPathComponent:@"lyh.pcm"];
459477
// [fileManager removeItemAtPath:h264File error:nil];
460478
// [fileManager createFileAtPath:h264File contents:nil attributes:nil];
461479
// _fileHandle = [NSFileHandle fileHandleForWritingAtPath:h264File];

Source/SDK/LinkVideo/TIoTCoreAudioConfig.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ typedef NS_ENUM(NSInteger, TIoTAVCaptionFLVAudioType) {
3030
*/
3131
@property (nonatomic,assign) BOOL isEchoCancel;
3232

33+
/**
34+
* 是否变声, Sets pitch change in semi-tones compared to the original pitch
35+
* (-12 .. +12),默认为0不变声
36+
*/
37+
@property (nonatomic,assign) int pitch;
38+
3339
@end
3440

3541
NS_ASSUME_NONNULL_END

Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ - (void)sendVoiceToServer:(NSString *)dev_name channel:(NSString *)channel_numbe
323323
audio_config.sampleRate = audio_rate;
324324
audio_config.channels = 1;
325325
audio_config.isEchoCancel = isEchoCancel;
326+
audio_config.pitch = 0;
326327

327328
TIoTCoreVideoConfig *video_config = [TIoTCoreVideoConfig new];
328329
video_config.localView = localView;
@@ -347,6 +348,7 @@ - (void)sendVoiceToServer:(NSString *)dev_name channel:(NSString *)channel_numbe
347348
systemAvCapture = [[TIoTAVCaptionFLV alloc] initWithAudioConfig:audio_config.sampleRate channel:audio_config.channels];
348349
systemAvCapture.videoLocalView = video_config.localView;
349350
systemAvCapture.isEchoCancel = audio_config.isEchoCancel;
351+
systemAvCapture.pitch = audio_config.pitch;
350352
}
351353
systemAvCapture.devicePosition = video_config.videoPosition;
352354
systemAvCapture.videoLocalView = video_config.localView;

TIoTLinkVideo.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Pod::Spec.new do |s|
2121
s.dependency 'TIoTLinkKit_XP2P', '2.4.27' #~> 2.4.21-beta.202202101145
2222
s.dependency 'TIoTLinkKit_FLV', '2.2.3'
2323
s.dependency 'CocoaAsyncSocket', '7.6.5'
24+
s.dependency 'TIoTLinkKit_SoundTouch', '0.0.3'
2425

2526
s.pod_target_xcconfig = {
2627
'VALID_ARCHS' => 'arm64'

0 commit comments

Comments
 (0)