zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit a8db2ca9d6be2c12b9d6982dce8acca056cc0750
parent 148147e99386742be673ad2c5f353d3115995ae0
Author: fundamental <mark.d.mccurry@gmail.com>
Date:   Mon, 17 May 2010 15:16:28 -0400

WavEngine: Fixing Recording

Diffstat:
Msrc/Misc/WavFile.cpp | 6+++++-
Msrc/Nio/WavEngine.cpp | 11++++++++---
2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/Misc/WavFile.cpp b/src/Misc/WavFile.cpp @@ -20,6 +20,7 @@ #include <cstdio> #include <cstring> #include <cstdlib> +#include <iostream> #include "WavFile.h" using namespace std; @@ -29,6 +30,7 @@ WavFile::WavFile(string filename, int samplerate, int channels) { if(file) { + cout << "INFO: Making space for wave file header" << endl; //making space for the header written at destruction char tmp[44]; memset(tmp, 0, 44*sizeof(char)); @@ -39,6 +41,8 @@ WavFile::WavFile(string filename, int samplerate, int channels) WavFile::~WavFile() { if(file) { + cout << "INFO: Writing wave file header" << endl; + unsigned int chunksize; rewind(file); @@ -73,7 +77,7 @@ WavFile::~WavFile() bool WavFile::good() const { - return NULL != file; + return file; } void WavFile::writeStereoSamples(int nsmps, short int *smps) diff --git a/src/Nio/WavEngine.cpp b/src/Nio/WavEngine.cpp @@ -26,7 +26,7 @@ using namespace std; WavEngine::WavEngine() - :AudioOut(), file(NULL), buffer(SAMPLE_RATE*2), pThread(NULL) + :AudioOut(), file(NULL), buffer(SAMPLE_RATE*4), pThread(NULL) { sem_init(&work, PTHREAD_PROCESS_PRIVATE, 0); } @@ -89,6 +89,10 @@ void WavEngine::newFile(WavFile *_file) //ensure system is clean destroyFile(); file = _file; + + //check state + if(!file->good()) + cerr << "ERROR: WavEngine handed bad file output WavEngine::newFile()" << endl; } void WavEngine::destroyFile() @@ -115,11 +119,12 @@ void *WavEngine::AudioThread() buffer.pop(right); recordbuf_16bit[2*i] = limit((int)(left * 32767.0), -32768, 32767); recordbuf_16bit[2*i+1] = limit((int)(right * 32767.0), -32768, 32767); - file->writeStereoSamples(SOUND_BUFFER_SIZE, recordbuf_16bit); } + file->writeStereoSamples(SOUND_BUFFER_SIZE, recordbuf_16bit); } delete[] recordbuf_16bit; - pthread_exit(NULL); + + return NULL; }