Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added copyright notice
network still need to be done

File size: 2.9 KB
Line 
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
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.
63
64                alutInit(NULL, 0);
65                alGetError();
66
67                // Load the wav data.
68
69                if(LoadALData() == AL_FALSE)
70                {
71                    printf("Error loading sound data.");
72
73                }
74
75                SetListenerValues();
76                std::cout << "Play sone ambient background sound";
77        }
78
79        AudioObject::~AudioObject()
80        {
81                KillALData();
82        }
83
84        ALboolean AudioObject::LoadALData()
85        {
86                ALenum format;
87                ALsizei size;
88                ALvoid* data;
89                ALsizei freq;
90                ALboolean loop;
91
92
93                alGenBuffers(1, &Buffer);
94
95                if(alGetError() != AL_NO_ERROR)
96                        return AL_FALSE;
97
98                alutLoadWAVFile((ALbyte*)audioFile_.c_str(), &format, &data, &size, &freq, &loop);
99                alBufferData(Buffer, format, data, size, freq);
100                alutUnloadWAV(format, data, size, freq);
101
102                alGenSources(1, &Source);
103
104                if(alGetError() != AL_NO_ERROR)
105                        return AL_FALSE;
106
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     );
113
114                if(alGetError() == AL_NO_ERROR)
115                        return AL_TRUE;
116
117
118                return AL_FALSE;
119        }
120
121        void AudioObject::SetListenerValues()
122        {
123                alListenerfv(AL_POSITION,    ListenerPos);
124                alListenerfv(AL_VELOCITY,    ListenerVel);
125                alListenerfv(AL_ORIENTATION, ListenerOri);
126        }
127
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);
138
139        }
140}
141
Note: See TracBrowser for help on using the repository browser.