Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Sources/CDunneAudioKit/SamplerDSP.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down
21 changes: 20 additions & 1 deletion Tests/DunneAudioKitTests/SamplerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,26 @@ class SamplerTests: XCTestCase {
sampler.stop(noteNumber: 88)
testMD5(audio)
}


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)

func testSamplerAttackVolumeEnvelope() {
let engine = AudioEngine()
let sampleURL = Bundle.module.url(forResource: "TestResources/12345", withExtension: "wav")!
let file = try! AVAudioFile(forReading: sampleURL)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force Try Violation: Force tries should be avoided. (force_try)

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)) //run test for a second before setting parameters
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment Spacing Violation: Prefer at least one space after slashes for comments. (comment_spacing)

sampler.attackDuration = 1.0
sampler.load(avAudioFile: file)
audio.append(engine.render(duration: 1.0))//run test to give time to load
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment Spacing Violation: Prefer at least one space after slashes for comments. (comment_spacing)

sampler.play(noteNumber: 65, velocity: 127)
audio.append(engine.render(duration: 6.0))
sampler.stop(noteNumber: 65)
testMD5(audio)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)

/// Run this test with thread sanitizer.
func testSamplerThreadSafety() {
let engine = AudioEngine()
Expand Down
1 change: 1 addition & 0 deletions Tests/DunneAudioKitTests/ValidatedMD5s.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extension XCTestCase {

let validatedMD5s: [String: String] = [
"-[SamplerTests testSampler]": "8739229f6bc52fa5db3cc2afe85ee580",
"-[SamplerTests testSamplerAttackVolumeEnvelope]": "bf00177ac48148fa4f780e5e364e84e2",
"-[SynthTests testChord]": "155d8175419836512ead0794f551c7a0",
"-[SynthTests testMonophonicPlayback]": "77fb882efcaf29c3a426036d85d04090",
"-[SynthTests testParameterInitialization]": "e27794e7055b8ebdbf7d0591e980484e",
Expand Down