• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: MixerHost sample code mono file output
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MixerHost sample code mono file output


  • Subject: Re: MixerHost sample code mono file output
  • From: Alexandre Trottier <email@hidden>
  • Date: Wed, 11 Apr 2012 15:04:38 -0400

Hi,

I do this in my AUGraph's input callback, maybe someone else has a better/cleaner approach:

void MultiplyFirstChannelInAudioBufferList(AudioBufferList *audioBufferList, 
                                           UInt32 bytesPerFrame)
{
    UInt32 numberOfBuffers = audioBufferList->mNumberBuffers;

    

    if (numberOfBuffers == 1) {
        AudioBuffer *audioBuffer = &audioBufferList->mBuffers[0];
        UInt32 numberOfChannels = audioBuffer->mNumberChannels;

        if (numberOfChannels > 1) {
            UInt32 bytesPerMultiChannelFrame = numberOfChannels * bytesPerFrame;
            UInt32 numberOfMultiChannelFrames = audioBuffer->mDataByteSize / bytesPerMultiChannelFrame;

            

            // get the offset for the current frame
            for (NSUInteger multiChannelFrameIndex = 0; multiChannelFrameIndex < numberOfMultiChannelFrames; multiChannelFrameIndex++) {
                NSUInteger frameFirstChannelByteOffset = multiChannelFrameIndex * bytesPerMultiChannelFrame;

                

                // get the offset for the current channel within the current frame
                for (NSUInteger channelIndex = 1; channelIndex < numberOfChannels; channelIndex++) {
                    NSUInteger frameChannelByteOffset = frameFirstChannelByteOffset + channelIndex * bytesPerFrame;

                    

                    // copy the data
                    memcpy((UInt8 *)audioBuffer->mData + frameChannelByteOffset, 
                           (UInt8 *)audioBuffer->mData + frameFirstChannelByteOffset,
                           bytesPerFrame);
                }
            }
        }
    } else if (numberOfBuffers > 0) {
        UInt32 dataByteSize = audioBufferList->mBuffers[0].mDataByteSize;

        

        for (NSUInteger bufferIndex = 1; bufferIndex < numberOfBuffers; bufferIndex++) {
            if (audioBufferList->mBuffers[bufferIndex].mDataByteSize == dataByteSize) {
                memcpy(audioBufferList->mBuffers[bufferIndex].mData,
                       audioBufferList->mBuffers[0].mData,
                       dataByteSize);
            }
        }
    }
}

Cheers,

Alex


On Apr 11, 2012, at 2:51 PM, Robert Carroll wrote:

I am working on a adapting version of the MixerHost sample code for Mac OS instead of IOS. Mostly, this is working, however, the mono audio file only plays back on the left channel in the mac version. In the IOS simulator with the original code, it plays on both left and right channels.

How can I get mono output on both channels for Mac OS?

Very little has been changed from the original sample code. References to AVAudioSession have been removed. At this point, I am not using NSNotifications for audio status changes and the output settings has been changed to the following:

#if TARGET_OS_IPHONE
    iOUnitDescription.componentSubType       = kAudioUnitSubType_RemoteIO;
#else
    iOUnitDescription.componentSubType       = kAudioUnitSubType_DefaultOutput;
#endif
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >MixerHost sample code mono file output (From: Robert Carroll <email@hidden>)

  • Prev by Date: MixerHost sample code mono file output
  • Next by Date: iPod Touch 4G unable to route audio to "Line Out" (iOS 5)
  • Previous by thread: MixerHost sample code mono file output
  • Next by thread: iPod Touch 4G unable to route audio to "Line Out" (iOS 5)
  • Index(es):
    • Date
    • Thread