📄 oasissoundresource.cpp
字号:
/******************************************************************************
* This source file is part of Bad Camel Gaming
* Copyright (C) 2003 Zephie Greyvenstein
* See Readme.html for acknowledgements
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
/******************************************************************************
* FILENAME : oasisSoundResource.cpp
* DESCRIPTION : Sound resource
* AUTHOR : Zephie Greyvenstein
*****************************************************************************/
#include "oasisSoundResource.h"
#include "oasisSoundSystem.h"
#include "oasisConfiguration.h"
#include "oasisAudioCommon.h"
#include "OgreLogManager.h"
#include "OgreSDDataChunk.h"
namespace Oasis {
soundResource::soundResource( const string &thisName ) : resource( thisName ) {
buffer = 0;
volume = SOUND_DEFAULT_VOLUME;
looping = SOUND_DEFAULT_LOOPING;
maxDistance = SOUND_DEFAULT_ATTMAX;
fileName = "";
}
soundResource::~soundResource( ) {
// Unload is called by Resource
}
void soundResource::setFileName( const string &name ) {
fileName = name;
if ( loaded ) {
unload( );
load( );
}
}
const string &soundResource::getFileName( void ) const {
return fileName;
}
void soundResource::setVolume( const real newVolume ) {
volume = newVolume;
}
const real soundResource::getVolume( void ) const {
return volume;
}
void soundResource::setLooping( const bool newLooping ) {
looping = newLooping;
}
const bool soundResource::getLooping( void ) const {
return looping;
}
void soundResource::setAttenuationMax( real newMax ) {
maxDistance = newMax;
}
const real soundResource::getAttenuationMax( void ) const {
return maxDistance;
}
void soundResource::load( void ) {
if ( !loaded ) {
Ogre::SDDataChunk file;
if ( !soundSystem::get( )._findResourceData( fileName, file ) ) {
oasisError( exception::ET_FILE_NOT_FOUND,
"Could not locate sound file" + fileName,
"soundResource::load" );
} else {
Ogre::LogManager::getSingleton( ).logMessage( Ogre::LML_NORMAL, "Loaded sound resource %s", fileName.c_str( ) );
}
alGenBuffers( 1, ( ALuint* )&buffer );
if ( alGetError( ) != AL_NO_ERROR ) {
oasisError( exception::ET_INTERNAL_ERROR,
"Could not allocate buffer for sound",
"soundResource::load" );
}
alBufferData( buffer,
#if OASIS_PLATFORM == OASIS_PLATFORM_LINUX
AL_FORMAT_WAVE_EXT,
#else
AL_FORMAT_STEREO16,
#endif
file.getPtr( ),
file.getSize( ),
0 );
if ( alGetError( ) != AL_NO_ERROR ) {
oasisError( exception::ET_INTERNAL_ERROR,
"Could not buffer sound",
"soundResource::load" );
}
loaded = true;
mySize = ( size )file.getSize( );
}
}
void soundResource::unload( void ) {
if ( loaded ) {
alDeleteBuffers( 1, ( ALuint* )&buffer );
if ( alGetError( ) != AL_NO_ERROR ) {
oasisError( exception::ET_INTERNAL_ERROR,
"Could not delete sound buffer",
"soundResource::unload" );
}
buffer = 0;
loaded = false;
mySize = 0;
}
}
const uint16 soundResource::getBuffer( void ) {
touch( );
return buffer;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -