⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adf_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
    Integral::makeTemp(output_fulla);     File::registerTemp(output_fulla);    AudioFile src;    src.setFileFormat(AudioFile::RAW);    src.setFileType(BINARY);    src.open(input);    AudioFile dst(BINARY, RAW);    dst.setID(src.getID());    dst.open(output_fulla, File::WRITE_ONLY);    src.setNumChannels(1);    dst.setNumChannels(1);        // loop through 100 samples at a time    //    Vector<VectorFloat> data(1);    src.getData(data(0), 0, 0l, 10000000l);    dst.writeAudioData(data, 0);    src.close();    dst.close();    // make sure the output file is equivalent    //    if (!File::compare(input, output_fulla)) {      return Error::handle(name(), L"compare", Error::TEST,__FILE__,__LINE__);    }  }  {    if (level_a >= Integral::BRIEF) {      Console::put(L"test 5a: testing swapped read :\n");    }    // test 5a: read data from swapped and unswapped sources and compare    //    Filename input(L"$ISIP_DEVEL/doc/examples/data/audio/input_8000.raw");    Filename input_swap(L"$ISIP_DEVEL/doc/examples/data/audio/input_8000_swapped.raw");        AudioFile src;    src.setFileFormat(AudioFile::RAW);    src.setFileType(BINARY);    src.open(input);    src.setNumChannels(1);    AudioFile src_swap;    src_swap.setFileFormat(AudioFile::RAW);    src_swap.setFileType(BINARY);    src_swap.open(input_swap);    src_swap.setNumChannels(1);    src_swap.setBMode(SWAP);    if (level_a >= Integral::ALL) {      src.debug(L"native");      src_swap.debug(L"swap");    }        // loop through 100 samples at a time    //    Vector<VectorFloat> data(1);    src.getData(data(0), 0, 0l, 100);    Vector<VectorFloat> data_swap(1);    src_swap.getData(data_swap(0), 0, 0l, 100);    if (data_swap(0).ne(data(0))) {      data_swap(0).debug(L"swapped");      data(0).debug(L"native");      return Error::handle(name(), L"read-swap", Error::TEST, __FILE__,			   __LINE__);    }    src.getData(data(0), 0, 100l, 100);    src_swap.getData(data_swap(0), 0, 100l, 100);    if (data_swap(0).ne(data(0))) {      return Error::handle(name(), L"read-swap", Error::TEST, __FILE__,			   __LINE__);    }    src.close();    src_swap.close();  }  {    if (level_a >= Integral::BRIEF) {      Console::put(L"test 5b: test swapped write\n");    }    // test 5b: read data unswapped source, write to a swapped source,    //          read it back in swapped and compare.    //    Filename input(L"$ISIP_DEVEL/doc/examples/data/audio/input_8000.raw");    Integral::makeTemp(output_swap);    output_swap.concat(L".raw");    File::registerTemp(output_swap);            AudioFile src;    src.setFileFormat(AudioFile::RAW);    src.setFileType(BINARY);    src.open(input);    src.setNumChannels(1);    AudioFile dst(BINARY, RAW);    dst.setID(src.getID());    dst.open(output_swap, File::WRITE_ONLY);    dst.setNumChannels(1);    dst.setBMode(SWAP);    // read in the data    //    Vector<VectorFloat> data(1);    src.getData(data(0), 0, 0l, 8000);    dst.writeAudioData(data, 0);    src.close();    dst.close();    // make sure the output file is equivalent to our reference file    //    if (!File::compare((unichar*)output_swap, L"$ISIP_DEVEL/doc/examples/data/audio/input_8000_swapped.raw")) {      return Error::handle(name(), L"compare", Error::TEST,__FILE__,__LINE__);    }  }  {    if (level_a >= Integral::BRIEF) {      Console::put(L"test 5c: test swapped read\n");    }    // test 5c: read data from swapped and unswapped sources and compare    //    Filename input(L"$ISIP_DEVEL/doc/examples/data/audio/input_8000.raw");    AudioFile src;    src.setFileFormat(AudioFile::RAW);    src.setFileType(BINARY);    src.open(input);    src.setNumChannels(1);    AudioFile src_swap;    src_swap.setFileFormat(AudioFile::RAW);    src_swap.setFileType(BINARY);    src_swap.open(output_swap);    src_swap.setNumChannels(1);    src_swap.setBMode(SWAP);    if (level_a >= Integral::ALL) {      src.debug(L"native");      src_swap.debug(L"swap");    }        // loop through 100 samples at a time    //    Vector<VectorFloat> data(1);    Vector<VectorFloat> data_swap(1);    long i = 0;    while (src.getData(data(0), 0, i * 100l, 100) > 0) {      // read in data from the swapped source      //      if (src_swap.getData(data_swap(0), 0, i * 100l, 100) != 100) {	return Error::handle(name(), L"getData", Error::TEST,			     __FILE__, __LINE__);      }      if (data_swap(0).ne(data(0))) {	data_swap(0).debug(L"swapped");	data(0).debug(L"native");	return Error::handle(name(), L"read-swap", Error::TEST, __FILE__,			     __LINE__);      }      i++;    }    src.close();    src_swap.close();  }  {    if (level_a >= Integral::BRIEF) {      Console::put(L"test 6a: write to an Sof audio file:\n");    }    // test 6a: write to an Sof audio file    //    Filename input(L"$ISIP_DEVEL/doc/examples/data/audio/input_8000.raw");    Integral::makeTemp(output_sof);     File::registerTemp(output_sof);        AudioFile src;    src.setFileFormat(AudioFile::RAW);    src.setFileType(BINARY);    src.open(input);    src.setNumChannels(1);    AudioFile dst(TEXT, SOF);    dst.setID(src.getID());    dst.open(output_sof, File::WRITE_ONLY);        // loop through 100 samples at a time    //    Vector<VectorFloat> data(1);    long i = 0;    while (src.getData(data(0), 0, i * 100l, 100) > 0) {      dst.writeAudioData(data, 0);      i++;    }    src.close();    dst.close();  }  {    if (level_a >= Integral::BRIEF) {      Console::put(L"test 6b: read from an Sof audio file:\n");    }    // test 6b: read from an Sof audio file    //    Filename input(L"$ISIP_DEVEL/doc/examples/data/audio/input_8000.raw");    AudioFile src;    src.setFileFormat(AudioFile::RAW);    src.setFileType(BINARY);    src.open(input);    src.setNumChannels(1);    AudioFile src_sof(TEXT, SOF);    src_sof.open(output_sof, File::READ_ONLY);        // loop through 100 samples at a time    //    Vector<VectorFloat> data(1);    Vector<VectorFloat> data_sof(1);    long i = 0;    while (src.getData(data(0), 0, i * 100l, 100) > 0) {      if (!src_sof.getData(data_sof(0), 0, i * 100l, 100) > 0) {	return Error::handle(name(), L"getData", Error::TEST,			     __FILE__, __LINE__);      }      if (data_sof(0).ne(data(0))) {	data_sof(0).debug(L"sof");	data(0).debug(L"raw");	return Error::handle(name(), L"read-sof", Error::TEST, __FILE__,			     __LINE__);      }      i++;    }    src.close();    src_sof.close();  }  {    if (level_a >= Integral::BRIEF) {      Console::put(L"test 6c: write to a big Sof audio file:\n");    }    // test 6c: write to a big Sof audio file    //    Filename input(L"$ISIP_DEVEL/doc/examples/data/audio/little_endian.raw");    Integral::makeTemp(output_full_sof);     File::registerTemp(output_full_sof);        AudioFile src;    src.setFileFormat(AudioFile::RAW);    src.setFileType(BINARY);    src.open(input);    src.setNumChannels(1);    AudioFile dst;    dst.setNumChannels(1);    dst.setID(src.getID());    dst.open(output_full_sof, File::WRITE_ONLY);        // loop through 100 samples at a time    //    Vector<VectorFloat> data(1);    long i = 0;    while (src.getData(data(0), 0, i * 100l, 100) > 0) {      dst.writeAudioData(data, 0);      i++;    }    src.close();    dst.close();  }  {    if (level_a >= Integral::BRIEF) {      Console::put(L"test 6d: read from a big Sof audio file:\n");    }    // test 6d: read from a big Sof audio file    //    Filename input(L"$ISIP_DEVEL/doc/examples/data/audio/little_endian.raw");    AudioFile src;    src.setFileFormat(AudioFile::RAW);    src.setFileType(BINARY);    src.open(input);    src.setNumChannels(1);    AudioFile src_sof;    src_sof.sample_num_bytes_d = 4;    src_sof.file_format_d = SOF;    src_sof.open(output_full_sof, File::READ_ONLY);    // the object should configure itself from the file    //    if (src_sof.sample_num_bytes_d != (Long)2) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }    if (src_sof.num_channels_d != (Long)1) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }    if (src_sof.file_format_d != SOF) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }        // loop through 100 samples at a time    //    Vector<VectorFloat> data(1);    Vector<VectorFloat> data_sof(1);    long i = 0;    while (src.getData(data(0), 0, i * 100l, 100) > 0) {      if (!src_sof.getData(data_sof(0), 0, i * 100l, 100) > 0) {	return Error::handle(name(), L"getData", Error::TEST,			     __FILE__, __LINE__);      }      if (data_sof(0).ne(data(0))) {	Long(i).debug(L"i=");	data_sof(0).debug(L"sof");	data(0).debug(L"raw");	return Error::handle(name(), L"read-sof", Error::TEST, __FILE__,			     __LINE__);      }      i++;    }    src.close();    src_sof.close();    // the object should restore it's configuration    //    if (src_sof.sample_num_bytes_d != (Long)4) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }    if (src_sof.file_format_d != SOF) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }  }    {    if (level_a >= Integral::BRIEF) {      Console::put(L"test 6e: write to a text Sof audio file:\n");    }    // test 6e: write to an Sof audio file    //    Filename input(L"$ISIP_DEVEL/doc/examples/data/audio/input_8000.raw");    Integral::makeTemp(output_text);     File::registerTemp(output_text);        AudioFile src;    src.setFileFormat(AudioFile::RAW);    src.setFileType(BINARY);    src.open(input);    src.setNumChannels(1);    AudioFile dst(TEXT, SOF);    dst.setID(src.getID());    dst.open(output_text, File::WRITE_ONLY);    // loop through 100 samples at a time    //    Vector<VectorFloat> data(1);    long i = 0;    while (src.getData(data(0), 0, i * 100l, 100) > 0) {      dst.writeAudioData(data, 0);      i++;    }    src.close();    dst.close();  }  {    if (level_a >= Integral::BRIEF) {      Console::put(L"test 6f: read from a text Sof audio file:\n");    }    // test 6f: read from an Sof audio file    //    Filename input(L"$ISIP_DEVEL/doc/examples/data/audio/input_8000.raw");    AudioFile src;    src.setFileFormat(AudioFile::RAW);    src.setFileType(BINARY);    src.open(input);    src.setNumChannels(1);    AudioFile src_sof(TEXT, SOF);    src_sof.open(output_text, File::READ_ONLY);    if (src_sof.getID().ne(L"input_8000")) {      return Error::handle(name(), L"getID", Error::TEST, __FILE__, __LINE__);    }        // loop through 100 samples at a time    //    Vector<VectorFloat> data(1);    Vector<VectorFloat> data_sof(1);    long i = 0;    while (src.getData(data(0), 0, i * 100l, 100) > 0) {      if (!src_sof.getData(data_sof(0), 0, i * 100l, 100) > 0) {	return Error::handle(name(), L"getData", Error::TEST,			     __FILE__, __LINE__);      }      if (data_sof(0).ne(data(0))) {	data_sof(0).debug(L"sof");	data(0).debug(L"raw");	return Error::handle(name(), L"read-sof", Error::TEST, __FILE__,			     __LINE__);      }      i++;    }    src.close();    src_sof.close();  }  // this code is to test multichannel capabilities of the AudioFile  // class but it causes segmentation fault. the reason is that there  // is a memory problem in multichannel processing of audiofile which  // is waiting for purify.  //  {    if (level_a >= Integral::BRIEF) {      Console::put(L"test 6g: testing 16000 bytes in 80 chunks for multichannel data:\n");    }    //  test 6g: copy a 16000 byte file in 80 chunks. note that    // this will require more data to be buffered since the block_size    // is 4096 samples.    //    Filename input(L"$ISIP_DEVEL/doc/examples/data/audio/input_8000.raw");        Filename output;    Integral::makeTemp(output);    output.concat(L".raw");    File::registerTemp(output);    AudioFile src(BINARY, RAW);    src.open(input);    AudioFile dst(TEXT);    dst.setID(src.getID());    src.setNumChannels(2);    dst.setNumChannels(2);    dst.open(output, File::WRITE_ONLY);    // loop through 100 samples at a time    //    for (long i = 0; i < 40; i++) {          Vector<VectorFloat> data(2);      src.getData(data, i * 100, 100l);            // write these 100 samples to the output      //      dst.writeAudioData(data);    }    src.close();    dst.close();  }  if (level_a >= Integral::BRIEF) {    Console::decreaseIndention();  }    //---------------------------------------------------------------------------  //  // 4. print completion message  //  //---------------------------------------------------------------------------  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }  if (level_a > Integral::NONE) {    String output(L"diagnostics passed for class ");    output.concat(name());    output.concat(L"\n");    Console::put(output);  }  // exit gracefully  //  return true;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -