0
votes

I have built an AUGraph with an AUMixer and the audio playback sounds awful when playing out the stream through the callback on iPhone7plus. You can hear the audio and what is being said but it is very scratchy. If I build and run on my iPhone6 it sounds fine.

I also have the setup implemented with a singular AudioUnit without the mixer and that sounds fine on both iPhone7 and iPhone6 but I of course lose the required functionality of the mixer. I am using the same AudioStreamBasicDescription for both setups (the graph with mixer, and the singular audiounit)

Ideas on to why it sounds so bad specifically with the graph on my iPhone7 plus?

My current ASBD:
_pcmASBD    AudioStreamBasicDescription 
mSampleRate Float64 44100
mFormatID   AudioFormatID   1819304813
mFormatFlags    AudioFormatFlags    12
mBytesPerPacket UInt32  4
mFramesPerPacket    UInt32  1
mBytesPerFrame  UInt32  4
mChannelsPerFrame   UInt32  2
mBitsPerChannel UInt32  16
mReserved   UInt32  0

I am doing AAC to PCM conversion and then feeding that data into the AURenderCallback and then finally to the pendingBufferList that is played out by the AudioUnit architecture.

I need to use the Mixer as I want to control volume and such so a singular AudioUnit approach (which doesnt display this error, yet uses the same callback and everything) will not work for me as I prefer not to modulate audio by affecting the raw data stream.

EDIT:

Going to add some more code and thoughts to this to hopefully solve the issue.

I process an incoming stream of AAC using an AudioConverter, this converts to LPCM which I then feed into my AudioBufferList that is being filled during the audiounit graph render proc.

I have noticed that if I go 48Khz (encode then stream) -> 48khz (receive stream, decode, play) it sounds good and my audio render proc shows inNumberFrames of 1024.

If I go 44.1khz -> 48khz it sounds scratchy (my audio unit graph makes is sound the right pitch though because of the sample rate converter I put in) but the audio render proc shows inNumberFrames as 941 or 940

I feel like this might be what hotpaw2 was talking about but when I set my AudioBufferList's size to a multiple of 4*inNumberFrames its still sounds scratchy.

@hotpaw2?

1

1 Answers

0
votes

Check the hardware sample rate. On many newer iOS devices, the hardware audio sample rate can default to 48000, not 44100, depending on what's plugged in or previously playing audio. If so, and your desired format is for 44100, the resampler will deliver varying and odd length buffers. An Audio Unit callback expecting a fixed or even length buffer might thus glitch.

The way to fix it might be to check the hardware sample rate. If it's 48000, then set your format to the same so no resampling needs to be done. Also make sure all your audio context callback blocks can handle varying and odd length/frameCounts of AudioBufferList buffers.