import UIKit
import AllisonLogic
class ViewController: UIViewController {
//MARK: Properties
var magnitudes1 : [Float] = []
var magnitudes2 : [Float] = []
let prepare = AllisonLogic.Prepare()
@IBOutlet weak var Record1Button: UIButton!
@IBOutlet weak var Record2Button: UIButton!
@IBOutlet weak var CompareButton: UIButton!
//MARK: Actions
@IBAction func RecordVoice1(_ sender: UIButton) {
prepare.LicenseKey = "enquiry@basic-signalprocessing.com"
magnitudes1 = prepare.record_audio_get_frequency()
var idx = 1
for magnitudeValue in magnitudes1
{
print("\(idx) magnitudeValue1 = \(magnitudeValue)")
idx = idx + 1
}
}
@IBAction func RecordVoice2(_ sender: UIButton) {
magnitudes2 = prepare.record_audio_get_frequency()
var idx = 1
for magnitudeValue in magnitudes2
{
print("\(idx) magnitudeValue2 = \(magnitudeValue)")
idx = idx + 1
}
}
@IBAction func CompareVoice(_ sender: UIButton) {
let compute = AllisonLogic.Compute()
let mag1_100_blocks = compute.sum_store_in_100_blocks(magnitudes1)
let mag2_100_blocks = compute.sum_store_in_100_blocks(magnitudes2)
//section 1: testing use
let score = compare_magnitudes_get_score(mag1_100_blocks, mag2_100_blocks)
//the authentication threshold should be set at >= 77%, the minumum score needed to be considered the same voice as the authorized person
print("score in % =\(score)")
//section 2: database integration design
//the process of storing voice sample 1
var idx1 = 1
for magnitudeValue in mag1_100_blocks //loop 1 to 100
{
print("Store this value \(magnitudeValue) in field \(idx1)")
idx1 = idx1 + 1
}
//the process of storing voice sample 2
var idx2 = 1
for magnitudeValue in mag2_100_blocks //loop 1 to 100
{
print("Store this value \(magnitudeValue) in field \(idx2)")
idx2 = idx2 + 1
}
}
func compare_magnitudes_get_score(_ magnitude1: [Float], _ magnitude2: [Float]) -> Int {
var block1: Float = 0
var block2: Float = 0
var ratio: Float = 0
var matchCount: Int = 0
for index in 0...99
{
block1 = magnitude1[index]
block2 = magnitude2[index]
ratio = block2 / block1
if ratio >= 0.5 && ratio <= 1.5
{
matchCount += 1
}
}
return matchCount
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
prepare.LicenseKey = "enquiry@basic-signalprocessing.com"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}