diff options
Diffstat (limited to 'maximilian.h')
| -rwxr-xr-x | maximilian.h | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/maximilian.h b/maximilian.h index fad99f2..11089fe 100755 --- a/maximilian.h +++ b/maximilian.h @@ -36,15 +36,27 @@ //#define MAXIMILIAN_PORTAUDIO #define MAXIMILIAN_RT_AUDIO - #include <iostream> #include <fstream> #include <string.h> #include <cassert> #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; @@ -98,16 +110,29 @@ public: class maxiEnvelope { - double period; + double period=0; double output; - double startval; + double phase; + double startVal; + double endVal; double currentval; double nextval; + bool noteOn; + bool releaseMode; + bool decayMode; + bool sustainMode; + bool attackMode; int isPlaying; -public: +public: + int trig; double line(int numberofsegments,double segments[100]); + double ramp(double startVal=0, double endVal=1, double duration=1); + double ramps(std::vector<double> rampsArray); + double ar(double attack=0.1, double release=0.1); + double adsr(double attack=0.1, double decay=0.1, double sustain=0.1, double release=0.1); void trigger(int index,double amp); + void trigger(bool noteOn=false); int valindex; double amplitude; @@ -222,7 +247,7 @@ public: short myChannels; int mySampleRate; long length; - void getLength(); + long getLength(); void setLength(unsigned long numSamples); short myBitsPerSample; @@ -797,5 +822,49 @@ public: }; +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 |
