SoundFileStream:
Filter:
ddwWavetableSynth/Classes (extension) | Files

SoundFileStream
ExtensionExtension

In-memory version of typical SoundFile operations

Description

The (undocumented) class CollStream imitates the File interface, while keeping data in memory. (This makes it possible to write code that can print to the post window or write text to a disk file or collect text in a String, using the file streaming interface.)

SoundFileStream is the counterpart for SoundFile.

Class Methods

.new

Create a new instance.

Arguments:

collection

Data to be read. If omitted, the object will be empty (ready for -writeData).

This should be a FloatArray or a subclass (most likely Signal).

Instance Methods

.readData

Get audio data from the stream.

Arguments:

floatArray

A FloatArray or Signal, initialized by ArrayedCollection: *newClear to the number of samples you want to read. See SoundFile: -readData.

.writeData

Write data from a FloatArray or Signal into the stream.

NOTE: In this version, written data are always appended at the end. seek does not apply to writing.

Arguments:

floatArray

The data to add to the end.

.seek

Move the read position to a given number of sample frames, relative to origin.

Arguments:

frames

How many (integer) frames to move relative to the origin.

origin

0 = measure from the start of the data; 1 = measure from the current position; 2 = measure from the end of the data.

.close

There is no real necessity to close an in-memory collection; however, this method resets the position to the beginning. This is convenient when, for instance, filling a SoundFileStream by -writeData, and then resetting to read from the same object.

.collection

The complete data collection.

Properties

Properties are "fake," in a sense -- there is no sound file header for an in-memory collection. But, for programming interface compatibility, the following methods are provided.

.numChannels

How many channels are represented (interleaved).

.headerFormat

Ignored.

.sampleRate

Largely ignored, although it does affect -duration.

.numFrames

Calculated from the size of the collection divided by numChannels.

.duration

Calculated from numFrames / sampleRate.

.sampleFormat

Ignored.

Examples

See WavetablePrep for a more interesting usage example.