Sample Class

The Sample class is not useful without the Audio class, so Sample is stored in the same class definition (Audio.h) and implementation (Audio.cpp) files with the Audio class. Following is the Sample class definition. Note the names of the FMOD objects in this listing: FMOD_SOUND and FMOD_CHANNEL. FMOD_SOUND is a sound buffer or sample, while FMOD_CHANNEL is a playback channel. Although you may reuse a single channel when playing multiple samples, it is simpler to use one channel per sample in our classes. (Note: The Sample class is embedded in the Audio.h and Audio.cpp files along with the Audio class.)

class Sample
{
private:
    std::string name;
public:
    FMOD_SOUND *sample;
    FMOD_CHANNEL *channel;
    Sample(void);
    ~Sample(void);
    std::string getName() { return name; }
    void setName(std::string value) { name = value; }
};

I’m not overly concerned about accessors and mutators in the Sample class. It is more convenient to expose the sample and channel pointers publicly to simplify the code in the Audio class.

And now for the Sample class implementation, which is stored in the Audio.cpp file with the Audio class implementation. The Sample class’ most important responsibility is to free the memory used by an audio sample using the FMOD_Sound_Release function.

Sample::Sample()
{
    sample = NULL;
    channel = NULL;
}

Sample::~Sample()
{
    if (sample != NULL) {
        FMOD_Sound_Release(sample);
        sample = NULL;
    }
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset