Skip to content

Commit 3eda70f

Browse files
Add SFZ Load Delay
1 parent 1baba79 commit 3eda70f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ 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 to get the correct Settings.sampleRate if it is 48_000.
27+
if let fileURL = Bundle.main.url(forResource: "Sounds/sqr", withExtension: "SFZ") {
28+
self.instrument.loadSFZ(url: fileURL)
29+
} else {
30+
Log("Could not find file")
31+
}
32+
self.instrument.masterVolume = 0.15
2933
}
30-
instrument.masterVolume = 0.15
3134
engine.output = instrument
3235
}
3336
}

0 commit comments

Comments
 (0)