Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio/wav.cc')
-rw-r--r--src/audio/wav.cc19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/audio/wav.cc b/src/audio/wav.cc
index 178f199..b6ca710 100644
--- a/src/audio/wav.cc
+++ b/src/audio/wav.cc
@@ -5,7 +5,7 @@
*/
/*
-see
+see
http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/
*/
@@ -19,7 +19,8 @@ http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/
#include "filesystem/filesystem.h"
#include "sys/sys.h"
-namespace audio {
+namespace audio
+{
PCM *Wav::load(std::string const & name)
{
@@ -29,7 +30,7 @@ PCM *Wav::load(std::string const & name)
std::string filename("sounds/");
filename.append(name);
filename.append(".wav");
-
+
filesystem::File *wav_file = filesystem::open(filename.c_str());
if (!wav_file) {
con_warn << "Could not open " << filename << std::endl;
@@ -52,7 +53,7 @@ PCM *Wav::load(std::string const & name)
}
// format WAVE
- if (strncmp((char *)header+8, "WAVE", 4) != 0) {
+ if (strncmp((char *)header + 8, "WAVE", 4) != 0) {
con_warn << "Error reading " << filename << ": invalid WAVE header!" << std::endl;
filesystem::close(wav_file);
return 0;
@@ -61,7 +62,7 @@ PCM *Wav::load(std::string const & name)
// file size
//size_t chunksize = header[4] + (header[5] << 8) + (header[6] << 16) + (header[7] << 24);
- if (strncmp((char *)header+12, "fmt ", 4) != 0) {
+ if (strncmp((char *)header + 12, "fmt ", 4) != 0) {
con_warn << "Error reading " << filename << ": invalid format header!" << std::endl;
filesystem::close(wav_file);
return 0;
@@ -78,7 +79,7 @@ PCM *Wav::load(std::string const & name)
}
unsigned int channels = header[22] + (header[23] << 8);
- if ((channels < 1) || (channels >2)) {
+ if ((channels < 1) || (channels > 2)) {
con_warn << "Error reading " << filename << ": invalid number of channels!" << std::endl;
filesystem::close(wav_file);
return 0;
@@ -89,7 +90,7 @@ PCM *Wav::load(std::string const & name)
//size_t blockalign = header[32] + (header[33] << 8);
size_t bitspersample = header[34] + (header[35] << 8);
- if (strncmp((char *)header + 36, "data", 4) !=0) {
+ if (strncmp((char *)header + 36, "data", 4) != 0) {
con_warn << "Error reading " << filename << ": invalid data header!" << std::endl;
filesystem::close(wav_file);
return 0;
@@ -109,8 +110,8 @@ PCM *Wav::load(std::string const & name)
con_warn << "Error reading " << filename << ": file truncated!" << std::endl;
}
- con_debug << " " << filename << " " << pcm->samplerate()<< "Hz " << pcm->bitspersample() << "bit " <<
- pcm->channels() << " chan " << pcm->size() << " bytes" << std::endl;
+ con_debug << " " << filename << " " << pcm->samplerate() << "Hz " << pcm->bitspersample() << "bit " <<
+ pcm->channels() << " chan " << pcm->size() << " bytes" << std::endl;
filesystem::close(wav_file);
return pcm;