csound BACK .. CSound: belibige Audiodateien konvertieren oder einfach Klänge programmieren ============================================================================ Csound Magazin Das programmieren soll hiermit ja wirklich toll funktionieren, aber das konvertieren haut noch nicht so einfach und Fehlerfrei hin. Dafür nehme ich lieber TiMidity. konvertieren: ============= http://www.csound.org http://www.csounds.com/istvan/html/csscripts.html Es können nur IRCAM, WAV, AIFF und RAW-Dateien geschrieben werden! MIDI (format 0) kann auch gelesen werden, und zum Beispiel in eine WAVE-Datei konvertieren aber man braucht auch eine orc- und eine sco-Datei, die man sich noch besorgen muss. MIDI-Datei konvertieren: ------------------------ Eine Einfache midi-, orc- und eine sco-Datei kann man für Testzwecke hier runterladen: mididemo.mid sinemid.orc sin1.sco (Standard MIDI file to Csound Score converter: Midi2Cs dieses Programm erstellt aus MIDI-Dateien die erforderlichen orc- und eine sco-Dateien; leider ist es nicht als Script, sondern nur als Binärdatei zu bekommen; es wurde von "rubo@snafu.berlin.de" geschrieben) (MIDI-Dateien können auch mit TiMidity auch ohne Programmieraufwand abgespielt und konvertiert werden.) # csound -d -m7 -H1 -W -b 4096 -B 4096 -F name.mid -o name.wav -i [sound input file] name.orc name.sco csound -d -m7 -H1 -W -b 4096 -B 4096 -F mididemo.mid -o mididemo.wav sinemid.orc sin1.sco ################################################################################ ### hier die gedruckte Version: sinemid.orc ################################################################################ ; A simple oscilator orchestra that gets notes from a MIDI ; file. sr=44100 kr=2205 ksmps=20 nchnls=1 instr 1 ; use function number 1 in score for sound wave: ; f1 0 8192 10 1 ; (the above example is a pure sine wave) ; get MIDI values for each note: icps cpsmidi ; get midi note in cps ivel veloc ; get midi velocity iamp = ivel*32000/(10*127) ; scale velocity to amplitude output ; the value 3200/(10*127) was arrived at by informed guessing ; and then trial and error to refine it. ; display the amplitude values print iamp ; create envelope: irise = .01 ; envelope attack in seconds idec = 2 ; envelope decay in seconds iatdec = .01 ; attenuation factor (do not change) ; "linenr" creates an envelope with a given rise and ; decay (time after note off). "iatdec" is an arbitrarily ; small non-zero number. Experiment with different values ; for irise and idec, but iatdec should always be .01. kamp linenr iamp, irise, idec, iatdec ; generate sound asig1 oscili kamp, icps, 1 ; signal out asig1 ; output to soundfile endin ; The above instrument should play all MIDI channels in your ; sequence. If you wanted to create a multi-timbral orchestra, ; you'd create additional instruments (instr 2, instr 3, etc.) ; and then MIDI channel 1 would trigger instr 1, channel 2 ; would trigger instr 2, etc. You'll see this with the ' ; subtractive synthesis orchestra. ################################################################################ ################################################################################ ### hier die gedruckte Version: sin1.sco ################################################################################ ; f1 defines the sound used by the oscilator. ; In this case there are four harmonics at the given ; relative loudnesses: 1 .5 0 .2 ; If you erased ".5 0 .2" you'd have a pure sine wave ; (no harmonics other than the fundamental). Experiment ; with different harmonic spectra. ; This file requires a MIDI file to generate sound. f1 0 8192 10 1 .5 0 .2 ; generate sine wave and harmonics f0 20 ; allot 20 seconds of time for MIDI performance e ################################################################################ nötige Informationen der Audiodatei anzeigen: --------------------------------------------- sndinfo [audiodatei] audiodatei: WAVE, 86297595 samples WAVE soundfile srate 44100, monaural, 16 bit shorts, 1956.86 seconds headersiz 46, datasiz 172595190 (86297595 sample frames) SCO-Datei erstellen: -------------------- echo "scale=6 ; ([sample frames audiodatei] + 32 ) / [srate audiodatei]" | bc -l -q echo "scale=6 ; (86297595 + 32 ) / 44100" | bc -l -q 1956.862290 echo " t 0 60 i 1 0 1956.862290 e" > [audiodatei].sco ORC-Datei erstellen (stereo): ----------------------------- echo "scale=6 ; [srate audiodatei] / 16" | bc -l -q 2756.250000 echo ' sr = 44100 kr = 2756.250000 ksmps = 16 nchnls = 2 seed 0 instr 1 a1,a2 soundin "[audiodatei]" a_ = a1 a__ unirand 1 a_ = a_+a__-0.5 a__ limit a_*2,-0.5,0.5 a_ limit a_+a__,-32767,32767 a1 = a_ a_ = a2 a__ unirand 1 a_ = a_+a__-0.5 a__ limit a_*2,-0.5,0.5 a_ limit a_+a__,-32767,32767 a2 = a_ outs a1,a2 endin' > [audiodatei].orc (Bei MONO ",a2" raus lassen! Bei vier Spuren, ",a3,a4" noch dazu schreiben!) neue Datei erstellen: --------------------- csound -d -m0 -H0 -W -s -b 65536 -B 65536 -o konvertiertedatei.wav [audiodatei].orc [audiodatei].sco Ausgabeformate: J = IRCAM-Datei W = WAV-Datei A = AIFF-Datei h = RAW-Datei TMP-Dateien löschen: -------------------- rm -f [audiodatei].orc [audiodatei].sco score.srt ################################################################################ ### BEISPIEL ################################################################################ bash-2.05b$ csound -d -m0 -H0 -W -s -b 65536 -B 65536 -o konvertiertedatei.wav audiodatei.orc audiodatei.sco Using /usr/X11R6/share/csound/csound.xmg 0dBFS level = 32767.0 Csound Version 4.23 (Feb 24 2004) orchname: audiodatei.orc scorename: audiodatei.sco orch compiler: 20 lines read instr 1 sorting score ... ... done Csound Version 4.23 (Feb 24 2004) displays suppressed Seeding from current time 135758336 0dBFS level = 32767.0 orch now loaded audio buffered in 65536 sample-frame blocks SFDIR undefined. using current directory writing 262144-byte blks of shorts to konvertiertedatei.wav (WAV) SECTION 1: [audiodatei]: WAVE, 86297595 samples audio sr = 44100, stereo, reading both channels end of score. overall amps: 32768.0 32768.0 overall samples out of range: 222 223 0 errors in performance peak Ch 1: 32768.000000 (written: 1.000000) at 3493252 peak Ch 2: 32768.000000 (written: 1.000000) at 3848289 1317 262144-byte soundblks of shorts written to konvertiertedatei.wav (WAV) ################################################################################ programmieren: ============== http://gy.bildungszentrum-markdorf.de/websites/ag/musik/csound/index.htm http://www.lakewoodsound.com/csound/hypertext/manual.htm Charakteristisch für CSound ist, dass der "eigentliche" Klang aus zwei Quellcode-Dateien erzeugt wird, einem sogenannten "score-file" (englisch: Auswertung; Endung .sco) und einem "orchestra-file" (englisch: Orchester; Endung .orc). Im SCO-File sind Informationen über den Verlauf des Klanges gespeichert, die im Klang vorkommenden Instrumente werden im ORC-File definiert. Kommentare werden mit einem Semikolon (;) eingeleitet, z.B.: ; Das ist ein Kommentar... [IMG]