// file: $isip/class/mmedia/FeatureFile/ftrf_05.cc // version: $Id: ftrf_05.cc 10636 2007-01-26 22:18:09Z tm334 $ // // isip include files // #include "FeatureFile.h" // method: writeFeatureData // // arguments: // Vector& data: (input) the feature data // int32 channel_tag: (input) the channel tag // // return: number of feature data read // // this is currently the only way to output data. it writes the // entire input vector at the current location. // int32 FeatureFile::writeFeatureData(Vector& data_a, int32 channel_tag_a) { // branch on file format // if (file_format_d == RAW) return writeRawData(data_a, channel_tag_a); else if (file_format_d == SOF) return writeSofData(data_a, channel_tag_a); else return 0; } // method: writeFeatureData // // arguments: // Vector& data: (input) the feature data // int32 channel_tag: (input) the channel tag // // return: number of feature data read // // this is currently supported only for backward compatibility // (especially for FeatureSelect and SegmentConcat classes) // use Vector output features instead // int32 FeatureFile::writeFeatureData(Vector& data_a, int32 channel_tag_a) { if (data_type_d == VECTOR_FLOAT) { int32 len = data_a.length(); Vector temp(len); for (int32 i = 0; i < len; i++) { temp(i).makeVectorFloat() = data_a(i); } return writeFeatureData(temp, channel_tag_a); } else { return Error::handle(name(), L"writeFeatureData", Error::NOT_IMPLEM, __FILE__, __LINE__); } return -1; } // method: readFeatureData // // arguments: // Vector& data: (input) the feature data to read // int32 start_pos: (input) the start position of the feature data // int32 num_elem: (input) the number of the feature data read // // return: the number of elements read // // this method reads the feature data from a file. // int32 FeatureFile::readFeatureData(Vector& data_a, int32 start_pos_a, int32 num_elem_a) { // branch on file format // if (file_format_d == RAW) return readRawData(data_a, start_pos_a, num_elem_a); else if (file_format_d == SOF) return readSofData(data_a, start_pos_a, num_elem_a); else return 0; } // method: readFeatureData // // arguments: // Vector& data: (output) the feature data // int32 ctag: (input) the channel to read // int32 start_pos: (input) the start pos from feature data // int32 num_elem: (input) the num of element read from feature data // // return: number of frames read // // this is currently supported only for backward compatibility // (especially for FeatureSelect and SegmentConcat classes) // use Vector input features instead // // int32 FeatureFile::readFeatureData(Vector& data_a, int32 ctag_a, int32 start_pos_a, int32 num_elem_a) { if (data_type_d == VECTOR_FLOAT) { Vector temp; int32 num_frames_read = readFeatureData(temp, start_pos_a, num_elem_a); for (int32 i = 0; i < temp.length(); i++) { data_a(i) = temp(i).makeVectorFloat(); } return num_frames_read; } else { return Error::handle(name(), L"readFeatureData", Error::NOT_IMPLEM, __FILE__, __LINE__); } return -1; } // method: readPartialData // // arguments: // int32 start_pos: (input) first entry to read // int32 num_elem: (input) number of elements to read // // return: the number of elements read // // this method has the object read itself from an Sof file. it assumes // that the Sof file is already positioned correctly. // bool8 FeatureFile::readPartialData(int32 start_pos_a, int32 num_elem_a) { if (data_type_d == ALGORITHM_DATA) { // create a temporary buffer // Vector temp; temp.readPartialData(in_sof_d, start_pos_a, num_elem_a, String::EMPTY, 0, false, false); v_d = temp; } else if (data_type_d == VECTOR_FLOAT) { // create a temporary buffer // Vector temp; temp.readPartialData(in_sof_d, start_pos_a, num_elem_a, String::EMPTY, 0, false, false); // loop over all elements // int32 len = temp.length(); v_d.setLength(len); for (int32 i = 0; i < len; i++) { // transfer the data // v_d(i).makeVectorFloat() = temp(i); } } else { return Error::handle(name(), L"readPartialData", Error::NOT_IMPLEM, __FILE__, __LINE__); } // exit gracefully // return true; } // method: writePartialData // // arguments: // int32 start_pos: (input) the index of the Vector to start to write // int32 num_elem: (input) the number of elements to write // // return: a bool8 value indicating status // // this method writes a portion of a feature stream to a file. // bool8 FeatureFile::writePartialData(int32 start_pos_a, int32 num_elem_a) { if (data_type_d == ALGORITHM_DATA) { // create a temporary buffer // Vector temp; temp = v_d; // write the data // if (!temp.writePartialData(in_sof_d, start_pos_a, num_elem_a)) { return Error::handle(name(), L"writePartialData", Error::IO, __FILE__, __LINE__); } } else if (data_type_d == VECTOR_FLOAT) { // create a temporary buffer // Vector temp; // loop over all elements // int32 len = v_d.length(); temp.setLength(len); for (int32 i = 0; i < len; i++) { // transfer the data // temp(i).setLength(v_d(i).getVectorFloat().length()); temp(i) = v_d(i).getVectorFloat(); } // write the data // if (!temp.writePartialData(in_sof_d, start_pos_a, num_elem_a)) { return Error::handle(name(), L"writePartialData", Error::IO, __FILE__, __LINE__); } } else { return Error::handle(name(), L"writePartialData", Error::NOT_IMPLEM, __FILE__, __LINE__); } // exit gracefully // return true; } // method: getBufferedData // // arguments: // Vector& data: (input) the feature data to read // int32 start_pos: (input) the start position of the feature data // int32 num_elem: (input) the number of the feature data read // // return: the number of elements read // // this method reads feature data from a file. // int32 FeatureFile::getBufferedData(Vector& data_a, int32 start_pos_a, int32 num_elem_a) { // branch on file format // if (file_format_d == RAW) return readRawData(data_a, start_pos_a, num_elem_a); else if (file_format_d == SOF) return readSofData(data_a, start_pos_a, num_elem_a); else return 0; } // method: setBufferSize // // arguments: // int32 nblocks: (input) number of blocks per buffer // // return: a bool8 value indicating status // // this method sets capacity of the buffer. // bool8 FeatureFile::setBufferSize(int32 nblocks_a) { // if (data_type_d == VECTOR_FLOAT) { // save the value to class data // int32 block_num_samp = block_size_d; for (int32 i = 0; i < num_channels_d; i++) { buffers_d(i).setCapacity(nblocks_a * block_num_samp); } // } // exit gracefully // return true; }