Squeak Class Documentation category index | class index  
 
SpectrumAnalyzerMorph
  category: Sound-Interface
  superclass: AlignmentMorph
  subclasses:

I am a tool for analyzing sound data from a microphone, CD, or other input source in real time. I have several display modes:

signal snapshots of the raw signal data as it arrives
spectrum frequency spectrum of the signal data as it arrives
sonogram scrolling plot of the frequency spectrum over time,
where the vertical axis is frequency, the horizontal
axis is time, and amount of energy at a given
frequency is shown as a grayscale value with
larger values being darker

To use this tool, be sure that you have selected the proper sound source using you host OS facilities. Set the desired sampling rate and FFT size (try 22050 samples/sec and an FFT size of 512) then click on the 'start' button. Use the slider to adjust the level so that the yellow level indicator peaks somewhere between the middle and the right edge at the maximum signal level.

Note that if the level meter peaks hit the right edge, you will get 'clipping', which creates a bunch of spurious high frequency noise in the frequency spectrum. If the display is set to 'signal' mode, you can actually see the tops and bottoms of the waveform being cut off when clipping occurs.

Many machines may not be able to perform spectrum analysis in real time, especially at higher sampling rates and larger FFT sizes. In both 'signal' and 'spectrum' modes, this tool will skip data to try to keep up with real time. However, in 'sonogram' mode it always processes all the data, even if it falls behind. This allows you to get a complete sonogram without dropouts even on a slower machine. However, as the sonogram display falls behind there will be a larger and larger time lag between when a sound is input and when it appears on the display.

The smaller the FFT size, the less frequency resolution you get. The lower the sampling rate, the less total frequency range you get. For an FFT size of N and a sampling rate of R, each of the N/2 'bins' of the frequency spectrum has a frequency resolution of R / N. For example, at a sampleing rate of 22050 samples/second, the total frequency range is 0 to 11025 Hz and an FFT of size 256 would divide this range into 128 bins (the output of an FFT of size N has N/2 bins), each of which covers a frequency band about 86 Hz wide.

To increase time resolution, increase the sampling rate and decrease the FFT size.

instance methods
  deletion
  delete

  initialization
 

  menu and buttons
  invokeMenu
resetDisplay
setDisplayType
setFFTSize
setSamplingRate
start
stop

  private
  addButtonRow
addLevelSlider
buttonName:action:
initialize
makeLevelMeter
makeStatusLight
processBuffer:
removeAllDisplays
showSignal
showSonogram
showSpectrum
updateDisplay

  stepping
  step
stepTime
stopStepping

class methods
  no messages
 

instance methods
  deletion top  
 

delete

Turn off recording when this morph is deleted.


  initialization top  

  menu and buttons top  
 

invokeMenu

Invoke the settings menu.


 

resetDisplay

Recreate my display after changing some parameter such as FFT size.


 

setDisplayType

Set the display type.


 

setFFTSize

Set the size of the FFT used for frequency analysis.


 

setSamplingRate

Set the sampling rate to be used for incoming sound data.


 

start

Start displaying sound data.


 

stop

Stop displaying sound data.


  private top  
 

addButtonRow


 

addLevelSlider


 

buttonName:action:


 

initialize


 

makeLevelMeter


 

makeStatusLight


 

processBuffer:

Analyze one buffer of data.


 

removeAllDisplays

Remove all currently showing displays.


 

showSignal

Display the actual signal waveform.


 

showSonogram

Display a sonogram showing the frequency spectrum versus time.


 

showSpectrum

Display the frequency spectrum.


 

updateDisplay

Update the display if any data is available.


  stepping top  
 

step

Update the record light, level meter, and display.


 

stepTime

Answer the desired time between steps in milliseconds. This default implementation requests that the 'step' method be called once every second.


 

stopStepping

Turn off recording.


class methods
  no messages top