#include <Sample.h>
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_t* | iterator8 |
typedef const data_t* | const_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 |
| |
bool | Is8Bit () const |
| |
bool | IsLooped () const |
| |
bool | IsSigned () const |
| |
bool | IsBIDI () const |
Is it a bidirectional (ping-pong) loop? | |
bool | IsStereo () const |
| |
position_t | GetLength () const |
| |
position_t | GetLoopStart () const |
| |
position_t | GetLoopEnd () const |
| |
position_t | GetLoopLength () const |
| |
position_t | GetLoopStartFrame () const |
| |
position_t | GetLoopEndFrame () const |
| |
position_t | GetLoopFrameLength () const |
| |
position_t | GetFrames () const |
| |
SampleCodec | GetCodec () const |
frequency_t | GetFrequency () const |
| |
finetune_t | GetFineTune () const |
| |
relative_note_t | GetRelativeNote () const |
| |
volume_t | GetVolume () const |
| |
location_t | GetPanning () const |
| |
location_t | GetX () const |
| |
location_t | GetY () const |
| |
location_t | GetZ () const |
| |
const std::string& | GetName () const |
| |
const std::string& | GetFilename () const |
| |
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.
| |
bool | SetLoopEnd (position_t end) |
Set the end of the loop.
| |
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_t* | GetData () const |
Get the sample data. | |
bool | AllocateDataLength (position_t length) |
Allocate stereo sample data memory of the given length.
| |
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_t* | m_data |
either all mono data or interleaved left/right channel data. |
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
|
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. |