Location: PHPKode > scripts > PHP VQF Metadata Extractor > php-vqf-metadata-extractor/vqf.php

  // PHP VQF Metadata Extraction Class
  //   Version 1.0
  //   Last Modified: October 9 2002
  //   (c) Adam Whitehead -- email: hide@address.com
  // Description:
  //   This class will extract the metadata (artist, song title, bitrate and channel mode)
  //   from a VQF (twinVQ)-encoded audio file. This is useful for online audio search
  //   engines etc.
  //   It will not return data for song title or artist if these are not explicity set when
  //   encoded.
  //   This PHP class can be distributed and modified freely. If you use it I would be more
  //   than happy to answer any queries you have via e-mail.


  class vqfInfo
    var $songTitle;
    var $artist;
    var $channelMode;
    var $bitrate;

    function vqfInfo($header)
      // You must pass in a parameter when instantiating this class. The parameter
      // must be the first few hundred bytes of the VQF file. I would recommend passing
      // in 128 bytes although you could theoretically pass in less depending on the
      // length of the artist/song title.


    function decodeVqfHeader($header)
      // Used internally by the class to decode the header. Please do not
      // call this function yourself!

      if (ord($header[OF_CHANNELMODE])==CM_MONO)
        $this->channelMode = "Mono";
      elseif (ord($header[OF_CHANNELMODE])==CM_STEREO)
        $this->channelMode = "Stereo";

      $this->bitrate = ord($header[OF_BITRATE]);

      $titleLength = ord($header[OF_SONG_TITLE]);
      $this->songTitle = substr($header,OF_SONG_TITLE+1,$titleLength);

      $artistBegin = OF_SONG_TITLE+OF_ARTIST_SONG_DIFF+strlen($this->songTitle);
      $artistLength = ord($header[$artistBegin]);
      $this->artist = substr($header,$artistBegin+1,$artistLength);

    // Public functions

    function getSongTitle()
      // Returns the song title
      return $this->songTitle;

    function getArtist() {
      // Returns the artist name
      return $this->artist;

    function getChannelMode() {
      // Returns the channel mode (either "Stereo" or "Mono)
      return $this->channelMode;

    function getBitrate() {
      // Returns the bitrate as an integer
      return $this->bitrate;

  // Example code -- remove this once you are familiar with it and would
  // like to use the class.

  $filename = "test.vqf";
  $fp = fopen($filename,"rb");
  $header = fread($fp,128);

  $vqf = new vqfInfo($header);
  echo $vqf->getSongTitle()."\n";
  echo $vqf->getArtist()."\n";
  echo $vqf->getChannelMode()."\n";
  echo $vqf->getBitrate()."kbps\n";
Return current item: PHP VQF Metadata Extractor