Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

sample.cpp

Go to the documentation of this file.
00001 #include <string>
00002 #include "sample.h"
00003 #include <SDL/SDL_mixer.h>
00004 #include <iostream>
00005 
00006 using namespace std;
00007 
00008 //default constructor
00009 Sample::Sample() : sample(NULL), channel(-1) {}
00010 
00011 //full constructor
00012 Sample::Sample(string fileName, int chan) {
00013         sample = Mix_LoadWAV(fileName.c_str());
00014         if (!sample) {
00015                 cerr << "Mix_LoadWav Error: " << Mix_GetError() << endl;
00016         }
00017         channel = chan;
00018 }
00019 
00020 //destructor
00021 Sample::~Sample() {
00022         Mix_FreeChunk(sample);
00023         sample = NULL;
00024         channel = -1;
00025 }
00026 
00027 //self explanatory
00028 int Sample::GetChannel() {
00029         return channel;
00030 }
00031 
00032 //same
00033 bool Sample::SetChannel(int chan) {
00034         channel = chan;
00035         return true;
00036 }
00037 
00038 //plays the sample on its channel loop+1 times. -1 == infinity.
00039 bool Sample::Play(int loops) {
00040         int success;
00041         success = Mix_PlayChannel(channel, sample, loops);
00042         // I was getting a ton of errors (but they weren't really..should
00043         // check for -1 not 0, i think). (CM)
00044         if (success == -1) {
00045                 cerr << "Mix_PlayChannel Error: " << Mix_GetError() << endl;
00046                 return false;
00047         }
00048         return true;
00049 }
00050 
00051 bool Sample::isPlaying() {
00052         if (Mix_Playing(channel)) {
00053                 return true;
00054         }
00055         return false;
00056 }
00057 

Generated on Sun Dec 8 12:02:20 2002 for nnc by doxygen1.3-rc1