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 711925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:47:27+00:00 2026-05-14T04:47:27+00:00

I am writing an audio player for OSX. One view is a custom view

  • 0

I am writing an audio player for OSX. One view is a custom view that displays a waveform. The waveform is stored as a instance variable of type NSImage with an NSBitmapImageRep. The view also displays a progress indicator (a thick red line). Therefore, it is updated/redrawn every 30 milliseconds.

Since it takes a rather long time to recalculate the image, I do that in a background thread after every window resize and update the displayed image once the new image is ready. In the meantime, the original image is scaled to fit the view like this:

// The drawing rectangle is slightly smaller than the view, defined by
//   the two margins.
NSRect drawingRect;
drawingRect.origin = NSMakePoint(sideEdgeMarginWidth, topEdgeMarginHeight);
drawingRect.size = NSMakeSize([self bounds].size.width-2*sideEdgeMarginWidth,
                              [self bounds].size.height-2*topEdgeMarginHeight);
[waveform drawInRect:drawingRect
            fromRect:NSZeroRect
           operation:NSCompositeSourceOver
            fraction:1];

The view makes up the biggest part of the window. During live resize, audio starts choking. Selecting the “big” graphic card on my Macbook Pro makes it less bad, but not by much. CPU utilization is somewhere around 20-40% during live resizes.
Instruments suggests that rescaling/redrawing of the image is the problem. Once I stop resizing the window, CPU utilization goes down and audio stops glitching.

I already tried to disable image interpolation to speed up the drawing like this:

[[NSGraphicsContext currentContext] 
    setImageInterpolation:NSImageInterpolationNone];

That helps, but audio still chokes during live resizes.

Do you have an idea how to improve this?
The main thing is to prevent the audio from choking.

  • 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-14T04:47:27+00:00Added an answer on May 14, 2026 at 4:47 am

    The graphics redraw should not affect audio playback. I have an audio app that does live redraw when resizing the window, as well as a background thread to render the waveform, and it has no problem playing back audio. The audio thread that the ioProc which reads the audio data is a real-time thread, and has a higher priority than most other threads.

    If your graphics thread has a lock or calls something that blocks (including memory allocations or freeing) something in the audio thread, that could cause the audio to stutter. Multi-threading issues are complex, with issues such as thread-safety of data structures, locks, priority inversion, blocking, and many other things to deal with.

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

Sidebar

Related Questions

I'm writing an audio player using MediaPlayer that allows the user to skip the
I'm writing an iOS application that will play audio instructions as one of it's
I'm writing an audio application that has multiple threads producing sound and one thread
I am writing an iPhone application that needs to record audio from the built-in
I'm writing an an application in C# that will record audio files (*.wav) and
I'm planning on writing a simple, plugin-friendly audio player in Python (à la foobar2000),
I am writing an iOS app that uses live audio analysis. It has an
I'm writing an audio player using java, and I want a title formatter similar
I am writing an application that records audio. I am looking into the feasibility
I'm working on an audio encoder cgi script that utilises libmp3lame. I'm writing in

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.