@@ -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