您的位置:首页 > 其它

iPhone/iPad 2012/05/14 take care of Audio Unit

2012-05-14 09:09 363 查看
1. something could be done:

* check volume code.

* double check stream format

* try moving buf code outside of render callback

* double check sample rate code

* double check audio session ( like ioBuffer related issue )

2. check volume code ( MixerHost )

终于找到了MixerHost不工作的原因:设置音量的代码与Audio Graph启动的顺序。

[audioMixer startAUGraph];

[audioMixer enableMixerInput:0 isOn:1];

[audioMixer enableMixerInput:1 isOn:1];

[audioMixer setMixerInput:0 gain:10];

[audioMixer setMixerInput:1 gain:10];

[audioMixer setMixerOutputGain:10];

注1:要先启动startAUGraph

注2:音量不能设1.0,太小。

1. something could be done:

* check volume code.

* double check stream format

* try moving buf code outside of render callback

* double check sample rate code

* double check audio session ( like ioBuffer related issue )

2. check volume code ( MixerHost )

终于找到了MixerHost不工作的原因:设置音量的代码与Audio Graph启动的顺序。

[audioMixer startAUGraph];

[audioMixer enableMixerInput:0 isOn:1];

[audioMixer enableMixerInput:1 isOn:1];

[audioMixer setMixerInput:0 gain:10];

[audioMixer setMixerInput:1 gain:10];

[audioMixer setMixerOutputGain:10];

注1:要先启动startAUGraph ( double check,与顺序无关,只和音量有关,原始音量 太小?)

注2:音量不能设1.0,太小。

3. 直接使用IO Unit,注意以下问题:

* 音量如何控制? ( 直接把 sample * N ???

* 使用voip unit ?

* Audio Session的IO Buffer控制?

4. 做一些确认实验(MixerHost)

5. IO Unit

* 音量倍数

音量:直接*10看结果。

10倍,听不见

30/100倍,能听见了,但音量偏小。

Q:如何在API上设音量 ?

300倍 ,音量可观,但音质仍不好,有破响,估计与inNumberFrames=186(readAudioData count = 160)有关。

* 传数据的长度

for (int i=0; i<audioPacketCount; i++) {
outSamplesChannelLeft[i] = ((AudioUnitSampleType) (*samplePtr)) *300;
// 300 times volume
samplePtr ++;
}

audioPacketCount = inNumberFrames,出现啸叫。

* 尝试设置Audio Session ioBuffer

相关资料:


setPreferredIOBufferDuration:error:

Sets the preferred audio I/O buffer duration, in seconds.

- (BOOL)setPreferredIOBufferDuration:(NSTimeInterval)duration error:(NSError **)outError


Parameters


duration

The audio I/O buffer duration, in seconds, that you want to use. The available range for I/O buffer duration is 0.005 through 0.093 s, corresponding to a range of 256 through 4,096 sample frames at 44.1 kHz.
outError

Pass in the address of a
nil
-initialized
NSError
object.
If an error occurs, upon return the
NSError
object describes the error. If you do not want error information, pass in
NULL
.


Return Value


Returns
YES
on success or
NO
on failure.


Discussion


The audio I/O buffer duration is the number of seconds for a single audio input/output cycle. For example, with an I/O buffer duration of 0.005 s, on each audio I/O cycle:

You receive 0.005 s of audio if obtaining input.

You must provide 0.005 s of audio if providing output.

To obtain the actual I/O buffer duration, call the
AudioSessionGetProperty
function
using the
kAudioSessionProperty_CurrentHardwareIOBufferDuration
key
as its inID parameter.

注:改成10ms后,callback的inFrameNumbers仍为186,没有变化。

6. 做一个类,专门处理data的read,及产生186个AudioSampleType的frame

@interface AudioBufferHandler :
NSObject {

int reamainedNumberFrames; // frame number in queue

}

- (void) putAudioDataBytes:(unsigned
char *)data;
- (BOOL) needMoreAudioData;
- (void) getAudioDataAudioSampleType:(AudioUnitSampleType *)data;

@end

注:这里需要一个3*186大小的一个queue,内容是short ( 从RT库里来的一个音频sample)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: