Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/sound/sound_buffer.cc @ 5835

Last change on this file since 5835 was 5422, checked in by bensch, 19 years ago

orxonox/trunk: windows works, and the default data-path in the resource-Manager changed to ./data

File size: 2.1 KB
RevLine 
[4744]1/*
[1853]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
[1855]10
11   ### File Specific:
[5386]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[5386]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND
[1853]17
[5386]18#include "sound_buffer.h"
[1853]19
[5386]20#include "sound_engine.h"
21
22
[1856]23using namespace std;
[1853]24
[1856]25
[5386]26//////////////////
27/* SOUND-BUFFER */
28//////////////////
[3245]29/**
[5386]30 *  Creates a Soundbuffer out of an inputfile
31 * @param fileName The name of the File
32 */
33SoundBuffer::SoundBuffer(const char* fileName)
[3365]34{
[5386]35  this->setClassID(CL_SOUND_BUFFER, "SoundBuffer");
36  this->setName(fileName);
[4320]37
[5386]38  SoundEngine::getInstance()->addBuffer(this);
[4320]39
[5386]40  ALenum format;
41  ALvoid* data;
42  ALsizei freq;
43
44  ALenum result;
45
46  // generate a Buffer
47  alGenBuffers(1, &this->bufferID);
48  if ((result = alGetError()) != AL_NO_ERROR)
49    SoundEngine::PrintALErrorString(result);
50
51  // read in the wav data
52  /* according to http://www.edenwaith.com/products/pige/tutorials/openal.php the alutLoadWAVFile differs from platform to platform*/
53#ifdef __APPLE__
54  alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq);
55#elif defined __WIN32__
[5422]56  alutLoadWAVFile((ALbyte*)fileName, &format, &data, &size, &freq, &this->loop);
[5386]57#else
58  alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq, &this->loop);
59#endif
60  if ((result = alGetError()) != AL_NO_ERROR)
61    SoundEngine::PrintALErrorString(result);
62
63  // send the loaded wav data to the buffer
64  alBufferData(this->bufferID, format, data, this->size, freq);
65  if ((result = alGetError()) != AL_NO_ERROR)
66    SoundEngine::PrintALErrorString(result);
67
68  // remove the wav data (redundant)
69  alutUnloadWAV(format, data, this->size, freq);
70  if ((result = alGetError()) != AL_NO_ERROR)
71    SoundEngine::PrintALErrorString(result);
[3365]72}
[1853]73
[5386]74SoundBuffer::~SoundBuffer()
[3543]75{
[5386]76//  SoundEngine::getInstance()->removeBuffer(this);
77  alDeleteBuffers(1, &this->bufferID);
[3543]78}
Note: See TracBrowser for help on using the repository browser.