iPhone音频录制设置采样率似乎不起作用

时间:2011-11-04 14:09:36

标签: iphone audio-recording

在音频录制中设置采样率时,似乎即使IOS表示采样率为8000k,它似乎也会返回44100k的数据。这是来自IOS 5 iPHone,但在IOS 4.x上也是如此

代码部分如下

 NSLog(@"Requested Sample Rate is %f",F64sampleRate);            
 u.propertyResult = AudioSessionSetProperty (  kAudioSessionProperty_PreferredHardwareSampleRate ,sizeof(F64sampleRate) , &F64sampleRate );
 NSLog(@"Set Error Set Sample Rate %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_CurrentHardwareSampleRate , &F64datasize, &F64realSampleRate );
 NSLog(@"Set Error Get Sample Rate %ld %lx %c%c%c%c",u.propertyResult,u.propertyResult,u.a[3],u.a[2],u.a[1],u.a[0]);
 NSLog(@"Sample Rate is %f",F64realSampleRate);

调试输出如下

2011-11-04 09:57:46.003 MyCode[634:707] Set Error Get Sample Rate 0 0 
2011-11-04 09:57:46.063 MyCode[634:707] Sample Rate is 8000.000000
2011-11-04 09:57:46.067 MyCode[634:707] Requested Sample Rate is 8000.000000
2011-11-04 09:57:46.085 MyCode[634:707] Set Error Set Sample Rate 0 0 
2011-11-04 09:57:46.105 MyCode[634:707] Set Error Get Sample Rate 0 0 
2011-11-04 09:57:46.109 MyCode[634:707] Sample Rate is 8000.000000
2011-11-04 09:57:46.112 MyCode[634:707] Sample Rate Will Be 8000
2011-11-04 09:57:46.115 MyCode[634:707] Set Error Get Property 0 0 
2011-11-04 09:57:46.119 MyCode[634:707] Category 1919247201 72656361 reca
2011-11-04 09:57:46.122 MyCode[634:707] Set Error Get Sample Rate 0 0 
2011-11-04 09:57:46.126 MyCode[634:707] IO Buffer Duration is 0.023000

数据回调如下,请注意缓冲区长度,请忽略其他数字。

 2011-11-04 09:57:47.808 MyCode[634:707] buffsize 16000, bytesleftinbuffer 16000, bytestocopy 2048, bufferlength 2048
 2011-11-04 09:57:47.812 MyCode[634:707] buffsize 16000, bytesleftinbuffer 13952, byte stocopy 2048, bufferlength 2048
 2011-11-04 09:57:47.818 MyCode[634:707] buffsize 16000, bytesleftinbuffer 11904, bytestocopy 2048, bufferlength 2048
 2011-11-04 09:57:47.824 MyCode[634:707] buffsize 16000, bytesleftinbuffer 9856, bytestocopy 2048, bufferlength 2048
 2011-11-04 09:57:47.829 MyCode[634:707] buffsize 16000, bytesleftinbuffer 7808, bytestocopy 2048, bufferlength 2048
 2011-11-04 09:57:47.834 MyCode[634:707] buffsize 16000, bytesleftinbuffer 5760, bytestocopy 2048, bufferlength 2048
 2011-11-04 09:57:47.839 MyCode[634:707] buffsize 16000, bytesleftinbuffer 3712, bytestocopy 2048, bufferlength 2048
 2011-11-04 09:57:47.843 MyCode[634:707] buffsize 16000, bytesleftinbuffer 1664, bytestocopy 1664, bufferlength 2048

所以,我们在这里做一些计算......

缓冲回调时间(采样时间)为0.023秒或约43.5次/秒

  • 通过调试时间和获取属性信息确认

缓冲区回调样本大小为1024(总缓冲区大小为2048)

所以1024 * 43 = 44032接近44100

所以,除非我在这里遗漏了一些东西,即使IOS说它是8000k,它看起来要回拨44100k。

任何人都有这方面的经验吗?

0 个答案:

没有答案