00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "engine.h"
00021 #include "device_p.h"
00022
00023 #include <QtCore/QDebug>
00024 #include <QtGui/QVector3D>
00025 #include <al.h>
00026 #include <alc.h>
00027 #ifndef Q_WS_MAC
00028 #include <alext.h>
00029 #endif
00030
00031 using namespace GluonAudio;
00032
00033 template<> Engine* GluonCore::Singleton<Engine>::m_instance = 0;
00034
00035 Engine::Engine()
00036 {
00037 m_context = 0;
00038 m_device = 0;
00039 setDevice( "" );
00040
00041 qDebug() << alGetError();
00042 }
00043
00044 Engine::~Engine()
00045 {
00046 alcMakeContextCurrent( 0 );
00047 alcDestroyContext( m_context );
00048 alcCloseDevice( m_device );
00049 }
00050
00051 QStringList Engine::deviceList()
00052 {
00053 if( !Device::isExtensionPresent( "ALC_ENUMERATION_EXT" ) )
00054 {
00055 return QStringList();
00056 }
00057
00058 if( Device::isExtensionPresent( "ALC_ENUMERATE_ALL_EXT" ) )
00059 {
00060 return Device::contextOption( ALC_ALL_DEVICES_SPECIFIER );
00061 }
00062 else
00063 {
00064 return Device::contextOption( ALC_DEVICE_SPECIFIER );
00065 }
00066 }
00067
00068 bool Engine::setDevice( const QString& deviceName )
00069 {
00070 if( m_device )
00071 {
00072 alcMakeContextCurrent( 0 );
00073 alcDestroyContext( m_context );
00074 }
00075
00076 if( !deviceName.isEmpty() )
00077 {
00078 m_device = alcOpenDevice( deviceName.toUtf8() );
00079 }
00080 else
00081 {
00082 m_device = alcOpenDevice( 0 );
00083 }
00084
00085 if( !m_device )
00086 {
00087 return false;
00088 }
00089
00090 m_context = alcCreateContext( m_device, 0 );
00091
00092 if( !m_context )
00093 {
00094 return false;
00095 }
00096
00097 if( !alcMakeContextCurrent( m_context ) )
00098 {
00099 return false;
00100 }
00101
00102 return true;
00103 }
00104
00105 QVector3D Engine::listenerPosition()
00106 {
00107 ALfloat listener[3];
00108 alGetListenerfv( AL_POSITION, listener );
00109
00110
00111 return QVector3D( listener[0], listener[1], listener[2] );
00112
00113 }
00114
00115 void Engine::setListenerPosition( const QVector3D& position )
00116 {
00117 alListener3f( AL_POSITION, position.x(), position.y(), position.z() );
00118 }
00119