Linux MIDI: A Brief Survey, Part 4
The venerable Csound music and sound programming language has long supported MIDI input as MIDI files for play by Csound instruments or by a MIDI device for playing a Csound instrument by way of external hardware--keyboard, sequencer, wind controller. Thanks primarily to the work of developer Gabriel Maldonado, Csound also is a useful programming language for real-time MIDI output.
Playing a Csound instrument, an orc in Csound-speak, through an external MIDI device is a fairly simple procedure. The following orc file prepares a MIDI-sensitive instrument :
instr 1 inum notnum ; receive MIDI note number iamp ampmidi inum*50 ; use it to set amplitude scaling kfreq cpsmidib ; convert MIDI note number to Hertz frequency value a1 oscil iamp,kfreq,1 ; three detuned oscillators, each using a different waveform (see score below) a2 oscil iamp,kfreq*1.003,2 a3 oscil iamp,kfreq*.997,3 asig = a1+a2+a3 ; audio signal equals sum of three oscillators kenv linenr 1,.07,.11,.01 ; MIDI-controlled envelope for scaling output out asig*kenv ; output equals oscillators shaped by envelope endin
Notice that once MIDI data is captured by Csound, it can be utilized for any purpose within an instrument design.
This code provides the Csound score file, a sco in Csound-speak, for this instrument :
f1 0 8192 10 .1 0 .2 0 0 .4 0 0 0 0 .8 ; function tables for oscillator waveforms f2 0 8192 10 1 0 .9 0 0 .7 0 0 0 .4 f3 0 8192 10 .5 0 .6 0 0 .3 0 0 0 .9 f0 10000 ; placeholder to activate instrument for 10000 seconds e ; end score
In classic Csound you would run this orc/sco like so:
csound -o devaudio -M /dev/midi -dm6
where -o determines the output target, -M selects a MIDI input device and -dm6 sets the graphics and messaging levels. Instrument, score and launch options all can be rolled into a single CSD file, a format that unifies Csound's necessary components into one handy form.
Designing a Csound instrument involves the definition and connection of components called opcodes. A Csound opcode could be an oscillator (oscil), an envelope generator (linenr, linseg), a mathematic operator (=), a MIDI capture function (ampmid, cpsmidib) or any of the hundreds of other functions and capabilities available as Csound opcodes.
The following CSD-formatted Csound code demonstrates the moscil opcode, a MIDI output function. The instrument, instr 1, transmits a major scale as a series of MIDI note messages starting from a given note-number, 48, and rising according to the envelope curve described by the linseg opcode.
<CsoundSynthesizer> <CsOptions> ;;; The -Q flag selects a MIDI output port. ;;; An audio output device is required. -Q0 -o devaudio -dm6 </CsOptions> <CsInstruments> sr=44100 ; audio sampling rate, behaves as a ; tempo control for MIDI output kr=44100 ; signal control rate (equals sr ; for MIDI output best results) ksmps=1 ; samples per control period nchnls=1 ; number of audio channels instr 1 ival = 48 kchn = 0 knum linseg ival,1,ival+2,1,ival+4,1,ival+5,1,ival+7,1,ival+9,1, ival+11,1,ival+12 kdur = .8 kpause = .2 moscil kchn,knum,44,kdur,kpause ; There is no audio output stage. endin </CsInstruments> <CsScore> i1 0 8 e </CsScore> </CsoundSynthesizer>
The linseg envelope generator creates a multistage envelope in which each step corresponds to a scale degree. When this file is run with csound moscil-test.csd, a C major scale is played by whatever instrument is receiving data on the MIDI interface selected by the -Q option.
Csound has many opcodes dedicated to the reception, transmission and alteration of MIDI messages. The possibilities are intriguing: simultaneous MIDI input/output, given two physical ports; MIDI control of synthesis parameters; instruments with combined audio/MIDI output; and even MIDI control by way of Csound's FLTK-based GUI opcodes. With Csound, your imagination is the limit.
In my next column, I'll finish this MIDI tour with a look at some GUI-based experimental MIDI applications, including Tim Thompson's KeyKit, Jeffrey Putnam's Grammidity and Elody from GRAME, the MidiShare people. See you next month!
Dave Phillips is a musician, teacher and writer living in Findlay, Ohio. He has been an active member of the Linux audio community since his first contact with Linux in 1995. He is the author of The Book of Linux Music & Sound, as well as numerous articles in Linux Journal.
Similis sum folio de quo ludunt venti.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- SUSE LLC's SUSE Manager
- Google's SwiftShader Released
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- My +1 Sword of Productivity
- Managing Linux Using Puppet
- Non-Linux FOSS: Caffeine!
- SuperTuxKart 0.9.2 Released
- Interview with Patrick Volkerding
- Parsing an RSS News Feed with a Bash Script
- Rogue Wave Software's Zend Server
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide