NoiseMeterViewController

class NoiseMeterViewController: GeneralUIViewController,  AVAudioRecorderDelegate

A custom class that inherits from GeneralUIViewController and AVAudioRecorderDelegate. It was created to control the NoiseMeterView.

  • 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()
  • dBs

    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 setupNoiseMeter to color all of the UIViews to make them look like a legend for the noiseLevelLabel.

    Declaration

    Swift

    override func viewWillAppear(_ animated: Bool)
  • This function sets up custom UI Elements specific to this view then calls setupAVAudioSession to set up the audio session that measures noise.

    Declaration

    Swift

    override func viewDidLoad()
  • Creates an AVAudioSession as a sharedInstance then requests recording permission from the user. If the user allows recording, the AVAudioSession has settings changed and the record method is called.

    Declaration

    Swift

    func setupAVAudioSession()
  • A function that allows the recorder to record storing the file at filename (@param), with settings settings (@param), a flag to determine if the recording should be metered, and a timeInterval for levelTimer.

    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: recorder calls updateMeters and updateLabels is called to update the view.

    Declaration

    Swift

    func levelTimerCallback()
  • This function changes the text in the noiseLevelLabel and sets the color of the text based on the NoiseMeterColors.

    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 UIViews that create the NoiseMeter at the top of this UIView. 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 recordingEnded function.

    Declaration

    Swift

    func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool)
  • Prints whether or not the recording session ended correctly.

    Declaration

    Swift

    func recordingEnded(success: Bool)