CLEO.BAS DMS Science Fair, May 1995. June 1997 by Marc Kummel aka Treebeard. Contact mkummel@rain.org, http://www.rain.org/~mkummel/ CLEO is recent code from the vault (1995) to work with sound samples using a Sound Baster sound card. Looking back at this project, I'm amazed what a big ambitious program it became! CLEO does things that shouldn't be possible in Basic, including realtime FFT frequency analysis, and playing samples on a MIDI keyboard, varying the playback rate to follow your playing. It's a powerful experience to literally play John Coltrane on a keyboard! CLEO is demanding, and it might not work right on any computer but mine. But give it a shot: * CLEO needs VGA, and a mouse, and at least 4MB of RAM. (No problem.) * CLEO needs expanded EMS memory, NOT extended XMS. EMS is now an antique, and you don't have it unless you loaded it on purpose. You can get EMS in DOS with the EMM386 driver in your CONFIG.SYS (without the /NOEMS switch) or with a driver like QEMM (which I use). Run MEM to see if EMS is available. Read the manuals. * I wrote CLEO for my original Sound Blaster Pro sound card which supports 8-bit stereo sampling to 44k (2x22k). CLEO accesses the SBPro through the CT-VOICE.DRV driver that Creative provided with my card, and that driver is probably hardware dependent. If you have a different SoundBaster card, look in your \SB\DRV directory to see if the file exists, and if so, copy it to your CLEO directory. If you don't find it or you have some other card without a driver, then try the provided file. I don't *think* you can hurt anything by trying, but you're on your own! If that doesn't work, then TS, you're out of luck! CTV3.DRV is a generic driver (mono only) that I started to write to see if I could do realtime effects. You can load *any* driver if you start CLEO with /D. * CLEO needs to find your sound card. The default address is (hex) 220. CLEO also checks for BLASTER and SOUND settings in your environment, or you can start CLEO with /SB200 to set the address to (hex) 200. * CLEO can speak MIDI only with a Roland-compatible MPU MIDI card. I use a MusicQuest card. Sound Blaster MIDI will NOT work. Without MIDI, you can still play samples with a mouse on a graphic keyboard, but a real keyboard is much more fun, and has extra features! CLEO also needs to find your MIDI card. The default address is (hex) 330. If yours is different, say (hex) 300 like mine, then start CLEO with /A300 or add SET TBMIDI=300 to your AUTOEXEC.BAT file. * CLEO cannot control an internal CD drive, but it can read from one. It's easier to supply audio through the MIC or LINE-IN (default) inputs on your sound card. Use the CLEO Mixer to change settings. * CLEO can read 8-bit WAV files, but it can only save VOC files. It adds a few bytes of loop data to saved VOC files hidden in a comment, but that won't interfere with other software. 16-bit sound files might confuse CLEO. There are shareware programs to change formats. * I can't get CLEO to run under Windows. I get a message that the Sound and MIDI devices are already in use. Is there a trick here? * CLEO can only use main memory to play samples because I couldn't figure out how to use EMS with the CT-VOICE driver. I'm sure this is fixable. As is, CLEO is limited to samples of about 300k, though it can store 16 different 300k tracks using EMS memory if it's available. Code overlays, screen windows, and some editing functions also use EMS, and unexpected things might happen if you use it all. * CLEO crashes regularly, especially with heavy MIDI play action. I follow my rule and always blame the hardware. The recessed RESET button on my computer is black from my pen! (But I've never lost anything.) Don't tempt fate with the highest sample rates, and don't have any other important programs running at the same time! * I wrote CLEO for MS Basic PDS v7.10. It will NOT work with QBasic because it uses a library and multiple modules. I haven't tested it with QuickBasic, but it might need work. * Use XQB.BAT to start PDS with the right switches and libraries. Even with PDS, CLEO grew to the point that it will not run within the IDE. What a pain! Do: Edit: Compile: Link: Test: [*Reset*] Loop. This is partly why I stopped playing with this. Of course this is the norm with C/C++! LIGHTSHO.BAS uses some of the same code to make a realtime lightshow. It's small enough to run inside the Basic IDE, so it might be easier to play with it first if you are interested in the source code. LIGHTSHO.BAS is available from Treebeard's Basic Vault. I only have MY computer to try my programs on. Let me know if you DO or DON'T get CLEO to work on your hardware, especially if you change anything. I'll give credit and update. CLEO is named for my mother-in-law Cleo Sonnenfeld, who passed away while I was working on this program. Cleo was also demanding, and worth it. To start CLEO, type: CLEO [/SB] [/A] [/D] Once it starts, CLEO is easy to navigate, but it has *lots* of menus. Options always appear on the bottom line. Click with the mouse, or use the cursor keys to select and press , or just press the first letter of the command. always goes back on a menu. Try ile nfo to see if the settings match your hardware. ile uit exits the program. CLEO has more features than I can remember, so explore! Select ile oad to load the TRANE.VOC sample that came with CLEO and should be in your current directory. Then try the different options from the main screen: Always plays the current sample. You can get nice scratch effects by pressing fast. Always backs out of a menu or cancels a selection. <0-9> Select active track. Tracks 10-16 are available with the mouse or menus.

lay Play the current sample, with options for looping between the different loop points. oice Should copy/merge tracks, but doesn't work yet, *sigh*. dit Opens an important sub-menu with lots of options to change or edit the current sample. You can't get here unless a sample is loaded. There's lots to do here. * There is an EDIT STACK so you can manipulate your sample and merge back a copy, which is handy for custom effects. It uses typical FORTH commands to push, pop, dup, etc., all available from the keyboard or on the button bar in the lower part of the screen. * Press <0-9> to ZOOM into your sample at different levels. * Try the x menu to add Echo, Delay, Noise, or other sound effects * Use the pectrum menu to view your sample as a frequency-domain spectrum or sonograph. * Use the ime menu to time-shift a sample or change the playback rate. * Use the ake menu to add mathematical waveforms to your sample. * Several important options are *Under Construction* aka on my wish list. ixer A nice graphic Mixer that lets you select inputs, set volume levels, and test them. I'm proud of this. ample Record a sample to memory from the current input device, with options for sampling rate, etc. ealtime Realtime displays of sound coming in. Lots of options. Try connecting a mic or electric guitar and watch the requency display--this is a whole class on the physics of sound! The aveform, scilloscope and ector displays are pretty cool with good music coming through line-in. ightshow is just an idea to have graphics follow the music. Cthugha is much better, but this proves it's possible in Basic! eyboard Play the current sample on a MIDI or virtual keyboard! This is major fun! You should set loop points first. (See below.) Try loading TRANE.VOC to get started with a sample of John Coltrane that already has decent loop points. avetable Custom make your own waveforms with splines, and then play them back with MIDI using the eyboard option. Results are so-so. Samples are much more interesting! ile Load, Save, Info, Quit, etc. You can load multiple samples by selecting different tracks, but only one sample at a time can play. elp I wish! This is it. Most of these menu choices - especially dit if there is a sample in memory - have their own sub-menus. Try everything. Usually you can UNDO, but SAVE first to be sure, or PUSH an extra copy to the edit stack. LOOP POINTS need an explanation. A sample starts at the ALPHA point and ends at the OMEGA point. But when you play back a sample from a MIDI keyboard, playback begins with the ATTACK or START POINT. As long as you hold the key down, it loops the SUSTAIN part between the start and end LOOP POINTS. When you release the key, it plays the RELEASE to the END POINT. The loop points are especially important, since if they are not set right, you will get a "click" or "pop" noise, or worse. You must pick your loop points so the end of the wave segues smoothly back into the start. It's a pain, and hard to get right, but real sampling keyboards work this way. The ATTACK, SUSTAIN, and RELEASE points are shown in the SAMPLE WINDOW as: -----------|--------|----------------------|---------------|----------- | | | /\ | | | | /\ | | /\ / \ | | /\ | | / \ | /\ | / \ / \ | /\ /\ | / \ | | / \ | / \ |/ \/ \ /\ | / \ / \ | / \| |/ \|/ \/| \ / \ | / \/ \ | / | | | | \/ \|/ \ | / | | | | | \|/ | -----------|--------|----------------------|---------------|----------- alpha [ < > ] omega start start start end end end sample play loop loop play sample | | | | | |______________________| | |_______________________________________________| ^ ^ ^ ^ | ATTACK | | RELEASE | ^ ^ MIDI MIDI key down key up You can set these pointers with your mouse if you click on a [<>] button and then click and release in the sample screen. You can also click and drag in the sample screen to make the sustain loop. If you select dit and then zoom in with <0-9>, you can get single byte precision. You can experiment with different sorts of playback from the

lay menu. Small differences in the loop points make a BIG difference in playback quality! CLEO saves your loop points along with your sample when you select VOC+ as the Save format. (This does NOT interfere with the file for other programs that use VOC files.) I've included the file TRANE.VOC which is a sample of John Coltrane's "I Want to Talk About You" from the Impulse _Live at Newport '63_ album. This was one of the first samples I made, and by luck I hit the loop just right to keep the drums and bass going smoothly through the sustain. There's something almost sinful about playing this from a keyboard! If you play this sample at different pitches, you'll also notice the biggest weakness of my program. When you play the sample at a high or low pitch, the timing changes. CLEO only changes the playback rate to change pitch, so lower notes are slower (and lower pitched) and higher notes are faster (and higher pitched). Everything is "Chipmonked"! I think the right way to do pitch-shifting is to do a FFT to get a spectrum of the original, shift the spectrum, and then do an inverse FFT to restore the sample. That IS beyond Basic, at least in realtime! There's good science to be done with this program. Load the BIRD.VOC file and Play it. Then slow it down with the Keyboard or Edit\Time options. It becomes a different bird! Maybe the diversity of bird calls is not so great as first appears? There are real discoveries waiting for someone who records nature sounds and manipulates with them with a program like this. It could show unsuspected links between species of insects or birds or amphibians. I bought a recording Walkman, and I'm working on it. You can tell I'm proud of CLEO. Let me know what you think! The files: CLEO.EXE DOS executable CLEO.PIF run CLEO full screen in Win31 (maybe) CLEO.ICO a Win31 icon (swiped from ICOLIB) CT-VOICE.DRV Sound Blaster Pro driver CTV3.DRV another driver to try VGAOEM.FON Win31 font TRANE.VOC John Coltrane sample with loop pointers BIRD.VOC bird sample (not Charlie Parker!) README.TXT this file TBVAULT.TXT about Treebeard's Basic Vault ------------ CLEO.MAK file list for PDS/QB CLEO.BAS source code: main module SBMOD12.BAS source code: more sound and menus SBSUP14.BAS source code: support routines SBMIDI01.BAS source code: MIDI stuff GFONT5.BAS source code: use Win31 fonts EMS3.BAS source code: EMS support SBMOD.BI include files of shared and common stuff SBSUP.BI SBMID.BI SBLIB6.LIB library for compiling with BC SBLIB6.QLB quick library for PDS IDE SBLIB6.TXT about the library SBDRV.ASM MASM source to call CT-VOICE (in SBLIB) CTV3.ASM MASM source for alternate SB driver XQB.BAT batch file to start PDS and load code MAKE.BAT batch file to compile and link from DOS prompt CLEO.LNK LINK response file called by MAKE.BAT Guidance from: Conger, C Programming For MIDI, 1988. Heimlich etc, Sound Blaster: The Official Book, Osborne, 1993. Munnik and Oostendorp, The Sound Blaster Book, Sybex, 1994. Music Quest, MIDI Co-Processor Card Technical Reference, 1988. Olson, Music, Physics and Engineering, 1967. Stolz, The Sound Blaster Book, Abacus, 1992. Winsor and DeLisa, Computer Music in C, 1991. This program and source code are yours to use and modify as you will, but they are offered as freeware with no warranty whatsoever. Give me credit, but do not distribute any changes under my name, or attribute such changes to me in any way. You're on your own! Send comments and fixes to: Marc Kummel aka Treebeard mkummel@rain.org http://www.rain.org/~mkummel/ For more interesting Basic software with source code, check out Treebeard's Basic Vault at http://www.rain.org/~mkummel/basic/