int main() { retstr(); retarr(); retunion(); retunempty(); E(6);// KEEP : error = Error 6 E(3); // ERROR(3) SUCCESS; }
chtk::htkarray chtk::htk_load(std::string fname, int FRM_EXT){ std::ifstream inp; inp.open(fname,std::ios::binary); if (!inp.is_open()){ std::string exept= "File " + fname + " cannot be opened !\n"; throw std::runtime_error(exept.c_str()); } chtk::htkheader header = load_header(inp); // Reading in the header file of any htk binary file // Generate the returning htk representation chtk::htkarray retarr(ntohl(header.nsamples),ntohl(header.sample_period),ntohs(header.samplesize),ntohs(header.parmkind),FRM_EXT); // Prepare vector to read in data std::vector<std::vector<char>> buf(retarr.nsamples); for ( auto i=0u ; i < retarr.nsamples; i++) { // buf[i] = new char[arr->samplesize]; std::vector<char> samplebuf(retarr.samplesize/sizeof(char)); inp.read(reinterpret_cast<char*>(samplebuf.data()),retarr.samplesize); // std::cout <<"samplesize for sample " << i << " is " << (arr)->samplesize/4 << std::endl; for(auto j = 0u ; j < samplebuf.size();j+=4){ // Swapping the elements from big endian to little endian std::swap(samplebuf.at(j+3),samplebuf.at(j)); std::swap(samplebuf.at(j+2),samplebuf.at(j+1)); } buf.at(i) = samplebuf; } auto offset=0; // Append the extended features for ( auto i=0; i< retarr.nsamples; i++){ for (auto j= -FRM_EXT;j < FRM_EXT+1;j++){ int tmpidx= i+j>0?(i+j):0; // Check if the extended index is in range, if it is use the extended index // otherwise use the last sample int index= (tmpidx>retarr.nsamples-1)?retarr.nsamples-1:tmpidx; // Copy the current extended frame into the current buffer std::copy(buf.at(index).begin(), buf.at(index).end(), retarr.data_holder.get()->begin()+offset ); offset+=retarr.samplesize; } } return retarr; }