-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlaySoundsViewController.swift
64 lines (54 loc) · 1.62 KB
/
PlaySoundsViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// PlaySoundsViewController.swift
// PitchPerfect
//
// Created by aaron stutzer on 04.08.17.
// Copyright © 2017 uda. All rights reserved.
//
import UIKit
import AVFoundation
class PlaySoundsViewController: UIViewController {
@IBOutlet weak var slowButton: UIButton!
@IBOutlet weak var fastButton: UIButton!
@IBOutlet weak var highPitchButton: UIButton!
@IBOutlet weak var lowPitchButton: UIButton!
@IBOutlet weak var echoButton: UIButton!
@IBOutlet weak var reverbButton: UIButton!
@IBOutlet weak var stopButton: UIButton!
var recordedAudioURL: URL!
var audioFile:AVAudioFile!
var audioEngine:AVAudioEngine!
var audioPlayerNode: AVAudioPlayerNode!
var stopTimer: Timer!
enum ButtonType: Int {
case slow = 0, fast, chipmunk, vader, echo, reverb
}
@IBAction func playSoundForButton(_ sender: UIButton) {
switch(ButtonType(rawValue: sender.tag)!) {
case .slow:
playSound(rate: 0.5)
case .fast:
playSound(rate: 1.5)
case .chipmunk:
playSound(pitch: 1000)
case .vader:
playSound(pitch: -1000)
case .echo:
playSound(echo: true)
case .reverb:
playSound(reverb: true)
}
configureUI(.playing)
}
@IBAction func stopButtonPressed(_ sender: AnyObject) {
stopAudio()
}
override func viewDidLoad() {
super.viewDidLoad()
setupAudio()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
configureUI(.notPlaying)
}
}