Mercurial > hg > easaier-soundaccess
view sv/audioio/AudioRecording.cpp @ 282:d9319859a4cf tip
(none)
author | benoitrigolleau |
---|---|
date | Fri, 31 Oct 2008 11:00:24 +0000 |
parents | 3f41cb822166 |
children |
line wrap: on
line source
#include "AudioRecording.h" AudioRecording::AudioRecording(){ _isRecording = false; } AudioRecording::~AudioRecording(){ } int AudioRecording::myCallback( void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, PaTimestamp outTime, void *userData ) { //float *in = (float *) inputBuffer; SNDFILE* file = (SNDFILE*)userData; if( inputBuffer == NULL ) return 0; // // sf_writef_float(file, (float*)inputBuffer, framesPerBuffer); //else sf_writef_short(file, (short*)inputBuffer, framesPerBuffer); return 0; } void AudioRecording::recordAudio(const char *path) //QString& fileName) { Pa_Initialize(); SF_INFO fileInfo; fileInfo.samplerate = 16000; fileInfo.channels = 1; fileInfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;//SF_FORMAT_FLOAT; _file = sf_open(path, SFM_WRITE, &fileInfo); if (_file != NULL) { Pa_OpenDefaultStream(&_stream,fileInfo.channels, 0, /* mon input, no output */ paInt16/*paFloat32*/, fileInfo.samplerate, 64, 0, /* 64 frames per buffer, let PA determine numBuffers */ myCallback, (void*)_file); Pa_StartStream( _stream ); } } void AudioRecording::rect(){ _isRecording = true; recordAudio("c:/test.wav"); } void AudioRecording::stopRect(){ if(_isRecording){ if(_file != NULL){ Pa_StopStream( _stream ); Pa_CloseStream( _stream ); sf_close(_file); } Pa_Terminate(); _isRecording = false; } } bool AudioRecording::isRecording(){ return _isRecording; }