Audio

class Audio

A singleton class to help abstract function calls and methods for setting up different AVFoundation components.

  • The engine that is used for all audio effects. AVAudioEngine allows for real time audio editing which let’s the programmer tap the microphone for input then forward all data through different effect chains. Finally, the output of these effect chains can be mixed together through audioMixerNode.

    Declaration

    Swift

    var audioEngine: AVAudioEngine = AVAudioEngine()
  • This is used if the user recorded on the previous screen. It is set up such that the audio plays in a faux-loop fasion. Rather than using the .loop feature which would repeat an audio buffer endlessly, audio files are scheduled such that when the file ends, UIElemnts are modified before the next audio file gets queued.

    Declaration

    Swift

    var audioPlayerNode: AVAudioPlayerNode!
  • This is used if the user skipped recording on the previous screen. It uses the audioEngine to tap input from the mic and send it to this AVAudioSession to play through the speakers after being manipulated for effects.

    Declaration

    Swift

    var audioSession: AVAudioSession!
  • The equalizer for the 0th channel.

    Declaration

    Swift

    var leftEqualizer: AVAudioUnitEQ!
  • The equalizer for the 1st channel.

    Declaration

    Swift

    var rightEqualizer: AVAudioUnitEQ!
  • The mixer is used to mix together multichannel audio.

    Declaration

    Swift

    var audioMixerNode: AVAudioMixerNode!
  • Information regarding the recorded clip from the previous GeneralUIViewController.

    Declaration

    Swift

    var recordedAudio: RecordedAudioObject!
  • The audio file in which this class attempts to record.

    Declaration

    Swift

    var audioFile: AVAudioFile!
  • The `AVAudioRecorder’ that performs recording from the microphone.

    Declaration

    Swift

    var recorder: AVAudioRecorder?
  • The AVAudioRecorderDelegate' that must be passed intorecorder.

    Declaration

    Swift

    var recorderDelegate: AVAudioRecorderDelegate?
  • A notification that is used to update UIElements in EqualizerViewController.

    Declaration

    Swift

    let notificationName = Notification.Name("NotificationIdentifier")
  • A type alias to allow creating functions that accept other functions as parameters.

    Declaration

    Swift

    typealias HandlerFunction = ()  -> Void
  • A sharedInstance that can be used by all other classes. This is reaquired to make this class a singleton.

    Declaration

    Swift

    static let sharedInstance = Audio()
  • Private initializer ensuring singleton pattern enforcement for the Audio manager. Creates the shared AVAudioSession instance that will be used throughout the application for managing audio hardware resources. The private access level prevents external instantiation, ensuring only one Audio instance exists via sharedInstance. - Note: Call Audio.sharedInstance to access the singleton instance - Important: The AVAudioSession must be configured via setupAVAudioSession() before use - SeeAlso: setupAVAudioSession() for microphone permission and session configuration

    Declaration

    Swift

    class Audio
  • 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()
  • Called in other VC’s viewDidLoad, this function sets up the equalizer with 14 bands per channel.

    Declaration

    Swift

    func setupEqualizer(numberOfBands: Int)
  • This function creates an AVAudioEngine stored in audioEngine. Then based on realTime, it sets up real-time multichannel microphone to speaker output or streams from an audio file. In both of these cases the input is sent to an equalizer that the user may modify. These two channels are then mixed together with audioEngine.mainMixerNode.

    Declaration

    Swift

    func setupAudioEngine(realTime: Bool, handler: @escaping HandlerFunction)
  • A recursive function that is used to infinitely schedule the same audio clip that was recorded on the previous screen.

    Declaration

    Swift

    func schedule()
  • Sets up the AVAudioRecorder and records into filename (@param) using settings (@param). A time interval is also included as an iterative callback which allows for getting metering results.

    Declaration

    Swift

    func recordWithAVAudioRecorder(filename: String, settings: [String:Int], metered: Bool, timeIntervalForResults: TimeInterval)
  • This function is called if in real-time mode. It starts the recording process and streams the audio to speaker after digital signal processing.

    Declaration

    Swift

    func startRecordingWithAudioEngine()
  • This function is called if in real-time mode. It stops the recording process and stops the audioEngine after removing the recording tap.

    Declaration

    Swift

    func stopRecordingWithAudioEngine()
  • Plays the audioPlayerNode

    Declaration

    Swift

    func playWithAudioPlayerNode()
  • Pauses the audioPlayerNode

    Declaration

    Swift

    func pauseWithAudioPlayerNode()
  • If the recording succeeded store the URL of the recorded clip then call performeSegue. Else notify the user that recording failed.

    Declaration

    Swift

    func recordingEndedSuccessfully()