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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:10:45+00:00 2026-06-07T11:10:45+00:00

In my app, I am trying to record on one device, transmit it and

  • 0

In my app, I am trying to record on one device, transmit it and play it back on an other device. I want to animate the sound levels on both the recording device and the Playback device.

Most of the code I have used for recording, playing back and animation is from the SpeakHere sample App.

I have two differences though:

  • I have the additional overhead of transmitting over the network.
  • I an trying to do the horizontal animation with and image(shown below) instead of the colored bands as in SpeakHere

Animation

I am recording and transmitting on a separate dispatch queue(GCD) and the same for receiving and playing back.

  • My first problem is: when I introduce the animation, the receiving and playback becomes very slow and the AudioQueue goes silent.
  • My next problem is with setting a clear background to the LevelMeter view. If I do that then the animation is garbled. Not sure how the animation is connected to the background color.

Below is my version of (not so elegantly modified) drawRect from the SpeakHere example.
Please advice on any mistakes I may have made.

My understanding is that I cannot use another thread here for the animation because of UIKit. If not, please correct me.

- (void)drawRect:(CGRect)rect
{
        //();
    CGContextRef cxt = NULL;
    cxt = UIGraphicsGetCurrentContext();

    CGColorSpaceRef cs = NULL;
    cs = CGColorSpaceCreateDeviceRGB();

    CGRect bds;


    if (_vertical)
    {
        CGContextTranslateCTM(cxt, 0., [self bounds].size.height);
        CGContextScaleCTM(cxt, 1., -1.);
        bds = [self bounds];
    } else {
        CGContextTranslateCTM(cxt, 0., [self bounds].size.height);
        CGContextRotateCTM(cxt, -M_PI_2);
        bds = CGRectMake(0., 0., [self bounds].size.height, [self bounds].size.width);
    }

    CGContextSetFillColorSpace(cxt, cs);
    CGContextSetStrokeColorSpace(cxt, cs);

    if (_numLights == 0)
    {
        int i;
        CGFloat currentTop = 0.;

        if (_bgColor)
        {
            [_bgColor set];
            CGContextFillRect(cxt, bds);
        }

        for (i=0; i<_numColorThresholds; i++)
        {
            LevelMeterColorThreshold thisThresh = _colorThresholds[i];
            CGFloat val = MIN(thisThresh.maxValue, _level);

            CGRect rect = CGRectMake(
                                     0, 
                                     (bds.size.height) * currentTop, 
                                     bds.size.width, 
                                     (bds.size.height) * (val - currentTop)
                                     );

            [thisThresh.color set];
            CGContextFillRect(cxt, rect);

            if (_level < thisThresh.maxValue) break;

            currentTop = val;
        }

        if (_borderColor)
        {
            [_borderColor set];
            CGContextStrokeRect(cxt, CGRectInset(bds, .5, .5));
        }

    } 
    else 
    {
        int light_i;
        CGFloat lightMinVal = 0.;
        CGFloat insetAmount, lightVSpace;
        lightVSpace = bds.size.height / (CGFloat)_numLights;
        if (lightVSpace < 4.) insetAmount = 0.;
        else if (lightVSpace < 8.) insetAmount = 0.5;
        else insetAmount = 1.;

        int peakLight = -1;
        if (_peakLevel > 0.)
        {
            peakLight = _peakLevel * _numLights;
            if (peakLight >= _numLights) peakLight = _numLights - 1;
        }

        for (light_i=0; light_i<_numLights; light_i++)
            {
                CGFloat lightMaxVal = (CGFloat)(light_i + 1) / (CGFloat)_numLights;
                CGFloat lightIntensity;
                CGRect lightRect;
                UIColor *lightColor;

                if (light_i == peakLight)
                {
                    lightIntensity = 1.;
                } 
                else 
                {
                    lightIntensity = (_level - lightMinVal) / (lightMaxVal - lightMinVal);
                    lightIntensity = LEVELMETER_CLAMP(0., lightIntensity, 1.);
                    if ((!_variableLightIntensity) && (lightIntensity > 0.)) lightIntensity = 1.;
                }

                lightColor = _colorThresholds[0].color;
                int color_i;
                for (color_i=0; color_i<(_numColorThresholds-1); color_i++)
                {
                    LevelMeterColorThreshold thisThresh = _colorThresholds[color_i];
                    LevelMeterColorThreshold nextThresh = _colorThresholds[color_i + 1];
                    if (thisThresh.maxValue <= lightMaxVal) lightColor = nextThresh.color;
                }

                lightRect = CGRectMake(
                                       0., 
                                       bds.size.height * ((CGFloat)(light_i) / (CGFloat)_numLights), 
                                       bds.size.width,
                                       bds.size.height * (1. / (CGFloat)_numLights)
                                       );
                lightRect = CGRectInset(lightRect, insetAmount, insetAmount);

                if (_bgColor)
                {
                    [_bgColor set];
                    CGContextFillRect(cxt, lightRect);
                }

                UIImage* image = [UIImage imageNamed:@"Pearl.png"];
                CGImageRef imageRef = image.CGImage;


                if (lightIntensity == 1.)
                {
                    CGContextDrawImage(cxt, lightRect, imageRef);

                    [lightColor set];
                    //CGContextFillRect(cxt, lightRect);
                } else if (lightIntensity > 0.) {
                    CGColorRef clr = CGColorCreateCopyWithAlpha([lightColor CGColor], lightIntensity);
                    CGContextSetFillColorWithColor(cxt, clr);
                    //CGContextFillRect(cxt, lightRect);
                    CGContextDrawImage(cxt, lightRect, imageRef);

                    CGColorRelease(clr);
                }

                if (_borderColor)
                {
                    [_borderColor set];
                    CGContextStrokeRect(cxt, CGRectInset(lightRect, 0.5, 0.5));
                }

                lightMinVal = lightMaxVal;
            }       
    }

    CGColorSpaceRelease(cs);
}
  • 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-07T11:10:46+00:00Added an answer on June 7, 2026 at 11:10 am

    Your drawing may be too slow, which can interfere with real time response requirements to the audio queue callbacks.

    But since you are drawing mostly a bunch of static images, you might want to consider putting the dots each in their own separate image views. The you can control the number of dots displayed just by hiding and unhiding sub views, without any drawRect code at all.

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

Sidebar

Related Questions

I'm trying to record and play movies with my app using qtkit. I record
I am working on an app that involves recording audio on one device and
I was trying to record a voice in my app and then store it
I'm trying to record sound using Android Emulator. I know that this question is
I'm trying to query records in Google App engine where an IntegerProperty is null
So I've been toiling over this app trying to figure out this strange behaviour
I have a Rails app and trying to make a remote form, so far
I'm making a 'post text' app and trying to update my database with name
I have Rails 3.1.3 app and trying to plug gem redis to it. I've
In my app I'm trying to render text along a path; this is fine

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.