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
相关资料:
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
If an error occurs, upon return the
Return Value
Returns
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
using the
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)
* 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
NSErrorobject.
If an error occurs, upon return the
NSErrorobject describes the error. If you do not want error information, pass in
NULL.
Return Value
Returns
YESon success or
NOon 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
AudioSessionGetPropertyfunction
using the
kAudioSessionProperty_CurrentHardwareIOBufferDurationkey
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)
相关文章推荐
- iPhone/iPad Audio Unit 2012/05/19
- iphone/iPad 搞定Audio Unit 2012/05/13
- iPhone/iPad Audio Unit声音播放
- UC故事+iPhone/iPad Audio Unit 2012/05/17
- iPhone/iPad开发札记2012/03/11 -2 Audio Unit
- iPhone/iPad搞定Audio Unit声音 2012/05/15
- UC故事与iPhone/iPad Audio Unit 2012/05/16
- Take care of the Details
- Take care of fopen
- Take good care of your eyes
- [2010/09/29]爱护牙齿Take Care of Your Teeth
- 【tcpdump】 especially take care of -s
- Take care of Segments before entering C programmed binaries
- Transfer big amount of data to iPhone/iPad
- well,take care of yourself!
- TAKE CARE OF PERMISSIONS!
- iPhone/iPad开发扎记 2012/02/11 - 玩转iOS Audio Service
- Take care on the encoding of web server
- take care of my eyes --感人小故事
- (iPhone/iPad开发)how to browse the document directory of iOS Devices