bool AudioRecord::openFile() { bool result = false; _debug ("AudioRecord: Open file()"); if (isFileExist()) { _debug ("AudioRecord: Filename does not exist, creating one"); byteCounter_ = 0; if (fileType_ == FILE_RAW) { result = setRawFile(); } else if (fileType_ == FILE_WAV) { result = setWavFile(); } } else { _debug ("AudioRecord: Filename already exist opening it"); if (fileType_ == FILE_RAW) { result = openExistingRawFile(); } else if (fileType_ == FILE_WAV) { result = openExistingWavFile(); } } return result; }
void WvOut :: openFile( const char *fileName, unsigned int nChannels, WvOut::FILE_TYPE type, Stk::STK_FORMAT format ) { closeFile(); if ( nChannels < 1 ) { sprintf(msg, "WvOut: the channels argument must be greater than zero!"); handleError( msg, StkError::FUNCTION_ARGUMENT ); } unsigned int lastChannels = channels; channels = nChannels; fileType = type; if ( format != STK_SINT8 && format != STK_SINT16 && format != STK_SINT32 && format != MY_FLOAT32 && format != MY_FLOAT64 ) { sprintf( msg, "WvOut: Unknown data type specified (%ld).", format ); handleError(msg, StkError::FUNCTION_ARGUMENT); } dataType = format; bool result = false; if ( fileType == WVOUT_RAW ) { if ( channels != 1 ) { sprintf(msg, "WvOut: STK RAW files are, by definition, always monaural (channels = %d not supported)!", nChannels); handleError( msg, StkError::FUNCTION_ARGUMENT ); } result = setRawFile( fileName ); } else if ( fileType == WVOUT_WAV ) result = setWavFile( fileName ); else if ( fileType == WVOUT_SND ) result = setSndFile( fileName ); else if ( fileType == WVOUT_AIF ) result = setAifFile( fileName ); else if ( fileType == WVOUT_MAT ) result = setMatFile( fileName ); else { sprintf(msg, "WvOut: Unknown file type specified (%ld).", fileType); handleError(msg, StkError::FUNCTION_ARGUMENT); } if ( result == false ) handleError(msg, StkError::FILE_ERROR); // Allocate new memory if necessary. if ( lastChannels < channels ) { if ( data ) delete [] data; data = (MY_FLOAT *) new MY_FLOAT[BUFFER_SIZE*channels]; } counter = 0; }
void WvOut :: openFile( const char *fileName, unsigned int nChannels, WvOut::FILE_TYPE type, Stk::StkFormat format ) { closeFile(); if ( nChannels < 1 ) { errorString_ << "WvOut::openFile: then channels argument must be greater than zero!"; handleError( StkError::FUNCTION_ARGUMENT ); } unsigned int lastChannels = channels_; channels_ = nChannels; fileType_ = type; if ( format != STK_SINT8 && format != STK_SINT16 && format != STK_SINT32 && format != STK_FLOAT32 && format != STK_FLOAT64 ) { errorString_ << "WvOut::openFile: unknown data type (" << format << ") specified!"; handleError( StkError::FUNCTION_ARGUMENT ); } dataType_ = format; bool result = false; if ( fileType_ == WVOUT_RAW ) { if ( channels_ != 1 ) { errorString_ << "WvOut::openFile: STK RAW files are, by definition, always monaural (channels = " << nChannels << " not supported)!"; handleError( StkError::FUNCTION_ARGUMENT ); } result = setRawFile( fileName ); } else if ( fileType_ == WVOUT_WAV ) result = setWavFile( fileName ); else if ( fileType_ == WVOUT_SND ) result = setSndFile( fileName ); else if ( fileType_ == WVOUT_AIF ) result = setAifFile( fileName ); else if ( fileType_ == WVOUT_MAT ) result = setMatFile( fileName ); else { errorString_ << "WvOut::openFile: unknown file type (" << fileType_ << ") specified!"; handleError( StkError::FUNCTION_ARGUMENT ); } if ( result == false ) handleError( StkError::FILE_ERROR ); // Allocate new memory if necessary. if ( lastChannels < channels_ ) { data_.resize( BUFFER_SIZE * channels_ ); } counter_ = 0; }
void FileWrite :: open( std::string fileName, unsigned int nChannels, FileWrite::FILE_TYPE type, Stk::StkFormat format ) { // Call close() in case another file is already open. this->close(); if ( nChannels < 1 ) { errorString_ << "FileWrite::open: then channels argument must be greater than zero!"; handleError( StkError::FUNCTION_ARGUMENT ); } channels_ = nChannels; fileType_ = type; if ( format != STK_SINT8 && format != STK_SINT16 && format != STK_SINT32 && format != STK_FLOAT32 && format != STK_FLOAT64 ) { errorString_ << "FileWrite::open: unknown data type (" << format << ") specified!"; handleError( StkError::FUNCTION_ARGUMENT ); } dataType_ = format; bool result = false; if ( fileType_ == FILE_RAW ) { if ( channels_ != 1 ) { errorString_ << "FileWrite::open: STK RAW files are, by definition, always monaural (channels = " << nChannels << " not supported)!"; handleError( StkError::FUNCTION_ARGUMENT ); } result = setRawFile( fileName.c_str() ); } else if ( fileType_ == FILE_WAV ) result = setWavFile( fileName.c_str() ); else if ( fileType_ == FILE_SND ) result = setSndFile( fileName.c_str() ); else if ( fileType_ == FILE_AIF ) result = setAifFile( fileName.c_str() ); else if ( fileType_ == FILE_MAT ) result = setMatFile( fileName.c_str() ); else { errorString_ << "FileWrite::open: unknown file type (" << fileType_ << ") specified!"; handleError( StkError::FUNCTION_ARGUMENT ); } if ( result == false ) handleError( StkError::FILE_ERROR ); frameCounter_ = 0; }