IPhone - show reverse audio recording using AVAudioRecorder
I am using the AVAudioRecorder class to write to a wav file. I would like to implement a writeback of a recording (like the SpeakHere example) that shows the recording level.
I looked at the SpeakHere sample but couldn't figure out how the recording level changed. Can someone explain to me what needs to be done?
Thank.
source to share
If you are using AVAudioRecorder, you can only use the following power levels:
- (float)peakPowerForChannel:(NSUInteger)channelNumber
- (void)updateMeters
Those give values for the graph. There are simpler ways to plot these values, but to see how the SpeakHere sample does, see their README:
AQLevelMeter.h
AQLevelMeter.mm
The AQLevelMeter class defines the level meter view for the applcation, displaying the metering data from an AudioQueue object
LevelMeter.h
LevelMeter.m
LevelMeter is a base metering class, providing simple functionality for displaying level data
GLLevelMeter.h
GLLevelMeter.m
GLLevelMeter is a subclass of LevelMeter that uses OpenGL for drawing
AQRecorder.h
AQRecorder.m
source to share
Mahboudz's answer is correct, although I found this method to be more responsive than "peakPowerForChannel":
- (float)averagePowerForChannel:(NSUInteger)channelNumber
Then I converted the float value to a slightly more useful 0-10 scale with this calculation: (Be sure to use MIN and MAX to ensure that the number is within the range, because on rare occasions it can go outside the 0-10 range.)
//
// Decrease the divisor to increase the responsiveness
//
int translatedValue = (averagePowerFloat / 6 + 11);
Then I have a loop on a background thread that calls "updateMeters" 10 times per second and updates the progress bar with the recording level. It seems to work pretty well.
source to share