Cabbage Logo
Back to Cabbage Site

Does selecting a range in soundfiler produce a output?

Found something. If you mark the region, then unmark it and save a new preset, the regionStart is not updated correctly in the new preset

Thatā€™s the position in samples of the place you last clicked. I can have it revert to 0 but thatā€™s even more of a lie. I guess setting it to -1 would be best?

[edit] setting it to -1 makes a mess of the entire thing, I think Iā€™ll leave it. regionStart means nothing unless regionLength is greater than 0. If you keep that in mind I donā€™t see any issues, or am I missing something?

Youā€™re right, seems to save and load presets correctly the way it is now.

ā€¦but something else I also noticed:

If you close Reaper, and reopen the project, the audio-file will not play until you re-load it into the sampler.

I think itā€™s just down to how you code it. This example works fine for me:

<Cabbage>
form caption("Stretch") size(600, 500), guiMode("queue"), pluginId("1287"), colour (0,100,0)
keyboard bounds(102, 380, 381, 95)
rslider bounds(378, 302, 60, 60) channel("Speed") range(0.001, 1, 1, 1, 0.001)
soundfiler bounds(110, 52, 300, 200), channel("Soundfiler1", "Soundfiler2"), colour(188, 188, 188), tableBackgroundColour(62, 71, 86), showScrubber(1), displayType("mono")
presetbutton bounds(24, 14, 120, 23), channel("PresetChannel"), colour:0(16, 19, 22, 255), fontColour(176, 176, 176), textColour(176, 176, 176), presetNameAsText(1), factoryFolder("#USER_APPLICATION_DATA_DIRECTORY/CabbageTest/Soundfiler/Presets/Factory", "*.psts"), userFolder("#USER_APPLICATION_DATA_DIRECTORY/CabbageTest/Soundfiler/Presets/User", "*.psts"), highlightedItemColour(200, 200, 200) highlightedTextColour(25, 25, 25), outlineColour(44, 47, 49), outlineThickness(1), corners(2)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 98
    gSfile cabbageGet "LAST_FILE_DROPPED"

    if (changed(gSfile) == 1) then
        cabbageSet 1, "Soundfiler1", "file", gSfile
    endif
endin

instr 1
   Sfile cabbageGet "Soundfiler1", "file"
   if filevalid(Sfile) == 1 then
        if filenchnls(Sfile) == 1 then
            a1 diskin2 Sfile, 1, 0, 1
            outs a1, a1
        else
            a1, a2 diskin2 Sfile, 1, 0, 1
            outs a1, a2
        endif
   endif 
endin
</CsInstruments>
<CsScore>
f0 z
i98 0 z
</CsScore>
</CsoundSynthesizer>

Seems like you got me again, this example works fine :+1:

1 Like

I think thereā€™s a bug when getting the RegionStart, like I wrote here:

The issue is that the RegionStart is not correctly initialized to 0 after releasing the region. The RegionLength however works correct. If you use this in setting the starting position when reading a file, it will read from another point than what the soundfiler is visually displaying.

Edit: I also suspect the region-length is a wrong amount of samples? But not sure. Check the example below :+1:

<Cabbage>
form caption("Stretch") size(600, 500), guiMode("queue"), pluginId("1287"), colour (0,100,0)
keyboard bounds(102, 380, 381, 95)
rslider bounds(378, 302, 60, 60) channel("Speed") range(0.001, 1, 1, 1, 0.001)
soundfiler bounds(110, 52, 300, 200), channel("Soundfiler1", "Soundfiler2"), colour(188, 188, 188), tableBackgroundColour(62, 71, 86), showScrubber(1), displayType("mono")
presetbutton bounds(24, 14, 120, 23), channel("PresetChannel"), colour:0(16, 19, 22, 255), fontColour(176, 176, 176), textColour(176, 176, 176), presetNameAsText(1), factoryFolder("#USER_APPLICATION_DATA_DIRECTORY/CabbageTest/Soundfiler/Presets/Factory", "*.psts"), userFolder("#USER_APPLICATION_DATA_DIRECTORY/CabbageTest/Soundfiler/Presets/User", "*.psts"), highlightedItemColour(200, 200, 200) highlightedTextColour(25, 25, 25), outlineColour(44, 47, 49), outlineThickness(1), corners(2)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 98
    gSfile cabbageGet "LAST_FILE_DROPPED"

    if (changed(gSfile) == 1) then
        cabbageSet 1, "Soundfiler1", "file", gSfile
    endif
endin

instr 1
    Sfile cabbageGet "Soundfiler1", "file"
    
    iRegionStart cabbageGetValue "Soundfiler1"
    iRegionLength cabbageGetValue "Soundfiler2"
   
    iFileSr filesr gSfile 
    
    iSampleLengthSeconds filelen gSfile
    iRegionLengthSeconds divz iRegionLength, iFileSr, 44100
    
    printk 0.1, iSampleLengthSeconds 
    printk 0.1, iRegionLengthSeconds 

    if filevalid(Sfile) == 1 then
        if filenchnls(Sfile) == 1 then
            a1 diskin2 Sfile, 1, 0, 1
            outs a1, a1
        else
            a1, a2 diskin2 Sfile, 1, 0, 1
            outs a1, a2
        endif
    endif 
endin
</CsInstruments>
<CsScore>
f0 z
i98 0 z
</CsScore>
</CsoundSynthesizer>

Seems fine in my tests here. I have a four second clips, when I select half the instrument returns 2, a quarter, 1, etc.

Iā€™m not sure why you would use regionStart to set the starting position of playback, if there is no region set. Check regionLength, if itā€™s 0 use scrubberPosition to set playback back to the start of the file. That should do the trick.

My logic was that since both regionStart and regionLength initializes to 0 when compiling, and the regionLength sets automatically to 0 when releasing the region, the regionStart would also set to 0 when releasing the region :thinking:

Thanks, that seems like a good solution :+1:

Okay thanks, going to test this further then, must be my implementation.

It seems like thereā€™s a issue with the soundfiler, and I think it has to do with sample rate. Tested it on 3 different files with different sample rates, happened on all of them. Check out the example, this demonstrates the wrongly read region length.

I am on 48k sr.

<Cabbage>
form caption("Stretch") size(600, 500), guiMode("queue"), pluginId("1287"), colour (0,100,0)
keyboard bounds(102, 380, 381, 95)
rslider bounds(378, 302, 60, 60) channel("Speed") range(0.001, 1, 1, 1, 0.001)
soundfiler bounds(110, 52, 300, 200), channel("Soundfiler1", "Soundfiler2"), colour(188, 188, 188), tableBackgroundColour(62, 71, 86), showScrubber(1), displayType("mono")
presetbutton bounds(24, 14, 120, 23), channel("PresetChannel"), colour:0(16, 19, 22, 255), fontColour(176, 176, 176), textColour(176, 176, 176), presetNameAsText(1), factoryFolder("#USER_APPLICATION_DATA_DIRECTORY/CabbageTest/Soundfiler/Presets/Factory", "*.psts"), userFolder("#USER_APPLICATION_DATA_DIRECTORY/CabbageTest/Soundfiler/Presets/User", "*.psts"), highlightedItemColour(200, 200, 200) highlightedTextColour(25, 25, 25), outlineColour(44, 47, 49), outlineThickness(1), corners(2)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 98
    gSfile cabbageGet "LAST_FILE_DROPPED"

    if (changed(gSfile) == 1) then
        cabbageSet 1, "Soundfiler1", "file", gSfile
    endif
endin

instr 1
    Sfile cabbageGet "Soundfiler1", "file"
    
    iRegionStart cabbageGetValue "Soundfiler1"
    iRegionLength cabbageGetValue "Soundfiler2"
   
    iFileSr filesr gSfile 
    iFileLengthSeconds filelen gSfile
    
    iFileLengthSamples = iFileLengthSeconds*iFileSr
    
    printk 0.1, iFileLengthSamples // Original length
    printk 0.1, iRegionLength // Wrong, too many samples
    printk 0.1, iRegionLength * 44100/48000 // Correct amount of samples for me

    if filevalid(Sfile) == 1 then
        if filenchnls(Sfile) == 1 then
            a1 diskin2 Sfile, 1, 0, 1
            outs a1, a1
        else
            a1, a2 diskin2 Sfile, 1, 0, 1
            outs a1, a2
        endif
    endif 
endin
</CsInstruments>
<CsScore>
f0 z
i98 0 z
</CsScore>
</CsoundSynthesizer>

Hereā€™s a recording:

Iā€™ll take a look at this in a few days, Iā€™m away from a PC until then. Thanks as always for the test .CSD :+1:

1 Like

Did you get a chance to look at this? :slightly_smiling_face:

So there was an issue whereby I using the session sample rate to determine various things, which wasnā€™t correct. Iā€™ve pushed a fix, but have not time to test, would you mind giving it a go? Note one thing, selecting regions with the mouse will always be a little hit or miss because of the resolution of the waveform vs its sample rate. If the soundfiler is displaying a full 1 minute file, and the soundfiler width is 100px, then each mouse click will be quantised to 0.6 seconds. And it gets worse the larger the file.

Thanks, yeah I will test it today :+1:

Ok, tested now, and it still seems like thereā€™s something odd with the example I posted previously.

Hereā€™s the file Iā€™m using.

Strange, it looks fine for me here? Iā€™d expect the region length to be somewhat short of the full file length, but itā€™s never longer. Also, Iā€™m surprised this works with mp3, Iā€™d forgotten that Csound now supports them out of the box.

I am on 48k Hz sample rate, are you on the same?

I am now :+1: And I see the same issueā€¦

[edit] itā€™s strange that it works with 44.1 considering the sample rate of the file is 24kHzā€¦

1 Like

Must be hardcoded to 44.1 somewhere in the soundfiler?

Got it I thinkā€¦just testingā€¦

Ok, itā€™s working now :slight_smile: