From 3143ecb6ed160acff42fdaa4c1947fc29d0003a2 Mon Sep 17 00:00:00 2001 From: Henri Herscher Date: Thu, 8 Dec 2005 17:09:51 +0000 Subject: Sample rate can now be set in SoundDevice plugin git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@99 09dcff7a-b715-0410-9601-b79a96267cd0 --- .../audiocaptureplugins/sounddevice/SoundDevice.cpp | 21 +++++++++++++++++---- .../sounddevice/SoundDeviceConfig.cpp | 2 ++ .../sounddevice/SoundDeviceConfig.h | 3 +++ 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'orkaudio') diff --git a/orkaudio/audiocaptureplugins/sounddevice/SoundDevice.cpp b/orkaudio/audiocaptureplugins/sounddevice/SoundDevice.cpp index 4252f0d..5326152 100644 --- a/orkaudio/audiocaptureplugins/sounddevice/SoundDevice.cpp +++ b/orkaudio/audiocaptureplugins/sounddevice/SoundDevice.cpp @@ -29,6 +29,9 @@ extern OrkLogManager* g_logManager; SoundDeviceConfigTopObjectRef g_soundDeviceConfigTopObjectRef; #define DLLCONFIG g_soundDeviceConfigTopObjectRef.get()->m_config +static LoggerPtr s_soundDeviceLog; +static LoggerPtr s_soundDeviceBufferLog; + typedef struct { @@ -43,6 +46,13 @@ int portAudioCallBack(void *inputBuffer, void *outputBuffer, unsigned long frame short * inputSamples = (short *)inputBuffer; CStdString portName; + if(s_soundDeviceBufferLog->isDebugEnabled()) + { + CStdString debug; + debug.Format("Dev:%u NumSamples:%u Time:%f", device->deviceID, framesPerBuffer, outTime); + LOG4CXX_DEBUG(s_soundDeviceBufferLog, debug); + } + if (device->channelCount == 2) { // stereo -> split into two different chunks @@ -55,12 +65,12 @@ int portAudioCallBack(void *inputBuffer, void *outputBuffer, unsigned long frame leftBuffer[sampleId] = inputSamples[2*sampleId+1]; } AudioChunkRef chunkRef(new AudioChunk); - chunkRef->SetBuffer(rightBuffer, sizeof(short)*framesPerBuffer, AudioChunk::PcmAudio); + chunkRef->SetBuffer(rightBuffer, sizeof(short)*framesPerBuffer, AudioChunk::PcmAudio, 0, 0, DLLCONFIG.m_sampleRate); portName.Format("port%d-%d", device->deviceID, 1); g_audioChunkCallBack(chunkRef, portName); chunkRef.reset(new AudioChunk); - chunkRef->SetBuffer(leftBuffer, sizeof(short)*framesPerBuffer, AudioChunk::PcmAudio); + chunkRef->SetBuffer(leftBuffer, sizeof(short)*framesPerBuffer, AudioChunk::PcmAudio, 0, 0, DLLCONFIG.m_sampleRate); portName.Format("port%d-%d", device->deviceID, 2); g_audioChunkCallBack(chunkRef, portName); @@ -71,7 +81,7 @@ int portAudioCallBack(void *inputBuffer, void *outputBuffer, unsigned long frame { // mono AudioChunkRef chunkRef(new AudioChunk); - chunkRef->SetBuffer(inputSamples, sizeof(short)*framesPerBuffer, AudioChunk::PcmAudio); + chunkRef->SetBuffer(inputSamples, sizeof(short)*framesPerBuffer, AudioChunk::PcmAudio, 0, 0, DLLCONFIG.m_sampleRate); portName.Format("port%d", device->deviceID); g_audioChunkCallBack(chunkRef, portName); } @@ -128,6 +138,9 @@ void SoundDevice::Initialize() { LOG4CXX_INFO(g_logManager->rootLog, "Initializing Sound Device plugin"); + s_soundDeviceLog = Logger::getLogger("sounddevice"); + s_soundDeviceBufferLog = Logger::getLogger("sounddevice.buffer"); + // create a default config object in case it was not properly initialized by Configure if(!g_soundDeviceConfigTopObjectRef.get()) { @@ -178,7 +191,7 @@ void SoundDevice::Initialize() 0, paInt16, NULL, - 8000.0, + (double)DLLCONFIG.m_sampleRate, DLLCONFIG.m_audioChunkSize, 0, 0, diff --git a/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.cpp b/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.cpp index 998eb72..a085bb2 100644 --- a/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.cpp +++ b/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.cpp @@ -20,11 +20,13 @@ SoundDeviceConfig::SoundDeviceConfig() { m_audioChunkSize = AUDIO_CHUNK_SIZE_DEFAULT; + m_sampleRate = SAMPLE_RATE_DEFAULT; } void SoundDeviceConfig::Define(Serializer* s) { s->IntValue(AUDIO_CHUNK_SIZE_PARAM, m_audioChunkSize); + s->IntValue(SAMPLE_RATE_PARAM, m_sampleRate); } void SoundDeviceConfig::Validate() diff --git a/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.h b/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.h index 6453523..df4447f 100644 --- a/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.h +++ b/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.h @@ -20,6 +20,8 @@ #define AUDIO_CHUNK_SIZE_PARAM "AudioChunkSize" #define AUDIO_CHUNK_SIZE_DEFAULT 8000 +#define SAMPLE_RATE_PARAM "SampleRate" +#define SAMPLE_RATE_DEFAULT 8000 /** This class defines various configuration parameters for the generator. */ class SoundDeviceConfig : public Object @@ -34,6 +36,7 @@ public: inline ObjectRef Process() {return ObjectRef();}; int m_audioChunkSize; + int m_sampleRate; }; //======================================== -- cgit v1.2.3