// file: $isip/class/mmedia/FeatureFile/ftrf_09.cc // version: $Id: ftrf_09.cc 10636 2007-01-26 22:18:09Z tm334 $ // // isip include files // #include "FeatureFile.h" // method: readSofData // // arguments: // Vector& data: (output) the audio data // int32 start_pos: (input) the start index of the features data // int32 num_elem: (input) the number of features data // // return: number of features read // // this method gets data from an Sof file and returns each // channel as a VectorFloat. // int32 FeatureFile::readSofData(Vector& data_a, int32 start_pos_a, int32 num_elem_a) { // read from sof file // if (file_format_d != SOF) { Error::handle(name(), L"readSofData", ERR, __FILE__, __LINE__); return -1; } // read the data // readPartialData(start_pos_a, num_elem_a); // copy from partially read internal data // data_a = v_d; /* // loop over all elements // int32 len = v_d.length(); data_a.setLength(len); for (int32 i = 0; i < len; i++) { // transfer the data // data_a(i).makeVectorFloat().setLength(v_d(i).getVectorFloat().length()); for (int32 j = 0; j < v_d(i).getVectorFloat().length(); j++) { data_a(i).getVectorFloat()(j) = v_d(i).getVectorFloat()(j); } } */ // return the number of samples read // return v_d.length(); } // method: writeSofData // // arguments: // Vector& data: (input) the audio data to write // int32 ctag: (input) channel tag // // return: the number of elements written // // this method writes audio data to an Sof file. // int32 FeatureFile::writeSofData(Vector& data_a, int32 ctag_a) { // check the format // if (file_format_d != SOF) { return Error::handle(name(), L"writeSofData", ERR, __FILE__, __LINE__); } v_d = data_a; /* // loop over all elements // int32 len = data_a.length(); v_d.setLength(len); for (int32 i = 0; i < len; i++) { // transfer the data // v_d(i).makeVectorFloat().setLength(data_a(i).getVectorFloat().length()); for (int32 j = 0; j < data_a(i).getVectorFloat().length(); j++) { v_d(i).getVectorFloat()(j) = data_a(i).getVectorFloat()(j); } } */ // write the data // int32 len = data_a.length(); writePartialData(0, len); // exit gracefully // return len; } /* // method: readSofData // // arguments: // Vector& data: (output) the audio data // int32 ctag: (input) channel index // int32 start_pos: (input) the start index of the features data // int32 num_elem: (input) the number of features data // // return: number of features read // // this method gets data from an Sof file and returns each // channel as a VectorFloat. // int32 FeatureFile::readSofData(Vector& data_a, int32 ctag_a, int32 start_pos_a, int32 num_elem_a) { // read from sof file // if (file_format_d != SOF) { Error::handle(name(), L"readSofData", ERR, __FILE__, __LINE__); return -1; } // read the data // readPartialData(start_pos_a, num_elem_a); // loop over all elements // int32 len = v_d.length(); data_a.setLength(len); for (int32 i = 0; i < len; i++) { // transfer the data // data_a(i).setLength(v_d(i).getVectorFloat().length()); for (int32 j = 0; j < v_d(i).getVectorFloat().length(); j++) { data_a(i)(j) = v_d(i).getVectorFloat()(j); } } // return the number of samples read // return len; } // method: writeSofData // // arguments: // Vector& data: (input) the audio data to write // int32 ctag: (input) channel tag // // return: the number of elements written // // this method writes the audio data to an Sof file. // int32 FeatureFile::writeSofData(Vector& data_a, int32 ctag_a) { // check the format // if (file_format_d != SOF) { return Error::handle(name(), L"writeSofData", ERR, __FILE__, __LINE__); } // loop over all the elements // int32 len = data_a.length(); v_d.setLength(len); for (int32 i = 0; i < len; i++) { // transfer the data // v_d(i).makeVectorFloat().setLength(data_a(i).length()); for (int32 j = 0; j < data_a(i).length(); j++) { v_d(i).getVectorFloat()(j) = data_a(i)(j); } } // write the data // writePartialData(0, len); // exit gracefully // return len; } */ // method: readSofStart // // arguments: none // // return: a bool8 value indicating status // // this method initializes reading of data from an Sof file. // bool8 FeatureFile::readSofStart() { if (!read(in_sof_d, tag_d)) { return Error::handle(name(), L"readSofStart", Error::READ, __FILE__, __LINE__, Error::WARNING); } if (file_format_d != SOF) { return Error::handle(name(), L"readSofStart", Error::READ, __FILE__, __LINE__, Error::WARNING); } if (no_data_d) { return Error::handle(name(), L"readSofStart", Error::READ, __FILE__, __LINE__); } // save the object size from the temporary placeholder // int32 object_size = sof_length_pos_d; // now set the sof_length_pos_d flag to the start of the object // sof_length_pos_d = in_sof_d.tell(); if (data_type_d == ALGORITHM_DATA) { // start the read // Vector vec; if (!vec.readStart(in_sof_d, PARAM_DATA, object_size, false, false)) { return Error::handle(name(), L"readSofStart", Error::READ, __FILE__, __LINE__, Error::WARNING); } } else if (data_type_d == VECTOR_FLOAT) { // start the read // Vector vec; if (!vec.readStart(in_sof_d, PARAM_DATA, object_size, false, false)) { return Error::handle(name(), L"readSofStart", Error::READ, __FILE__, __LINE__, Error::WARNING); } } // exit gracefully // return true; } // method: writeSofStart // // arguments: none // // return: a bool8 value indicating status // // this method initializes writing of data to an Sof file. // bool8 FeatureFile::writeSofStart() { // write the object configuration to the Sof file. // if (!write(in_sof_d, tag_d)) { return Error::handle(name(), L"writeSofStart", Error::WRITE, __FILE__, __LINE__); } // initialize sof pointers // bool8 status = false; if (data_type_d == ALGORITHM_DATA) { // now write a zero-length vector to the file // Vector vec(1); status = vec.writeStart(in_sof_d, PARAM_DATA); } else if (data_type_d == VECTOR_FLOAT) { // now write a zero-length vector to the file // Vector vec(1); status = vec.writeStart(in_sof_d, PARAM_DATA); } // set the sof pointers // sof_length_pos_d = in_sof_d.getStartPos(); // exit gracefully // return status; }