Squeak Class Documentation category index | class index  
 
LoopedSampledSound
  category: Sound-Synthesis
  superclass: AbstractSound
  subclasses:

I respresent a sequence of sound samples, often used to record a single note played by a real instrument. I can be pitch-shifted up or down, and can include a looped portion to allow a sound to be sustained indefinitely.

instance methods
  accessing
  beUnlooped
duration
duration:
firstSample
firstSample:
gain
gain:
isLooped
isStereo
leftSamples
leftSamples:
loopEnd
loopLength
originalSamplingRate
perceivedPitch
pitch
pitch:
rightSamples
rightSamples:
samples

  disk i/o
  comeFullyUpOnReload:
objectForDataStream:

  initialization
  addReleaseEnvelope
computeSampleCountForRelease
fromAIFFFileNamed:mergeIfStereo:
fromAIFFFileReader:mergeIfStereo:
initialize
samples:loopEnd:loopLength:pitch:samplingRate:
setPitch:dur:loudness:
unloopedSamples:pitch:samplingRate:

  other
  copyDownSampledLowPassFiltering:
edit
fftAt:
findStartPointAfter:
findStartPointForThreshold:
highestSignificantFrequencyAt:
indexOfFirstPointOverThreshold:

  private
  downSampleLowPassFiltering:
fftWindowSize:startingAt:
normalizedResultsFromFFT:

  sound generation
  mixSampleCount:into:startingAt:leftVol:rightVol:
reset
samplesRemaining
stopAfterMSecs:

class methods
  class initialization
  initialize

  instance creation
  fromAIFFFileNamed:mergeIfStereo:
fromAIFFStream:
fromAIFFStream:mergeIfStereo:
samples:loopEnd:loopLength:pitch:samplingRate:
unloopedSamples:pitch:samplingRate:

instance methods
  accessing top  
 

beUnlooped


 

duration

Answer the duration of this sound in seconds.


 

duration:

Scale my envelopes to the given duration. Subclasses overriding this method should include a resend to super.


 

firstSample


 

firstSample:


 

gain


 

gain:


 

isLooped


 

isStereo


 

leftSamples


 

leftSamples:


 

loopEnd


 

loopLength


 

originalSamplingRate


 

perceivedPitch


 

pitch


 

pitch:


 

rightSamples


 

rightSamples:


 

samples

For compatability with SampledSound. Just return my left channel (which is the only channel if I am mono).


  disk i/o top  
 

comeFullyUpOnReload:

Convert my sample buffers from ByteArrays into SampleBuffers after raw loading from a DataStream. Answer myself.


 

objectForDataStream:

Answer an object to store on a data stream, a copy of myself whose SampleBuffers have been converted into ByteArrays.


  initialization top  
 

addReleaseEnvelope

Add a simple release envelope to this sound.


 

computeSampleCountForRelease

Calculate the number of samples before the end of the note after which looping back will be be disabled. The units of this value, sampleCountForRelease, are samples at the original sampling rate. When playing a specific note, this value is converted to releaseCount, which is number of samples to be computed at the current pitch and sampling rate.


 

fromAIFFFileNamed:mergeIfStereo:

Initialize this sound from the data in the given AIFF file. If mergeFlag is true and the file is stereo, its left and right channels are mixed together to produce a mono sampled sound.


 

fromAIFFFileReader:mergeIfStereo:

Initialize this sound from the data in the given AIFF file. If mergeFlag is true and the file is stereo, its left and right channels are mixed together to produce a mono sampled sound.


 

initialize

This default initialization creates a loop consisting of a single cycle of a sine wave.


 

samples:loopEnd:loopLength:pitch:samplingRate:

Make this sound use the given samples array with a loop of the given length starting at the given index. The loop length may have a fractional part; this is necessary to achieve pitch accuracy for short loops.


 

setPitch:dur:loudness:

(LoopedSampledSound pitch: 440.0 dur: 2.5 loudness: 0.4) play


 

unloopedSamples:pitch:samplingRate:

Make this sound play the given samples unlooped. The samples have the given perceived pitch when played at the given sampling rate. By convention, unpitched sounds such as percussion sounds should specify a pitch of nil or 100 Hz.


  other top  
 

copyDownSampledLowPassFiltering:

Answer a copy of the receiver at half its sampling rate. The result consumes half the memory space, but has only half the frequency range of the original. If doFiltering is true, the original sound buffers are low-pass filtered before down-sampling. This is slower, but prevents aliasing of any high-frequency components of the original signal. (While it may be possible to avoid low-pass filtering when down-sampling from 44.1 kHz to 22.05 kHz, it is probably essential when going to lower sampling rates.)


 

edit

Open a WaveEditor on this sound.


 

fftAt:

Answer the Fast Fourier Transform (FFT) of my samples (only the left channel, if stereo) starting at the given index.


 

findStartPointAfter:

Answer the index of the last zero crossing sample before the given index.


 

findStartPointForThreshold:

Answer the index of the last zero crossing sample before the first sample whose absolute value (in either the right or left channel) exceeds the given threshold.


 

highestSignificantFrequencyAt:

Answer the highest significant frequency in the sample window starting at the given index. The a frequency is considered significant if it's power is at least 1/50th that of the maximum frequency component in the frequency spectrum.


 

indexOfFirstPointOverThreshold:

Answer the index of the first sample whose absolute value exceeds the given threshold.


  private top  
 

downSampleLowPassFiltering:

Cut my sampling rate in half. Use low-pass filtering (slower) if doFiltering is true.


 

fftWindowSize:startingAt:

Answer a Fast Fourier Transform (FFT) of the given number of samples starting at the given index (the left channel only, if stereo). The window size will be rounded up to the nearest power of two greater than the requested size. There must be enough samples past the given starting index to accomodate this window size.


 

normalizedResultsFromFFT:

Answer an array whose size is half of the FFT window size containing power in each frequency band, normalized to the average power over the entire FFT. A value of 10.0 in this array thus means that the power at the corresponding frequences is ten times the average power across the entire FFT.


  sound generation top  
 

mixSampleCount:into:startingAt:leftVol:rightVol:

Play samples from a wave table by stepping a fixed amount through the table on every sample. The table index and increment are scaled to allow fractional increments for greater pitch accuracy. If a loop length is specified, then the index is looped back when the loopEnd index is reached until count drops below releaseCount. This allows a short sampled sound to be sustained indefinitely.


 

reset

Reset my internal state for a replay. Methods that override this method should do super reset.


 

samplesRemaining

Answer the number of samples remaining until the end of this sound.


 

stopAfterMSecs:

Terminate this sound this note after the given number of milliseconds.


class methods
  class initialization top  
 

initialize

LoopedSampledSound initialize


  instance creation top  
 

fromAIFFFileNamed:mergeIfStereo:

Initialize this sound from the data in the given AIFF file. If mergeFlag is true and the file is stereo, its left and right channels are mixed together to produce a mono sampled sound.


 

fromAIFFStream:

Initialize this sound from the data in the given AIFF file. If mergeFlag is true and the file is stereo, its left and right channels are mixed together to produce a mono sampled sound.


 

fromAIFFStream:mergeIfStereo:

Initialize this sound from the data in the given AIFF file. If mergeFlag is true and the file is stereo, its left and right channels are mixed together to produce a mono sampled sound.


 

samples:loopEnd:loopLength:pitch:samplingRate:

See the comment in the instance method of this name.


 

unloopedSamples:pitch:samplingRate:

See the comment in the instance method of this name.