001: /*
002: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
003: *
004: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
005: * royalty free, license to use, modify and redistribute this
006: * software in source and binary code form,
007: * provided that i) this copyright notice and license appear on all copies of
008: * the software; and ii) Licensee does not utilize the software in a manner
009: * which is disparaging to Silvere Martin-Michiellot.
010: *
011: * This software is provided "AS IS," without a warranty of any kind. ALL
012: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
013: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
014: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
015: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
016: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
018: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
019: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
020: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
021: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
022: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
023: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
024: *
025: * This software is not designed or intended for use in on-line control of
026: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
027: * the design, construction, operation or maintenance of any nuclear
028: * facility. Licensee represents and warrants that it will not use or
029: * redistribute the Software for such purposes.
030: *
031: */
032:
033: // This code is repackaged after the code from Craig A. Lindley, from Digital Audio with Java
034: // Site ftp://ftp.prenhall.com/pub/ptr/professional_computer_science.w-022/digital_audio/
035: // Email
036: package com.db.media.audio.dsp.processors;
037:
038: public class Reverb extends AbstractAudio {
039:
040: // Private class data
041: private boolean initializationComplete;
042: private boolean endOfData;
043: private double sustainTimeInMs;
044: private int sampleRate;
045: private int numberOfChannels;
046: private SchroederReverb reverb;
047:
048: public Reverb() {
049:
050: super ("Reverb", AbstractAudio.PROCESSOR);
051:
052: // Initialization will take place after sample rate is known
053: initializationComplete = false;
054: endOfData = false;
055:
056: }
057:
058: // Prepare for running reverb again
059: public void reset() {
060:
061: o("ReverbWithUI reset");
062:
063: endOfData = false;
064:
065: // Calling this function will reset all comb and allpass filters
066: // in preparation for running again.
067: reverb.setSustainInMs(sustainTimeInMs);
068:
069: }
070:
071: public int getSamples(short[] buffer, int length) {
072:
073: // If bypass is enabled, short circuit processing
074: if (getByPass() || !initializationComplete)
075: return previous.getSamples(buffer, length);
076:
077: // Must use endOfData to stop reading input otherwise
078: // if source is file it will continually be reread.
079: if (!endOfData) {
080: // Ask for a buffer of samples
081: length = previous.getSamples(buffer, length);
082: if (length == -1)
083: endOfData = true;
084:
085: // Do the reverb on the samples
086: return reverb.doReverb(buffer, length);
087: } else {
088: // Propagate the sustain samples
089: return reverb.doReverb(buffer, -1);
090: }
091:
092: }
093:
094: // These methods called when UI controls are manipulated
095: public void comb1Delay(double delay) {
096:
097: if (reverb != null)
098: reverb.setComb1Delay(delay);
099:
100: }
101:
102: public void comb2Delay(double delay) {
103:
104: if (reverb != null)
105: reverb.setComb2Delay(delay);
106:
107: }
108:
109: public void comb3Delay(double delay) {
110:
111: if (reverb != null)
112: reverb.setComb3Delay(delay);
113:
114: }
115:
116: public void comb4Delay(double delay) {
117:
118: if (reverb != null)
119: reverb.setComb4Delay(delay);
120:
121: }
122:
123: public void allpass1Delay(double delay) {
124:
125: if (reverb != null)
126: reverb.setAllpass1Delay(delay);
127:
128: }
129:
130: public void allpass2Delay(double delay) {
131:
132: if (reverb != null)
133: reverb.setAllpass2Delay(delay);
134:
135: }
136:
137: public void setSustainTime(double sustainTimeInMs) {
138:
139: // Remember what sustain time was requested
140: this .sustainTimeInMs = sustainTimeInMs;
141:
142: if (reverb != null) {
143: reverb.setSustainInMs(sustainTimeInMs);
144: }
145:
146: }
147:
148: public void setDryWetMix(double mix) {
149:
150: if (reverb != null)
151: reverb.setDryWetMix(mix);
152:
153: }
154:
155: private void doInitialization() {
156:
157: reverb = new SchroederReverb(sampleRate, numberOfChannels);
158:
159: // Set the saved sustain time
160: reverb.setSustainInMs(sustainTimeInMs);
161:
162: // Indicate initialization is complete
163: initializationComplete = true;
164:
165: }
166:
167: public void minMaxSamplingRate(int min, int max, int preferred) {
168:
169: super .minMaxSamplingRate(min, max, preferred);
170: sampleRate = preferred;
171: doInitialization();
172:
173: }
174:
175: // Negotiate the number of channels
176: public void minMaxChannels(int min, int max, int preferred) {
177:
178: super.minMaxChannels(min, max, preferred);
179: numberOfChannels = preferred;
180:
181: }
182: }
|