Skip to content

Commit b33d2c8

Browse files
committed
Added key to pitchcorrect
1 parent 2ca1e0c commit b33d2c8

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

Sources/CSoundpipeAudioKit/Effects/PitchCorrectDSP.mm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ void init(int channelCount, double sampleRate) override {
4444
pitchcorrect_create(&pitchcorrect_r);
4545
pitchcorrect_init(sp, pitchcorrect_r);
4646

47-
// Default chromatic scale from A1 (55Hz) to A6 (1760Hz)
48-
float defaultScale[1] = {440.00};
49-
setWavetable(defaultScale, 1, 0);
5047
}
5148

5249
void deinit() override {
@@ -82,6 +79,7 @@ void process(FrameRange range) override {
8279
pitchcorrect_set_scale_freqs(pitchcorrect_l, scale, scaleCount);
8380
pitchcorrect_set_scale_freqs(pitchcorrect_r, scale, scaleCount);
8481

82+
8583
pitchcorrect_set_speed(pitchcorrect_l, speed);
8684
pitchcorrect_set_amount(pitchcorrect_l, amount);
8785

@@ -103,4 +101,3 @@ void process(FrameRange range) override {
103101
AK_REGISTER_DSP(PitchCorrectDSP, "pcrt")
104102
AK_REGISTER_PARAMETER(PitchCorrectParameterSpeed)
105103
AK_REGISTER_PARAMETER(PitchCorrectParameterAmount)
106-

Sources/SoundpipeAudioKit/Effects/PitchCorrect.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import Tonic
1010
public class PitchCorrect: Node {
1111
let input: Node
1212

13-
var key: Key
13+
public var key: Key {
14+
didSet {
15+
updateScaleFrequencies()
16+
}
17+
}
1418

1519
/// Connected nodes
1620
public var connections: [Node] { [input] }
@@ -84,24 +88,20 @@ public class PitchCorrect: Node {
8488
for octave in 0...7 {
8589
for noteClass in key.noteSet.noteClassSet.array {
8690
let noteWithOctave = Note(noteClass.letter, accidental: noteClass.accidental, octave: octave)
87-
print(noteClass)
88-
frequencies.append(Float(noteWithOctave.pitch.frequency))
91+
frequencies.append(UInt8(noteWithOctave.pitch.midiNoteNumber).midiNoteToFrequency())
8992
}
9093
}
9194

9295
// Sort frequencies in ascending order
9396
frequencies.sort()
94-
print(frequencies)
95-
print(frequencies.count)
9697

9798
// Set the frequencies in the DSP
98-
au.setWavetable(frequencies)
99+
setScaleFrequencies(frequencies)
99100
}
100-
101-
}
102-
103-
extension Pitch {
104-
var frequency: Double {
105-
return Double(UInt8(midiNoteNumber).midiNoteToFrequency())
101+
102+
/// Set the scale frequencies for pitch correction
103+
/// - Parameter frequencies: Array of frequencies in Hz
104+
public func setScaleFrequencies(_ frequencies: [Float]) {
105+
au.setWavetable(frequencies)
106106
}
107107
}

Tests/SoundpipeAudioKitTests/Effects Tests/PitchCorrectTests.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@ class PitchCorrectTests: XCTestCase {
2727

2828
// Ramp frequency from 110 to 880 over 10 seconds
2929
oscillator.$frequency.ramp(to: 440, duration: 5.0)
30-
31-
// pitchCorrect.setScaleFrequencies([220,245,350,395])
32-
// pitchCorrect.setValidNotes(root: .C, scale: .major)
33-
// pitchCorrect.setValidNotes(.C, .Dsharp, .E)
34-
35-
30+
3631
audio.append(engine.render(duration: 5.0))
3732

3833
testMD5(audio)
39-
audio.audition()
4034
}
4135
}

Tests/SoundpipeAudioKitTests/ValidatedMD5s.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ let validatedMD5s: [String: String] = [
5454
"-[VocoderTests testVocoder]": "3836def448fed8ac901b179e943e6922",
5555
"-[VibratoTests testVibrato]": "4bad4a6d951683cf6745a79b96b6aae2",
5656
"-[VibratoTests testParameterSweep]": "cc3613847ed31d6566bbd4f6907e26e5",
57-
"-[PitchCorrectTests testPitchCorrect]": "7585bf87d60d73a700da0921cbc72981"
57+
"-[PitchCorrectTests testPitchCorrect]": "9128a5a1eb68d491af693028fcbc9668"
5858
]

0 commit comments

Comments
 (0)