NoiseMeterViewController
class NoiseMeterViewController: GeneralUIViewController, AVAudioRecorderDelegate
A custom class that inherits from GeneralUIViewController and AVAudioRecorderDelegate. It was created to control the NoiseMeterView.
-
A dynamic
GeneralUILabelthat displays the Noise Level.Declaration
Swift
@IBOutlet weak var noiseLevelLabel: GeneralUILabel! -
A static
GeneralUILabelthat displays the dB Unit.Declaration
Swift
@IBOutlet weak var dbLabel: GeneralUILabel! -
A static
GeneralUILabelthat captions the silent UIView.Declaration
Swift
@IBOutlet weak var silentLabel: GeneralUILabel! -
A static
GeneralUILabelthat captions the quiet UIView.Declaration
Swift
@IBOutlet weak var quietLabel: GeneralUILabel! -
A static
GeneralUILabelthat captions the average UIView.Declaration
Swift
@IBOutlet weak var averageLabel: GeneralUILabel! -
A static
GeneralUILabelthat captions the noisy UIView.Declaration
Swift
@IBOutlet weak var noisyLabel: GeneralUILabel! -
A static
GeneralUILabelthat captions the loud UIView.Declaration
Swift
@IBOutlet weak var loudLabel: GeneralUILabel! -
A static
UIViewthat is coloredUIColor.BLUEto represent the ‘silent’ noise range.Declaration
Swift
@IBOutlet weak var noiseMeterViewOne: UIView! -
A static
UIViewthat is coloredUIColor.GREENto represent the ‘quiet’ noise range.Declaration
Swift
@IBOutlet weak var noiseMeterViewTwo: UIView! -
A static
UIViewthat is coloredUIColor.PURPLEto represent the ‘average’ noise range.Declaration
Swift
@IBOutlet weak var noiseMeterViewThree: UIView! -
A static
UIViewthat is coloredUIColor.ORANGEto represent the ‘noisy’ noise range.Declaration
Swift
@IBOutlet weak var noiseMeterViewFour: UIView! -
A static
UIViewthat is coloredUIColor.REDto represent the ‘loud’ noise range.Declaration
Swift
@IBOutlet weak var noiseMeterViewFive: UIView!
-
The recorder object on which the noise meter relies..
Declaration
Swift
var recorder: AVAudioRecorder? -
A timer object to gathers noise data frequently.
Declaration
Swift
var levelTimer = Timer() -
An array to store the recorded noise levels. This can possibly be used to display a history graph of the past noise levels.
Declaration
Swift
var dBs: NSArray = NSArray()
-
Calls
setupNoiseMeterto color all of theUIViewsto make them look like a legend for thenoiseLevelLabel.Declaration
Swift
override func viewWillAppear(_ animated: Bool) -
This function sets up custom UI Elements specific to this view then calls
setupAVAudioSessionto set up the audio session that measures noise.Declaration
Swift
override func viewDidLoad()
-
Creates an
AVAudioSessionas asharedInstancethen requests recording permission from the user. If the user allows recording, theAVAudioSessionhas settings changed and therecordmethod is called.Declaration
Swift
func setupAVAudioSession() -
A function that allows the
recorderto record storing the file atfilename (@param), with settingssettings (@param), a flag to determine if the recording should be metered, and a timeInterval forlevelTimer.Declaration
Swift
func record(filename: String, settings: [String:Int], metered: Bool, timeIntervalForResults: TimeInterval) -
The callback function for
levelTimer. This allows the view to be updated with the new noise levels:recordercallsupdateMetersandupdateLabelsis called to update the view.Declaration
Swift
func levelTimerCallback() -
This function changes the text in the
noiseLevelLabeland sets the color of the text based on theNoiseMeterColors.Declaration
Swift
func updateLabels(dB: Float) -
Converts from Apple standard noise levels to the universally used decibel system. Changes values from a linear [-160, 0] scale to a logrithmic [0, 120] scale.
Declaration
Swift
func convertToDecibel (originalValue: Float) -> Float -
This function sets up the different small
UIViewsthat create the NoiseMeter at the top of thisUIView. Also sets the font for the labels that describe each color of the meter.Declaration
Swift
func setupNoiseMeter()
-
Ensures that when the recording ends a sucess or failure flag is sent to
recordingEndedfunction.Declaration
Swift
func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool) -
Prints whether or not the recording session ended correctly.
Declaration
Swift
func recordingEnded(success: Bool)
View on GitHub
NoiseMeterViewController Class Reference