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

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 thekAudioSessionProperty_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)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值