aboutsummaryrefslogtreecommitdiffstats
path: root/maximilian.h
diff options
context:
space:
mode:
authorLeon Fedden <lfedd001@gold.ac.uk>2016-10-16 23:45:47 +0100
committerLeon Fedden <lfedd001@gold.ac.uk>2016-10-16 23:45:47 +0100
commite607b8ba18b51aab2efe3d44cf043b6994642127 (patch)
tree7934ae067a21e81894bc0cba277f28e36215ef81 /maximilian.h
parentdf18758a04f36e74f0fa74a65ee11572015a9aff (diff)
fixed maxiRecorder with OS multithreading APIs
Diffstat (limited to 'maximilian.h')
-rwxr-xr-xmaximilian.h93
1 files changed, 58 insertions, 35 deletions
diff --git a/maximilian.h b/maximilian.h
index 6cb7628..d2db173 100755
--- a/maximilian.h
+++ b/maximilian.h
@@ -36,14 +36,26 @@
//#define MAXIMILIAN_PORTAUDIO
#define MAXIMILIAN_RT_AUDIO
-
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdlib>
#include "math.h"
+#include <cerrno>
+#include <queue>
+#include <vector>
+
+#if !defined(_WIN32) && (defined(unix) || defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
+#define OS_IS_UNIX true
+#include <pthread.h>
+#include <unistd.h>
+#endif
+
#ifdef _WIN32 //|| _WIN64
+#define OS_IS_WIN true
#include <algorithm>
+#include <Windows.h>
+#include <process.h>
#endif
using namespace std;
@@ -795,39 +807,50 @@ public:
bool tick;
};
-//
-//class maxiRecorder
-//{
-//public:
-// maxiRecorder();
-// ~maxiRecorder();
-//
-// void setup(std::string _filename);
-// void startRecording();
-// void stopRecording();
-// bool isRecording() const;
-// void passData(double* _in, int _inBufferSize);
-// void passData(float* _in, int _inBufferSize);
-// void saveToWav();
-//
-//protected:
-//// std::vector<double> getProcessedData();
-// void update();
-// void enqueueBuffer();
-// void freeResources();
-//
-//private:
-// template <typename T>
-// void write(std::ofstream& _stream, const T& _t);
-// const int bufferQueueSize;
-// const int bufferSize;
-// long int bufferIndex;
-// long int recordedAmountFrames;
-//// std::queue<double*> bufferQueue;
-//// std::queue<double*> savedBuffers;
-// bool doRecord;
-// std::string filename;
-//};
-//
+
+class maxiRecorder
+{
+public:
+ maxiRecorder();
+ ~maxiRecorder();
+
+ void setup(std::string _filename);
+ void startRecording();
+ void stopRecording();
+ bool isRecording() const;
+ void passData(double* _in, int _inBufferSize);
+ void passData(float* _in, int _inBufferSize);
+ void saveToWav();
+
+private:
+ template <typename T>
+ void write(std::ofstream& _stream, const T& _t);
+ void* update(void* _context);
+ std::vector<double> getProcessedData();
+ void enqueueBuffer();
+ void freeResources();
+ bool threadRunning;
+ const int bufferQueueSize;
+ const int bufferSize;
+ long int bufferIndex;
+ long int recordedAmountFrames;
+ std::queue<double*> bufferQueue;
+ std::queue<double*> savedBuffers;
+ bool doRecord;
+ std::string filename;
+#if defined(OS_IS_UNIX)
+ pthread_t daemon;
+ static void* update_pthread_helper(void* _context)
+#elif defined(OS_IS_WIN)
+ HANDLE daemonHandle;
+ static unsigned __stdcall
+ update_pthread_helper(void* _context)
+#endif
+ {
+ maxiRecorder* _this = static_cast<maxiRecorder*>(_context);
+ _this->update(_this);
+ return 0;
+ }
+};
#endif