Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6429 was 5930, checked in by bensch, 19 years ago

orxonox/trunk: remake of the SoundEngine (faster, and millions of SoundSources can be defined, as Many are not needed for playing

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
[1856]22using namespace std;
[1853]23
[5386]24//////////////////
25/* SOUND-BUFFER */
26//////////////////
[3245]27/**
[5386]28 *  Creates a Soundbuffer out of an inputfile
29 * @param fileName The name of the File
30 */
31SoundBuffer::SoundBuffer(const char* fileName)
[3365]32{
[5386]33  this->setClassID(CL_SOUND_BUFFER, "SoundBuffer");
34  this->setName(fileName);
[4320]35
[5386]36  ALenum format;
37  ALvoid* data;
38  ALsizei freq;
39
40  ALenum result;
41
42  // generate a Buffer
43  alGenBuffers(1, &this->bufferID);
44  if ((result = alGetError()) != AL_NO_ERROR)
[5930]45    PRINTF(2)("%s\n", SoundEngine::getALErrorString(result));
[5386]46
47  // read in the wav data
48  /* according to http://www.edenwaith.com/products/pige/tutorials/openal.php the alutLoadWAVFile differs from platform to platform*/
49#ifdef __APPLE__
50  alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq);
51#elif defined __WIN32__
[5422]52  alutLoadWAVFile((ALbyte*)fileName, &format, &data, &size, &freq, &this->loop);
[5386]53#else
54  alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq, &this->loop);
55#endif
56  if ((result = alGetError()) != AL_NO_ERROR)
[5930]57    PRINTF(2)("%s\n", SoundEngine::getALErrorString(result));
[5386]58
59  // send the loaded wav data to the buffer
60  alBufferData(this->bufferID, format, data, this->size, freq);
61  if ((result = alGetError()) != AL_NO_ERROR)
[5930]62    PRINTF(2)("%s\n", SoundEngine::getALErrorString(result));
[5386]63
64  // remove the wav data (redundant)
65  alutUnloadWAV(format, data, this->size, freq);
66  if ((result = alGetError()) != AL_NO_ERROR)
[5930]67    PRINTF(2)("%s\n", SoundEngine::getALErrorString(result));
[3365]68}
[1853]69
[5386]70SoundBuffer::~SoundBuffer()
[3543]71{
[5386]72//  SoundEngine::getInstance()->removeBuffer(this);
73  alDeleteBuffers(1, &this->bufferID);
[3543]74}
Note: See TracBrowser for help on using the repository browser.