Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/audio/_AudioObject.cc @ 542

Last change on this file since 542 was 513, checked in by nicolasc, 17 years ago

added copyright notice
network still need to be done

File size: 2.9 KB
RevLine 
[513]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      ...
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28
[339]29#include <iostream>
30#include <string>
31#include "AudioObject.h"
32
33namespace audio
34{
35        AudioObject::AudioObject(std::string audioFile)
36        {
37                audioFile_ = audioFile;
38                SourcePos[0]=0;
39                SourcePos[1]=0;
40                SourcePos[2]=0;
41
42                 SourceVel[0]=0;
43                 SourceVel[1]=0;
44                 SourceVel[2]=0;
45
46                 ListenerPos[0]=0;
47                 ListenerPos[1]=0;
48                 ListenerPos[2]=0;
49
50                 ListenerVel[0]=0;
51                 ListenerVel[1]=0;
52                 ListenerVel[2]=0;
53
54                 ListenerOri[0]=0;
55                 ListenerOri[1]=0;
56                 ListenerOri[2]=-1;
57                 ListenerOri[3]=0;
58                 ListenerOri[4]=1;
59                 ListenerOri[5]=0;
60
61
62                // Initialize OpenAL and clear the error bit.
[513]63
[339]64                alutInit(NULL, 0);
65                alGetError();
[513]66
[339]67                // Load the wav data.
[513]68
[339]69                if(LoadALData() == AL_FALSE)
70                {
71                    printf("Error loading sound data.");
[513]72
[339]73                }
74
75                SetListenerValues();
76                std::cout << "Play sone ambient background sound";
77        }
[513]78
[339]79        AudioObject::~AudioObject()
[513]80        {
[339]81                KillALData();
82        }
[513]83
[339]84        ALboolean AudioObject::LoadALData()
85        {
86                ALenum format;
87                ALsizei size;
88                ALvoid* data;
89                ALsizei freq;
90                ALboolean loop;
[513]91
92
[339]93                alGenBuffers(1, &Buffer);
[513]94
[339]95                if(alGetError() != AL_NO_ERROR)
96                        return AL_FALSE;
[513]97
[339]98                alutLoadWAVFile((ALbyte*)audioFile_.c_str(), &format, &data, &size, &freq, &loop);
99                alBufferData(Buffer, format, data, size, freq);
100                alutUnloadWAV(format, data, size, freq);
[513]101
[339]102                alGenSources(1, &Source);
[513]103
[339]104                if(alGetError() != AL_NO_ERROR)
105                        return AL_FALSE;
[513]106
[339]107                alSourcei (Source, AL_BUFFER,   Buffer   );
108                alSourcef (Source, AL_PITCH,    1.0      );
109                alSourcef (Source, AL_GAIN,     1.0      );
110                alSourcefv(Source, AL_POSITION, SourcePos);
111                alSourcefv(Source, AL_VELOCITY, SourceVel);
112                alSourcei (Source, AL_LOOPING,  loop     );
[513]113
[339]114                if(alGetError() == AL_NO_ERROR)
115                        return AL_TRUE;
[513]116
117
[339]118                return AL_FALSE;
[513]119        }
[339]120
121        void AudioObject::SetListenerValues()
122        {
123                alListenerfv(AL_POSITION,    ListenerPos);
124                alListenerfv(AL_VELOCITY,    ListenerVel);
125                alListenerfv(AL_ORIENTATION, ListenerOri);
126        }
[513]127
[339]128        void AudioObject::KillALData()
129        {
130                alDeleteBuffers(1, &Buffer);
131                alDeleteSources(1, &Source);
132                alutExit();
133        }
134
135        void AudioObject::play()
136        {
137                alSourcePlay(Source);
[513]138
[339]139        }
140}
141
Note: See TracBrowser for help on using the repository browser.