CUHK-CMD / timbre-visualization-on-ios

Sounds are hard to understand and explain 🎵
https://apps.apple.com/hk/app/soundsgood/id1597764029
0 stars 1 forks source link

created struct AudioRecording under 'Models/AudioRecording.swift', mo… #5

Closed JohnYeung-dojjy closed 2 years ago

JohnYeung-dojjy commented 2 years ago

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

                    CaptureTimeButton(
                        action: {
                            vm.audio.recording.toggleRecording()

                        },
                        captureTime: vm.audio.captureTime,
                        isRecording: vm.audio.recording.isRecording)
//                    Text(String(vm.audio.recording.recordedAmplitude.count))
//                    Text(String(vm.audio.recording.isRecording))
//                    Text(String(vm.audio.recording.timeCap))
IamMrandrew commented 2 years ago

@JohnYeung-dojjy ok i will check this later

IamMrandrew commented 2 years ago

@JohnYeung-dojjy Sorry for super late reply. Will get with u on task 2 later