Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Sample Class Reference

A class for manipulating samples. More...

#include <Sample.h>

List of all members.

Public Types

typedef unsigned long position_t
 position in sample ie 0 .. sample_length.

typedef int finetune_t
typedef int volume_t
 0 .. 128?

typedef int location_t
 location in x,y,z.

typedef int frequency_t
typedef int relative_note_t
 100..100000.

typedef unsigned char data_t
 -96..96?

typedef data_titerator8
typedef const data_tconst_iterator8
typedef signed short* iterator16
typedef signed short* const_iterator16
enum  SampleCodec { PCM, MULAW, ALAW, ADPCM }
enum  {
  MAX_VOLUME = 128, MIN_VOLUME = 0, PAN_LEFT = -127, PAN_CENTER = 0,
  PAN_RIGHT = 128
}

Public Methods

 Sample ()
 default constructor.

 Sample (const Sample& sample)
 copy constructor.

 Sample (const char* filename)
virtual ~Sample ()
const Sample& operator= (const Sample& sample)
 assignment operator.

bool Load (const char* filename)
 Load the given filename and put the data in a new Sample object.

bool Save (const char* filename) const
 Save the sample basing the type on the filenames extension.

bool Is16Bit () const
 
Returns:
True if sample is 16 bit.


bool Is8Bit () const
 
Returns:
True if sample is 8 bit.


bool IsLooped () const
 
Returns:
True if sample is loop.


bool IsSigned () const
 
Returns:
True if sample is signed.


bool IsBIDI () const
 Is it a bidirectional (ping-pong) loop?

bool IsStereo () const
 
Returns:
True if sample is stereo.


position_t GetLength () const
 
Returns:
The length of sample data in bytes.


position_t GetLoopStart () const
 
Returns:
The start of the loop.


position_t GetLoopEnd () const
 
Returns:
The end of the loop.


position_t GetLoopLength () const
 
Returns:
The length of the loop.


position_t GetLoopStartFrame () const
 
Returns:
The first frame of the loop.


position_t GetLoopEndFrame () const
 
Returns:
The first frame after the loop. May be nonexistant.


position_t GetLoopFrameLength () const
 
Returns:
The length of the loop in sample frames.


position_t GetFrames () const
 
Returns:
The number of samples.


SampleCodec GetCodec () const
frequency_t GetFrequency () const
 
Returns:
The default frequency of the sample.


finetune_t GetFineTune () const
 
Returns:
The finetune of the sample.


relative_note_t GetRelativeNote () const
 
Returns:
The relative note of the sample.


volume_t GetVolume () const
 
Returns:
The default volume of the loop.


location_t GetPanning () const
 
Returns:
The default panning of the loop.


location_t GetX () const
 
Returns:
The default x (horizontal) location of the sound. Use this for normal panning.


location_t GetY () const
 
Returns:
The default y (vertical) location of the sound.


location_t GetZ () const
 
Returns:
The default z (into the screen) location of the sound.


const std::string& GetName () const
 
Returns:
The name of the sample.


const std::string& GetFilename () const
 
Returns:
The filename of the sample.


void Filter (Filters::SimpleFilter<signed short>& f)
bool Filter (Filters::SimpleFilter<signed short>& f, position_t start, position_t end)
bool Generate (Generators::SimpleGenerator<short>& g)
 Replace the current sample data with the data generated by g.

bool Generate (Generators::SimpleGenerator<short>& g, position_t start, position_t end)
 Replace the selected sample data with the data generated by g.

bool Generate (Generators::SimpleGenerator<short>& g, position_t length)
 Allocate sample data and fill it with data generated by g. More...

void SetLooped (bool looped = true)
 Force the sample to loop.

void SetBIDI (bool on = true)
 Force the sample to loop bidirectionally. When the sample gets to the end of the loop it will play the reverse direction.

bool SetLoopStart (position_t start)
 Set the start of the loop.
Returns:
False if position is out of range.


bool SetLoopEnd (position_t end)
 Set the end of the loop.
Returns:
False if position is out of range.


bool SetLoopStartFrame (position_t start)
bool SetLoopEndFrame (position_t end)
void SetFineTune (finetune_t finetune)
 Set the finetune for the sample.

void SetVolume (volume_t volume)
 Set the default volume of the sample.

void Set8Bit ()
 Force the sample to 8 bit sample width.

void Set16Bit ()
 Force the sample to 16 bit sample width.

void SetSigned ()
 Force the sample to signed.

void SetStereo ()
 Force the sample to stereo.

void SetMono ()
 Force the sample to mono.

void SetPanning (location_t p)
 Set the pan position.

void SetX ( location_t x )
 Set the x location.

void SetY ( location_t y )
 Set the y location.

void SetZ ( location_t z )
 Set the z location.

void SetXYZ (location_t x, location_t y, location_t z)
 Set the x, y and z location.

void SetName (std::string name)
 Set the name of the sample.

void SetFilename (std::string name)
 Set the file name of the sample.

void SetFrequency (frequency_t frequency)
 Set the default frequency of the sample.

void SetRelativeNote (relative_note_t relative_note)
 Set the relative note of the sample.

data_tGetData () const
 Get the sample data.

bool AllocateDataLength (position_t length)
 Allocate stereo sample data memory of the given length.
Returns:
True on successful allocation.


bool Resize (position_t length)
 Change the length of the sample, either trucating the original data or padding the excesss with zeros.

bool ResizeFrames (position_t length)
void SetLength (position_t length)
 This sets the sample data length in bytes. We probably shouldn't let the length be changed but we'll allow it anyway.

void SetFrames (position_t samples)
 Same as SetLength but takes stereo and the size of the samples into account.

void SwapBytes ()
 Switch the order of the bytes to little endian / big endian. Only affect 16 bit sample data.

void SwitchSign ()
void Clear ()
iterator8 begin8 ()
const_iterator8 begin8 () const
iterator8 end8 ()
const_iterator8 end8 () const
iterator16 begin16 ()
 16 bit versions - this will have to make do.

const_iterator16 begin16 () const
iterator16 end16 ()
const_iterator16 end16 () const
position_t size () const
position_t max_size () const
bool empty () const
void swap (Sample& sample)
bool Cut (iterator8 begin, iterator8 end)
bool Paste (iterator8 begin, iterator8 end, iterator8 start)
int GetUploadedID ()
void SetUploadedID (int id)
bool Uploaded () const

Public Attributes

data_tm_data
 either all mono data or interleaved left/right channel data.


Detailed Description

A class for manipulating samples.

This is used primarily to store information about samples.

There are two ways to load a sample. The simplest way is to use the Load method. Given the file name, this method will look up the correct SampleIO subclass to create using a factory (see http://c2.com/cgi-bin/wiki?Factory). It will then load the file and fill the sample class with the data from the file.

eg.

    Sample sample;
    sample.Load("ding.wav");
    

The other way is to create a SampleIO object of the correct type and then use that objects Load method.

eg.

    Sample sample;
    SampleWav sampleio;
    sampleio.Load("ding.wav", sample);
    

Saving is similar. I haven't yet paid much attention to the codec that the sample should be saved in - at the moment it can be assumed that it is in pcm format.

Stereo sample data is stored in m_data as interleaved left/right samples.

After implementing some simple iterators I ran into trouble due to the fact that the sample stores two different types of data: 16 bit and 8 bit.

This problem has been solved by the creation of an adapter from 8bit to 16bit, and the creation of methods for filtering and generating. Filter and Generate correspond to transform and generate respectively


Member Function Documentation

bool Sample::Generate ( Generators::SimpleGenerator< short >& g,
position_t length )
 

Allocate sample data and fill it with data generated by g.

The data allocated will be the same as the current type of the sample. Previously allocated data will be deallocated.


The documentation for this class was generated from the following files:
Generated at Mon Nov 27 01:47:13 2000 for LibPenguinPlay by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000