Skip to content

Commit d4e2f38

Browse files
authored
Merge pull request #2 from eljeff/develop
Develop
2 parents 01cf8bf + 729b14d commit d4e2f38

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ let package = Package(
1919
exclude: [
2020
"DunneCore/Sampler/Wavpack/license.txt",
2121
"DunneCore/Common/README.md",
22-
"DunneCore/Common/Envelope.hpp",
2322
"DunneCore/Sampler/README.md",
2423
"DunneCore/README.md",
2524
],

Sources/DunneAudioKit/Sampler.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,26 @@ public class Sampler: Node {
481481
}
482482
}
483483

484+
// Public load function that makes sense on a sample player - simply takes an AVfile and loads that
485+
public func loadAudioFile(file: AVAudioFile, rootNote: UInt8 = 48, noteFrequency: Float = 440,
486+
loKey: UInt8 = 0, hiKey: UInt8 = 127, loVelocity: UInt8 = 0, hiVelocity: UInt8 = 127,
487+
startPoint: Float = 0, endPoint: Float? = nil,
488+
loopEnabled: Bool = false, loopStartPoint: Float = 0, loopEndPoint: Float? = nil) {
489+
stopAllVoices()
490+
let descriptor = SampleDescriptor(noteNumber: Int32(rootNote), noteFrequency: noteFrequency,
491+
minimumNoteNumber: Int32(loKey), maximumNoteNumber: Int32(hiKey),
492+
minimumVelocity: Int32(loVelocity), maximumVelocity: Int32(hiVelocity),
493+
isLooping: loopEnabled,
494+
loopStartPoint: loopStartPoint,
495+
loopEndPoint: loopEndPoint ?? Float(file.length),
496+
startPoint: startPoint,
497+
endPoint: endPoint ?? Float(file.length))
498+
unloadAllSamples()
499+
loadAudioFile(from: descriptor, file: file)
500+
buildKeyMap()
501+
restartVoices()
502+
}
503+
484504
/// Stop all voices
485505
public func stopAllVoices() {
486506
akSamplerStopAllVoices(au.dsp)

0 commit comments

Comments
 (0)