Skip to content

Commit 82d07d0

Browse files
committed
Fixed Vocoder
1 parent 5a895b3 commit 82d07d0

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

Sources/CSoundpipeAudioKit/Effects/VocoderDSP.mm

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717
ParameterRamper attackRamp{0.1};
1818
ParameterRamper releaseRamp{0.1};
1919
ParameterRamper bwRatioRamp{0.5};
20-
21-
float attackTimeL = 0.1;
22-
float releaseTimeL = 0.1;
23-
float bwRatioL = 0.5;
24-
float attackTimeR = 0.1;
25-
float releaseTimeR = 0.1;
26-
float bwRatioR = 0.5;
2720

2821
public:
2922
VocoderDSP() {
@@ -35,9 +28,13 @@
3528

3629
void init(int channelCount, double sampleRate) override {
3730
SoundpipeDSPBase::init(channelCount, sampleRate);
31+
32+
// Create and initialize vocoders first
3833
sp_vocoder_create(&vocoderL);
39-
sp_vocoder_init(sp, vocoderL);
4034
sp_vocoder_create(&vocoderR);
35+
36+
// Initialize vocoders after setting parameters
37+
sp_vocoder_init(sp, vocoderL);
4138
sp_vocoder_init(sp, vocoderR);
4239
}
4340

@@ -50,6 +47,7 @@ void deinit() override {
5047
void reset() override {
5148
SoundpipeDSPBase::reset();
5249
if (!isInitialized) return;
50+
5351
sp_vocoder_init(sp, vocoderL);
5452
sp_vocoder_init(sp, vocoderR);
5553
}
@@ -62,22 +60,11 @@ void process(FrameRange range) override {
6260
float excitationInR = input2Sample(1, i); // modulator input right
6361
float outSampleL;
6462
float outSampleR;
65-
66-
attackTimeL = attackRamp.getAndStep();
67-
releaseTimeL = releaseRamp.getAndStep();
68-
bwRatioL = bwRatioRamp.getAndStep();
6963

70-
attackTimeR = attackTimeL;
71-
releaseTimeR = releaseTimeL;
72-
bwRatioR = bwRatioL;
73-
74-
vocoderL->atk = &attackTimeL;
75-
vocoderL->rel = &releaseTimeL;
76-
vocoderL->bwratio = &bwRatioL;
77-
vocoderR->atk = &attackTimeR;
78-
vocoderR->rel = &releaseTimeR;
79-
vocoderR->bwratio = &bwRatioR;
80-
64+
*vocoderL->atk = *vocoderR->atk = attackRamp.getAndStep();
65+
*vocoderL->rel = *vocoderR->rel = releaseRamp.getAndStep();
66+
*vocoderL->bwratio = *vocoderR->bwratio = bwRatioRamp.getAndStep();
67+
8168
sp_vocoder_compute(sp, vocoderL, &sourceInL, &excitationInL, &outSampleL);
8269
sp_vocoder_compute(sp, vocoderR, &sourceInR, &excitationInR, &outSampleR);
8370

Tests/SoundpipeAudioKitTests/Effects Tests/VocoderTests.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class VocoderTests: XCTestCase {
1616
excitation.$frequency.ramp(to: 440, duration: 5.0)
1717

1818
// Create vocoder with both signals
19-
let vocoder = Vocoder(source, excitation: excitation, attackTime: 0.123, releaseTime: 0.24, bandwidthRatio: 0.324)
20-
vocoder.$attackTime.ramp(from: 0.01, to: 0.5, duration: 5.0)
21-
vocoder.$releaseTime.ramp(from: 0.01, to: 0.5, duration: 5.0)
19+
let vocoder = Vocoder(source, excitation: excitation)
20+
vocoder.$attackTime.ramp(from: 0.1, to: 0.5, duration: 5.0)
21+
vocoder.$releaseTime.ramp(from: 0.1, to: 0.5, duration: 5.0)
2222
vocoder.$bandwidthRatio.ramp(from: 0.1, to: 2.0, duration: 5.0)
2323

2424
engine.output = vocoder
@@ -32,7 +32,5 @@ class VocoderTests: XCTestCase {
3232
audio.append(engine.render(duration: 5.0))
3333

3434
testMD5(audio)
35-
// audio.audition()
3635
}
3736
}
38-

Tests/SoundpipeAudioKitTests/ValidatedMD5s.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ let validatedMD5s: [String: String] = [
5151
"-[PitchTapTests testBasic]": "5b6ae6252df77df298996a7367a00a9e",
5252
"-[PluckedStringTests testDefault]": "3f13907e6e916b7a4bf6046a4cbf0764",
5353
"-[TalkboxTests testTalkbox]": "316ef6638793f5fb6ec43fae1919ccff",
54-
"-[VocoderTests testVocoder]": "1e084a4d0399923b923ff6a07dc8a320",
54+
"-[VocoderTests testVocoder]": "3836def448fed8ac901b179e943e6922",
5555
]

0 commit comments

Comments
 (0)