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?
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?
<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>
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.
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.
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: