Hdf5read crashes when used from cabbage

Hello everybody
I’m using Cabbage as a frontend for CSound and I’m trying to user hdf5write/hdf5read to save and restore datas to disk.
More precisely, in my instrument I make use of thos 2 lines:

hdf5write “test.h5”, kAvg, kWindowNumber, kWindowWriteIdx, kWindowReadIdx ; Write variables to an hdf5 file

;kAvg[], kWindowNumber, kWindowWriteIdx, kWindowReadIdx hdf5read "test.h5", "kAvg", "kWindowNumber", "kWindowWriteIdx", "kWindowReadIdx" ; Open hdf5 file and read variable

but if I remove the comment from the second one Cabbage suddenly crashes.
Both of these lines are used just when the user activate a button of the GUI (they are under 2 separate if) so should be a compile time issue.

Anyone as a problem like this?
Any alternative hints on how to save/load a k-array to/from disk?

I’m running under the following SW stack:

  • Windows 10
  • CSound 6.16 (double samples) Jul 17 2021
  • Cabbage 2.8.0

Thank you in advance

Sergio

Can you try this with vanilla Csound, i.e., from the command line outside of any host? I suspect you might have a similar issues there. Also, can you post the full .csd file so we can see if it’s not something else that is causing the problem?

Sorry for my late reply, I attach my files but I see I cannot upload file so I will post them separately

F:\mypath\src\cabbage>csound test_3.csd
0dBFS level = 32768.0
–Csound version 6.16 (double samples) Jul 17 2021
[commit: fb5bdb3681e15f56c216b4e4487b45848aa6b9f4]
libsndfile-1.0.31
UnifiedCSD: test_3.csd
STARTING FILE
Creating options
Creating orchestra
closing tag
Creating score
graph init…
rtaudio: PortAudio module enabled …
using callback interface
instr Hasher uses instrument number 1
instr hdf5read uses instrument number 2
Elapsed time at end of orchestra compile: real: 0.006s, CPU: 0.005s
sorting score …
… done
Elapsed time at end of score sort: real: 0.006s, CPU: 0.006s
midi channel 1 using instr 1
midi channel 2 using instr 2
midi channel 3 using instr 1
midi channel 4 using instr 1
midi channel 5 using instr 1
midi channel 6 using instr 1
midi channel 7 using instr 1
midi channel 8 using instr 1
midi channel 9 using instr 1
midi channel 10 using instr 1
midi channel 11 using instr 1
midi channel 12 using instr 1
midi channel 13 using instr 1
midi channel 14 using instr 1
midi channel 15 using instr 1
midi channel 16 using instr 1
midi channel 17 using instr 1
midi channel 18 using instr 1
midi channel 19 using instr 1
midi channel 20 using instr 1
midi channel 21 using instr 1
midi channel 22 using instr 1
midi channel 23 using instr 1
midi channel 24 using instr 1
midi channel 25 using instr 1
midi channel 26 using instr 1
midi channel 27 using instr 1
midi channel 28 using instr 1
midi channel 29 using instr 1
midi channel 30 using instr 1
midi channel 31 using instr 1
midi channel 32 using instr 1
midi channel 33 using instr 1
midi channel 34 using instr 1
midi channel 35 using instr 1
midi channel 36 using instr 1
midi channel 37 using instr 1
midi channel 38 using instr 1
midi channel 39 using instr 1
midi channel 40 using instr 1
midi channel 41 using instr 1
midi channel 42 using instr 1
midi channel 43 using instr 1
midi channel 44 using instr 1
midi channel 45 using instr 1
midi channel 46 using instr 1
midi channel 47 using instr 1
midi channel 48 using instr 1
midi channel 49 using instr 1
midi channel 50 using instr 1
midi channel 51 using instr 1
midi channel 52 using instr 1
midi channel 53 using instr 1
midi channel 54 using instr 1
midi channel 55 using instr 1
midi channel 56 using instr 1
midi channel 57 using instr 1
midi channel 58 using instr 1
midi channel 59 using instr 1
midi channel 60 using instr 1
midi channel 61 using instr 1
midi channel 62 using instr 1
midi channel 63 using instr 1
midi channel 64 using instr 1
0dBFS level = 1.0
!!WARNING: real time midi input disabled, using dummy functions
orch now loaded
audio buffered in 4096 sample-frame blocks
not writing to sound disk
SECTION 1:
new alloc for instr Hasher:

F:\mypath\src\cabbage>

<CsoundSynthesizer>
<CsOptions>
-n --displays -M0 -+rtmidi=NULL 
;-odac           -iadc     -d     ;;;RT audio I/O
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 48000
ksmps = 1
nchnls_i = 1
nchnls = 2
0dbfs = 1
 
instr Hasher
    ; Maximum window size in control units 
    ; (10 minutes control unit @48khz 1 ksmps = (control unit/samples ksmps) * samples/sec * sec/minute * number of minutes = 2.880.000)
    iMaxSamples = (1/ksmps) * sr * 60 * 10
;    iMaxSamples = 1000000
    
    ; window size (number of control rate units m)
    kWindowsSeconds = 60
    kWindowSize = (1/ksmps) * sr * kWindowsSeconds

    ; initial channels' slice size 
    kWindowNumber       init      0           ; current window number
    kWindowWriteIdx     init      -2          ; window sample write index
    kWindowReadIdx      init      -1          ; window sample read index
    kAvg[]              init      iMaxSamples ; sample average array
	
    ; init sample average to 0 just for the very first k time
    if (kWindowWriteIdx == -2) then
printks"before hdf5read:\n", 0
        aArray[], aVar, kVar hdf5read "f:/mypath/src/cabbage/example.h5", "aArray*", "aVar", "kVar" ; Open hdf5 file and read variables
printks"after hdf5read:\n", 0
;        kAvg[] = kAvg - kAvg
        kWindowWriteIdx = -1
    endif

    ; update sample read index
    kWindowReadIdx = (kWindowReadIdx + 1) % kWindowSize
    ; play current sample average
    aAverage = kAvg[kWindowReadIdx]

    ; dry / average signal mix is sent to both stereo channels
    aOut1 = aAverage *4;
    aOut2 = aOut1

    ; play audio output
    outs aOut1, aOut2

endin


</CsInstruments>
<CsScore>

;starts instrument 1 and runs it for a week
i "Hasher" 0 [60*60*24*7] 

</CsScore>
</CsoundSynthesizer>

And here is what’s reported from windows event viewer:


<Event xmlns="**http://schemas.microsoft.com/win/2004/08/events/event** ">

<System>

<Provider Name="**Application Error** " />

<EventID Qualifiers="**0** ">1000</EventID>

<Version>0</Version>

<Level>2</Level>

<Task>100</Task>

<Opcode>0</Opcode>

<Keywords>0x80000000000000</Keywords>

<TimeCreated SystemTime="**2022-01-11T10:18:44.6707481Z** " />

<EventRecordID>44770</EventRecordID>

<Correlation />

<Execution ProcessID="**0** " ThreadID="**0** " />

<Channel>Application</Channel>

<Computer>DESKTOP-7VKQU95</Computer>

<Security />

</System>

[-](#) <EventData>

<Data>csound.exe</Data>

<Data>0.0.0.0</Data>

<Data>60f29bb6</Data>

<Data>hdf5ops.dll</Data>

<Data>0.0.0.0</Data>

<Data>60f29bc2</Data>

<Data>c0000409</Data>

<Data>00000000001fd771</Data>

<Data>3378</Data>

<Data>01d806d49cc6ff60</Data>

<Data>C:\Program Files\Csound6_x64\bin\csound.exe</Data>

<Data>C:\Program Files\Csound6_x64\plugins64\hdf5ops.dll</Data>

<Data>4de3f3f3-394e-422f-bd59-64278f3a74a6</Data>

<Data />

<Data />

</EventData>

</Event>

So does it work Ok when you run it from the command line? Sorry, I don’t have access to a Windows machine right now to test this.

I don’t think so, because it starts allocation for the instrument and dies.
As you can see there’s neither “before hdf5read:” nor “after hdf5read:” in the output.
It seems like the invocation of hdf5read requires CSound to do something with hdf5ops.dll at compile time, when performing this task CSound dies abnormally so it cannot execute the code.
Obviously if I comment out the hdf5read line CSound compile and execute normally the file.

Is there a CSound log file, apart from Windows Event Viewer, where I can see some more details?

Unfortunately I cannot truss or strace the csound call on Windows, as far as I know.

I’m afraid not. You would need to build your Csound in debug mode and step through it with a debugger. Do the hdf5read examples work Ok? I’ve never used these opcodes, but if the examples don’t work you should file an issue on the Csound github tracker.

As I mentioned in the Cabbage list, you can use ftsave/ftread in conjunction with copya2ftab/copyf2array if you wish to save array data to disk and read it back again later.

no, they have the same problem

ok, but I’d like to use big arrays, so I think it’s not good for me because I should use pagination due to ftable limitations

That’s the reason why I’m trying to start using Juce as a CSound alternative: if I need to use a second tool to compile CSound maybe it’s easier start it again from scratch with a different tool

I also tried to invoke hdf5read from python in CSound, but the problem seems to be the same. If I read the file from python it works, If I use python from CSound doesn’t work.
I guess it could be caused by my antivirus or voicemeeter or something else, but hdfs5write works well, so I doubt that the read operation could be more invasive than the write one.

If the examples don’t work then post an issue. Even if you don’t end up using them, it means they can potentially be fixed for future users. If you have some experience in C/C++ it would be quite simple to create an opcode to do this. For example, check out these simple opcodes for reading/writing data to/from disk:

strToFile
fileToStr

Reading and writing array data is also pretty trivial.