Skip to content

Commit 0d1e5bb

Browse files
committed
Merged with develop
2 parents dcc8e05 + ebd3fc3 commit 0d1e5bb

File tree

169 files changed

+3488
-757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+3488
-757
lines changed

AudioKit.podspec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "AudioKit",
3-
"version": "3.4.1",
3+
"version": "3.4.3",
44
"authors": {
55
"Aurelius Prochazka": "audiokit@audiokit.io"
66
},
@@ -12,7 +12,7 @@
1212
"social_media_url": "http://twitter.com/AudioKitMan",
1313
"documentation_url": "http://audiokit.io/docs/",
1414
"source": {
15-
"http": "https://github.com/audiokit/AudioKit/releases/download/v3.4.1/AudioKit.framework.zip"
15+
"http": "https://github.com/audiokit/AudioKit/releases/download/v3.4.3/AudioKit.framework.zip"
1616
},
1717
"summary": "Open-source audio synthesis, processing, & analysis platform.",
1818
"platforms": {

AudioKit/Common/Internals/AKNodeRecorder.swift

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,48 @@ import AVFoundation
1212

1313
/// Simple audio recorder class
1414
@objc open class AKNodeRecorder: NSObject {
15-
15+
1616
// MARK: - Properties
17-
17+
1818
// The node we record from
1919
fileprivate var node: AKNode?
20-
20+
2121
// The file to record to
2222
fileprivate var internalAudioFile: AKAudioFile
23-
23+
2424
fileprivate var recording = false
25-
25+
26+
// An optional duration for the recording to auto-stop when reached
27+
open var durationToRecord: Double = 0
28+
2629
/// True if we are recording.
2730
open var isRecording: Bool {
2831
return recording
2932
}
30-
33+
3134
/// Duration of recording
3235
open var recordedDuration: Double {
3336
return internalAudioFile.duration
3437
}
35-
38+
3639
/// Used for fixing recordings being truncated
3740
fileprivate var recordBufferDuration: Double = 16384 / AKSettings.sampleRate
38-
41+
3942
/// return the AKAudioFile for reading
4043
open var audioFile: AKAudioFile? {
4144
do {
4245
return try AKAudioFile(forReading: internalAudioFile.url)
43-
46+
4447
} catch let error as NSError {
4548
print("Cannot create internal audio file for reading")
4649
print("Error: \(error.localizedDescription)")
4750
return nil
4851
}
49-
52+
5053
}
51-
54+
5255
// MARK: - Initialization
53-
56+
5457
/// Initialize the node recorder
5558
///
5659
/// Recording buffer size is defaulted to be AKSettings.bufferLength
@@ -62,9 +65,9 @@ import AVFoundation
6265
///
6366
public init(node: AKNode = AudioKit.output!,
6467
file: AKAudioFile? = nil) throws {
65-
68+
6669
// AVAudioSession buffer setup
67-
70+
6871
if file == nil {
6972
// We create a record file in temp directory
7073
do {
@@ -73,9 +76,9 @@ import AVFoundation
7376
print("AKNodeRecorder Error: Cannot create an empty audio file")
7477
throw error
7578
}
76-
79+
7780
} else {
78-
81+
7982
do {
8083
// We initialize AKAudioFile for writing (and check that we can write to)
8184
self.internalAudioFile = try AKAudioFile(forWriting: file!.url,
@@ -87,21 +90,21 @@ import AVFoundation
8790
}
8891
self.node = node
8992
}
90-
93+
9194
// MARK: - Methods
92-
95+
9396
/// Start recording
9497
open func record() throws {
9598
if recording {
9699
print("AKNodeRecorder Warning: already recording !")
97100
return
98101
}
99-
100-
102+
103+
101104
#if os(iOS)
102105
// requestRecordPermission...
103106
var permissionGranted: Bool = false
104-
107+
105108
AKSettings.session.requestRecordPermission() {
106109
(granted: Bool)-> Void in
107110
if granted {
@@ -110,16 +113,16 @@ import AVFoundation
110113
permissionGranted = false
111114
}
112115
}
113-
116+
114117
if !permissionGranted {
115118
print("AKNodeRecorder Error: Permission to record not granted")
116119
throw NSError(domain: NSURLErrorDomain,
117120
code: NSURLErrorUnknown,
118121
userInfo: nil)
119122
}
120-
123+
121124
// Sets AVAudioSession Category to be Play and Record
122-
125+
123126
if (AKSettings.session.category != AKSettings.SessionCategory.playAndRecord.rawValue) {
124127
do {
125128
try AKSettings.setSession(category: .playAndRecord)
@@ -129,37 +132,43 @@ import AVFoundation
129132
}
130133
}
131134
#endif
132-
133-
135+
136+
134137
if node != nil {
135-
138+
136139
let recordingBufferLength: AVAudioFrameCount = AKSettings.recordingBufferLength.samplesCount
137140
recording = true
138-
139-
print("recording")
141+
142+
print("AKNodeRecorder: recording")
140143
node!.avAudioNode.installTap(onBus: 0, bufferSize: recordingBufferLength,
141-
format: internalAudioFile.processingFormat) {
142-
(buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
143-
do {
144-
self.recordBufferDuration = Double(buffer.frameLength) / AKSettings.sampleRate
145-
try self.internalAudioFile.write(from: buffer)
146-
print("writing ( file duration: \(self.internalAudioFile.duration) seconds)")
147-
} catch let error as NSError {
148-
print("Write failed: error -> \(error.localizedDescription)")
149-
}
144+
format: internalAudioFile.processingFormat) {
145+
(buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
146+
do {
147+
self.recordBufferDuration = Double(buffer.frameLength) / AKSettings.sampleRate
148+
try self.internalAudioFile.write(from: buffer)
149+
print("AKNodeRecorder writing (file duration: \(self.internalAudioFile.duration) seconds)")
150+
151+
// allow an optional timed stop
152+
if self.durationToRecord != 0 && self.internalAudioFile.duration >= self.durationToRecord {
153+
self.stop()
154+
}
155+
156+
} catch let error as NSError {
157+
print("Write failed: error -> \(error.localizedDescription)")
158+
}
150159
}
151160
} else {
152161
print("AKNodeRecorder Error: input node is not available")
153162
}
154163
}
155-
164+
156165
/// Stop recording
157166
open func stop() {
158167
if !recording {
159168
print("AKNodeRecorder Warning: Cannot stop recording, already stopped !")
160169
return
161170
}
162-
171+
163172
recording = false
164173
if node != nil {
165174
if AKSettings.fixTruncatedRecordings {
@@ -168,34 +177,34 @@ import AVFoundation
168177
usleep(delay)
169178
}
170179
node!.avAudioNode.removeTap(onBus: 0)
171-
print("Recording Stopped.")
172-
180+
print("AKNodeRecorder: Recording Stopped.")
181+
173182
} else {
174183
print("AKNodeRecorder Error: input node is not available")
175184
}
176185
}
177-
178-
186+
187+
179188
/// Reset the AKAudioFile to clear previous recordings
180189
open func reset() throws {
181-
190+
182191
// Stop recording
183192
if recording {
184193
stop()
185194
}
186-
195+
187196
// Delete the physical recording file
188197
let fileManager = FileManager.default
189198
let settings = internalAudioFile.processingFormat.settings
190199
let url = internalAudioFile.url
191-
200+
192201
do {
193202
try fileManager.removeItem(atPath: audioFile!.url.absoluteString)
194203
} catch let error as NSError {
195204
print("AKNodeRecorder Error: cannot delete Recording file: \(audioFile!.fileNamePlusExtension)")
196205
throw error
197206
}
198-
207+
199208
// Creates a blank new file
200209
do {
201210
internalAudioFile = try AKAudioFile(forWriting: url, settings: settings)

AudioKit/Common/Internals/AKSettings.swift

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ import AVFoundation
106106

107107
open static func setSession(category: SessionCategory,
108108
with options: AVAudioSessionCategoryOptions? = nil ) throws {
109-
109+
110110
if AKSettings.disableAVAudioSessionCategoryManagement == false {
111-
112-
// print( "ask for category: \(category.rawValue)")
113-
// Category
111+
114112
if options != nil {
115113
do {
116114
try session.setCategory(category.rawValue, with: options!)
@@ -119,15 +117,16 @@ import AVFoundation
119117
print("AKAsettings Error: \(error))")
120118
throw error
121119
}
122-
}
123-
} else {
124-
125-
do {
126-
try session.setCategory(category.rawValue)
127-
} catch let error as NSError {
128-
print("AKAsettings Error: Cannot set AVAudioSession Category to \(String(describing: category))")
129-
print("AKAsettings Error: \(error))")
130-
throw error
120+
121+
} else {
122+
123+
do {
124+
try session.setCategory(category.rawValue)
125+
} catch let error as NSError {
126+
print("AKAsettings Error: Cannot set AVAudioSession Category to \(String(describing: category))")
127+
print("AKAsettings Error: \(error))")
128+
throw error
129+
}
131130
}
132131
}
133132

AudioKit/Common/Internals/AKTable.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,23 @@ public struct AKTable: Collection {
160160
mutating func standardSawtoothWave() {
161161
let phaseOffset = Int(phase * count)
162162
for i in indices {
163-
values[i] = -1.0 + 2.0 * Float((i + phaseOffset) % count) / Float(count)
163+
values[i] = Float(-1.0 + 2.0 * Float((i + phaseOffset) % count) / Float(count))
164164
}
165165
}
166166

167167
/// Instantiate the table as a reverse sawtooth wave
168168
mutating func standardReverseSawtoothWave() {
169169
let phaseOffset = Int(phase * count)
170170
for i in indices {
171-
values[i] = 1.0 - 2.0 * Float((i + phaseOffset) % count) / Float(count)
171+
values[i] = Float(1.0 - 2.0 * Float((i + phaseOffset) % count) / Float(count))
172172
}
173173
}
174174

175175
/// Instantiate the table as a sine wave
176176
mutating func standardSineWave() {
177177
let phaseOffset = Int(phase * count)
178178
for i in indices {
179-
values[i] = sin(2 * 3.14159265 * Float(i + phaseOffset) / Float(count))
179+
values[i] = Float(sin(2 * 3.14159265 * Float(i + phaseOffset) / Float(count)))
180180
}
181181
}
182182

@@ -217,15 +217,15 @@ public struct AKTable: Collection {
217217
mutating func positiveReverseSawtoothWave() {
218218
let phaseOffset = Int(phase * count)
219219
for i in indices {
220-
values[i] = 1.0 - Float((i + phaseOffset) % count) / Float(count)
220+
values[i] = Float(1.0) - Float((i + phaseOffset) % count) / Float(count)
221221
}
222222
}
223223

224224
/// Instantiate the table as a sine wave
225225
mutating func positiveSineWave() {
226226
let phaseOffset = Int(phase * count)
227227
for i in indices {
228-
values[i] = 0.5 + 0.5 * sin(2 * 3.14159265 * Float(i + phaseOffset) / Float(count))
228+
values[i] = Float(0.5 + 0.5 * sin(2 * 3.14159265 * Float(i + phaseOffset) / Float(count)))
229229
}
230230
}
231231
}

AudioKit/Common/Internals/Audio File/AKAudioFile+ConvenienceInitializers.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ extension AKAudioFile {
2222
baseDir: BaseDirectory = .resources) throws {
2323

2424
let filePath: String
25-
let fileNameWithExtension = name
2625

2726
switch baseDir {
2827
case .temp:
@@ -39,6 +38,9 @@ extension AKAudioFile {
3938
throw NSError(domain: NSURLErrorDomain, code: NSURLErrorFileDoesNotExist, userInfo: nil)
4039
}
4140
filePath = path!
41+
case .custom:
42+
print( "ERROR AKAudioFile: custom creation directory not implemented yet")
43+
throw NSError(domain: NSURLErrorDomain, code: NSURLErrorCannotCreateFile, userInfo: nil)
4244

4345
}
4446
let fileUrl = URL(fileURLWithPath: filePath)
@@ -101,6 +103,9 @@ extension AKAudioFile {
101103

102104
print( "ERROR AKAudioFile: cannot create a file in applications resources")
103105
throw NSError(domain: NSURLErrorDomain, code: NSURLErrorCannotCreateFile, userInfo: nil)
106+
case .custom:
107+
print( "ERROR AKAudioFile: custom creation directory not implemented yet")
108+
throw NSError(domain: NSURLErrorDomain, code: NSURLErrorCannotCreateFile, userInfo: nil)
104109
}
105110

106111
let nsurl = URL(string: filePath)

0 commit comments

Comments
 (0)