Cabbage Logo
Back to Cabbage Site

fout can't open sound file?

Hi! I’m trying to record my drum instrument with the fout upcode, however it only gives me an error where it can’t open the sound file. Can anyone help me with this issue?

Edit: Hope this helps

<Cabbage>
    form caption("Drum´n´Samp") size(320, 200), guiMode("queue"), pluginId("1002") colour(100, 150, 170), bundle("Clap.wav", "GlitchSnare.wav", "Jacku.wav")
    keyboard bounds(14, 228, 326, 74) channel("keyboard3")

    vslider bounds(10, 24, 50, 150) channel("Kick") range(0, 1, 0.5, 0.8, 0.01) text("Kick") trackerColour(0, 255, 255, 255) fontColour(0, 0, 0, 255) textColour(0, 0, 0, 255)
    vslider bounds(60, 24, 50, 150) channel("Snare") range(0, 1, 0.5, 0.8, 0.01) text("Snare") trackerColour(0, 255, 255, 255) fontColour(0, 0, 0, 255) textColour(0, 0, 0, 255)
    vslider bounds(110, 24, 50, 150) channel("HH") range(0, 1, 0.5, 0.8, 0.01) text("Hi-Hat") trackerColour(0, 255, 255, 255) fontColour(0, 0, 0, 255) textColour(0, 0, 0, 255)
    vslider bounds(160, 24, 50, 150) channel("Clap") range(0, 1, 0.5, 0.8, 0.01) text("Clap") trackerColour(0, 255, 255, 255) fontColour(0, 0, 0, 255) textColour(0, 0, 0, 255)
    vslider bounds(210, 24, 50, 150) channel("GlitchSnare") range(0, 1, 0.5, 0.8, 0.01) text("Glitch") trackerColour(0, 255, 255, 255) fontColour(0, 0, 0, 255) textColour(0, 0, 0, 255)
    vslider bounds(260, 24, 50, 150) channel("Jacku") range(0, 1, 0.5, 0.8, 0.01) text("Jacku") trackerColour(0, 255, 255, 255) fontColour(0, 0, 0, 255) textColour(0, 0, 0, 255)
</Cabbage>

<CsoundSynthesizer>
    <CsOptions>
        -n -d -+rtmidi=NULL -M0 --midi-key=4 --midi-velocity-amp=5
    </CsOptions>
    <CsInstruments>
        ; Initialiserer globale verdier
        ksmps   = 32
        nchnls  = 2
        0dbfs   = 1

        ; Distortion Table
        gifn ftgen 0, 0, 257, 9, 0.5, 1, 270


        instr 1
            ; Initialiserer i-variabler
            iNote = p4
            iAmp = p5

            ; Initialiserer k-variabler
            kKick   cabbageGetValue "Kick"
            kSnare  cabbageGetValue "Snare"
            kHH     cabbageGetValue "HH"
            kClap   cabbageGetValue "Clap"
            kGlitch cabbageGetValue "GlitchSnare"
            kJacku  cabbageGetValue "Jacku"

            ; EGENGENERERTE LYDER
            ; KICK
            if iNote == 36 then
                kOscEnv expon 1, 0.15, 0.00001
                kPitchEnv expon 150, 0.5, 50
                aOsc oscil kOscEnv, kPitchEnv
                kNoiseEnv expon 0.1, 0.05, 0.00001
                aNoise rand kNoiseEnv * iAmp
                aKick = aOsc + aNoise
                aMix distort aKick, 0.3, gifn
                aMaster = aMix * kKick
                outs aMaster, aMaster

            ; SNARE
            elseif iNote == 38 then
                kOscEnv expon 0.4, 0.1, 0.00001
                aOsc oscil kOscEnv, 150
                kOscEnv2 expon 0.7, 0.02, 0.00001
                aOsc2 vco2 kOscEnv2, 300
                aOsc3 oscil kOscEnv, 300
                kNoiseEnv expon 0.4, 0.2, 0.00001
                aNoise rand kNoiseEnv * iAmp
                aKick = aOsc + aOsc2 + aOsc3 + aNoise
                aMix distort aKick, 0.3, gifn
                aMaster = aMix * kSnare
                outs aMaster, aMaster

            ; HIGH-HAT
            elseif iNote == 40 then
                kOscEnv2 expon 0.2, 0.02, 0.00001
                aOsc2 vco2 kOscEnv2, 500
                kNoiseEnv expon 0.3, 0.1, 0.00001
                aNoise rand kNoiseEnv * iAmp
                aKick = aOsc + aOsc2 + aNoise
                aMix distort aKick, 0.3, gifn
                aMaster = aMix * kHH
                outs aMaster, aMaster

            ; SAMPLES
            ; SAMPLE  1
            elseif iNote == 41 then
                aSampleL, aSampleR diskin2 "Clap.wav", 1, 0, 0
                iLen filelen "Clap.wav"
                xtratim iLen
                aMaster = (aSampleL * iAmp) * kClap
                outs aMaster, aMaster

            ; SAMPLE  2
            elseif iNote == 43 then
                aSampleL, aSampleR diskin2 "GlitchSnare.wav", 1, 0, 0
                iLen filelen "GlitchSnare.wav"
                xtratim iLen
                aMaster = (aSampleL * iAmp) * kGlitch
                outs aMaster, aMaster

            ; SAMPLE  3
            elseif iNote == 45 then
                aSampleL, aSampleR diskin2 "Jacku.wav", 1, 0, 0
                iLen filelen "Jacku.wav"
                xtratim iLen
                aMaster = (aSampleL * iAmp) * kJacku
                outs aMaster, aMaster
            endif

            fout "hello.wav", 18, aMaster, aMaster
        endin


    </CsInstruments>
    <CsScore>
        f0 z
    </CsScore>
</CsoundSynthesizer>

Hi @Hoodi3, welcome to the forum. Can you edit your post so the code appears formatted. Right now it’s kind of tricky to read.

1 Like

I think you might need to use an absolute path for the sound file name?

Sorry, but what do you mean with an absolute path? Do you have an example?

I mean a full path, for example, if you’re on a mac it might looks something like this:

“/Users/name/Document/hello.wav”

but you’ll need to check with your system where you want to output the file to

1 Like

It worked! However, the sample rate or something seems to be completely off. Could this be because the path is on my iCloud or should that not have any say?

I don’t think that should make a difference, where are you getting 18 from in the fout line? I usually use 4 for 16bit recordings.

Thought 18 = 24 bit wav, maybe 4 will give a better result. Let me try that.

Oh you could be right :thinking: It’s a while since I read that particular manual page :rofl:

So I’ve but the recording time to 10 seconds in score, its not using iCloud, and its set to 4. Still however, the sound file is 16 seconds long?? and sounds all messed up.

Oh wait, I see an issue. You should use a separate instrument for recording. Try something like this:

instr 99
a1, a2 monitor
fout "hello.wav", 4, a1, a2
endin
schedule(99, 0, 9999)
1 Like

Have anyone told you you’re a genius? Well you are! Thanks for the help Rory! It all worked out.

Ha, no genius here. Just another poor soul who’s been down the same road you’re on now!

1 Like