From 88ae7dece8f512086fb2a2f28b677a33f1898065 Mon Sep 17 00:00:00 2001 From: Jeff Cooper Date: Wed, 20 Apr 2022 12:39:28 -0500 Subject: [PATCH 1/3] failing test showing attack is reset when loading a new sample --- Tests/DunneAudioKitTests/SamplerTests.swift | 25 +++++++++++++++++++- Tests/DunneAudioKitTests/ValidatedMD5s.swift | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Tests/DunneAudioKitTests/SamplerTests.swift b/Tests/DunneAudioKitTests/SamplerTests.swift index 46fc93d..7dc20fe 100644 --- a/Tests/DunneAudioKitTests/SamplerTests.swift +++ b/Tests/DunneAudioKitTests/SamplerTests.swift @@ -37,7 +37,30 @@ class SamplerTests: XCTestCase { sampler.stop(noteNumber: 88) testMD5(audio) } - + + func testSamplerAttackVolumeEnvelope() { + let engine = AudioEngine() + let sampleURL = Bundle.module.url(forResource: "TestResources/12345", withExtension: "wav")! + let file = try! AVAudioFile(forReading: sampleURL) + let sampler = Sampler() + sampler.load(avAudioFile: file) + sampler.masterVolume = 1 + engine.output = sampler + let audio = engine.startTest(totalDuration: 8.0) + audio.append(engine.render(duration: 1.0)) + sampler.attackDuration = 1.0 + // if you comment out the following load function, the test will pass + // i have confirmed via audio.audition() that setting attack above works, + // until you load a new sample, and then attack is rest, + // even though sampler.attackDuration will report back the value that was set + sampler.load(avAudioFile: file) + audio.append(engine.render(duration: 1.0)) + sampler.play(noteNumber: 65, velocity: 127) + audio.append(engine.render(duration: 6.0)) + sampler.stop(noteNumber: 65) + testMD5(audio) + } + /// Run this test with thread sanitizer. func testSamplerThreadSafety() { let engine = AudioEngine() diff --git a/Tests/DunneAudioKitTests/ValidatedMD5s.swift b/Tests/DunneAudioKitTests/ValidatedMD5s.swift index deb93d6..0a52883 100644 --- a/Tests/DunneAudioKitTests/ValidatedMD5s.swift +++ b/Tests/DunneAudioKitTests/ValidatedMD5s.swift @@ -12,6 +12,7 @@ extension XCTestCase { let validatedMD5s: [String: String] = [ "-[SamplerTests testSampler]": "8739229f6bc52fa5db3cc2afe85ee580", + "-[SamplerTests testSamplerEnvelopes]": "bf00177ac48148fa4f780e5e364e84e2", "-[SynthTests testChord]": "155d8175419836512ead0794f551c7a0", "-[SynthTests testMonophonicPlayback]": "77fb882efcaf29c3a426036d85d04090", "-[SynthTests testParameterInitialization]": "e27794e7055b8ebdbf7d0591e980484e", From af456aea2b82ab1afaa87c64fe0a132cf7045277 Mon Sep 17 00:00:00 2001 From: Jeff Cooper Date: Wed, 20 Apr 2022 12:39:45 -0500 Subject: [PATCH 2/3] brute force fix for failing test --- Sources/CDunneAudioKit/SamplerDSP.mm | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Sources/CDunneAudioKit/SamplerDSP.mm b/Sources/CDunneAudioKit/SamplerDSP.mm index 3cc779e..d8d5e3f 100644 --- a/Sources/CDunneAudioKit/SamplerDSP.mm +++ b/Sources/CDunneAudioKit/SamplerDSP.mm @@ -99,6 +99,42 @@ void akCoreSamplerSetLoopThruRelease(CoreSamplerRef pSampler, bool value) { void updateCoreSampler(CoreSampler* newSampler) { newSampler->init(sampleRate); + newSampler->setADSRAttackDurationSeconds(sampler->getADSRAttackDurationSeconds()); + newSampler->setADSRDecayDurationSeconds(sampler->getADSRDecayDurationSeconds()); + newSampler->setADSRHoldDurationSeconds(sampler->getADSRHoldDurationSeconds()); + newSampler->setADSRSustainFraction(sampler->getADSRSustainFraction()); + newSampler->setADSRReleaseHoldDurationSeconds(sampler->getADSRReleaseHoldDurationSeconds()); + newSampler->setADSRReleaseDurationSeconds(sampler->getADSRReleaseDurationSeconds()); + + newSampler->setFilterAttackDurationSeconds(sampler->getFilterAttackDurationSeconds()); + newSampler->setFilterDecayDurationSeconds(sampler->getFilterDecayDurationSeconds()); + newSampler->setFilterSustainFraction(sampler->getFilterSustainFraction()); + newSampler->setFilterReleaseDurationSeconds(sampler->getFilterReleaseDurationSeconds()); + + newSampler->setPitchAttackDurationSeconds(sampler->getPitchAttackDurationSeconds()); + newSampler->setPitchDecayDurationSeconds(sampler->getPitchDecayDurationSeconds()); + newSampler->setPitchSustainFraction(sampler->getPitchSustainFraction()); + newSampler->setPitchReleaseDurationSeconds(sampler->getPitchReleaseDurationSeconds()); + newSampler->pitchADSRSemitones = sampler->pitchADSRSemitones; + + newSampler->pitchOffset = sampler->pitchOffset; + newSampler->cutoffEnvelopeStrength = sampler->cutoffEnvelopeStrength; + newSampler->cutoffMultiple = sampler->cutoffMultiple; + newSampler->filterEnvelopeVelocityScaling = sampler->filterEnvelopeVelocityScaling; + newSampler->glideRate = sampler->glideRate; + newSampler->isFilterEnabled = sampler->isFilterEnabled; + newSampler->isLegato = sampler->isLegato; + newSampler->isMonophonic = sampler->isMonophonic; + newSampler->keyTracking = sampler->keyTracking; + newSampler->linearResonance = sampler->linearResonance; + newSampler->masterVolume = sampler->masterVolume; + newSampler->portamentoRate = sampler->portamentoRate; + newSampler->vibratoDepth = sampler->vibratoDepth; + newSampler->vibratoFrequency = sampler->vibratoFrequency; + newSampler->voiceVibratoDepth = sampler->voiceVibratoDepth; + newSampler->voiceVibratoFrequency = sampler->voiceVibratoFrequency; + newSampler->setLoopThruRelease(sampler->loopThruRelease); + sampler.set(newSampler); } }; From c6b860564f44a4d8f4f48eedc9c237fca84300f5 Mon Sep 17 00:00:00 2001 From: Jeff Cooper Date: Wed, 20 Apr 2022 12:42:06 -0500 Subject: [PATCH 3/3] clean up test (which now passes) --- Tests/DunneAudioKitTests/SamplerTests.swift | 8 ++------ Tests/DunneAudioKitTests/ValidatedMD5s.swift | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Tests/DunneAudioKitTests/SamplerTests.swift b/Tests/DunneAudioKitTests/SamplerTests.swift index 7dc20fe..63813dc 100644 --- a/Tests/DunneAudioKitTests/SamplerTests.swift +++ b/Tests/DunneAudioKitTests/SamplerTests.swift @@ -47,14 +47,10 @@ class SamplerTests: XCTestCase { sampler.masterVolume = 1 engine.output = sampler let audio = engine.startTest(totalDuration: 8.0) - audio.append(engine.render(duration: 1.0)) + audio.append(engine.render(duration: 1.0)) //run test for a second before setting parameters sampler.attackDuration = 1.0 - // if you comment out the following load function, the test will pass - // i have confirmed via audio.audition() that setting attack above works, - // until you load a new sample, and then attack is rest, - // even though sampler.attackDuration will report back the value that was set sampler.load(avAudioFile: file) - audio.append(engine.render(duration: 1.0)) + audio.append(engine.render(duration: 1.0))//run test to give time to load sampler.play(noteNumber: 65, velocity: 127) audio.append(engine.render(duration: 6.0)) sampler.stop(noteNumber: 65) diff --git a/Tests/DunneAudioKitTests/ValidatedMD5s.swift b/Tests/DunneAudioKitTests/ValidatedMD5s.swift index 0a52883..6f05d4a 100644 --- a/Tests/DunneAudioKitTests/ValidatedMD5s.swift +++ b/Tests/DunneAudioKitTests/ValidatedMD5s.swift @@ -12,7 +12,7 @@ extension XCTestCase { let validatedMD5s: [String: String] = [ "-[SamplerTests testSampler]": "8739229f6bc52fa5db3cc2afe85ee580", - "-[SamplerTests testSamplerEnvelopes]": "bf00177ac48148fa4f780e5e364e84e2", + "-[SamplerTests testSamplerAttackVolumeEnvelope]": "bf00177ac48148fa4f780e5e364e84e2", "-[SynthTests testChord]": "155d8175419836512ead0794f551c7a0", "-[SynthTests testMonophonicPlayback]": "77fb882efcaf29c3a426036d85d04090", "-[SynthTests testParameterInitialization]": "e27794e7055b8ebdbf7d0591e980484e",