From: Eylon Caspi Newsgroups: ucb.class.cs150 Subject: Zero-length attack/sustain/decay Date: 27 Apr 2000 07:06:19 GMT [This is a repeat post... the news system swallowed my first post] The instrument files "agtr.bin" and "marimba.bin" have generated considerable confusion with their zero-length sustain and release sections. The use of a zero-length sample section is not a change to the project spec. Rather, it is a "corner case," an extreme instance of the spec that has a well-defined meaning. From page 3 of the project spec: "... to generate a note, the synthesizer will play the attack and continue playing into the sustain. While the note is held, it will continue to play the sustain part by looping. When the key is released, to signal the end of the note, the synthesizer will continue playing the sustain to the end of the current loop iteration and then play the release portion of the stored note." The attack, sustain, and release sections must be played as prescribed above even if they contain zero samples. Specifically, the above passage would mean: (1) For a zero-length attack, the synth would begin a note by playing zero samples of attack, then proceed to sustain. (2) For a zero-length sustain, the synth would play zero samples of sustain in each iteration of the loop, resulting in silence. The DAC will continue to output the last sample of attack whether your synth resends it or not (normal operation for the DAC is to hold the last sample transmitted to it until a new one is transmitted; it would even be happy to hold 0 from a previous note if both attack and sustain are zero length!). (3) For a zero-length release, the synth would end a note by playing to the end of sustain once, then playing zero samples of release. If your synth FSM uses a sufficiently fast clock (e.g. 8MHz), then it will transition through zero-length sections in well under 32us (1 sample period) and not need to drop samples. If your synth uses a slow clock (e.g. 64kHz) then you probably will drop samples. Let's look at some practical examples. (1) Piano (attack / zero-length sustain / zero-length release). When a piano key is pressed, a soft "hammer" strikes a string, causing the string to vibrate and make sound. So long as the key is held, the vibration fades slowly to zero amplitude. The vibration is stopped immediately if the key is released. There is no "sustain" section where sound continues with constant amplitude. Similarly, there is no useful release sound. We might want to use a fast fade-out for release, but we cannot know its amplitude -- it must be loud for an early release but soft for a late release -- this is impossible to represent in our attack/sustain/release model. Thus, sustain and release are made empty, and the sound is represented entirely by attack. (2) Harpsichord (attack / zero-length sustain / release). When a harpsichord key is pressed, a pick plucks a string, causing the string to vibrate and make sound. So long as the key is held, the vibration fades slowly to zero amplitude. Like the piano, there is no "sustain" section. However, when the key is released, the pick again touches the string, making a short buzz. This buzz will sound regardless of whether the string is still vibrating. It can be represented by a real release section. (3) Synth sounds (zero-length attack / sustain / release) It is possible to make an electronic (artificial) instrument sound with no attack. Such an instrument would play a note by immediately sounding a fixed-amplitude pitch with no fade-in or transient attack ("transient" meaning a short, loud sound). Similarly, there need be no release if the sound does not have a fade-out or transient release. Depending on your synth design, you may or may not want/need to detect and handle zero-length sections as special cases. It is possible to design an FSM and datapath that handle zero-length and non-zero-length sections in the same way, though this may require more states and logic. In looping through sustain, it may simplify your design to assume that a sustain section is at least as long as any step-size use to read through it (unless it is zero-length!). This is a consequence of the Nyquist Theorem which holds that a sound requires at least 2 samples per period in order to represent a frequency. Thus our model requires a sustain to be at least twice as long as the maximum step-size used with it. Otherwise it cannot represent a note's fundamental frequency. (note, this is consistent with zero-length sustains which play silence!) Keep in mind that it is considered fair game for the prof. and TAs to test your design with new instrument files at semester's end. Your design should be robust enough to handle any EPROM configuration. So far, we have only provided zero-length cases in "agtr.bin" and "marimba.bin". If time permits, we will circulate additional cases. -- Eylon Caspi University of California, Berkeley eylon@cs.berkeley.edu Electrical Engineering & Computer Science tel. 510-843-8689