Different output frequency on mobile. Readded efx extensions initialization. Changed...
authorlpcamargo <lucaspcamargo@gmail.com>
Sat, 20 Jun 2015 12:59:06 +0000 (15:59 +0300)
committerlpcamargo <lucaspcamargo@gmail.com>
Sat, 20 Jun 2015 12:59:06 +0000 (15:59 +0300)
src/nSoundBuffer.cpp
src/nSoundListener.cpp
src/nSoundSource.cpp
src/nSoundStreamer.cpp
src/nSoundSystem.cpp
src/nSoundSystem.h

index c06cb6311305a7dd3204baa605f05a32b5936783..b0d85eb68ae29d5e516f4fe5e41396d6deae7414 100644 (file)
@@ -43,7 +43,7 @@ nSoundBuffer::nSoundBuffer(QString name, nSoundSystem * parent) :
     ALenum error = alGetError();
     if(error!=AL_NO_ERROR)
     {
-        throw QString("nSoundBuffer: alGenBuffers() failed.");
+        qWarning("nSoundBuffer: alGenBuffers() failed.");
     }
 }
 
@@ -54,7 +54,7 @@ nSoundBuffer::~nSoundBuffer()
     alDeleteBuffers(1, &m_handle);    
 
     if(alGetError()!=AL_NO_ERROR)
-        throw QString("nSoundBuffer::~nSoundBuffer(): Error destroying openal buffer.");
+        qWarning("nSoundBuffer::~nSoundBuffer(): Error destroying openal buffer.");
 }
 
 void nSoundBuffer::setData(nSoundBag * bag)
@@ -64,7 +64,7 @@ void nSoundBuffer::setData(nSoundBag * bag)
     alBufferData(m_handle, openalFormat(bag->m_format), bag->m_data, bag->m_data_size, bag->m_frequency);
 
     if(alGetError()!=AL_NO_ERROR)
-        throw QString("nSoundBuffer::setData(): Error loading buffer data.");
+        qWarning("nSoundBuffer::setData(): Error loading buffer data.");
 }
 
 void nSoundBuffer::setData(nSoundStream * stream)
index f880b7fd47e3d2b1f2d2cac3a1d211ae1d696a74..a09223a99782c9da91f21a449c49fa805350ecff 100644 (file)
@@ -99,5 +99,5 @@ void nSoundListener::updateManual(QVector3D pos, QVector3D dir, QVector3D up, QV
     alListener3f(AL_VELOCITY, vel[0], vel[1], vel[2]);
 
     if(alGetError()!=AL_NO_ERROR)
-        throw QString("nSoundListener: Failed to update listener transformations.");
+        qWarning("nSoundListener: Failed to update listener transformations.");
 }
index 2d6ce929de7e0be130ab78285b55336572181c4c..fdeb5fb3104bca7699713eff6bf9bf48ac3e1b0a 100644 (file)
@@ -50,7 +50,7 @@ nSoundSource::nSoundSource(QString name, nSoundSourceRole role, nSoundSystem * p
     ALenum error = alGetError();
     if(error!=AL_NO_ERROR)
     {
-        throw QString("nSoundSource: alGenSources() failed.");
+        qWarning("nSoundSource: alGenSources() failed.");
     }
 
     alSourcef(m_handle, AL_GAIN, m_gainMirror);
@@ -58,7 +58,7 @@ nSoundSource::nSoundSource(QString name, nSoundSourceRole role, nSoundSystem * p
     alSource3f(m_handle, AL_VELOCITY, 0.0f ,0.0f ,0.0f);
     alSource3f(m_handle, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
     if(error!=AL_NO_ERROR)
-        throw QString("nSoundSource: Setting of source properties failed.");
+        qWarning("nSoundSource: Setting of source properties failed.");
 
 }
 
@@ -216,14 +216,13 @@ void nSoundSource::attachBuffer(nSoundBuffer * buffer)
     ALint sourceType;
     alGetSourcei(m_handle, AL_SOURCE_TYPE, &sourceType);
     if(sourceType == AL_STREAMING)
-        throw QString("nSoundSource: Tried to play a single buffer on a streaming source.");
+        qWarning("nSoundSource: Tried to play a single buffer on a streaming source.");
 
     alSourcei(m_handle, AL_BUFFER, buffer->openalHandle());
 
     ALenum err = alGetError();
     if(err!=AL_NO_ERROR)
-        throw QString("nSoundSource: failed to bind buffer \"")+buffer->objectName()+
-                QString("\" to source \"")+objectName()+QString("\".");
+        qWarning("nSoundSource: failed to bind buffer to source");
 }
 
 void nSoundSource::play()
@@ -231,7 +230,7 @@ void nSoundSource::play()
     alGetError();
     alSourcePlay(m_handle);
     if(alGetError()!=AL_NO_ERROR)
-        throw QString("nSoundSource: Failed to play source.");
+        qWarning("nSoundSource: Failed to play source.");
 }
 
 void nSoundSource::pause()
@@ -239,7 +238,7 @@ void nSoundSource::pause()
     alGetError();
     alSourcePause(m_handle);
     if(alGetError()!=AL_NO_ERROR)
-        throw QString("nSoundSource: Failed to pause source.");
+        qWarning("nSoundSource: Failed to pause source.");
 }
 
 void nSoundSource::stop()
@@ -247,7 +246,7 @@ void nSoundSource::stop()
     alGetError();
     alSourceStop(m_handle);
     if(alGetError()!=AL_NO_ERROR)
-        throw QString("nSoundSource: Failed to stop source.");
+        qWarning("nSoundSource: Failed to stop source.");
 }
 
 void nSoundSource::rewind()
@@ -255,7 +254,7 @@ void nSoundSource::rewind()
     alGetError();
     alSourceRewind(m_handle);
     if(alGetError()!=AL_NO_ERROR)
-        throw QString("nSoundSource: Failed to rewind source.");
+        qWarning("nSoundSource: Failed to rewind source.");
 }
 
 // GAIN CFG SUPPORT
index ccdc388f60075d53672e27d4b43e528806c5780a..2c5d20418c003cc064715573a5b1f3edc65b690e 100644 (file)
@@ -50,7 +50,7 @@ nSoundStreamer::nSoundStreamer(QString name, nSoundSource * source, nSoundStream
     int sourceType;
     alGetSourcei(source->openalHandle(), AL_SOURCE_TYPE, &sourceType);
     if(sourceType == AL_STATIC)
-        throw QString("nSoundStreamer::nSoundStreamer(...): Tried to create stream \"")+name+("\" to an AL_STATIC source.");
+        qWarning("nSoundStreamer::nSoundStreamer(...): Tried to create stream to an AL_STATIC source.");
     m_source = source;
 
     // create OpenAL buffers
@@ -61,7 +61,7 @@ nSoundStreamer::nSoundStreamer(QString name, nSoundSource * source, nSoundStream
     m_buffer1 = buffers[1];
     m_buffer2 = buffers[2];
     if(alGetError()!=AL_NO_ERROR)
-        throw QString("nSoundStreamer::nSoundStreamer(...): Failed to create streaming buffers for \"")+name+QString("\".");
+        qWarning("nSoundStreamer::nSoundStreamer(...): Failed to create streaming buffers");
 
 
     //reserve buffer memory
@@ -147,7 +147,7 @@ void nSoundStreamer::update(float frameTime)
             unsigned int buffer;
             alSourceUnqueueBuffers(sourceHandle, 1, &buffer);
             if(alGetError()!=AL_NO_ERROR)
-                throw QString("nSoundStreamer::update(...): Failed to unqueue buffer.");
+                qWarning("nSoundStreamer::update(...): Failed to unqueue buffer.");
 
             if(m_keepStreaming) m_keepStreaming = fillAndQueueBuffer(buffer);
         }
@@ -205,11 +205,11 @@ bool nSoundStreamer::fillAndQueueBuffer(unsigned int buffer)
     alGetError();
     alBufferData(buffer, openalFormat(m_bag->m_format), m_bag->m_data, readFrames*byteFactor, m_bag->m_frequency);
     if(alGetError()!=AL_NO_ERROR)
-        throw QString("nSoundStreamer::fillAndQueueBuffer(...): Failed to refill buffer.");
+        qWarning("nSoundStreamer::fillAndQueueBuffer(...): Failed to refill buffer.");
 
     alSourceQueueBuffers(m_source->openalHandle(), 1, &buffer);
     if(alGetError()!=AL_NO_ERROR)
-        throw QString("nSoundStreamer::fillAndQueueBuffer(...): Failed to queue buffer.");
+        qWarning("nSoundStreamer::fillAndQueueBuffer(...): Failed to queue buffer.");
 
     return keep;
 }
index 6b9519cbf7ce9081b9cac0c09d0e76606a188469..509ea7761cf75d966871406d4b6bee6c53edd68f 100644 (file)
 #include <AL/al.h>
 #include <AL/alc.h>
 #include <AL/alext.h>
+#include <AL/efx.h>
 
 #include "util/nEfxHelper.h"
 #include <QSettings>
 #include <QUuid>
+#include <QDebug>
 
 nSoundSystem::nSoundSystem(QObject *parent) :
     QObject(parent), m_success(false)
@@ -48,12 +50,12 @@ nSoundSystem::nSoundSystem(QObject *parent) :
 
     m_device = alcOpenDevice(0); //default device
     if(!m_device)
-        throw QString("Error creating OpenAL device.");
+        qWarning("Error creating OpenAL device.");
 
-    int attributes[] = {ALC_FREQUENCY, 44100, 0};
+    int attributes[] = {ALC_FREQUENCY, NEIASOUND_FREQ, 0};
     m_context = alcCreateContext(m_device, attributes);
     if(!m_context)
-        throw QString("Error creating OpenAL context.");
+        qWarning("Error creating OpenAL context.");
 
     alcMakeContextCurrent(m_context);
     if( alGetError()!=AL_NO_ERROR)
@@ -79,6 +81,16 @@ nSoundSystem::nSoundSystem(QObject *parent) :
     setMasterGain(settings.value("MasterGain", 100).toFloat()/100.0f);
     settings.endGroup();
 
+
+    int efxMaj, efxMin;
+    alcGetIntegerv(m_device, ALC_EFX_MAJOR_VERSION, 1, &efxMaj);
+    alcGetIntegerv(m_device, ALC_EFX_MINOR_VERSION, 1, &efxMin);
+
+    qDebug("nSoundSystem::nSoundSystem(): initialized successfully");
+    qDebug() << QStringLiteral("EFX OpenAL Extension version %1.%2").arg(efxMaj).arg(efxMin);
+
+    nEfxHelper::initialize(m_device);
+
 }
 
 nSoundSystem::~nSoundSystem()
@@ -90,17 +102,17 @@ nSoundSystem::~nSoundSystem()
 
     foreach(nSoundStreamer * streamer, streamers)
     {
-        destroyStreamer(streamer);
+        delete (streamer);
     }
 
     foreach(nSoundSource * source, sources)
     {
-        destroySource(source);
+        delete (source);
     }
 
     foreach(nSoundBuffer * buffer, buffers)
     {
-        destroyBuffer(buffer);
+        delete (buffer);
     }
 
 
index e5a95ea3a56650d6a9df5f7fe3b686f81b6f4691..3f3503877f341b00a44dfd6b0f7b6b429b224356 100644 (file)
 #include "nSoundSourceRole.h"
 #include "nSoundFormat.h"
 
+
+#ifdef ANDROID
+#define NEIASOUND_FREQ 22050
+#else
+#define NEIASOUND_FREQ 48000
+#endif
+
 // *sigh* ugly but necessary
 struct ALCcontext_struct;
 struct ALCdevice_struct;