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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:18:38+00:00 2026-05-24T02:18:38+00:00

I’ve just finished waveform drawing code for my app. I’m pretty happy with it

  • 0

I’ve just finished waveform drawing code for my app. I’m pretty happy with it and on the simulator it looks great.

The problem I have is when I run it on an ipad it doesnt draw properly. On the simulator the drawing looks like a nice regular waveform drawing whereas on the ipad the waveform just looks like one big rectangle.

I’m very unsure how I could even begin to start trouble shooting and resolving something like this.

Can you offer any suggestions as to why its working on the simulator & not the ipad?

If I can submit anymore information that might help please let me know.

calculation

-(void) plotwaveform:(AudioSourceOBJ )source
{

    int count =source->framecount;
    int blocksize= count/resolution;
    currentmaxvalue=0;


    int readindex=0;
    CGRect *addrects= malloc(resolution * sizeof(CGRect));
    float *heights=malloc(resolution * sizeof(float));

    for (int i=0; i<resolution;i++) {

        AudioUnitSampleType *blockofaudio;
        blockofaudio =malloc(blocksize * sizeof(AudioUnitSampleType));

        memcpy(blockofaudio, &source->leftoutput[readindex],(blocksize * sizeof(AudioUnitSampleType)));

        float sample= [self getRMS:blockofaudio blocksize:blocksize];
        heights[i]=sample;
        readindex+=blocksize;

    }

    for (int scale=0; scale<resolution; scale++) {


        float h= heights[scale];

        h= (h/currentmaxvalue)* 45;
        addrects[scale]=CGRectMake(scale, 0, 1, h);


    }



    if (waveform) {

        [waveform release];

        [waveform removeFromSuperview];
        waveform=nil;
    }



    CGMutablePathRef halfpath=CGPathCreateMutable();
    CGPathAddRects(halfpath, NULL, addrects, resolution);



    CGMutablePathRef path= CGPathCreateMutable();


   CGAffineTransform xf = CGAffineTransformIdentity;
    xf= CGAffineTransformTranslate(xf, 0.0,45);


    CGPathAddPath(path,&xf, halfpath);


    xf= CGAffineTransformIdentity;
    xf= CGAffineTransformTranslate(xf, 0.0, 45);
    xf=CGAffineTransformScale(xf, 1.0, -1);

    CGPathAddPath(path, &xf, halfpath);


    CGPathRelease(halfpath);

    free(addrects);
    waveform = [[Waveform alloc] initWithFrameAndPlotdata:CGRectMake(0, 0, 400,90) thepoints:path];
    [self.view addSubview:waveform];



}

-(float ) getRMS:(AudioUnitSampleType *)blockofaudio blocksize:(int)blocksize


{

    float output;
    float sqsummed;
    float sqrootofsum;
    float val;

    for (int i=0;i<blocksize; i++) {
        val= blockofaudio[i];
        sqsummed+= val* val;

    }

    sqrootofsum=sqsummed / blocksize;

    output = sqrt(sqrootofsum);

    // find the max
    if(output> currentmaxvalue)
    {
        currentmaxvalue=output;
    }
    return output;

}

Drawing

- (void)drawRect:(CGRect)rect
{

    CGContextRef ctx= UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(ctx, 0, 0, 0, .5);
    CGContextBeginPath(ctx);
    CGContextAddPath(ctx, mutatablepath);
    //CGContextStrokePath(ctx);
    CGContextFillPath(ctx);
    CFRelease(mutatablepath);

}

DESC EDIT

I pass a bunch of audio data to the plotwaveform function and divide it into chunks. For each chunk of audio I calculate the RMS for each chunk and keep a track of the maximum value. When all that is done I use the max value to scale my rms values to fit my view port.

I have noticed a strange thing. If I NSLog the values for the “output” variable in the getRMS function the waveform draws fine on the device. If I do not NSLog the values the waveform does not draw properly?!?

That to me is bizarre.

  • 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-24T02:18:39+00:00Added an answer on May 24, 2026 at 2:18 am

    One major error I see is that you never initialize sqsummed inside the getRMS:blocksize: method, so its initial value is garbage. What the garbage happens to be depends on the details of the surrounding code, how the compiler allocates registers for variables, and so on. Adding an NSLog statement could well change what the garbage is next time around the loop.

    If the garbage happens to always correspond to a very small float value you’ll get expected behavior, while if it happens to always correspond to some extremely large float value (large enough to swamp the actual samples) you’ll get one big rectangle, while if it happens to vary you’ll get a noise-like output.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

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.