// file: $isip/class/mmedia/AudioFile/adf_09.cc // version: $Id: adf_09.cc 9280 2003-08-02 15:00:05Z parihar $ // // isip include files // #include "AudioFile.h" #include #include #include // method: writeAudioData // // 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 raw audio file // int32 AudioFile::writeAudioData(Vector& data_a, int32 ctag_a) { // make sure the file is open // if (!isOpen()) { Error::handle(name(), L"writeAudioData", ERR_NOTOPN, __FILE__, __LINE__); return -1; } // write to raw file // if (file_format_d == RAW) { // call the raw method // return writeRawData(data_a, ctag_a); } // Sof file // else if (file_format_d == SOF) { // call the sof method // return writeSofData(data_a, ctag_a); } // sphere not yet supported // else if (file_format_d == SPHERE) { // call the sphere method // return writeSphereData(data_a, ctag_a); } // else format supported bu sgi's audiofile library // else { // call the AF method // return writeAFData(data_a, ctag_a); } // exit gracefully // return true; } // method: revertData // // arguments: // VectorLong& whole_data: (output) the Vector to hold all channel data // Vector& data: (input) the input multi-channel data // int32 ctag: (input) the tag of channels to be processed // // return: a bool8 value indicating status // // this method combines the data of multiple channels and put into a // VectorLong // bool8 AudioFile::revertData(VectorLong& whole_data_a, Vector& data_a, int32 ctag_a) const { // local variables // int32 num_channels = 0; float32 sample_value; // get the number of channels to write // if (ctag_a >= 0) { num_channels = 1; } else if (ctag_a == CHANNEL_TAG_ALL) { num_channels = num_channels_d; } else { num_channels = 1; } // compute the total number of samples // int32 num_samples = data_a(0).length(); int32 num_write = num_samples * num_channels; // set the output data // whole_data_a.setLength(num_write); if (ctag_a >= 0) { for (int32 i = 0; i < num_samples; i++) { sample_value = (float32)(data_a(ctag_a)(i)) * max_sample_val_d; whole_data_a(i) = (int32)Integral::round(sample_value); } } else if (ctag_a == CHANNEL_TAG_ALL) { // return Error::handle(name(), L"revertData", ERR, __FILE__, __LINE__); for (int32 i = 0; i < num_samples; i++) { // loop each channel sample // for (int32 ctag = 0; ctag < num_channels; ctag++) { sample_value = ((float32)data_a(ctag)(i)) * max_sample_val_d; whole_data_a((int32)(i*num_channels + ctag)) = (int32)Integral::round(sample_value); } } } // exit gracefully // return true; }