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.monitors;
037:
038: public class SpectrumAnalyzer extends AbstractAudio {
039:
040: // Private class data
041: private TriggerFlag tf;
042: private String name;
043: private int sampleRate;
044: private int numberOfChannels;
045:
046: /**
047: * Spectrum Analyzer device class constructor
048: *
049: * @param String name is the name to be shown in the title bar of
050: * the spectrum analyzer's UI for identification purposes.
051: */
052: public SpectrumAnalyzer(String name) {
053:
054: super ("Spectrum Analyzer", AbstractAudio.MONITOR);
055:
056: this .name = name;
057:
058: // Flag object for controlling analyzer triggering
059: tf = new TriggerFlag();
060:
061: }
062:
063: // Grab samples from previous stage and store for analysis
064: public int getSamples(short[] buffer, int length) {
065:
066: if (length == 0)
067: return 0;
068:
069: // Get samples from the previous stage
070: int samples = previous.getSamples(buffer, length);
071:
072: // See if scope should trigger
073: if (!tf.trigger()) {
074:
075: // Indicate scope has triggered
076: tf.triggered();
077:
078: // Clone the array for the scope
079: short[] newBuffer = new short[samples];
080:
081: // Copy the data
082: System.arraycopy(buffer, 0, newBuffer, 0, length);
083:
084: }
085:
086: // Return samples read
087: return samples;
088:
089: }
090:
091: public void minMaxSamplingRate(int min, int max, int preferred) {
092:
093: super .minMaxSamplingRate(min, max, preferred);
094: sampleRate = preferred;
095:
096: }
097:
098: // Negotiate the number of channels
099: public void minMaxChannels(int min, int max, int preferred) {
100:
101: super.minMaxChannels(min, max, preferred);
102: numberOfChannels = preferred;
103:
104: }
105:
106: }
|