Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6376495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:45:11+00:00 2026-05-25T01:45:11+00:00

I have a Multichannel Mixer audio unit playing back audio files in an iOS

  • 0

I have a Multichannel Mixer audio unit playing back audio files in an iOS app, and I need to figure out how to update the app’s UI and perform a reset when the render callback hits the end of the longest audio file (which is set up to run on bus 0). As my code below shows I am trying to use KVO to achieve this (using the boolean variable tapesUnderway – the AutoreleasePool is necessary as this Objective-C code is running outside of its normal domain, see http://www.cocoabuilder.com/archive/cocoa/57412-nscfnumber-no-pool-in-place-just-leaking.html).

static OSStatus tapesRenderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
{
    SoundBufferPtr sndbuf = (SoundBufferPtr)inRefCon;

    UInt32 bufferFrames = sndbuf[inBusNumber].numFrames;
    AudioUnitSampleType *in = sndbuf[inBusNumber].data; 

    // These mBuffers are the output buffers and are empty; these two lines are just  setting the references to them (via outA and outB)
    AudioUnitSampleType *outA = (AudioUnitSampleType *)ioData->mBuffers[0].mData;
    AudioUnitSampleType *outB = (AudioUnitSampleType *)ioData->mBuffers[1].mData;

    UInt32 sample = sndbuf[inBusNumber].sampleNum;


    // --------------------------------------------------------------
    // Set the start time here
    if(inBusNumber == 0 && !tapesFirstRenderPast)
    {
        printf("Tapes first render past\n");

        tapesStartSample = inTimeStamp->mSampleTime;
        tapesFirstRenderPast = YES;                     // MAKE SURE TO RESET THIS ON SONG RESTART
        firstPauseSample = tapesStartSample;
    }

    // --------------------------------------------------------------
    // Now process the samples
     for(UInt32 i = 0; i < inNumberFrames; ++i)
     {
         if(inBusNumber == 0)
         {
            // ------------------------------------------------------
            // Bus 0 is the backing track, and is always playing back

            outA[i] = in[sample++];
            outB[i] = in[sample++];     // For stereo set desc.SetAUCanonical to (2, true) and increment samples in both output calls

            lastSample = inTimeStamp->mSampleTime + (Float64)i;     // Set the last played sample in order to compensate for pauses


            // ------------------------------------------------------
            // Use this logic to mark end of tune
            if(sample >= (bufferFrames * 2) && !tapesEndPast)
            {
                // USE KVO TO NOTIFY METHOD OF VALUE CHANGE

                NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
                FuturesEPMedia *futuresMedia = [FuturesEPMedia sharedFuturesEPMedia];
                NSNumber *boolNo = [[NSNumber alloc] initWithBool: NO];
                [futuresMedia setValue: boolNo forKey: @"tapesUnderway"];
                [boolNo release];
                [pool release];

                tapesEndPast = YES;
            }
        }
        else
        {
            // ------------------------------------------------------
            // The other buses are the open sections, and are synched through the tapesSectionsTimes array

            Float64 sectionTime = tapesSectionTimes[inBusNumber] * kGraphSampleRate;        // Section time in samples
            Float64 currentSample = inTimeStamp->mSampleTime + (Float64)i;

            if(!isPaused && !playFirstRenderPast)
            {
                pauseGap += currentSample - firstPauseSample;
                playFirstRenderPast = YES;
                pauseFirstRenderPast = NO;
            }


            if(currentSample > (tapesStartSample + sectionTime + pauseGap) && sample < (bufferFrames * 2))
            {
                outA[i] = in[sample++];
                outB[i] = in[sample++];
            }
            else
            {
                outA[i] = 0;
                outB[i] = 0;
            }
        }
    }

   sndbuf[inBusNumber].sampleNum = sample;

   return noErr;
}

At the moment when this variable is changed it triggers a method in self, but this leads to an unacceptable delay (20-30 seconds) when executed from this render callback (I am thinking because it is Objective-C code running in the high priority audio thread?). How do I effectively trigger such a change without the delay? (The trigger will change a pause button to a play button and call a reset method to prepare for the next play.)

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:45:12+00:00Added an answer on May 25, 2026 at 1:45 am

    Yes. Don’t use objc code in the render thread since its high priority. If you store state in memory (ptr or struct) and then get a timer in the main thread to poll (check) the value(s) in memory. The timer need not be anywhere near as fast as the render thread and will be very accurate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have a n-tire web application and search often times out after 30 secs. How
Have searched the database but need to specifically sum(of hours flown or days off)in
have been trying couple of hours now to make my iphone app universal. The
have Googled the cr*p out of this one so apologies if the answer is
Have a really weird one here. The app has two targets, just to be
Have a simple iPhone app with a single UIViewController and two Views in one
Have a linking (or ref) table which has a dual primary key. Need to
Have an app that can use tts to read text messages. It can also
Have just started to get into CakePHP since a couple of weeks back. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.