Exemplo n.º 1
0
int main( unsigned int argc, char * const argv[])
{
  ID3D_INIT_DOUT();

  gengetopt_args_info args;

  if (cmdline_parser(argc, argv, &args) != 0)
  {
    exit(1);
  }

#if defined ID3_ENABLE_DEBUG
  if (args.warning_flag)
  {
    ID3D_INIT_WARNING();
    ID3D_WARNING ( "warnings turned on" );
  }
  if (args.notice_flag)
  {
    ID3D_INIT_NOTICE();
    ID3D_NOTICE ( "notices turned on" );
  }
#endif


  const char* filename = NULL;
  for (size_t i = 0; i < args.inputs_num; ++i)
  {
    filename = args.inputs[i];
    ID3_Tag myTag;
    
    myTag.Link(filename, ID3TT_ALL);
    const Mp3_Headerinfo* mp3info;
    mp3info = myTag.GetMp3HeaderInfo();

    cout << endl << "*** Tag information for " << filename << endl;
    if (!args.assign_given)
    {
      PrintInformation(myTag);
    }
    else
    {
      cout << "*** Testing assignment operator" << endl;
      ID3_Tag tmpTag(myTag);
      PrintInformation(tmpTag);
    }
    if (mp3info)
    {
      cout << "*** mp3 info\n";

      switch (mp3info->version)
      {
      case MPEGVERSION_2_5:
        cout << "MPEG2.5/";
        break;
      case MPEGVERSION_2:
        cout << "MPEG2/";
        break;
      case MPEGVERSION_1:
        cout << "MPEG1/";
        break;
      default:
        break;
      }

      switch (mp3info->layer)
      {
      case MPEGLAYER_III:
        cout << "layer III\n";
        break;
      case MPEGLAYER_II:
        cout << "layer II\n";
        break;
      case MPEGLAYER_I:
        cout << "layer I\n";
        break;
      default:
        break;
      }

      cout << "Bitrate: " << mp3info->bitrate/1000 << "KBps\n";
      cout << "Frequency: " << mp3info->frequency/1000 << "KHz\n";
    }


  }

  return 0;
}
Exemplo n.º 2
0
//***************************************************************************
bool Kwave::MP3Decoder::open(QWidget *widget, QIODevice &src)
{
    qDebug("MP3Decoder::open()");
    metaData().clear();
    Q_ASSERT(!m_source);
    if (m_source) qWarning("MP3Decoder::open(), already open !");

    /* open the file in readonly mode with seek enabled */
    if (src.isSequential()) return false;
    if (!src.open(QIODevice::ReadOnly)) {
	qWarning("unable to open source in read-only mode!");
	return false;
    }

    /* read all available ID3 tags */
    ID3_Tag tag;
    ID3_QIODeviceReader adapter(src);
    tag.Link(adapter, static_cast<flags_t>(ID3TT_ALL));

    qDebug("NumFrames = %u", Kwave::toUint(tag.NumFrames()));
    /** @bug: id3lib crashes in this line on some MP3 files */
    if (tag.GetSpec() != ID3V2_UNKNOWN) {
	qDebug("Size = %u",      Kwave::toUint(tag.Size()));
    }
    qDebug("HasLyrics = %d", tag.HasLyrics());
    qDebug("HasV1Tag = %d",  tag.HasV1Tag());
    qDebug("HasV2Tag = %d",  tag.HasV2Tag());

    m_prepended_bytes = tag.GetPrependedBytes();
    m_appended_bytes  = tag.GetAppendedBytes();
    qDebug("prepended=%lu, appended=%lu", m_prepended_bytes, m_appended_bytes);

    const Mp3_Headerinfo *mp3hdr = tag.GetMp3HeaderInfo();
    if (!mp3hdr) {
	Kwave::MessageBox::sorry(widget,
	    i18n("The opened file is no MPEG file or it is damaged.\n"
	    "No header information has been found."));
	return false;
    }

    /* parse the MP3 header */
    if (!parseMp3Header(*mp3hdr, widget)) return false;

    /* parse the ID3 tags */
    if (!parseID3Tags(tag)) return false;

    /* accept the source */
    m_source = &src;
    Kwave::FileInfo info(metaData());
    info.set(Kwave::INF_MIMETYPE, _("audio/mpeg"));
    metaData().replace(Kwave::MetaDataList(info));

    // allocate a transfer buffer with 128 kB
    if (m_buffer) free(m_buffer);
    m_buffer_size = (128 << 10);

    m_buffer = static_cast<unsigned char *>(malloc(m_buffer_size));
    if (!m_buffer) return false; // out of memory :-(

    return true;
}