Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

/home/vlg/develop/gwavmerger/raven/WavInfo.cpp

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 // Generated by assa-genesis
00003 //------------------------------------------------------------------------------
00004 // $Id: WavInfo.cpp,v 1.4 2003/02/07 05:15:08 vlg Exp $
00005 //------------------------------------------------------------------------------
00006 //                            WavInfo.cpp
00007 //------------------------------------------------------------------------------
00008 //
00009 // Author : Vladislav Grinchenko
00010 // Date   : Sun Dec 16 18:27:08 2001
00011 //
00012 // History:
00013 //
00014 // When        Who  What
00015 // ----------  ---  --------------------------
00016 // 12/16/01    VLG  Created
00017 //
00018 //------------------------------------------------------------------------------
00019 
00020 #include <iostream>
00021 #include <audiofile.h>
00022 
00023 #include "WavInfo-main.h"
00024 #include "WavInfo.h"
00025 
00026 using ASSA::APP;
00027 using ASSA::ERROR;
00028 
00029 // Static declarations mandated by Singleton class
00030 
00031 WavInfo* ASSA::Singleton<WavInfo>::m_instance;
00032 ASSA::Destroyer<WavInfo> ASSA::Singleton<WavInfo>::m_destroyer;
00033 
00034 WavInfo::WavInfo ()
00035     : m_pos_arg_count (0),
00036       m_exit_value (0),
00037       m_silent (false)
00038 {
00039     // ---Configuration---
00040     rm_opt ('f', "config-file"  );
00041     rm_opt ('n', "instance"     );
00042     rm_opt ('p', "port"         );
00043 
00044     // ---Process bookkeeping---
00045     rm_opt ('b', "daemon"       );
00046     rm_opt ('l', "pidfile"      );
00047     rm_opt ('L', "ommit-pidfile");
00048 
00049     add_flag_opt (0, "silent", &m_silent);
00050 
00051     m_log_file = "/dev/null";
00052     m_debug_mask = 0;
00053 }
00054 
00055 void
00056 WavInfo::pos_arg (const char* arg_)
00057 {
00058     trace("WavInfo::pos_arg");
00059 
00060     switch(m_pos_arg_count) {
00061     case 0:
00062         m_wav_file = arg_;
00063         break;
00064 
00065     default:
00066         std::cerr << "Error: unexpected argument " << arg_ << '\n'
00067                   << "Try `WavInfo --help` for more information.\n";
00068         Assert_exit (false);
00069     }
00070     m_pos_arg_count++;
00071 }
00072 
00073 void
00074 WavInfo::initServer ()
00075 {
00076     trace("WavInfo::initServer");
00077     ASSA::Log::disable_timestamp ();
00078 
00079     if (m_pos_arg_count != 1) {
00080         std::cerr << "WavPause: missing wav file\n"
00081                   << "Try `WavPause --help` for more information.\n";
00082         set_exit_value (1);
00083         return;
00084     }
00085 
00086     if (m_silent) {
00087         close (1);
00088         close (2);
00089         pid_t nullfd = 0;
00090         nullfd = open("/dev/null", O_WRONLY | O_CREAT, 0666);
00091         (void) dup2 (nullfd, 1);
00092         (void) dup2 (nullfd, 2);
00093         (void) close (nullfd);
00094     }
00095     DL((APP,"Service has been initialized\n"));
00096 }
00097 
00098 void
00099 WavInfo::processServer ()
00100 {
00101     trace("WavInfo::processServer");
00102     
00103     if (stopServer ()) {
00104         return;
00105     }
00106 
00107     AFfilehandle in_file;
00108     in_file = afOpenFile (m_wav_file.c_str (), "r", NULL);
00109 
00110     if (in_file == NULL) {
00111         EL((ERROR,"File \"%s\" open error\n", m_wav_file.c_str ()));
00112         set_exit_value (1);
00113         return;
00114     }
00115 
00116     char* formatstring;
00117     char* labelstring;
00118     int in_file_format = -1;
00119     int version;
00120 
00121     in_file_format = afGetFileFormat (in_file, &version);
00122 
00123     formatstring = 
00124         (char *) afQueryPointer (AF_QUERYTYPE_FILEFMT,
00125                                  AF_QUERY_DESC,
00126                                  in_file_format,
00127                                  0, 0);
00128     labelstring = 
00129         (char *) afQueryPointer (AF_QUERYTYPE_FILEFMT,
00130                                  AF_QUERY_LABEL,
00131                                  in_file_format,
00132                                  0, 0);
00133 
00134     if (formatstring == NULL || labelstring == NULL) {
00135         EL((ERROR,"Corrupted header in \"%s\"\n", m_wav_file.c_str ()));
00136         set_exit_value (1);
00137         return;
00138     }
00139 
00140     std::cout << '\n'
00141               << "File Name:     " << m_wav_file << '\n'
00142               << "File Format:   " << formatstring << " (" 
00143               << labelstring << ")\n";
00144 
00145     int sampleFormat;
00146     int sampleWidth;
00147     int byteOrder;
00148     int compressionType;
00149 
00150     afGetSampleFormat(in_file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth);
00151     byteOrder = afGetByteOrder(in_file, AF_DEFAULT_TRACK);
00152 
00153     std::cout << "Data Format:   ";
00154 
00155     compressionType = afGetCompression (in_file, AF_DEFAULT_TRACK);
00156 
00157     if (compressionType == AF_COMPRESSION_NONE) {
00158         switch (sampleFormat) {
00159         case AF_SAMPFMT_TWOSCOMP:
00160             std::cout << sampleWidth << "-bit integer (2's complement, " 
00161                       << (byteOrder == AF_BYTEORDER_BIGENDIAN ? 
00162                           "big endian" : "little endian")
00163                       << ")";
00164             break;
00165 
00166         case AF_SAMPFMT_UNSIGNED:
00167             std::cout << sampleWidth << "-bit integer (unsigned, " 
00168                       << (byteOrder == AF_BYTEORDER_BIGENDIAN ?
00169                           "big endian" : "little endian")
00170                       << ")";
00171             break;
00172 
00173         case AF_SAMPFMT_FLOAT:
00174             std::cout << "single-precision (32-bit) floating point, "
00175                       << (byteOrder == AF_BYTEORDER_BIGENDIAN ?
00176                           "big endian" : "little endian");
00177             break;
00178 
00179         case AF_SAMPFMT_DOUBLE:
00180             std::cout << "double-precision (64-bit) floating point, "
00181                       << (byteOrder == AF_BYTEORDER_BIGENDIAN ?
00182                           "big endian" : "little endian");
00183             break;
00184 
00185         default:
00186             std::cout << "unknown";
00187             break;
00188         }
00189     }
00190     else {
00191         char* compressionName;
00192         compressionName = (char*) afQueryPointer (AF_QUERYTYPE_COMPRESSION,
00193                                                   AF_QUERY_NAME, 
00194                                                   compressionType,
00195                                                   0, 0);
00196         if (compressionName == NULL) {
00197             std::cout << "unknown compression";
00198         }
00199         else {
00200             std::cout << compressionName << " compression";
00201         }
00202     }
00203     std::cout << "\n";
00204 
00205     std::cout << "Audio Data:    "
00206               << afGetTrackBytes(in_file, AF_DEFAULT_TRACK)
00207               << " bytes begins at offset "
00208               << afGetDataOffset(in_file, AF_DEFAULT_TRACK)
00209               << '(' << std::hex << afGetDataOffset(in_file, AF_DEFAULT_TRACK)
00210               <<  " hex)\n";
00211 
00212     AFframecount total_frames = afGetFrameCount (in_file, AF_DEFAULT_TRACK);
00213     int frame_size = (int)afGetVirtualFrameSize (in_file, AF_DEFAULT_TRACK, 1);
00214     
00215     int channel_count = afGetChannels(in_file, AF_DEFAULT_TRACK);
00216 
00217     std::cout << "               " << channel_count << " channel" 
00218               << (afGetChannels(in_file, AF_DEFAULT_TRACK) > 1 ? "s, " : ", ")
00219               << std::dec << total_frames << " frames\n";
00220 
00221     double sample_rate = afGetRate(in_file, AF_DEFAULT_TRACK);
00222     std::cout << "Sampling Rate: " << sample_rate << " Hz\n";
00223 
00224     double duration = afGetFrameCount(in_file, AF_DEFAULT_TRACK) / 
00225         afGetRate(in_file, AF_DEFAULT_TRACK);
00226 
00227     std::cout << "Duration:      " << duration  << " seconds\n"
00228               << '\n';
00229 
00230     afCloseFile (in_file);
00231     m_reactor.stopReactor ();
00232     DL((APP,"Service stopped!\n"));
00233 }
00234 
00235 

Generated on Tue Feb 11 23:05:19 2003 for gwavmerger by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002