Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 13, 2007, 5:58:14 PM (16 years ago)
Author:
nicolasc
Message:

added copyright notice
network still need to be done

Location:
code/branches/FICN/src/audio
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/audio/AudioBuffer.cc

    r389 r513  
     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
    128#include "AudioBuffer.h"
    229
     
    1845                if(alGetError() != AL_NO_ERROR)
    1946                        loaded=AL_FALSE;
    20        
     47
    2148                loaded=AL_TRUE;
    2249        }
    23        
     50
    2451        AudioBuffer::~AudioBuffer()
    2552        {
    26                
     53
    2754        }
    2855}
  • code/branches/FICN/src/audio/AudioManager.cc

    r458 r513  
     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
    128#include "AudioManager.h"
    229
  • code/branches/FICN/src/audio/AudioSource.cc

    r389 r513  
     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
    128#include "AudioSource.h"
    229
     
    734
    835        }
    9        
     36
    1037        AudioSource::~AudioSource()
    1138        {
    12                
     39
    1340        }
    1441}
  • code/branches/FICN/src/audio/AudioStream.cc

    r430 r513  
     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
    128
    229#include "AudioStream.h"
     
    835                this->path = path;
    936                loaded = false;
    10         }       
     37        }
    1138
    1239        void AudioStream::open()
     
    1441            int result;
    1542
    16            
     43
    1744            if(!(oggFile = fopen(path.c_str(), "rb")))
    1845                        {
     
    2350            if((result = ov_open(oggFile, &oggStream, NULL, 0)) < 0)
    2451            {
    25         fclose(oggFile);               
     52        fclose(oggFile);
    2653              orxonox::Error("Could not open Ogg stream. " + errorString(result));
    2754                                return;
     
    2956
    3057                        loaded = true;
    31        
     58
    3259            vorbisInfo = ov_info(&oggStream, -1);
    3360            vorbisComment = ov_comment(&oggStream, -1);
    34        
     61
    3562            if(vorbisInfo->channels == 1)
    3663                format = AL_FORMAT_MONO16;
    3764            else
    3865                format = AL_FORMAT_STEREO16;
    39                
    40                
     66
     67
    4168            alGenBuffers(2, buffers);
    4269            check();
    4370            alGenSources(1, &source);
    4471            check();
    45            
     72
    4673            alSource3f(source, AL_POSITION,        0.0, 0.0, 0.0);
    4774            alSource3f(source, AL_VELOCITY,        0.0, 0.0, 0.0);
     
    5077            alSourcei (source, AL_SOURCE_RELATIVE, AL_FALSE      );
    5178        }
    52        
    53        
    54        
    55        
     79
     80
     81
     82
    5683        void AudioStream::release()
    5784        {
     
    6390            alDeleteBuffers(1, buffers);
    6491            check();
    65        
     92
    6693            ov_clear(&oggStream);
    6794                        loaded = false;
    68                
    69         }
    70        
    71        
    72        
    73        
     95
     96        }
     97
     98
     99
     100
    74101        void AudioStream::display()
    75102        {
     
    86113                << "\n"
    87114                << "vendor " << vorbisComment->vendor << "\n";
    88                
     115
    89116            for(int i = 0; i < vorbisComment->comments; i++)
    90117                std::cout << "   " << vorbisComment->user_comments[i] << "\n";
    91                
    92             std::cout << std::endl;     
     118
     119            std::cout << std::endl;
    93120                }
    94121        }
    95        
    96        
    97        
    98        
     122
     123
     124
     125
    99126        bool AudioStream::playback()
    100127        {
     
    106133            if(playing())
    107134                return true;
    108                
     135
    109136            if(!stream(buffers[0]))
    110137                return false;
    111                
     138
    112139            if(!stream(buffers[1]))
    113140                return false;
    114            
     141
    115142            alSourceQueueBuffers(source, 2, buffers);
    116143            alSourcePlay(source);
    117            
     144
    118145            return true;
    119146        }
    120        
    121        
    122        
    123        
     147
     148
     149
     150
    124151        bool AudioStream::playing()
    125152        {
     
    133160            return (state == AL_PLAYING);
    134161        }
    135        
    136        
    137        
    138        
     162
     163
     164
     165
    139166        bool AudioStream::update()
    140167        {
    141168            int processed;
    142169            bool active = true;
    143        
     170
    144171            alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
    145        
     172
    146173            while(processed--)
    147174            {
    148175                ALuint buffer;
    149                
     176
    150177                alSourceUnqueueBuffers(source, 1, &buffer);
    151178                check();
    152        
     179
    153180                active = stream(buffer);
    154        
     181
    155182                alSourceQueueBuffers(source, 1, &buffer);
    156183                check();
    157184            }
    158        
     185
    159186                        if (active==false)
    160187                        {
     
    163190            return active;
    164191        }
    165        
    166        
    167        
    168        
     192
     193
     194
     195
    169196        bool AudioStream::stream(ALuint buffer)
    170197        {
     
    173200            int  section;
    174201            int  result;
    175        
     202
    176203            while(size < BUFFER_SIZE)
    177204            {
    178205                result = ov_read(&oggStream, pcm + size, BUFFER_SIZE - size, 0, 2, 1, &section);
    179            
     206
    180207                if(result > 0)
    181208                    size += result;
     
    186213                        break;
    187214            }
    188            
     215
    189216            if(size == 0)
    190217                return false;
    191                
     218
    192219            alBufferData(buffer, format, pcm, size, vorbisInfo->rate);
    193220            check();
    194            
     221
    195222            return true;
    196223        }
    197        
    198        
     224
     225
    199226
    200227        void AudioStream::empty()
    201228        {
    202229            int queued;
    203            
     230
    204231            alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
    205            
     232
    206233            while(queued--)
    207234            {
    208235                ALuint buffer;
    209            
     236
    210237                alSourceUnqueueBuffers(source, 1, &buffer);
    211238                check();
    212239            }
    213240        }
    214        
    215        
    216        
    217        
     241
     242
     243
     244
    218245        void AudioStream::check()
    219246        {
    220247                int error = alGetError();
    221        
     248
    222249                if(error != AL_NO_ERROR)
    223250                        orxonox::Error("OpenAL error was raised.");
    224251        }
    225        
    226        
    227        
     252
     253
     254
    228255        std::string AudioStream::errorString(int code)
    229256        {
  • code/branches/FICN/src/audio/_AudioObject.cc

    r389 r513  
     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
    129#include <iostream>
    230#include <string>
     
    3361
    3462                // Initialize OpenAL and clear the error bit.
    35        
     63
    3664                alutInit(NULL, 0);
    3765                alGetError();
    38        
     66
    3967                // Load the wav data.
    40        
     68
    4169                if(LoadALData() == AL_FALSE)
    4270                {
    4371                    printf("Error loading sound data.");
    44                        
     72
    4573                }
    4674
     
    4876                std::cout << "Play sone ambient background sound";
    4977        }
    50        
     78
    5179        AudioObject::~AudioObject()
    52         {       
     80        {
    5381                KillALData();
    5482        }
    55        
     83
    5684        ALboolean AudioObject::LoadALData()
    5785        {
     
    6189                ALsizei freq;
    6290                ALboolean loop;
    63        
    64        
     91
     92
    6593                alGenBuffers(1, &Buffer);
    66        
     94
    6795                if(alGetError() != AL_NO_ERROR)
    6896                        return AL_FALSE;
    69        
     97
    7098                alutLoadWAVFile((ALbyte*)audioFile_.c_str(), &format, &data, &size, &freq, &loop);
    7199                alBufferData(Buffer, format, data, size, freq);
    72100                alutUnloadWAV(format, data, size, freq);
    73        
     101
    74102                alGenSources(1, &Source);
    75        
     103
    76104                if(alGetError() != AL_NO_ERROR)
    77105                        return AL_FALSE;
    78        
     106
    79107                alSourcei (Source, AL_BUFFER,   Buffer   );
    80108                alSourcef (Source, AL_PITCH,    1.0      );
     
    83111                alSourcefv(Source, AL_VELOCITY, SourceVel);
    84112                alSourcei (Source, AL_LOOPING,  loop     );
    85        
     113
    86114                if(alGetError() == AL_NO_ERROR)
    87115                        return AL_TRUE;
    88        
    89        
     116
     117
    90118                return AL_FALSE;
    91         }       
     119        }
    92120
    93121        void AudioObject::SetListenerValues()
     
    97125                alListenerfv(AL_ORIENTATION, ListenerOri);
    98126        }
    99        
     127
    100128        void AudioObject::KillALData()
    101129        {
     
    108136        {
    109137                alSourcePlay(Source);
    110        
     138
    111139        }
    112140}
Note: See TracChangeset for help on using the changeset viewer.