SoundBufferWav.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <sound/SoundBufferWav.h>
00022 #include <sound/SoundBufferStaticSourceInstance.h>
00023 #include <sound/Sound.h>
00024 #ifdef __DARWIN__
00025 #include <OpenAL/al.h>
00026 #include <OpenAL/alut.h>
00027 #else
00028 #include <AL/al.h>
00029 #include <AL/alut.h>
00030 #endif
00031 
00032 SoundBufferWav::SoundBufferWav(const char *fileName) : 
00033         SoundBuffer(fileName),
00034         buffer_(0)
00035 {
00036         unsigned int error;
00037 
00038         // Create a buffer
00039         alGetError();
00040         alGenBuffers(1, &buffer_);
00041         if ((error = alGetError()) != AL_NO_ERROR)
00042         {
00043                 return;
00044         }
00045 
00046         // Load WAV
00047         void *data;
00048         ALenum format;
00049         ALsizei size;
00050         ALsizei freq;
00051         ALboolean loop;
00052 
00053 #ifdef __DARWIN__
00054         alutLoadWAVFile((ALbyte*) fileName,&format,&data,&size,&freq);
00055 #else
00056         alutLoadWAVFile((ALbyte*) fileName,&format,&data,&size,&freq,&loop);
00057 #endif
00058 
00059         if ((error = alGetError()) != AL_NO_ERROR)
00060         {
00061                 return;
00062         }
00063 
00064         // Load WAV into buffer
00065         alBufferData(buffer_,format,data,size,freq);
00066         if ((error = alGetError()) != AL_NO_ERROR)
00067         {
00068                 return;
00069         }
00070 
00071         // Delete WAV memory
00072         alutUnloadWAV(format,data,size,freq);
00073         if ((error = alGetError()) != AL_NO_ERROR)
00074         {
00075                 return;
00076         }
00077 }
00078 
00079 SoundBufferWav::~SoundBufferWav()
00080 {
00081         if (buffer_) alDeleteBuffers (1, &buffer_);
00082         buffer_ = 0;
00083 }
00084 
00085 SoundBufferSourceInstance *SoundBufferWav::createSourceInstance(unsigned int source)
00086 {
00087         return new SoundBufferStaticSourceInstance(source, buffer_);
00088 }

Generated on Mon Feb 16 15:14:47 2009 for Scorched3D by  doxygen 1.5.3