// file: $isip/doc/examples/class/mmedia/mmedia_example_02/example.cc
// version: $Id: example.cc 8652 2002-08-26 01:18:57Z zheng $
//

// isip include files
//
#include <AudioDatabase.h>

// main program starts here
//
int main() {
  
  // generate an audio database given identifiers and file list
  //
  Sdb id_sdb, file_sdb;
  Filename id_list_file(L"./identifier.sof");
  Filename file_list_file(L"./file_list.sof");
  id_sdb.append(id_list_file, true);
  file_sdb.append(file_list_file, true);

  // load to AudioDatabase
  //
  AudioDatabase audb_03;
  Vector<Filename> vec_file;
  String name_00(L"TIDIGITS");
  audb_03.setDataBaseName(name_00);
  audb_03.load(id_sdb, file_sdb, vec_file);

  // write AudioDatabase to sof file
  //
  Sof tmp_file3;
  String tmp_filename3(L"audio_database.sof");
  tmp_file3.open(tmp_filename3, File::WRITE_ONLY, File::TEXT);
  audb_03.store(tmp_file3, (long)0, vec_file);
  tmp_file3.close();
	       
  // read back the sof file to AudioDatabase and compare it to original one
  //
  tmp_file3.open(tmp_filename3);

  AudioDatabase audb_04;
  audb_04.read(tmp_file3, (long)0);
  if (!audb_03.eq(audb_04)) {
    return Error::handle(AudioDatabase::name(), L"failed to read audio database!", Error::TEST, __FILE__, __LINE__);
  }

  // test getRecord() method
  //
  Filename record0;
  String id0(L"ae_2789385a");
  audb_04.getRecord(id0, record0);
  if (record0.ne(L"/isip/data/exp/production/t_00011/data_preparation/train/output/ae_2789385a.sof")) {
    record0.debug(L"getRecord");
    return Error::handle(AudioDatabase::name(), L"cannot get record correctly!", Error::TEST, __FILE__, __LINE__);
  }
  
  // exit gracefully
  //
  Integral::exit();
}
