Hi!
I’m on the steep part of the learning curve and would appreciate help getting me over a bump.
I’ve extended sfload.csd that comes with the Environment Vars sample of the CsoundUnity package to play back a simple major scale sequence of notes from an array. I’ve also added basic functionality to change the preset instrument via a slider. In the Unity and Cabbage editors this works fine, but I’m having weird pitch issues in my Android build. The pitches for the different presets appear to be offset - some worse than others. I wonder if it’s an issue with the way I’m triggering the notes? I’m attaching my edit to sfload.csd and a recording of the out of tune playback from my Android device.
<Cabbage>
form caption("Sequencer"), size(300, 200)
rslider bounds(108, 78, 60, 60) channel("BPM") range(30, 300, 130, 1, 0.001)
rslider bounds(202, 76, 60, 60) channel("patch") range(0, 127, 0, 1, 1)
</Cabbage>
<CsoundSynthesizer>![sf2SequencerAndroidPitchIssue|audio](upload://is1bNlOKClTeCqKSeAlBVKpifqw.mp3)
<CsOptions>
-n -d
</CsOptions>
<CsInstruments>
; By Menno Knevel - 2020
sr = 48000
ksmps = 64
nchnls = 2
0dbfs = 1
; load in two soundfonts
isf sfload "sf_GMbank.sf2"
ir sfload "07AcousticGuitar.sf2"
sfplist isf
sfplist ir
; first sf_GMbank.sf2 is loaded and assigned to start at 0 and counting up to 328
; as there are 329 presets in sf_GMbank.sf2 (0-328).
; then 07AcousticGuitar.sf2 is loaded and assigned to replace the 10th preset of already loaded sf_GMbank.sf2
sfpassign 0, isf
sfpassign 10, ir
instr SEQUENCER
kBeat init 0
kPatch = abs(chnget:k("patch"))
kBPM = abs(chnget:k("BPM"))
kNotes[] fillarray 60, 62, 64, 65, 67, 69, 71, 72
if metro(kBPM/60) == 1 then
event "i", "PlayVoice", 0, 0.75, kNotes[kBeat], kPatch
kBeat = (kBeat < 7 ? kBeat+1 : 0)
endif
endin
instr PlayVoice
iptc = p5
inum = p4
idur = p3
ivel = 100
kamp linsegr 1, idur, 0, .1, 0
kamp = kamp/500000 ;scale amplitude
kfreq = 1 ;do not change freq from sf
a1,a2 sfplay3 ivel, inum, kamp*ivel, kfreq, iptc ;preset index = 60
outs a1, a2
endin
</CsInstruments>
<CsScore>
f0 z
i"SEQUENCER" 0 z
</CsScore>
</CsoundSynthesizer>