devs.musicpackage
Class SpectrumAnalyzer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by devs.musicpackage.SpectrumAnalyzer
All Implemented Interfaces:
com.lightdev.lib.audio.PlayerListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, kj.dsp.KJDigitalSignalProcessor

public class SpectrumAnalyzer
extends java.awt.Canvas
implements com.lightdev.lib.audio.PlayerListener, kj.dsp.KJDigitalSignalProcessor

A user interface component to display the sound pressure for a range of frequencies over time as produced by an audio data stream.

This is the second version of the spectrum analyzer component. It has significantly improved performance with the help of the KJ signal processor package by Kris Fudalewski. KJ signal processor synchronizes processed bytes with the audio output.

Version:
2, January 20, 2005
Author:
Ulrich Hilger, Light Development, http://www.lightdev.com, info@lightdev.com, KJ signal processor by Kris Fudalewski at http://sirk.sytes.net/, published under the terms and conditions of the GNU General Public License, for details see file license.txt in the distribution package of this software
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SpectrumAnalyzer(int freqCount, int expFftSize)
          constructor
 
Method Summary
 void decoded(com.lightdev.lib.audio.Player p, byte[] buf, int byteCount)
          unused here
 void exception(com.lightdev.lib.audio.Player p, java.lang.Exception ex)
          unused here
 SpectrumAnalyzerListener getListener()
           
 void paint(java.awt.Graphics g)
          Paints this component.
 void process(float[] samples)
          process a range of samples received from the KJ signal processor, i.e.
 void progress(com.lightdev.lib.audio.Player p, long progressValue)
          unused here
 void setListener(SpectrumAnalyzerListener listener)
           
 void setSize(java.awt.Dimension d)
          set the size of this component
 void setSize(int w, int h)
          set the size of this component
 void stateChanged(com.lightdev.lib.audio.Player p, int fromStatus, int toStatus)
          take stateChanged messages from the audio player as a trigger to start and stop the spectrum analyzer
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpectrumAnalyzer

public SpectrumAnalyzer(int freqCount,
                        int expFftSize)
constructor

Parameters:
freqCount - int number of level meters to show for one channel (i.e. number of frequencies to measure amplitudes for)
expFftSize - int the power of two to use to set the size of a fast fourier transform. When expFftSize is 8 for instance the fft will be of size 2^8 = 256, i.e. the fft will transform 256 values of the amplitude/time domain to 128 values of the amplitude/frequency domain.
Method Detail

paint

public void paint(java.awt.Graphics g)
Paints this component.

Overrides:
paint in class java.awt.Canvas
Parameters:
g - the graphics context to use for painting

setSize

public void setSize(java.awt.Dimension d)
set the size of this component

Overrides:
setSize in class java.awt.Component
Parameters:
d - Dimension the new size

setSize

public void setSize(int w,
                    int h)
set the size of this component

Overrides:
setSize in class java.awt.Component
Parameters:
w - int the width
h - int the height

stateChanged

public void stateChanged(com.lightdev.lib.audio.Player p,
                         int fromStatus,
                         int toStatus)
take stateChanged messages from the audio player as a trigger to start and stop the spectrum analyzer

Specified by:
stateChanged in interface com.lightdev.lib.audio.PlayerListener
Parameters:
p - Player the player whose status changed
fromStatus - int the status changed from
toStatus - int the status changed to

progress

public void progress(com.lightdev.lib.audio.Player p,
                     long progressValue)
unused here

Specified by:
progress in interface com.lightdev.lib.audio.PlayerListener
Parameters:
p - Player the player that fired the event
progressValue - long the microseconds played so far

exception

public void exception(com.lightdev.lib.audio.Player p,
                      java.lang.Exception ex)
unused here

Specified by:
exception in interface com.lightdev.lib.audio.PlayerListener
Parameters:
p - Player the player that fired the event
ex - Exception the exception that occurred

decoded

public void decoded(com.lightdev.lib.audio.Player p,
                    byte[] buf,
                    int byteCount)
unused here

Specified by:
decoded in interface com.lightdev.lib.audio.PlayerListener
Parameters:
p - Player the player that fired the event
buf - byte[] the decoded bytes
byteCount - int the number of bytes in buf

process

public void process(float[] samples)
process a range of samples received from the KJ signal processor, i.e. repaint level meters

Specified by:
process in interface kj.dsp.KJDigitalSignalProcessor
Parameters:
samples - float[] the samples to process

getListener

public SpectrumAnalyzerListener getListener()
Returns:
Returns the listener.

setListener

public void setListener(SpectrumAnalyzerListener listener)
Parameters:
listener - The listener to set.