Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/audio/src/audio/Ambient.cc @ 335

Last change on this file since 335 was 335, checked in by nicolape, 16 years ago

Added missing static libs

File size: 2.1 KB
Line 
1#include <iostream>
2#include "Ambient.h"
3#include "../../include/AL/al.h"
4#include "../../include/AL/alc.h"
5#include "../../include/AL/alut.h"
6
7namespace audio
8{
9        Ambient::Ambient()
10        {
11                SourcePos[0]=0;
12                SourcePos[1]=0;
13                SourcePos[2]=0;
14
15                 SourceVel[0]=0;
16                 SourceVel[1]=0;
17                 SourceVel[2]=0;
18
19                 ListenerPos[0]=0;
20                 ListenerPos[1]=0;
21                 ListenerPos[2]=0;
22
23                 ListenerVel[0]=0;
24                 ListenerVel[1]=0;
25                 ListenerVel[2]=0;
26
27                 ListenerOri[0]=0;
28                 ListenerOri[1]=0;
29                 ListenerOri[2]=-1;
30                 ListenerOri[3]=0;
31                 ListenerOri[4]=1;
32                 ListenerOri[5]=0;
33
34
35        // Initialize OpenAL and clear the error bit.
36
37        alutInit(NULL, 0);
38        alGetError();
39
40        // Load the wav data.
41
42        if(LoadALData() == AL_FALSE)
43        {
44            printf("Error loading sound data.");
45               
46        }
47
48        SetListenerValues();
49
50        // Setup an exit procedure.
51
52        //atexit(KillALData);
53
54                std::cout << "Play sone ambient background sound";
55        }
56       
57        ALboolean Ambient::LoadALData()
58        {
59                ALenum format;
60                ALsizei size;
61                ALvoid* data;
62                ALsizei freq;
63                ALboolean loop;
64       
65       
66                alGenBuffers(1, &Buffer);
67       
68                if(alGetError() != AL_NO_ERROR)
69                        return AL_FALSE;
70       
71                alutLoadWAVFile((ALbyte*)"wavdata/pirate.wav", &format, &data, &size, &freq, &loop);
72                alBufferData(Buffer, format, data, size, freq);
73                alutUnloadWAV(format, data, size, freq);
74       
75                alGenSources(1, &Source);
76       
77                if(alGetError() != AL_NO_ERROR)
78                        return AL_FALSE;
79       
80                alSourcei (Source, AL_BUFFER,   Buffer   );
81                alSourcef (Source, AL_PITCH,    1.0      );
82                alSourcef (Source, AL_GAIN,     1.0      );
83                alSourcefv(Source, AL_POSITION, SourcePos);
84                alSourcefv(Source, AL_VELOCITY, SourceVel);
85                alSourcei (Source, AL_LOOPING,  loop     );
86       
87                if(alGetError() == AL_NO_ERROR)
88                        return AL_TRUE;
89       
90       
91                return AL_FALSE;
92        }       
93
94        void Ambient::SetListenerValues()
95        {
96                alListenerfv(AL_POSITION,    ListenerPos);
97                alListenerfv(AL_VELOCITY,    ListenerVel);
98                alListenerfv(AL_ORIENTATION, ListenerOri);
99        }
100       
101        void Ambient::KillALData()
102        {
103                alDeleteBuffers(1, &Buffer);
104                alDeleteSources(1, &Source);
105                alutExit();
106        }
107
108        void Ambient::play()
109        {
110                alSourcePlay(Source);
111       
112        }
113}
114
Note: See TracBrowser for help on using the repository browser.