I have an audio recorder and I was wondering if anyone has a code to show a audio meter (the bar that most of audio recorders have which shows the level of input audio).
Asked
Active
Viewed 8,142 times
2 Answers
4
Apple's SpeakHere example code includes a LevelView class which seems to be exactly what you are looking for.

Bill the Lizard
- 398,270
- 210
- 566
- 880

Jonah
- 17,918
- 1
- 43
- 70
-
4This apple sample code is anything but simple to implement it within your own project. Extremely confusing and needlessly complicated – Sam B Jul 16 '13 at 21:55
-
Yeah. It is not simple at all. What it does pretty simple but code is so much confusing... – bpolat Sep 09 '14 at 17:45
-
@SamB Can I use apple's SpeakHear example in my project? – Gajendra K Chauhan May 25 '15 at 07:00
-
The link is broken.. Can anyone share the level view class? – Neil Galiaskarov Jul 10 '17 at 15:52
-
Looks like there's a copy of the SpeakHere example at https://github.com/robovm/apple-ios-samples/tree/master/SpeakHere – Jonah Jul 10 '17 at 18:30
2
Heres an example that calculates output and prints it:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"]; // Your audio save path
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if (recorder) {
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.03 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
}
}
- (void)levelTimerCallback:(NSTimer *)timer {
[recorder updateMeters];
const double ALPHA = 0.05;
double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;
NSLog(@"%f",(lowPassResults*100.0f));
}
Depending on the lowPassResults you can animate a view accordingly.

Ushan87
- 1,608
- 8
- 15
-
'lowPassResults' is used uninitialized, is it iVar? What is initial value for it? – myeyesareblind Aug 28 '13 at 19:25