Main Index : Reference :

BaseSound


Description

A sound class.

Definition

class BaseSound
{
public:
  BaseSound();

  // Main functions
  [bool] Init([int] samples, [int] fmode, [bool] stereo, [bool] b16);
  [bool] Free();
  [bool] Load([Filename] fname);
  [bool] Save([Filename] fname);

  // Access to general parameters
  [bool] GetStereo();
  [bool] Get16Bit();
  [int] GetFrequency();
  [int] GetSampleCount();
  [BaseTime] GetLength();

  // Direct access to the sound data
  [int] GetSample([int] sample, [bool] right);
  [bool] SetSample([int] sample, [bool] right, [int] value);

  [array] GetSamples([bool] right);
  [bool] SetSamples([bool] right, [array] data);

  // Additional functions
  [BaseBitmap] GetBitmap([int] width, [int] height, 
                         [BaseTime] start, [BaseTime] stop);

  [MarkerKey] GetFirstMarker();
  [bool] InsertMarker([MarkerKey] key);

  [bool] CopyTo([BaseSound] dest);
  [BaseSound] GetClone();
}

Explanation

A class that is used to store, load, access and save .wav sounds.

Example: Sin440.cof

Members

Init( samples, fmode, stereo, b16 )

[bool] Init([int] samples, [int] fmode, [bool] stereo, [bool] b16);

Allocates internal data for making a sound with the specified number of samples and the specified frequency mode (0 = 11025 Hz, 1 = 22050 Hz, 2 = 44100 Hz). The two last booleans determine if the sound should be in stereo and if it should be using 8 bit or 16 bit data. Alternatively one can load an existing sound from the harddrive by using Load().

Free()

[bool] Free();

Cleanups all internal memory allocations. Before using the class again one first has to call Init() or Load().

Load( fname )

[bool] Load([Filename] fname);

Loads a .wav file from the file that fname points to. One doesn't have to call Init() before. Returns TRUE if successful.

Save( fname )

[bool] Save([Filename] fname);

Saves the sound data as a .wav to the file that fname points to. Returns TRUE if successful.


GetStereo()

[bool] GetStereo();

Returns TRUE if the sound is using stereo data, otherwise FALSE.

Get16Bit()

[bool] Get16Bit();

Returns TRUE if the sound is using 16 bit data, otherwise FALSE.

GetFrequency()

[int] GetFrequency();

Returns the frequency of the sound as an integer (0 = 11025 Hz, 1 = 22050 Hz, 2 = 44100 Hz).

GetSampleCount()

[int] GetSampleCount();

Returns number of samples in the sound.

GetLength()

[BaseTime] GetLength();

Convenience function for calculating the length of the sound. Returns the length as a basetime object.


GetSample( sample, right )

[int] GetSample([int] sample, [bool] right);

Return the value at position sample. With right one can specify if one wants to have the left or right channel value returned. If using mono sound data, either TRUE or FALSE for right will return the same value.

Note: The value range is always between -32768 and +32768 no matter if the sound is 16 bit or not.

SetSample( sample, right, value )

[bool] SetSample([int] sample, [bool] right, [int] value);

Sets the value at position sample to value. With right one can specify if one wants to set the left or right channel value. If using mono sound data, either TRUE or FALSE for right will set the same value. When using stereo data one has to call this function twice.

Note: The value range should always be between -32768 and +32768 no matter if the sound is 16 bit or not.


GetSamples( right )

[array] GetSamples([bool] right);

Returns all the sound data as an array of integer values. One can get the size of the array using GetSampleCount(). With right one can specify if one wants to have the left or right channel value returned. If using mono sound data, either TRUE or FALSE for right will return the same array.

Note: The value range is always between -32768 and +32768 no matter if the sound is 16 bit or not.

SetSamples( right, data )

[bool] SetSamples([bool] right, [array] data);

Sets all sound data at once using the data array. With right one can specify if one wants to set the left or right channel. If using mono sound data, either TRUE or FALSE for right will set the same data. When using stereo data one has to call this function twice.

Note: The value range should always be between -32768 and +32768 no matter if the sound is 16 bit or not.


GetBitmap( width, height, start, stop )

[BaseBitmap] GetBitmap([int] width, [int] height, 
                       [BaseTime] start, [BaseTime] stop);

Returns a bitmap out of the sound data (for control purposes or for display in the picture manager) of specified width and height. One also has to specify if one wants to see the full sound in the bitmap (start=BaseTime(0.0) and stop=GetLength()) or if one wants to see a smaller part.


GetFirstMarker()

[MarkerKey] GetFirstMarker();

Returns the first marker of the sound, or NULL if there are no markers.

InsertMarker( key )

[bool] InsertMarker([MarkerKey] key);

Inserts the marker key in the sounds marker list.


CopyTo( dest )

[bool] CopyTo([BaseSound] dest);

Copies the sound to dest. Returns TRUE if successful.

GetClone()

[BaseSound] GetClone();

Returns a copy of the sound.