Wave format not recognized on Windows

I’ve been trying to play a sample with CSound without a frontend in multiple ways but failed. The output says this:

INIT ERROR in instr 1 (opcode diskin) line 16: diskin2: samples/snaredrum
.wav: failed to open file: Format not recognised.
 from file .\main.csd (1),aRead diskin  "samples/snaredrum.wav" kSpeed  i
Skip    iLoop   0       0       0       0       0
          B  0.000 - note deleted.  i1 (snare) had 0 init errors

I downloaded or played different wave and ogg files but I get the same result. Also, I copied the exact code from different tutorial but same luck. I even install Cabbage and open my csd file and still didn’t get anything. This is my code taken from the official tutorial.

<CsoundSynthesizer>
<CsOptions>
-odac --env:SSDIR+=samples
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

instr snare
 kSpeed = p4
 iSkip = p5
 iLoop = p6
 aRead[] diskin "samples/snaredrum.wav", kSpeed, iSkip, iLoop
out aRead[0], aRead[0]
endin

</CsInstruments>
<CsScore>
i "snare" 0 2 1
</CsScore>
</CsoundSynthesizer>

I’m currently coding inside WSL NixOs although I run csound.exe from powershell to avoid setting up a pulseaudio server on Windows which is frankly a pain in the back.

Why I know this is related to samples only? Because I succesfully played a note from the osc opcode so it has to do with samples.

Can anyone lend me a hand on this please?

I’m wondering if the wav error is a red herring, perhaps Csound just can’t find the actual file. Can you try passing the absolute path?

1 Like

Thanks for taking time!

Yeah I feel the same, maybe csound can’t find my file. I’ll be trying to pass the absolute path and get back to you in few hours

Alright, I’m back with some progress.

I found this question on another forum after doing a bit of research to find a way to print out my sample path.

<CsoundSynthesizer>
<CsOptions>
-odac 
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

opcode getFullPath, S,S
    SFile xin
    xout sprintf("%s/%s", chnget:S("CSD_PATH"), SFile)
endop
instr snare
    a1, a2 diskin2 getFullPath("samples/snaredrum.wav"), 1, 0, 1
    outs a1, a2
endin

</CsInstruments>
<CsScore>
i "snare" 0 2 1
</CsScore>
</CsoundSynthesizer>

Now CSound complains with an failed to open file

INIT ERROR in instr 1 (opcode diskin2) line 17: diskin2: /samples/snaredrum.wav: failed to open file (No Error.)

I wish there was a more descriptive error log to describe why my sample file can’t be opened.

Is there a way to get a clearer output from my error on CSound?

I’ve just tried something different:

instr snare
    iCnt int 0
    SFilenames[] directory "samples"
    iNumberOfFiles lenarray SFilenames

    until iCnt>=iNumberOfFiles do
        printf_i "Filename = %s \n", 1, SFilenames[iCnt]
        iCnt = iCnt+1
    od
endin

This code actually outputs files on samples folder

Filename = samples\.
Filename = samples\..
Filename = samples\hihats.wav
Filename = samples\kick_drum.wav
Filename = samples\kick_o.ogg
Filename = samples\snaredrum.wav

So paths are fine, I’m gonna find another opcode for file names that can give me more clues on why I can’t open a file

i have some ideas / questions:

  1. your output always uses the backslash. did you try to use backslash
    in your own code, instead of slash?
  2. can you play the sound files with another application?
  3. did you install csound with libsndfile? actually when you use a
    normal installer, it should be included.
  4. instead of using diskin, you can also try to load your .wav into a
    function table via GEN01, just to see if there is the same issue. you
    can try this code in the global space (outside any instrument):
    gitable ftgen 0,0,0,1,“samples/snaredrum.wav”,0,0,1

joachim

1 Like

Thanks for taking time!

  1. My output has backslashes because I’m running csound from powershell. To get sound out from Windows Subsytem Linux I would have to use routing in a weird way that never worked for me :frowning:

  2. Bingo! That was the problem. For some reason I believed that my file was ok, it actually wasn’t though.

  3. I installed csound with the normal installer so it had to include lbsndfile

  4. Thanks! I tried to do that with my “snaredrum.wav” sample (corrupted file) so I had the same output. Code is right sample is not

Key lesson here is to check sample file first before working with them. I did a lot of things before doing that. One of them was to install csound on my desktop computer.

Your example was really useful as well :slight_smile: thanks for that Joachim

Have a good one :slight_smile:

glad to know you could figure out the reason, and thanks for the
feedback to the example!

1 Like