Convert mono audio input to iOS stereo output

I am trying to route mono audio input to stereo output. I have already looked into this similar question in detail , but there has never been a resolution.

First, I create an AVAudioSession using a category AVAudioSessionCategoryPlayAndRecord

, AVAudioSessionModeHearingAccessibility

and AVAudioSessionCategoryOptionAllowBluetoothA2DP

. Once it is active, I start configuring the I / O.

My mono format:

AudioStreamBasicDescription monoFormat;
monoFormat.mSampleRate = 44100;
monoFormat.mFormatID = kAudioFormatLinearPCM;
monoFormat.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked | kAudioFormatFlagIsNonInterleaved;
monoFormat.mBytesPerPacket = 4;
monoFormat.mFramesPerPacket = 1;
monoFormat.mBytesPerFrame = 4;
monoFormat.mChannelsPerFrame = 1; //mono
monoFormat.mBitsPerChannel = 32;
monoFormat.mReserved = 0;

      

My stereo format:

AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate = 44100;
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked | kAudioFormatFlagIsNonInterleaved;
audioFormat.mBytesPerPacket = 8;
audioFormat.mFramesPerPacket = 1;
audioFormat.mBytesPerFrame = 8;
audioFormat.mChannelsPerFrame = 2;//stereo
audioFormat.mBitsPerChannel = 32;
audioFormat.mReserved = 0;

      

Description of audio components:

    AudioComponentDescription desc;
    desc.componentType = kAudioUnitType_Output;
    desc.componentSubType = kAudioUnitSubType_RemoteIO;
    desc.componentManufacturer = kAudioUnitManufacturer_Apple;
    desc.componentFlags = 0;
    desc.componentFlagsMask = 0;

AudioUnit unit;
AudioComponent comp = AudioComponentFindNext(NULL, &desc);
result = AudioComponentInstanceNew(comp, &rioUnit);
result = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof(one));
result = AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &monoFormat, sizeof(monoFormat));

      

Setting up an input channel map which I assume should convert mono input to stereo output?

SInt32 channelMap[2] = { 0, 0 };
        result = AudioUnitSetProperty(unit,
                                      kAudioOutputUnitProperty_ChannelMap,
                                      kAudioUnitScope_Input,
                                      0 ,
                                      channelMap,
                                      sizeof(channelMap));

result = AudioOutputUnitInitialize(unit);
result = AudioOutputUnitStart(unit);

      

When I run this code, no sound is output and the mono audio input (iPhone microphone) is not converted to stereo. Does any envelope convert? I tried using a mixer but couldn't achieve this.

Is there any other way to copy all audio data from one channel to another?

+3
ios avaudioplayer core-audio audiounit


source to share


No one has answered this question yet

See similar questions:

five
Setting up an iOS audio device with mono input and stereo output

or similar:

7
Can AVAssetReader be used to return a stereo panel?
five
Setting up an iOS audio device with mono input and stereo output
2
How to play audio on a specific output channel on a USB audio interface?
2
CoreAudio Audio Unit only plays one channel of stereo audio
2
Monaural playback output with Core Audio
1
Is there any high-level audio alert recording service library for iOS?
1
AudioUnit kAudioUnitSubType_Reverb2 and kAudioUnitType_FormatConverter
1
Panning a mono signal with MultiChannelMixer & MTAudioProcessingTap
0
CoreAudio, iOS: Unable to use mono input and stereo output with RemoteIO
0
How to make system input from a remote audio I / O device and play this sample in stereo



All Articles
Loading...
X
Show
Funny
Dev
Pics