gpt4 book ai didi

IOS iPhone 设置 kAudioSessionProperty_PreferredHardwareIOBufferDuration 似乎不起作用

转载 作者:行者123 更新时间:2023-11-29 04:49:55 24 4
gpt4 key购买 nike

这里是一些设置音频捕获缓冲区大小(以秒为单位)的代码

union 
{
OSStatus propertyResult;
char a[4];
} u;

union
{
UInt32 UI32sessionCat;
char a[4];
} usc;

UInt32 UI32sessionCatSize = 4;
Float32 F32realIOBufferDuration = 0.0;
Float32 F32requestedIOBufferDuration = 0.5;
UInt32 F32datasize = 4;

u.propertyResult = AudioSessionGetProperty ( kAudioSessionProperty_PreferredHardwareIOBufferDuration , &F32datasize, &F32realIOBufferDuration );
NSLog(@"Error Get IO Duration Time %ld %lx %c%c%c%c",u.propertyResult,u.propertyResult,u.a[3],u.a[2],u.a[1],u.a[0]);
NSLog(@"IO Buffer Duration is %f",F32realIOBufferDuration);

u.propertyResult = AudioSessionSetProperty ( kAudioSessionProperty_PreferredHardwareIOBufferDuration ,sizeof(F32requestedIOBufferDuration) , &F32requestedIOBufferDuration );
NSLog(@"Error Set IO Duration Time %ld %lx %c%c%c%c",u.propertyResult,u.propertyResult,u.a[3],u.a[2],u.a[1],u.a[0]);

u.propertyResult = AudioSessionGetProperty ( kAudioSessionProperty_PreferredHardwareIOBufferDuration , &F32datasize, &F32realIOBufferDuration );
NSLog(@"Error Get IO Duration Time %ld %lx %c%c%c%c",u.propertyResult,u.propertyResult,u.a[3],u.a[2],u.a[1],u.a[0]);
NSLog(@"IO Buffer Duration is %f",F32realIOBufferDuration);

u.propertyResult = AudioSessionGetProperty ( kAudioSessionProperty_AudioCategory, &UI32sessionCatSize, &usc.UI32sessionCat );
NSLog(@"Error Get Property %ld %lx %c%c%c%c",u.propertyResult,u.propertyResult,u.a[3],u.a[2],u.a[1],u.a[0]);
NSLog(@"Category %ld %lx %c%c%c%c",usc.UI32sessionCat,usc.UI32sessionCat,usc.a[3],usc.a[2],usc.a[1],usc.a[0]);

这似乎有效/设置持续时间...

2012-01-25 12:28:01.275 recordonlytest[1623:707] Error Get IO Duration Time 0 0 
2012-01-25 12:28:01.276 recordonlytest[1623:707] IO Buffer Duration is 0.023000
2012-01-25 12:28:01.278 recordonlytest[1623:707] Error Set IO Duration Time 0 0
2012-01-25 12:28:01.280 recordonlytest[1623:707] Error Get IO Duration Time 0 0
2012-01-25 12:28:01.281 recordonlytest[1623:707] IO Buffer Duration is 0.500000
2012-01-25 12:28:01.283 recordonlytest[1623:707] Error Get Property 0 0
2012-01-25 12:28:01.284 recordonlytest[1623:707] Category 1919247201 72656361 reca

您可以看到 get 属性确实返回 0.50000

但是回调仍然以 0.023000 的速度发生

2012-01-25 12:28:04.035 recordonlytest[1623:707] In Capture Output
2012-01-25 12:28:04.058 recordonlytest[1623:707] In Capture Output
2012-01-25 12:28:04.081 recordonlytest[1623:707] In Capture Output
2012-01-25 12:28:04.104 recordonlytest[1623:707] In Capture Output
2012-01-25 12:28:04.128 recordonlytest[1623:707] In Capture Output
2012-01-25 12:28:04.151 recordonlytest[1623:707] In Capture Output
2012-01-25 12:28:04.174 recordonlytest[1623:707] In Capture Output
2012-01-25 12:28:04.197 recordonlytest[1623:707] In Capture Output
2012-01-25 12:28:04.220 recordonlytest[1623:707] In Capture Output
2012-01-25 12:28:04.244 recordonlytest[1623:707] In Capture Output

正在设置

 [self getRequestedSampleRate];  // routine to set the duration

NSError* activationError = nil;

[[AVAudioSession sharedInstance] setActive: YES error: &activationError];

audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
captureSession = [[AVCaptureSession alloc] init];

那么是否需要执行不同的顺序等,或者 IOS 只是忽略此请求?

最佳答案

来自here :

虽然无论 session 激活状态如何,设置 Audio Session 属性(例如音频类别 (kAudioSessionProperty_AudioCategory) 或属性监听器)都是安全的,但通常最好提出首选项请求,例如首选硬件缓冲区持续时间 (kAudioSessionProperty_PreferredHardwareIOBufferDuration) 或首选硬件 Audio Session 未激活时的采样率 (kAudioSessionProperty_PreferredHardwareSampleRate)。

您可能错过了:

//* 在请求“当前”属性之前激活 Audio Session *AudioSessionSetActive(true);

关于IOS iPhone 设置 kAudioSessionProperty_PreferredHardwareIOBufferDuration 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9007362/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com