iOS Audio Unit playback with constant noise

元气小坏坏 提交于 2019-12-11 08:56:57

问题


I am using audio unit for audio playback. I have download the tone generator from http://cocoawithlove.com/2010/10/ios-tone-generator-introduction-to.html and try to play around with it. For some reason I need to use ulaw instead of linear PCM. Here is my audio format setup:

AudioStreamBasicDescription streamFormat;
streamFormat.mSampleRate = 8000;
streamFormat.mFormatID = kAudioFormatULaw;
streamFormat.mFormatFlags = 0;
streamFormat.mFramesPerPacket = 1;
streamFormat.mBytesPerFrame = 2;
streamFormat.mBytesPerPacket = streamFormat.mBytesPerFrame;
streamFormat.mChannelsPerFrame = 1;
streamFormat.mBitsPerChannel = 16;

When I run the sample code, I get a constant noise. Does anyone could help on this issue? Thanks a lot.


回答1:


You can use only linearPCM format using Audio Units. Even kAudioUnitType_FormatConverter provides conversions betwean linearPCM formats (with different sample rate, bytesPerPacket, etc). To convert from compressed format you should use AudioConverter.

https://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/AudioConverterServicesReference/Reference/reference.html




回答2:


If you want to use another codec different from Linear PCM, you will need to avoid Audio Units, since they only support Linear PCM.

However, you can use Audio Queues, they support ULaw, ALaw, among others. If latency is not an issue, use audio queues.



来源:https://stackoverflow.com/questions/8426967/ios-audio-unit-playback-with-constant-noise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!