Squeak Class Documentation category index | class index  
 
SoundBuffer
  category: Sound-Synthesis
  superclass: ArrayedCollection
  subclasses:

SoundBuffers store 16 bit unsigned quantities.

instance methods
  accessing
  bytesPerElement
monoSampleCount
size
stereoSampleCount

  as yet unclassified
  writeOnGZIPByteStream:

  objects from disk
  restoreEndianness
reverseEndianness

  primitives
  at:
at:put:
primFill:

  utilities
  asByteArray
averageEvery:from:upTo:
downSampledLowPassFiltering:
extractLeftChannel
extractRightChannel
indexOfFirstSampleOver:
indexOfLastSampleOver:
lowPassFiltered
mergeStereo
normalized:
splitStereo
trimmedThreshold:

class methods
  instance creation
  averageEvery:from:upTo:
fromArray:
fromByteArray:
new:
newMonoSampleCount:
newStereoSampleCount:

  objects from disk
  startUp
startUpFrom:

instance methods
  accessing top  
 

bytesPerElement

Number of bytes in each item. This multiplied by (self size)*8 gives the number of bits stored.


 

monoSampleCount

Return the number of monaural 16-bit samples that fit into this SoundBuffer.


 

size

Return the number of 16-bit sound samples that fit in this sound buffer. To avoid confusion, it is better to get the size of SoundBuffer using monoSampleCount or stereoSampleCount.


 

stereoSampleCount

Return the number of stereo slices that fit into this SoundBuffer. A stereo 'slice' consists of two 16-bit samples, one for each channel.


  as yet unclassified top  
 

writeOnGZIPByteStream:

We only intend this for non-pointer arrays. Do nothing if I contain pointers.


  objects from disk top  
 

restoreEndianness

This word object was just read in from a stream. It was stored in Big Endian (Mac) format. Swap each pair of bytes (16-bit word), if the current machine is Little Endian.
Why is this the right thing to do? We are using memory as a byteStream. High and low bytes are reversed in each 16-bit word, but the stream of words ascends through memory. Different from a Bitmap.


 

reverseEndianness

Swap the bytes of each 16-bit word, using a fast BitBlt hack.


  primitives top  
 

at:

Return the 16-bit integer value at the given index of the receiver.


 

at:put:

Store the given 16-bit integer at the given index in the receiver.


 

primFill:

Fill the receiver, an indexable bytes or words object, with the given positive integer. The range of possible fill values is [0..255] for byte arrays and [0..(2^32 - 1)] for word arrays.


  utilities top  
 

asByteArray

Answer a ByteArray containing my sample data serialized in most-significant byte first order.


 

averageEvery:from:upTo:


 

downSampledLowPassFiltering:

Answer a new SoundBuffer half the size of the receiver consisting of every other sample. If doFiltering is true, a simple low-pass filter is applied to avoid aliasing of high frequencies. Assume that receiver is monophonic.


 

extractLeftChannel

Answer a new SoundBuffer half the size of the receiver consisting of only the left channel of the receiver, which is assumed to contain stereo sound data.


 

extractRightChannel

Answer a new SoundBuffer half the size of the receiver consisting of only the right channel of the receiver, which is assumed to contain stereo sound data.


 

indexOfFirstSampleOver:

Return the index of the first sample whose absolute value is over the given threshold value. Return an index one greater than my size if no sample is over the threshold.


 

indexOfLastSampleOver:

Return the index of the last sample whose absolute value is over the given threshold value. Return zero if no sample is over the threshold.


 

lowPassFiltered

Answer a simple low-pass filtered copy of this buffer. Assume it is monophonic.


 

mergeStereo

Answer a new SoundBuffer half the size of the receiver that mixes the left and right stereo channels of the receiver, which is assumed to contain stereo sound data.


 

normalized:

Increase my amplitudes so that the highest peak is the given percent of full volume. For example 's normalized: 50' would normalize to half of full volume.


 

splitStereo

Answer an array of two SoundBuffers half the size of the receiver consisting of the left and right channels of the receiver (which is assumed to contain stereo sound data).


 

trimmedThreshold:


class methods
  instance creation top  
 

averageEvery:from:upTo:


 

fromArray:

Return a new SoundBuffer whose contents are copied from the given Array or ByteArray.


 

fromByteArray:

Convert the given ByteArray (stored with the most significant byte first) into 16-bit sample buffer.


 

new:

See the comment in newMonoSampleCount:. To avoid confusion, it is best to create new instances using newMonoSampleCount: or newStereoSampleCount:.


 

newMonoSampleCount:

Return a SoundBuffer large enough to hold the given number of monaural samples (i.e., 16-bit words).


 

newStereoSampleCount:

Return a SoundBuffer large enough to hold the given number of stereo slices. A stereo 'slice' consists of two 16-bit samples, one for each channel.


  objects from disk top  
 

startUp

Check if the word order has changed from the last save.


 

startUpFrom:

In this case, do we need to swap word halves when reading this segement?