summaryrefslogtreecommitdiff
path: root/orkaudio/audiocaptureplugins/generator
diff options
context:
space:
mode:
authorHenri Herscher <henri@oreka.org>2005-10-20 13:40:58 +0000
committerHenri Herscher <henri@oreka.org>2005-10-20 13:40:58 +0000
commit7e1d63dd9fd149e4934bf77095c8610fac786b04 (patch)
tree5fe486a1b0300c3b84fb559107a868e5cc2c95da /orkaudio/audiocaptureplugins/generator
parent467768fc956fc3e5a253373f26c71c681b31b6b8 (diff)
First checkin
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@2 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkaudio/audiocaptureplugins/generator')
-rw-r--r--orkaudio/audiocaptureplugins/generator/Generator.cpp147
-rw-r--r--orkaudio/audiocaptureplugins/generator/Generator.dsp126
-rw-r--r--orkaudio/audiocaptureplugins/generator/GeneratorConfig.cpp70
-rw-r--r--orkaudio/audiocaptureplugins/generator/GeneratorConfig.h66
-rw-r--r--orkaudio/audiocaptureplugins/generator/Makefile.am10
5 files changed, 419 insertions, 0 deletions
diff --git a/orkaudio/audiocaptureplugins/generator/Generator.cpp b/orkaudio/audiocaptureplugins/generator/Generator.cpp
new file mode 100644
index 0000000..77bfdf9
--- /dev/null
+++ b/orkaudio/audiocaptureplugins/generator/Generator.cpp
@@ -0,0 +1,147 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#define _WINSOCKAPI_ // prevents the inclusion of winsock.h
+
+#include "Utils.h"
+#include "AudioCapturePlugin.h"
+#include "AudioCapturePluginCommon.h"
+#include "ConfigManager.h"
+#include "GeneratorConfig.h"
+
+extern AudioChunkCallBackFunction g_audioChunkCallBack;
+extern CaptureEventCallBackFunction g_captureEventCallBack;
+extern LogManager* g_logManager;
+
+GeneratorConfigTopObjectRef g_generatorConfigTopObjectRef;
+#define GCONFIG g_generatorConfigTopObjectRef.get()->m_config
+
+void Configure(DOMNode* node)
+{
+ if (node)
+ {
+ GeneratorConfigTopObjectRef generatorConfigTopObjectRef(new GeneratorConfigTopObject);
+ try
+ {
+ generatorConfigTopObjectRef.get()->DeSerializeDom(node);
+ g_generatorConfigTopObjectRef = generatorConfigTopObjectRef;
+ }
+ catch (CStdString& e)
+ {
+ LOG4CXX_WARN(g_logManager->rootLog, "Generator.dll: " + e + " - using defaults");
+ }
+ }
+ else
+ {
+ LOG4CXX_WARN(g_logManager->rootLog, "Generator.dll: got empty DOM tree");
+ }
+}
+
+void Initialize()
+{
+ // create a default config object in case it was not properly initialized by Configure
+ if (!g_generatorConfigTopObjectRef.get())
+ {
+ g_generatorConfigTopObjectRef.reset(new GeneratorConfigTopObject);
+ }
+}
+
+void Run()
+{
+
+#define NUM_SAMPLES_PER_CHUNK 8000
+
+ // Load test file data into memory
+ int fileSize = 0;
+ int audioBufferSize = 0;
+ int numChunks;
+ short* audioBuffer = NULL;
+ FILE* file = fopen((PCSTR)GCONFIG.m_audioFilename,"rb");
+ if (file)
+ {
+ fseek (file, 0, SEEK_END);
+ fileSize = ftell(file);
+ fseek (file, 0, SEEK_SET);
+
+ // round up file size to the next NUM_SAMPLES_PER_CHUNK multiple
+ numChunks = (fileSize/NUM_SAMPLES_PER_CHUNK) + 1;
+ fileSize = numChunks * NUM_SAMPLES_PER_CHUNK;
+
+ audioBuffer = (short *)malloc(sizeof(short)*fileSize);
+ audioBufferSize = fileSize/sizeof(short);
+ for(int i=0; i<fileSize; i++)
+ {
+ audioBuffer[i] = 0;
+ }
+ int numRead = fread(audioBuffer, sizeof(short), fileSize, file);
+ fclose(file);
+ }
+ else
+ {
+ // can't find test file - have a single zeroed buffer in memory
+ LOG4CXX_WARN(g_logManager->rootLog, "Generator.dll: Could not load audio test file:" + GCONFIG.m_audioFilename + " using empty buffer instead");
+
+ numChunks = 1;
+ audioBuffer = (short *)malloc(sizeof(short)*NUM_SAMPLES_PER_CHUNK);
+ audioBufferSize = NUM_SAMPLES_PER_CHUNK;
+ for(int i=0; i<NUM_SAMPLES_PER_CHUNK; i++)
+ {
+ audioBuffer[i] = 0;
+ }
+ }
+
+ int elapsed = 0;
+
+ for(;;)
+ {
+
+ for(int portId = 0; portId<GCONFIG.m_numConcurrentPorts; portId++)
+ {
+ CStdString portName;
+ portName.Format("port%d", portId);
+
+ if ((elapsed%GCONFIG.m_audioDuration) == 0)
+ {
+ // signal call stop and start on all ports
+ CaptureEventRef stopEvent(new CaptureEvent);
+ stopEvent->m_type = CaptureEvent::EtStop;
+ stopEvent->m_timestamp = time(NULL);
+ g_captureEventCallBack(stopEvent, portName);
+
+ CaptureEventRef startEvent(new CaptureEvent);
+ startEvent->m_type = CaptureEvent::EtStart;
+ startEvent->m_timestamp = time(NULL);
+ g_captureEventCallBack(startEvent, portName);
+ }
+ // send audio buffer
+ AudioChunkRef chunkRef(new AudioChunk);
+ int sampleOffset = (elapsed % numChunks)*NUM_SAMPLES_PER_CHUNK;
+ chunkRef->SetBuffer(audioBuffer+sampleOffset, sizeof(short)*NUM_SAMPLES_PER_CHUNK, AudioChunk::PcmAudio);
+ g_audioChunkCallBack(chunkRef, portName);
+ }
+
+ ACE_OS::sleep(1);
+ elapsed++;
+ }
+}
+
+
+void __CDECL__ StartCapture(CStdString& capturePort)
+{
+ ;
+}
+
+void __CDECL__ StopCapture(CStdString& capturePort)
+{
+ ;
+}
diff --git a/orkaudio/audiocaptureplugins/generator/Generator.dsp b/orkaudio/audiocaptureplugins/generator/Generator.dsp
new file mode 100644
index 0000000..23353c7
--- /dev/null
+++ b/orkaudio/audiocaptureplugins/generator/Generator.dsp
@@ -0,0 +1,126 @@
+# Microsoft Developer Studio Project File - Name="Generator" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=Generator - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Generator.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Generator.mak" CFG="Generator - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Generator - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "Generator - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Generator - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "GENERATOR_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../.." /I "../../../OrkBaseCxx" /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "../Common" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "GENERATOR_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 OrkBase.lib ace.lib log4cxx.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /libpath:"../../../OrkBaseCxx/Release" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Release" /libpath:"C:\devExt\ACE_wrappers\lib"
+
+!ELSEIF "$(CFG)" == "Generator - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "GENERATOR_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../.." /I "../../../OrkBaseCxx" /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "../Common" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "GENERATOR_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 OrkBaseD.lib aced.lib log4cxx.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"../../../OrkBaseCxx/Debug" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Debug" /libpath:"C:\devExt\ACE_wrappers\lib"
+
+!ENDIF
+
+# Begin Target
+
+# Name "Generator - Win32 Release"
+# Name "Generator - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=..\..\AudioCapturePlugin.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\Common\AudioCapturePluginCommon.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\Common\AudioCapturePluginCommon.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Generator.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\GeneratorConfig.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\GeneratorConfig.h
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/orkaudio/audiocaptureplugins/generator/GeneratorConfig.cpp b/orkaudio/audiocaptureplugins/generator/GeneratorConfig.cpp
new file mode 100644
index 0000000..785e33f
--- /dev/null
+++ b/orkaudio/audiocaptureplugins/generator/GeneratorConfig.cpp
@@ -0,0 +1,70 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#define _WINSOCKAPI_ // prevents the inclusion of winsock.h
+
+#include "serializers/Serializer.h"
+#include "GeneratorConfig.h"
+
+GeneratorConfig::GeneratorConfig()
+{
+ m_numConcurrentPorts = NUM_CONCURRENT_PORTS_DEFAULT;
+ m_audioDuration = AUDIO_DURATION_DEFAULT;
+ m_audioFilename = AUDIO_FILE_NAME_DEFAULT;
+}
+
+void GeneratorConfig::Define(Serializer* s)
+{
+ s->IntValue(NUM_CONCURRENT_PORTS_PARAM, m_numConcurrentPorts);
+ s->IntValue(AUDIO_DURATION_PARAM, m_audioDuration);
+ s->StringValue(AUDIO_FILE_NAME_PARAM, m_audioFilename);
+}
+
+void GeneratorConfig::Validate()
+{
+ ;
+}
+
+CStdString GeneratorConfig::GetClassName()
+{
+ return CStdString("GeneratorConfig");
+}
+
+ObjectRef GeneratorConfig::NewInstance()
+{
+ return ObjectRef(new GeneratorConfig);
+}
+
+//====================================
+
+
+void GeneratorConfigTopObject::Define(Serializer* s)
+{
+ s->ObjectValue(GENERATOR_CONFIG_PARAM, m_config, true);
+}
+
+void GeneratorConfigTopObject::Validate()
+{
+ ;
+}
+
+CStdString GeneratorConfigTopObject::GetClassName()
+{
+ return CStdString("GeneratorConfigTopObject");
+}
+
+ObjectRef GeneratorConfigTopObject::NewInstance()
+{
+ return ObjectRef(new GeneratorConfigTopObject);
+}
+
diff --git a/orkaudio/audiocaptureplugins/generator/GeneratorConfig.h b/orkaudio/audiocaptureplugins/generator/GeneratorConfig.h
new file mode 100644
index 0000000..8e9c6a1
--- /dev/null
+++ b/orkaudio/audiocaptureplugins/generator/GeneratorConfig.h
@@ -0,0 +1,66 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __GENERATORCONFIG_H__
+#define __GENERATORCONFIG_H__
+
+#include "StdString.h"
+#include "Object.h"
+#include "boost/shared_ptr.hpp"
+
+#define NUM_CONCURRENT_PORTS_PARAM "NumConcurrentPorts"
+#define NUM_CONCURRENT_PORTS_DEFAULT 10
+#define AUDIO_DURATION_PARAM "AudioDuration"
+#define AUDIO_DURATION_DEFAULT 10
+#define AUDIO_FILE_NAME_PARAM "AudioFilename"
+#define AUDIO_FILE_NAME_DEFAULT "test.wav"
+
+/** This class defines various configuration parameters for the generator. */
+class GeneratorConfig : public Object
+{
+public:
+ GeneratorConfig();
+ void Define(Serializer* s);
+ void Validate();
+
+ CStdString GetClassName();
+ ObjectRef NewInstance();
+ inline ObjectRef Process() {return ObjectRef();};
+
+ int m_numConcurrentPorts;
+ int m_audioDuration;
+ CStdString m_audioFilename;
+};
+
+//========================================
+
+#define GENERATOR_CONFIG_PARAM "Generator"
+
+/** This class represents the top of the configuration hierarchy for the generator. */
+class GeneratorConfigTopObject : public Object
+{
+public:
+ void Define(Serializer* s);
+ void Validate();
+
+ CStdString GetClassName();
+ ObjectRef NewInstance();
+ inline ObjectRef Process() {return ObjectRef();};
+
+ GeneratorConfig m_config;
+};
+
+typedef boost::shared_ptr<GeneratorConfigTopObject> GeneratorConfigTopObjectRef;
+
+
+#endif
diff --git a/orkaudio/audiocaptureplugins/generator/Makefile.am b/orkaudio/audiocaptureplugins/generator/Makefile.am
new file mode 100644
index 0000000..44624f8
--- /dev/null
+++ b/orkaudio/audiocaptureplugins/generator/Makefile.am
@@ -0,0 +1,10 @@
+METASOURCES = AUTO
+lib_LTLIBRARIES = libgenerator.la
+libgenerator_la_SOURCES = GeneratorConfig.cpp Generator.cpp \
+ AudioCapturePluginCommon.cpp
+libgenerator_la_LDFLAGS = -module
+AM_CPPFLAGS = -D_REENTRANT
+libgenerator_la_LIBADD = -lACE -lxerces-c -llog4cxx -lorkbase
+INCLUDES = -I@top_srcdir@ -I../../../orkbasecxx -I../common
+AudioCapturePluginCommon.cpp:
+ ln -s ../common/AudioCapturePluginCommon.cpp AudioCapturePluginCommon.cpp