Created
May 18, 2012 20:56
-
-
Save C4Code/2727571 to your computer and use it in GitHub Desktop.
Audio meter for C4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// C4WorkSpace.m | |
// audioMeter | |
// | |
// Created by Travis Kirton on 12-05-17. | |
// Copyright (c) 2012 POSTFL. All rights reserved. | |
// | |
#import "C4WorkSpace.h" | |
@interface C4WorkSpace () | |
-(void)printMeters; | |
@end | |
@implementation C4WorkSpace { | |
C4Sample *s; | |
C4Shape *l1, *r1, *l2, *r2; | |
} | |
-(void)setup { | |
s = [C4Sample sampleNamed:@"C4Loop.aif"]; | |
s.loops = YES; | |
s.meteringEnabled = YES; | |
[s prepareToPlay]; | |
[s play]; | |
C4Log(@"%d",s.player.numberOfChannels); | |
CGPoint linePoints[2] = {CGPointMake(384/2, 1024),CGPointMake(384/2, 0)}; | |
l1 = [C4Shape line:linePoints]; | |
[self.canvas addShape:l1]; | |
linePoints[0].x += 20; | |
linePoints[1].x += 20; | |
l2 = [C4Shape line:linePoints]; | |
[self.canvas addShape:l2]; | |
linePoints[0].x += 364; | |
linePoints[1].x += 364; | |
r1 = [C4Shape line:linePoints]; | |
[self.canvas addShape:r1]; | |
linePoints[0].x += 20; | |
linePoints[1].x += 20; | |
r2 = [C4Shape line:linePoints]; | |
[self.canvas addShape:r2]; | |
l1.lineWidth = 20.0; | |
l2.lineWidth = 20.0; | |
r1.lineWidth = 20.0; | |
r2.lineWidth = 20.0; | |
l1.animationDuration = 0.0; | |
r1.animationDuration = 0.0; | |
l2.animationDuration = 0.0; | |
r2.animationDuration = 0.0; | |
NSTimer *t = [NSTimer timerWithTimeInterval:1.0/60.0f target:self selector:@selector(printMeters) userInfo:nil repeats:YES]; | |
[[NSRunLoop mainRunLoop] addTimer:t forMode:NSDefaultRunLoopMode]; | |
} | |
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { | |
[self printMeters]; | |
} | |
-(void)printMeters { | |
[s.player updateMeters]; | |
l1.strokeEnd = pow (10, (0.05 *[s.player peakPowerForChannel:0])); | |
l2.strokeEnd = pow (10, (0.05 *[s.player averagePowerForChannel:0])); | |
r1.strokeEnd = pow (10, (0.05 *[s.player peakPowerForChannel:1])); | |
r2.strokeEnd = pow (10, (0.05 *[s.player averagePowerForChannel:1])); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment