Skip to content

Commit 858da7e

Browse files
Merge pull request #168 from NickCulbertson/Sampler-Load-Delay
Add SFZ Load Delay
2 parents 1baba79 + 408579d commit 858da7e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ class InstrumentSFZConductor: ObservableObject, HasAudioEngine {
2121
}
2222

2323
init() {
24-
// Load SFZ file with Dunne Sampler
25-
if let fileURL = Bundle.main.url(forResource: "Sounds/sqr", withExtension: "SFZ") {
26-
instrument.loadSFZ(url: fileURL)
27-
} else {
28-
Log("Could not find file")
24+
DispatchQueue.main.async {
25+
// Load SFZ file with Dunne Sampler.
26+
// This needs to be loaded after a delay the first time
27+
// to get the correct Settings.sampleRate if it is 48_000.
28+
if let fileURL = Bundle.main.url(forResource: "Sounds/sqr", withExtension: "SFZ") {
29+
self.instrument.loadSFZ(url: fileURL)
30+
} else {
31+
Log("Could not find file")
32+
}
33+
self.instrument.masterVolume = 0.15
2934
}
30-
instrument.masterVolume = 0.15
3135
engine.output = instrument
3236
}
3337
}

0 commit comments

Comments
 (0)