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

  • Home
  • SEARCH
  • 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 8336257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:55:40+00:00 2026-06-09T03:55:40+00:00

My app basically plays notes after each other and I want to show which

  • 0

My app basically plays notes after each other and I want to show which note is being played at each time. Each note is a square in the UI and I have a 1-pixel view that moves from left to right to the note that is being played.

The problem is that I’m not sure how to do these two things at the same time. I can’t send a message from my sample-rendering function because that could be to slow and could cause glitches in my audio playback. Does anyone have any suggestions how I should update my UI to reflect what is being played?

My music playing code is based on this example and I think that the RenderTone method is run in a different thread. I want to move my 1-pixel view 1 pixel every time 1000 samples have been played (just an example, could also be more pr less) but I don’t know how to message the UI and send it updates on how many samples have been played.

So while a variation of the code below is being run I have to somehow update my UI.

OSStatus RenderTone(
    void *inRefCon, 
    AudioUnitRenderActionFlags *ioActionFlags, 
    const AudioTimeStamp *inTimeStamp, 
    UInt32 inBusNumber, 
    UInt32 inNumberFrames, 
    AudioBufferList *ioData)

{
    // Fixed amplitude is good enough for our purposes
    const double amplitude = 0.25;

    // Get the tone parameters out of the view controller
    ToneGeneratorViewController *viewController =
        (ToneGeneratorViewController *)inRefCon;
    double theta = viewController->theta;
    double theta_increment =
        2.0 * M_PI * viewController->frequency / viewController->sampleRate;

    // This is a mono tone generator so we only need the first buffer
    const int channel = 0;
    Float32 *buffer = (Float32 *)ioData->mBuffers[channel].mData;

    // Generate the samples
    for (UInt32 frame = 0; frame < inNumberFrames; frame++) 
    {
        buffer[frame] = sin(theta) * amplitude;

        theta += theta_increment;
        if (theta > 2.0 * M_PI)
        {
            theta -= 2.0 * M_PI;
        }
    }

    // Store the updated theta back in the view controller
    viewController->theta = theta;

    return noErr;
}
  • 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-06-09T03:55:43+00:00Added an answer on June 9, 2026 at 3:55 am

    I would suggest that as various times in this code you use a simple block back to the main thread:

    dispatch_async(dispatch_get_main_queue(), ^{ someViewController makeSomeChange:withParam; } );
    

    You can send those infrequently. You can run your RenderTone code in the highPriority queue so the mainQueue is only run when you have no essential work to do.

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

Sidebar

Related Questions

I'm making a Android app that basically plays video from a website on the
How can I build an android app which basically get the inputs from user
I have a need for a model(?) on my app which basically contains a
i want to change the locale programmatically in my iphone app (basically because not
Some time ago i saw an app on the market which had an option
I have a small app which runs in background doing some tasks which basically
Ok, so I want to implement tags in my play 2.0 app, Basically what
Im going to write some android app, which will basically consists of two activities.
So my app is basically a shell with a ContentControl that I populate with
I created a native Android app that basically hosts a webView control. That webView

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.