WaveForm on IOS

后端 未结 5 1772
清歌不尽
清歌不尽 2020-12-02 05:00

I\'m looking for how to draw the sound amplitude.

I found http://supermegaultragroovy.com/2009/10/06/drawing-waveforms/ but i have some problems. How get a list of f

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-02 05:48

    this is my answer, thx all geek

    obj-c
    

    here is code:

    -(void) listenerData:(NSNotification *) notify
    {
    int resnum=112222;
    unsigned int bitsum=0;
    for(int i=0;i<4;i++)
    {
        bitsum+=(resnum>>(i*8))&0xff;
    }
    bitsum=bitsum&0xff;
    NSString * check=[NSString stringWithFormat:@"%x %x",resnum,bitsum];
    check=nil; 
    self.drawData=notify.object;``
    [self setNeedsDisplay];
    }
    
    -(void)drawRect:(CGRect)rect
    {
    NSArray *data=self.drawData;
    NSData *tdata=[data objectAtIndex:0];
    double *srcdata=(double*)tdata.bytes;
    int datacount=tdata.length/sizeof(double);
    tdata=[data objectAtIndex:1];
    double *coveddata=(double*)tdata.bytes;
    
    CGContextRef context=UIGraphicsGetCurrentContext();
    CGRect bounds=self.bounds;
    CGContextClearRect(context, bounds);
    CGFloat midpos=bounds.size.height/2;
    CGContextBeginPath(context);
    
    const double scale=1.0/100;
    CGFloat step=bounds.size.width/(datacount-1);
    CGContextMoveToPoint(context, 0, midpos);
    CGFloat xpos=0;
    for(int i=0;i

提交回复
热议问题