Exporting wav from midi-based instruments

Hello all.

I am trying to export to wav and I get no errors, but I also get no wav-file. My code is all in a csd-file and I call it with csound filename.csd and if I use -o dac than it plays as I want it to in the wav-file. A, somewhat simplified, version of my code is below:

< CsoundSynthesizer >
< CsOptions >
-Q0 -W -d -o test.wav
< CsOptions >
< CsInstruments >
; Regular definitions of sampling rate, signal control rate, ksmps, nchnls and massign

instr1
ichn = 1
midiout = 192, 1, p6, 1
noteondur2 ichn, p4, p5, p3
endin
< /CsInstruments >
< CsScore >
i1 0 0.5 43 127 1
< /CsScore >
< /CsoundSynthesizer >

Re: Exporting wav from midi-based instruments

I don't see how your orchestra is supposed to make any output sound. The midiout and noteondur2 opcodes send Midi commands to an external Midi device and you have no other sound producing opcodes in instr 1. Is that what you intend here?

Also, I am not sure why you are not getting an error for this line:

midiout = 192, 1, p6, 1

There should be no equals sign in that line.

I also suspect that running an orchestra that produces Midi output with -o test.wav instead of -odac will not do what you want. -o test.wav tells Csound to run in NON-real-time which means it performs the CSD file as fast as it can. Sending Midi output under these conditions will not result in the correct timing for the Midi events. It is possible that you are not hearing anything because the "Note On" and "Note Off" events generated by the noteondur2 opcode are occurring nearly simultaneously.

Let us know if you continue to have trouble.

Anthony

There are not supposed to be

There are not supposed to be any other sound producing opcodes in instr1, it is to play the midi. The idea with the code is to create an easy to read and implement way to generate a midi of a certain note, length and type of instrument that confirms to rules needed for a program that I have. The reason for wanting to export to a wav-file is so that the end user does not require CSound on their machine, only the wav-files, and that developers only need the .csd file and CSound to easily create their own wav-files to be used.

So in essence this is what I was going for:
1. Create a midi instrument where note number, length and type of instrument can be defined in the score.
2. Export this midi instrument to a wav-file to be used in another program.

When I play this in realtime I am hearing the sound perfectly, exactly as I want it. When I try to export it to wav NO file, absolutely none, is created from the above code. No error is shown, but no file is created in the same folder as I run and have the csd file. If I got a file that was empty I would agree with above, but being that I get no output file at all I am stumped.

Christoffer

PS There is no "=" in the code, I am sitting on two seperate machines and transcribed incorrectly.

MIDI is not WAV!

I'm afraid you're confusing two completely separate protocols here. I imagine what is happening when you play the file real-time is that somehow the MIDI events are getting automatically redirected to the soft-synth in your computer. (Don't know your setup, so I have no idea how this is happening.)

MIDI events are note descriptions, not audio signals in themselves, so they can't be recorded in a WAV file (an audio-only format). They can be preserved in a ".mid' file for playback on other machines, and Csound should be able to write one for you (use the "--midioutfile=..." command line option), but then others will have to have a midifile player on their machines as well.

If you really want to produce a WAV audio file, you will either actually have to generate the actual audio from Csound, or somehow capture the output from your computer's synth.

Yes I know MIDI is not WAV :-)

I may have written incorrectly. Simply what I wanted to do is use the performance from the score that I hear when I do -odac to be recorded as wav, but I think I understand what you are saying. I have now tested the --midioutfile=FILENAME, using test.mid as the file name, but am not getting an output file from there either. Is it because I am not using enough in the commandline? To get the file to play sounds, the ones I want to save, I used:
< CsOptions >
-Q0 -o dac dm6
< /CsOptions >

I tried changing this to:
--midioutfile=test.mid
as well as
-M a --midioutfile=test.mid

I even tried combining the first with those two and I am still not getting an outfile. If anyone knows why, please let me know.

I have already sat trying to capture the output to my speakers, but due to my soundcard and Vista this is not the easiest thing. Have one more option, line out-line in and recording this which will hopefully work. Thanks for the help, I will be doing all my future sound projects on anything but a Vista-machine and try to avoid MIDI :-)

OK, but...

I'm still thoroughly confused as to what your goal actually is. I gather that the desired end result is a wav file that has, say, some piano sounds in it, rather than any synthesized audio. So in essence you're feeding midi to the synth in Vista, and want to record the output of that into a wav. What I can't figure is why Csound is necessary here at all -- there are easier ways of supplying midi -- like sequencers.

In any case, it sounds as if your main problem is channelling synth output to a file, and as a non-Microsoft user I can't help you here (:-/) I'd be inclined to put the Csound part aside, and use a standard midifile to drive things.

I did play a while, though, and I find first that -- under Linux -- I can generate a standard midifile with command line options like:
--midioutfile=test.mid -d -n

If I don't put the '-n' in, I always get a wav file generated (unless I have '-o dac'). Having dac there or not doesn't affect the generated midifile -- it always gets the same timing, so you don't have to run in real-time to produce it.

Looking back at your original options line '-Q0 -o test.wav', if you got no errors, you should definitely have written an output file (though it would have been full of silence)! Are you sure it's not in some other folder? Did you do a Search for it? You should also have gotten the same MIDI output as you did with 'o dac', but it would have been generated at full speed, not in real-time, so you wouldn't hear anything. (Same thoughts on finding test.mid...)

If you do want Csound to generate midi, I found there are some things to bear in mind. For one thing, 'midiout' is executed (continuously) at k-rate, so your example was generating an awful lot of program changes! You need to do something like:

kstatus init 192
midiout kstatus, 1, p4, 1
kstatus = 0

so it only gets invoked once. Even if you do that, though, using the same start-time as the note-generator opcode doesn't seem to work! ...Definitely a Csound nasty...
It invariably sends (or writes) the note-on before the program-change! As:

0: Note On chan 1 G-3 [43] vel=127
0: Program Change chan 1 Bright Piano [2]
1500: Note Off chan 1 G-3 [43] (vel=127)

I found this happens even if you use separate instruments! You have to send the program-change (in a separate instrument) slightly earlier than the note-on. Mnyehh.
[Personally I'd avoid Csound for MIDI generation...]

cheap generic viagra viagra uk ed pills z pak cialis online Canadian pharmacy viagra buy zithromax pharmacy uk z pack z-pack avanafil kamagra uk Canadian pharmacy buy viagra uk viagra online ed drugs generic cialis z-pak generic viagra zpack staxyn zpak cialis uk