A structure storing the Recording information is created under Models, see details in the code file
struct AudioRecording {
var recordedAmplitude: Array<Double> = [] // the stored Amplitudes
var timeCap: Int = -1 // the maximum size for the recorded amplitude, -1 means unlimited
var isRecording: Bool=false
mutating func addAmplitude(lastAmplitude: Double)->Void{
if (self.isRecording){
if ((self.timeCap == -1) || (self.recordedAmplitude.count < timeCap)){
self.recordedAmplitude.append(lastAmplitude)
} else{ // if max size is reached, pause the recording.
self.endRecording()
}
}
}
mutating func toggleRecording(){
if (self.isRecording){
self.endRecording()
} else {
self.startRecording()
}
}
the object is created in Audio, which's method is called in AudioViewModel
208 // update the last captured amplitude
209 self.audio.lastAmplitude = Double(amplitude[0])
210 self.audio.recording.addAmplitude(lastAmplitude: self.audio.lastAmplitude)
211
212 self.updateReferenceTimbre()
213 self.updateIsPitchAccurate()
Currently, the recording can only be triggered if islive.
upon clicking the button, it turns red, clears the previous recording data and starts appending newly received lastAmpliture to audio.recording.recordedAmplitude (a get method is provided in the struct)
you can view the realtime length, attritube values of the object by uncomenting these code in SoundView.swift
A structure storing the Recording information is created under Models, see details in the code file
the object is created in Audio, which's method is called in AudioViewModel
Currently, the recording can only be triggered if islive. upon clicking the button, it turns red, clears the previous recording data and starts appending newly received lastAmpliture to audio.recording.recordedAmplitude (a get method is provided in the struct)
you can view the realtime length, attritube values of the object by uncomenting these code in SoundView.swift