Skip to content

Commit 6fc74c3

Browse files
committed
Updated dynamic oscillator to use protocol
1 parent 8460b4c commit 6fc74c3

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SoundpipeAudioKit/Generators/DynamicOscillator.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import CAudioKitEX
99
/// Reads from the table sequentially and repeatedly at given frequency.
1010
/// Linear interpolation is applied for table look up from internal phase values.
1111
///
12-
public class DynamicOscillator: Node {
12+
public class DynamicOscillator: DynamicWaveformNode {
1313

1414
/// Connected nodes
1515
public var connections: [Node] { [] }
@@ -20,7 +20,7 @@ public class DynamicOscillator: Node {
2020
fileprivate var waveform: Table?
2121

2222
/// Callback whten the wavetable is updated
23-
public var wavetableUpdateHandler: ([Float]) -> Void = { _ in }
23+
var waveformUpdateHandler: ([Float]) -> Void = { _ in }
2424

2525
/// Specification details for frequency
2626
public static let frequencyDef = NodeParameterDef(
@@ -100,20 +100,24 @@ public class DynamicOscillator: Node {
100100

101101
}
102102

103-
// MARK: - Public Methods
103+
// MARK: - Protocol methods
104104

105105
/// Sets the wavetable of the oscillator node
106-
///
107-
/// - Parameters:
108-
/// - waveform: The waveform of oscillation
109-
public func setWaveTable(waveform: Table) {
106+
/// - Parameter waveform: The waveform of oscillation
107+
public func setWaveform(_ waveform: Table) {
110108
au.setWavetable(waveform.content)
111109
self.waveform = waveform
112-
wavetableUpdateHandler(waveform.content)
110+
waveformUpdateHandler(waveform.content)
113111
}
114112

115113
/// Gets the floating point values stored in the oscillator's wavetable
116-
public func getWavetableValues() -> [Float] {
114+
public func getWaveformValues() -> [Float] {
117115
return waveform?.content ?? []
118116
}
117+
118+
/// Set the waveform change handler
119+
/// - Parameter handler: Closure with an array of floats as the argument
120+
public func setWaveformUpdateHandler(_ handler: @escaping ([Float]) -> Void) {
121+
waveformUpdateHandler = handler
122+
}
119123
}

Tests/SoundpipeAudioKitTests/Generator Tests/DynamicOscillatorTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ class DynamicOscillatorTests: XCTestCase {
8383
oscillator.start()
8484
let audio = engine.startTest(totalDuration: 1.0)
8585
audio.append(engine.render(duration: 0.5))
86-
oscillator.setWaveTable(waveform: Table(.square))
86+
oscillator.setWaveform(Table(.square))
8787
audio.append(engine.render(duration: 0.5))
8888
testMD5(audio)
8989
}
9090

9191
func testGetWavetableValues() {
9292
let engine = AudioEngine()
9393
let oscillator = DynamicOscillator(waveform: Table(.square), frequency: 400)
94-
let floats = oscillator.getWavetableValues()
94+
let floats = oscillator.getWaveformValues()
9595
XCTAssertEqual(floats, Table(.square).content)
9696
engine.output = oscillator
9797
oscillator.start()
@@ -104,13 +104,13 @@ class DynamicOscillatorTests: XCTestCase {
104104
let engine = AudioEngine()
105105
var floats: [Float] = []
106106
let oscillator = DynamicOscillator(waveform: Table(.square), frequency: 400)
107-
oscillator.wavetableUpdateHandler = { newFloats in
107+
oscillator.setWaveformUpdateHandler { newFloats in
108108
floats = newFloats
109109
}
110110
engine.output = oscillator
111111
oscillator.start()
112112
let audio = engine.startTest(totalDuration: 1.0)
113-
oscillator.setWaveTable(waveform: Table(.square))
113+
oscillator.setWaveform(Table(.square))
114114
audio.append(engine.render(duration: 1.0))
115115
XCTAssertEqual(floats, Table(.square).content)
116116
testMD5(audio)

0 commit comments

Comments
 (0)