💾 Archived View for mirrors.apple2.org.za › archive › ground.icaen.uiowa.edu › apple8 › Sounds › sou… captured on 2023-01-29 at 10:58:00.
-=-=-=-=-=-=-
SOUND EDITOR v2.2 ================= June 25, 1995 THE SOUND EDITOR ---------------- To make the SoftDAC sound capability on 8-bit Apples more useful and fun, I wrote a sound editor which can load sounds up to 1.8 seconds long, play them, display them, and manipulate them in various useful ways. Version 2.2 extends the capabilities of the sound editor significantly, by supporting 2:1 compression of sounds to conserve disk space, and by allowing the sample rate (and therefore the pitch and duration) of sounds to be altered. The editor allows you to adjust the volume or pitch up or down on a whole sound or any sub-segment of a sound. You can also cut and paste between and within sounds, allowing editing and "Max Headroom" effects. THE DISPLAY ----------- The editor display is a mixed hi-res/text screen. The hi-res portion contains two "oscilloscope" displays which show the envelope of the sound. The upper display shows the whole sound file and has two "marks"--vertical lines which can be moved by the left and right arrow keys. Only one mark is "active" and can be moved at a time. The active mark flashes. The RETURN key makes the other mark active. The text part of the display is used to display the size and duration (in milliseconds) of the currently marked segment, the amount of space available for sound and the length of the last segment "cut", the current prefix, and the current compression mode. (It also hides the lower 32 lines of the hi-res screen, which contain the code for the software DAC!) EDITOR COMMAND SUMMARY ---------------------- Load & Save The L and S keys "load" and "save" sounds from/to disk. Load replaces the sound currently in memory with the new sound. Save saves the currently marked sub-segment of the sound to disk. You will be asked to provide the file name. Typing apostrophe (') followed by RETURN will produce a disk catalog for the current prefix. (When specifying a file name, you are free to provide a complete or relative path name.) If you press L or S accidentally, type just RETURN without a file name and the load or save operation will be cancelled. The type of file loaded or saved depends on the current "compression mode", displayed in the lower left of the text area. In "uncompressed mode", raw binary sound files are loaded and saved. In "compressed mode", files loaded or saved are in a 2:1 compressed form with ProDOS filetype $F2 ("User type 2"). The default mode is compressed mode. For more information on sound compression, see "COMPRESSION" below. Toggle Compression Mode The K key toggles between "compressed mode" and "uncompressed mode." This mode determines what kind of file will be loaded or saved. Move Active Mark The left and right arrow keys move the active (flashing) mark in the corresponding direction. The speed of movement is multiplied by ten if the open-Apple key is held down while an arrow key is pressed. After the marks are positioned, pressing a command key (say, the SPACE bar) updates the oscilloscope and text displays. Activate Other Mark The RETURN key activates the inactive mark and deactivates the active mark. The active mark is always flashing. Play The SPACE bar updates the lower oscilloscope display and the text display to reflect the current placement of the marks, then plays the marked segment. Set Prefix The / key allows you to set the current prefix. The initial prefix is "<startup prefix>/sounds". If you type apostrophe (') followed by RETURN, a catalog of the subdirectories in the current subdirectory will be produced. If just RETURN is pressed, the set prefix operation will be cancelled. If the specified prefix starts with a "/", it is interpreted as a complete pathname. Otherwise, it is a relative prefix. If a relative prefix starts with a ".", the last element of the pathname will be removed before the new prefix is appended. A "." alone simply drops off the last element of the pathname. (I wish that ProDOS's PREFIX command worked this way!) It's no "SF.Get" (not enough space!) but you will find it's pretty easy to navigate. Both the current and the previous prefixes are saved, and can be "swapped" by the "$" command, below--this is, in some ways, handier than SF.Get! Swap Prefixes The $ key "$waps" (if you'll pardon the expression!) the current prefix and the previous prefix. This is particularly handy when you are editing sounds in one directory and saving them in another. Cut The C key (all command keys may be upper or lower case) "cuts" the currently marked sub-segment out of the sound and closes up the gap. The sound which was cut is saved in the "cut buffer", on /RAM disk. (If there is no /RAM volume when the editor is run, then the cut buffer will be saved at the current prefix.) The size of the cut buffer is displayed in the text area. Both marks are left at the point of the cut, so if you cut the wrong thing, just do a paste (see below) and everything will be as it was. Paste The P key "pastes" the contents of the cut buffer into the current sound at the location of the active marker, unless doing so would exceed the available space. The cut buffer can be pasted multiple times to produce various effects. The position of the marks after a paste permits it to be "undone" by performing a cut without moving the marks. The paste operation is aborted if nothing has been previously cut or if there is insufficient space to complete the paste. Adjust Volume The V key adjusts the "volume" of the current sub-segment by a factor which you supply. This can be used to "equalize" parts of a sound that were of very different amplitudes when they were sampled, or it can be used to set a sub-segment to silence by supplying a factor of zero. (This corrects a bug in earlier versions.) Pressing just RETURN will cause the volume adjust operation to be cancelled. The algorithm used to adjust volume is much faster than in earlier versions, so the "thermometer" display has been eliminated. Note that a series of volume adjustments may cause loss of information in the sound, such as clipping the peaks or losing bits of resolution. Although this can be used to produce some interesting effects, in general it results in loss of sound quality. Resample The R key is new in version 2. It "re-samples" the selected segment of a sound to 11025 Hz. from whatever sampling rate you input in samples per second. Resampling from rates other than 11025 Hz. is handy for changing the occasional non-11 kHz. sound to 11 kHz., but you will probably use it most for its effect of altering the pitch and duration of sounds or parts of sounds. For example, if you enter "11025" as the presumed rate, no change will occur, since 11025 samples per second is always the target rate. If you enter "8000", then additional samples will be interpolated to increase the size (and duration) of the sound by the ratio of 11025/8000, with a resulting decrease in pitch. If you enter a number of samples per second greater than 11025, then the size and duration of the segment will be decreased by the ratio 11025/<input freq>, and the pitch of the sound will increase. Pressing just RETURN without entering a rate will cancel the resample operation. The resampling algorithm used is a simple interpolative scheme, not based on digital filtering. While the result is approximate, it is good enough for most purposes, and is very fast. (In fact, it operates at approximately the speed of a single 8-bit multiply per generated sample!) Resampling, particularly "down-sampling" from a higher frequency to 11025 Hz., does not, in general, conserve all the information in the original sound. As a result, down-sampling followed by up-sampling will cause a noticeable loss of high frequencies in the sound. Your best bet is to try to resample directly from the original sound at the desired frequency in a single step for best fidelity. Resampling at ratios less than 1:10 or greater than 10:1 is not permitted (nor is it very useful). Play with resampling to get a feel for what works--remember, no harm is done as long as you don't "save" over the original sound. You may find a great cannon shot in that sampled pistol shot! Help The ? key will display a help screen with abbreviated descriptions of the available commands. (Who am I kidding? They aren't "descriptions" so much as "reminders" of what the keys do!) Quit The Q key ends the program and quits to ProDOS. (If you would prefer to quit to Basic, just change SOUND.EDITOR by replacing 'PRINT D$"bye"' with 'END' in statement 840 (minus the single quotes, of course). COMPRESSION ----------- If you get interested in sounds, you will start collecting them. Soon you will notice how quickly sampled sounds can eat up disk space at 11025 bytes per second! Saving them with 2:1 compression provides substantial relief with negligible loss in sound quality. SOUND.EDITOR uses a fast, effective, "lossy" compression technology known as ADPCM (for Adaptive Differential Pulse Code Modulation--you can see why it's known as ADPCM!). The algorithm used is similar to the IIgs's ACE tool algorithm in concept and fidelity, but is much smaller and faster in implementation. It is derived from the 16-bit ADPCM algorithm proposed by Intel as a standard for DVI (Digital Video Interactive). The assembler source (COMP.S and DECOMP.S) are provided to encourage wider use of ADPCM in the 8-bit Apple world. (In addition to being very small and very fast, this algorithm has the advantage of being openly available, unlike the ACE tool algorithm.) The idea of ADPCM is straightforward: instead of encoding the actual value of each 8-bit sample, a 4-bit value is used to encode the difference between the previous reconstructed sample and the current sample. The differences are crammed into 4 bits by employing an implicit scale factor which varies adaptively as a function of previously encoded differences. The effect is a sliding scale of differences, so that when the input is changing slowly, the resolution of the encoded differences is a single unit, allowing perfect reconstruction. When the input changes more rapidly, larger differences are encoded with less resolution, so the reconstructed output may not be accurate in the low bits. Fortunately, the human ear is not very sensitive to small errors in large (loud) signals, so ADPCM permits 2:1 compression with practically inaudible error. The particular algorithm I used, like most well designed ADPCM algorithms, does not compound errors when used repeatedly. That is, although small errors are introduced when compressing a sound which was not previously compressed, subsequent decompression and recompression does not introduce any additional errors. (Put another way, the algorithm is lossless for any sounds it has decompressed.) The decompression routine fits on page 3 with room to spare, while the compression routine uses most of one page at $9000. Space is tight in SOUND.EDITOR, forcing this placement, but you can reassemble the sources to put them anywhere you like. (You can also combine the sources, eliminating a copy of a table.) For a number of convenience reasons, like selective "catalogs" and error detection, it's handy for compressed files to have a unique ProDOS type. Since types $F1 to $F8 are reserved as "user defined" file types, I somewhat arbitrarily picked type $F2 for SOUND.EDITOR ADPCM sound files. If it gets to be popular, then perhaps a more formal allocation will be appropriate. SOUND SOURCES Unfortunately, you can't (yet!) digitize sounds with more than 1 bit precisonn on an unaided Apple ][, but there are a wealth of 8-bit digitized sounds available in the IIgs and Mac worlds, and many can be easily downloaded from online services. Sound files of "binary" type can be played without further ado. Type $D8 ("SND") files can be played and edited if you change their type to binary and ignore (meaning "cut" off) the 64-byte headers on them. The SOUND.EDITOR loads, plays, and edits uncompressed binary or compressed "type $F2" files, and saves in either format. If the original sample rate is not 11 kHz. then things will sound faster or slower than intended. Most sounds are digitized at 11 kHz., but if you encounter sounds that sound too high-pitched or too fast, it was sampled at a lower rate than 11025 Hz., so resample it from a lower frequency (8000 Hz. is common in some quarters). If it sounds lower or slower than intended, resample from a higher frequency (the Mac world has a bunch of sounds sampled at 22050 Hz.). An annoying obstacle to accessing all the IIgs and Mac sounds is the use of compression formats for which there are no 8-bit Apple decompressors (such as the IIgs version of ShrinkIt). This problem arises when a "great" sound is embedded in a forked file. If you can find a way to de-archive the file, then the widely available program UNFORKIT can make (either) fork into a plain binary file, so its sound content can be used on 8-bit Apples. A program to decompress "ACE" files on 8-bit Apples would also be very useful, but, as I mentioned in the section on compression, documentation of the ACE algorithms and file formats is not (yet) available. GENERAL ------- I'd like to give special thanks to Steve Carpenter in Portland, Maine, for writing machine language display and volume adjusting routines for Version 1. The resulting speedup made the editor comfortably fast even when running on an unaccelerated Apple. His efforts inspired me to implement even faster routines for Version 2 and several powerful new features in machine language, although the basic framework of the editor is still in Applesoft. You may want to make modifications to SOUND.EDITOR to suit your purposes, but be careful. The entire Applesoft program must fit below the machine language routines at $1E00, which include hi-res screen 1 ($2000) and decompression and compression code which is moved to $300 and $9000. There are currently less than 100 bytes unused below $1E00. The program's once liberal comments have been savaged by the addition of new features, so it's getting harder to make space. Those of you who have examined earlier versions will also note that a number of changes have been made to save space, occasionally at the expense of clarity. Michael Mahon 1975 Adele Place San Jose, CA 95125 Internet: mjmahon@aol.com AOL: MJMahon Apple ][ forever!