Miscellaneous Code
  Home arrow Miscellaneous Code arrow classAudioFile
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS CODE

classAudioFile
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-04-26

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    this class allows you to load audio-files (wav,aif,mp3 at the moment) and check their attributes like sample-frequency, resolution, channels, length, format, compression, id3-tags and more. besides this it visualizes audio-samples they way you know it from waveLab, CoolEdit or any other audio-editor. find the complete package & feedback area at:

    http://www.entropy.at/forum.php?action=thread&t_id=15

    By : mika

    <?php

    // ************************************************************************
    // Class AudioFile
    // Version: 0.4
    // Date: 24/04/2002
    // Author: michael kamleitner (mika@ssw.co.at)
    // reto gassmann (gassi@gassi.cx) - additional mp3-code
    // WWW: http://www.entropy.at/forum.php?action=thread&t_id=15
    // (suggestions, bug-reports & general shouts are welcome)
    // ************************************************************************

    class AudioFile
    {
    var $wave_id;
    var $wave_type;
    var $wave_compression;
    var $wave_channels;
    var $wave_framerate;
    var $wave_byterate;
    var $wave_bits;
    var $wave_size;
    var $wave_filename;
    var $wave_length;

    var $id3_tag;
    var $id3_title;
    var $id3_artist;
    var $id3_album;
    var $id3_year;
    var $id3_comment;
    var $id3_genre;

    var $visual_graph_color;
    var $visual_background_color;
    var $visual_grid_color;
    var $visual_border_color;
    var $visual_grid;
    var $visual_border;
    var $visual_width;

    // ************************************************************************
    // mp3info extracts the attributes of mp3-files
    // (code contributed by reto gassmann (gassi@gassi.cx)
    // ************************************************************************

    function mp3info()
    {
    $byte = array();
    $version = array("MPEG Version 2.5",false,"MPEG Version 2 (ISO/IEC 13818-3)","MPEG Version 1 (ISO/IEC 11172-3)");
    $version_bitrate = array(1,false,1,0);
    $version_sampling = array(2,false,1,0);
    $layer = array(false,"Layer III","Layer II","Layer I");
    $layer_bitrate = array(false,2,1,0);
    $layer_lengt = array(false,1,1,0);
    $protection = array("Protected by CRC (16bit crc follows header)","Not protected");
    $byterate = array(
    array(
    array("free",32,64,96,128,160,192,224,256,288,320,352,384,416,448,"bad"),
    array("free",32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,"bad"),
    array("free",32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,"bad")
    ),
    array(
    array("free",32,48,56, 64, 80, 96,112,128,144,160,176,192,224,256,"bad"),
    array("free", 8,16,24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160,"bad"),
    array("free", 8,16,24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160,"bad")
    )
    );
    $samplingrate = array(
    array(44100,48000,32000,false),
    array(22050,24000,16000,false),
    array(11025,12000, 8000,false)
    );
    $cannel_mode = array("Stereo","Joint stereo (Stereo)","Dual channel (Stereo)","Single channel (Mono)");
    $copyright = array("Audio is not copyrighted","Audio is copyrighted ");
    $original = array("Copy of original media","Original media");
    $emphasis = array("none","50/15 ms",false,"CCIT J.17 ");

    //id3-stuff

    $genre = array
    ("Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge","Hip-Hop","Jazz","Metal","New Age","Oldies","Other","Pop","R&B",
    "Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska","Death Metal","Pranks","Soundtrack","Euro-Techno","Ambient","Trip-Hop",
    "Vocal","Jazz+Funk","Fusion","Trance","Classical","Instrumental","Acid","House","Game","Sound Clip","Gospel","Noise","Alternative Rock",
    "Bass","Soul","Punk","Space","Meditative","Instrumental Pop","Instrumental Rock","Ethnic","Gothic","Darkwave","Techno-Industrial",
    "Electronic","Pop-Folk","Eurodance","Dream","Southern Rock","Comedy","Cult","Gangsta","Top 40","Christian Rap","Pop/Funk","Jungle",
    "Native US","Cabaret","New Wave","Psychadelic","Rave","Showtunes","Trailer","Lo-Fi","Tribal","Acid Punk","Acid Jazz","Polka","Retro",
    "Musical","Rock & Roll","Hard Rock","Folk","Folk-Rock","National Folk","Swing","Fast Fusion","Bebob","Latin","Revival","Celtic","Bluegrass",
    "Avantgarde","Gothic Rock","Progressive Rock","Psychedelic Rock","Symphonic Rock","Slow Rock","Big Band","Chorus","Easy Listening","Acoustic",
    "Humour","Speech","Chanson","Opera","Chamber Music","Sonata","Symphony","Booty Bass","Primus","Porn Groove","Satire","Slow Jam","Club",
    "Tango","Samba","Folklore","Ballad","Power Ballad","Rhytmic Soul","Freestyle","Duet","Punk Rock","Drum Solo","Acapella","Euro-House",
    "Dance Hall","Goa","Drum & Bass","Club-House","Hardcore","Terror","Indie","BritPop","Negerpunk","Polsk Punk","Beat","Christian Gangsta Rap",
    "Heavy Metal","Black Metal","Crossover","Contemporary Christian","Christian Rock","Merengue","Salsa","Trash Metal","Anime","Jpop","Synthpop");

    //id3v2 check----------------------------

    $footer = 0;
    $header = 0;
    $v1tag = 0;
    $fp = fopen($this->wave_filename,"r");
    $tmp = fread($fp,3);
    if($tmp == "ID3")
    {
    $tmp = ord(fread($fp,1));
    $tmp2 = ord(fread($fp,1));
    $info["mpeg_id3v2_tag"]["version"] = "ID3v2.".$tmp.".".$tmp2;
    $tmp = ord(fread($fp,1));
    if($tmp & 128)$info["mpeg_id3v2_tag"]["flag"]["unsync"] = "set";
    if($tmp & 64) $info["mpeg_id3v2_tag"]["flag"]["extended"] = "set";
    if($tmp & 32) $info["mpeg_id3v2_tag"]["flag"]["experimental"] = "set";
    if($tmp & 16)
    {
    $info["mpeg_id3v2_tag"]["flag"]["footer"] = "set";
    $footer = 10;
    }
    $tmp = ord(fread($fp,1))& 127;
    $tmp2 = ord(fread($fp,1))& 127;
    $tmp3 = ord(fread($fp,1))& 127;
    $tmp4 = ord(fread($fp,1))& 127;
    $info["mpeg_id3v2_tag"]["header_lenght"] = ($tmp * 2097152) + ($tmp2 * 16384) + ($tmp3 * 128) + $tmp4 + 10 + $footer;
    fseek ($fp,$info["mpeg_id3v2_tag"]["header_lenght"]);
    $header = $info["mpeg_id3v2_tag"]["header_lenght"];
    } else {
    fseek ($fp,0);
    $info["mpeg_id3v2_tag"] = false;
    }

    for ($x=0;$x<4;$x++)
    {
    $byte[$x] = ord(fread($fp,1));
    }
    fseek ($fp, -128 ,SEEK_END);
    $TAG = fread($fp,128);
    fclose($fp);

    //id tag?-------------------------------

    if(substr($TAG,0,3) == "TAG")
    {
    $v1tag = 128;
    $info["mpeg_id3v1_tag"]["title"] = substr($TAG,3,30);
    $info["mpeg_id3v1_tag"]["artist"] = substr($TAG,33,30);
    $info["mpeg_id3v1_tag"]["album"] = substr($TAG,63,30);
    $info["mpeg_id3v1_tag"]["year"] = substr($TAG,93,4);
    $info["mpeg_id3v1_tag"]["comment"] = substr($TAG,97,30);
    $info["mpeg_id3v1_tag"]["genre"] = "";
    $tmp = ord(substr($TAG,127,1));
    if($tmp < count($genre))
    {
    $info["mpeg_id3v1_tag"]["genre"] = $genre[$tmp];
    }
    } else {
    $info["mpeg_id3v1_tag"] = false;
    }

    //version-------------------------------

    $tmp = $byte[1] & 24;
    $tmp = $tmp >> 3;
    $info_i["mpeg_version"] = $tmp;
    $byte_v = $version_bitrate[$tmp];
    $byte_vs = $version_sampling[$tmp];
    $info["mpeg_version"] = $version[$tmp];

    //layer---------------------------------

    $tmp = $byte[2] & 6;
    $tmp = $tmp >> 1;
    $info_i["mpeg_layer"] = $tmp;
    $byte_l = $layer_bitrate[$tmp];
    $byte_len = $layer_lengt[$tmp];
    $info["mpeg_layer"] = $layer[$tmp];

    //bitrate-------------------------------

    $tmp = $byte[2] & 240;
    $tmp = $tmp >> 4;
    $info_i["mpeg_bitrate"] = $tmp;
    $info["mpeg_bitrate"] = $byterate[$byte_v][$byte_l][$tmp]." Kbits/sec.";

    //samplingrate--------------------------

    $tmp = $byte[2] & 12;
    $tmp = $tmp >> 2;
    $info["mpeg_sampling_rate"] = $samplingrate[$byte_vs][$tmp];

    //protection----------------------------

    $tmp = $byte[1] & 1;
    $info["mpeg_protection"] = $protection[$tmp];

    //paddingbit----------------------------

    $tmp = $byte[2] & 2;
    $tmp = $tmp >> 1;
    $byte_pad = $tmp;
    $info["mpeg_padding_bit"] = $tmp;

    //privatebit----------------------------

    $tmp = $byte[2] & 1;
    $byte_prv = $tmp;

    //channel_mode--------------------------

    $tmp = $byte[3] & 192;
    $tmp = $tmp >> 6;
    $info["mpeg_channel_mode"] = $cannel_mode[$tmp];

    //copyright-----------------------------

    $tmp = $byte[3] & 8;
    $tmp = $tmp >> 3;
    $info["mpeg_copyright"] = $copyright[$tmp];

    //original------------------------------

    $tmp = $byte[3] & 4;
    $tmp = $tmp >> 2;
    $info["mpeg_original"] = $original[$tmp];

    //emphasis------------------------------

    $tmp = $byte[3] & 3;
    $info["mpeg_emphasis"] = $emphasis[$tmp];

    //framelenght---------------------------

    if($byte_len == 0)
    {
    $rate_tmp = $info["mpeg_bitrate"] * 1000;
    $info["mpeg_framelenght"] = (12 * $rate_tmp / $info["mpeg_sampling_rate"] + $byte_pad) * 4 ;
    } elseif($byte_len == 1) {
    $rate_tmp = $info["mpeg_bitrate"] * 1000;
    $info["mpeg_framelenght"] = 144 * $rate_tmp /
    $info["mpeg_sampling_rate"] + $byte_pad;
    }

    //duration------------------------------

    $tmp = filesize($this->wave_filename);
    $tmp = $tmp - $header - 4 - $v1tag;
    $info["mpeg_frames"] = floor($tmp/$info["mpeg_framelenght"]);
    $tmp = $tmp * 8;
    $info["mpeg_playtime"] = $tmp/$rate_tmp;

    // transfer the extracted data into classAudioFile-structure

    $this->wave_id = "MPEG";
    $this->wave_type = $info["mpeg_version"];
    $this->wave_compression = $info["mpeg_layer"];
    $this->wave_channels = $info["mpeg_channel_mode"];
    $this->wave_framerate = $info["mpeg_sampling_rate"];
    $this->wave_byterate = $info["mpeg_bitrate"];
    $this->wave_bits = "n/a";
    $this->wave_size = filesize($this->wave_filename);
    $this->wave_length = $info["mpeg_playtime"];

    $this->id3_tag = $info["mpeg_id3v1_tag"];

    if ($this->id3_tag)
    {
    $this->id3_title = $info["mpeg_id3v1_tag"]["title"];
    $this->id3_artist = $info["mpeg_id3v1_tag"]["artist"];
    $this->id3_album = $info["mpeg_id3v1_tag"]["album"];
    $this->id3_year = $info["mpeg_id3v1_tag"]["year"];
    $this->id3_comment = $info["mpeg_id3v1_tag"]["comment"];
    $this->id3_genre = $info["mpeg_id3v1_tag"]["genre"];
    }
    }

    // ************************************************************************
    // longCalc calculates the decimal value of 4 bytes
    // mode = 0 ... b1 is the byte with least value
    // mode = 1 ... b1 is the byte with most value
    // ************************************************************************

    function longCalc ($b1,$b2,$b3,$b4,$mode)
    {
    $b1 = hexdec(bin2hex($b1));
    $b2 = hexdec(bin2hex($b2));
    $b3 = hexdec(bin2hex($b3));
    $b4 = hexdec(bin2hex($b4));
    if ($mode == 0)
    {
    return ($b1 + ($b2*256) + ($b3 * 65536) + ($b4 * 16777216));
    } else {
    return ($b4 + ($b3*256) + ($b2 * 65536) + ($b1 * 16777216));
    }
    }

    // ************************************************************************
    // shortCalc calculates the decimal value of 2 bytes
    // mode = 0 ... b1 is the byte with least value
    // mode = 1 ... b1 is the byte with most value
    // ************************************************************************

    function shortCalc ($b1,$b2,$mode)
    {
    $b1 = hexdec(bin2hex($b1));
    $b2 = hexdec(bin2hex($b2));
    if ($mode == 0)
    {
    return ($b1 + ($b2*256));
    } else {
    return ($b2 + ($b1*256));
    }
    }

    // ************************************************************************
    // getCompression delivers a string which identifies the compression-mode
    // of the AudioFile-Object
    // ************************************************************************

    function getCompression ($id)
    {
    if ($this->wave_id <> "MPEG")
    {
    $append = "($id)";
    switch ($id)
    {
    case 0: return ("unknown $append"); break;
    case 1: return ("pcm/uncompressed $append"); break;
    case 2: return ("microsoft adpcm $append"); break;
    case 6: return ("itu g.711 a-law $append"); break;
    case 7: return ("itu g.711 u-law $append"); break;
    case 17: return ("ima adpcm $append"); break;
    case 20: return ("itu g.723 adpcm (yamaha) $append"); break;
    case 49: return ("gsm 6.10 $append"); break;
    case 64: return ("itu g.721 adpcm $append"); break;
    case 80: return ("mpeg $append"); break;
    case 65536:return ("experimental $append"); break;
    default: return ("not defined $append"); break;
    }
    } else {
    return ($id);
    }
    }

    // ************************************************************************
    // getVisualization creates a graphical visualization of the audio-sample
    // (works ONLY * for uncompressed waves!
    // * files with 1 or 2 channels
    // * 8/16/24/32 bit sample-resolution )
    // ************************************************************************

    function getVisualization ($output)
    {
    $width=$this->visual_width;
    if ($this->wave_filename<>"" && $this->wave_id == "RIFF" && $this->wave_type == "WAVE" && ($this->wave_channels>=1 && $this->wave_channels<=2) && $this->wave_bits%8==0)
    {
    $file = fopen ($this->wave_filename,"r");

    // read the first 12 bytes (RIFF- & WAVE-chunk)

    for ($i=0;$i<12;$i++)
    {
    $null = fgetc ($file);
    }

    // Read the next chunk-id, supposed to be "fmt "

    $chunk_id_3 = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
    if ($chunk_id_3 == "fmt ")
    {
    $chunk_size_3 = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
    for ($i=0;$i<$chunk_size_3;$i++)
    {
    $null = fgetc($file);
    }

    // Read the next chunk-id, supposed to be "data"

    $chunk_id_4 = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
    if ($chunk_id_4 == "data")
    {
    $chunk_size_4 = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
    $visualData = array();
    $bytes_per_frame = ($this->wave_bits/8)*($this->wave_channels);
    $bytes_per_channel = ($this->wave_bits/8);
    $frames = $chunk_size_4 / $bytes_per_frame;
    $visual_frames = ceil($frames / $width);
    $frame_index = 1;
    $data_index = 1;
    while (!feof($file))
    {
    for ($j=0;$j<$this->wave_channels;$j++)
    {
    $bytes = array();
    for ($i=0;$i<$bytes_per_channel;$i++)
    {
    $bytes[$i] = fgetc($file);
    }
    if ($frame_index == $visual_frames)
    {
    switch ($bytes_per_channel)
    {
    case 1: $visualData[$j][$data_index]= $this->shortCalc($bytes[0],$bytes[1],0);
    break;
    case 2: $f=128;
    if (ord($bytes[1])&128) $f = 0;
    $x=chr((ord($bytes[1])&127) + $f);
    $visualData[$j][$data_index]= floor($this->shortCalc($bytes[0],$x,0)/256);
    break;
    }
    if (($j+1) == $this->wave_channels)
    {
    $data_index++;
    $frame_index = 1;
    }
    } else {
    if (($j+1) == $this->wave_channels) $frame_index++;
    }
    }
    }
    $im = @ImageCreate ($width, (256*$this->wave_channels)+1) or die ("Cannot Initialize new GD image stream!");
    $background_color = ImageColorAllocate ($im, hexdec(substr($this->visual_background_color,1,2)),hexdec(substr($this->visual_background_color,3,2)),hexdec(substr($this->visual_background_color,5,2)));
    $cBlack = ImageColorAllocate ($im, hexdec(substr($this->visual_background_color,1,2)),hexdec(substr($this->visual_background_color,3,2)),hexdec(substr($this->visual_background_color,5,2)));
    $cGreen = ImageColorAllocate ($im, hexdec(substr($this->visual_graph_color,1,2)),hexdec(substr($this->visual_graph_color,3,2)),hexdec(substr($this->visual_graph_color,5,2)));
    $cRed = ImageColorAllocate ($im, hexdec(substr($this->visual_border_color,1,2)),hexdec(substr($this->visual_border_color,3,2)),hexdec(substr($this->visual_border_color,5,2)));
    $cBlue = ImageColorAllocate ($im, hexdec(substr($this->visual_grid_color,1,2)),hexdec(substr($this->visual_grid_color,3,2)),hexdec(substr($this->visual_grid_color,5,2)));
    if ($this->visual_border)
    {
    ImageRectangle ($im,0,0,($width-1),(256*$this->wave_channels),$cRed);
    for ($i=0;$i<=$this->wave_channels;$i++)
    {
    ImageLine ($im,1,($i*128)+128,$width,($i*128)+128,$cRed);
    }
    }
    if ($this->visual_grid)
    {
    for ($i=1;$i<=($width/100*2);$i++)
    {
    ImageLine ($im,$i*50,0,$i*50,(256*$this->wave_channels),$cBlue);
    }
    }

    // this for-loop draws a graph for every channel

    for ($j=0;$j<sizeof($visualData);$j++)
    {
    $last_x = 1;
    $last_y = 128;

    // this for-loop draws the graph itself

    for ($i=1;$i<sizeof($visualData[$j]);$i++)
    {
    ImageLine ($im,$last_x,($last_y+($j*256)),$i,($visualData[$j][$i]+($j*256)),$cGreen);
    $last_x = $i;
    $last_y = $visualData[$j][$i];
    }
    }

    // change this to generate JPG or direct output to browser

    ImagePng ($im,$output);
    }
    }
    fclose ($file);
    } else {
    // AudioSample - AudioFile-Object not initialized!
    }
    }

    // ************************************************************************
    // getSampleInfo extracts the attributes of the AudioFile-Object
    // ************************************************************************

    function getSampleInfo ()
    {
    $valid = true;

    if (strstr(strtoupper($this->wave_filename),"MP3"))
    {
    $this->mp3info ();
    } else {

    $this->wave_size = filesize ($this->wave_filename);
    if ($this->wave_size > 16)
    {

    $file = fopen ($this->wave_filename,"r");
    $chunk_id = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
    $null = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
    $chunk_id_2 = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
    $this->wave_id = $chunk_id;
    $this->wave_type = $chunk_id_2;
    if (substr($chunk_id,0,2)=="PK")
    {
    // it's a ZIP-file

    $this->wave_id = "ZIP";
    $this->wave_type = "ZIP";
    $this->valid = true;
    } else {
    if ($this->wave_id == "RIFF" && $this->wave_type == "WAVE")
    {
    // it's a Wave-File

    $chunk_id = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
    $chunk_size = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
    if ($chunk_id == "fmt ")
    {
    $format_len = $chunk_size;
    $this->wave_compression = $this->shortCalc (fgetc ($file), fgetc ($file),0);
    $this->wave_channels = $this->shortCalc (fgetc ($file), fgetc ($file),0);
    $this->wave_framerate = $this->longCalc (fgetc ($file), fgetc ($file), fgetc ($file), fgetc ($file),0);
    $this->wave_byterate = $this->longCalc (fgetc ($file), fgetc ($file), fgetc ($file), fgetc ($file),0);
    $null = fgetc($file) . fgetc($file);
    $this->wave_bits = $this->shortCalc (fgetc ($file), fgetc ($file),0);
    $read = 16;
    if ($read < $format_len)
    {
    $extra_bytes = $this->shortCalc (fgetc ($file), fgetc ($file),1);
    $j = 0;
    while ($j < $extra_bytes && !feof($file))
    {
    $null = fgetc ($file);
    $j++;
    }
    }
    $chunk_id = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
    $chunk_size = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
    if ($chunk_id == "data")
    {
    $this->wave_length = (($chunk_size / $this->wave_channels) / ($this->wave_bits/8)) / $this->wave_framerate;
    } else {
    while ($chunk_id <> "data" && !feof($file))
    {
    $j = 1;
    while ($j <= $chunk_size && !feof($file))
    {
    $null = fgetc ($file);
    $j++;
    }
    $chunk_id = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
    //print "<br>$chunk_id*";
    $chunk_size = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
    }
    if ($chunk_id == "data")
    {
    $this->wave_length = (($chunk_size / $this->wave_channels) / ($this->wave_bits/8)) / $this->wave_framerate;
    print "* $chunk_id * $chunk_size *";
    }

    }
    } else {
    $valid = false;
    }
    } else {
    if ($this->wave_id == "FORM" && $this->wave_type == "AIFF")
    {
    // we have a AIFF file here

    $chunk_id = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
    $chunk_size = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
    if ($chunk_id == "COMM")
    {
    $format_len = $chunk_size;
    $this->wave_channels = $this->shortCalc (fgetc ($file), fgetc ($file),1);
    $null = $this->longCalc (fgetc ($file), fgetc ($file), fgetc ($file), fgetc ($file),1);
    $this->wave_bits = $this->shortCalc (fgetc ($file), fgetc ($file),1);
    $null = fgetc ($file) . fgetc ($file);
    $this->wave_framerate = $this->shortCalc (fgetc ($file), fgetc ($file),1);

    $read = 16;
    } else {
    $valid = false;
    }
    } else {
    // probably crap

    $valid = false;
    }
    }
    }
    fclose ($file);
    } else {
    $valid = false;
    }
    return ($valid);
    }
    }

    // ************************************************************************
    // printSampleInfo prints the attributes of the AudioFile-Object
    // ************************************************************************

    function printSampleInfo()
    {
    print "<table width=100% border=1>";
    print "<tr><td align=right>filename</td> <td>&nbsp;$this->wave_filename</td></tr>";
    print "<tr><td align=right>id</td> <td>&nbsp;$this->wave_id</td></tr>";
    print "<tr><td align=right>type</td> <td>&nbsp;$this->wave_type</td></tr>";
    print "<tr><td align=right>size</td> <td>&nbsp;$this->wave_size</td></tr>";
    print "<tr><td align=right>compression</td> <td>&nbsp;".$this->getCompression ($this->wave_compression)."</td></tr>";
    print "<tr><td align=right>channels</td> <td>&nbsp;$this->wave_channels</td></tr>";
    print "<tr><td align=right>framerate</td> <td>&nbsp;$this->wave_framerate</td></tr>";
    print "<tr><td align=right>byterate</td> <td>&nbsp;$this->wave_byterate</td></tr>";
    print "<tr><td align=right>bits</td> <td>&nbsp;$this->wave_bits</td></tr>";
    print "<tr><td align=right>length</td> <td>&nbsp;".number_format ($this->wave_length,"2")." sec.</td></tr>";

    if ($this->id3_tag)
    {
    print "<tr><td align=right>id3v1-tags</td><td>";
    print "<table width=100% border=1>";
    print "<tr><td width=70 align=right>title</td><td>&nbsp;$this->id3_title</td></tr>";
    print "<tr><td align=right>artist</td><td>&nbsp;$this->id3_artist</td></tr>";
    print "<tr><td align=right>album</td><td>&nbsp;$this->id3_album</td></tr>";
    print "<tr><td align=right>year</td><td>&nbsp;$this->id3_year</td></tr>";
    print "<tr><td align=right>comment</td><td>&nbsp;$this->id3_comment</td></tr>";
    print "<tr><td align=right>genre</td><td>&nbsp;$this->id3_genre</td></tr>";
    print "</table>";
    print "</td></tr>";
    }
    else
    {
    print "<tr><td align=right>id3v1-tags</td><td>Not found</td></tr>";
    }

    print "</table>";
    }

    // ************************************************************************
    // loadFile initializes the AudioFile-Object
    // ************************************************************************

    function loadFile ($loadFilename)
    {
    $this->wave_filename = $loadFilename;
    $this->getSampleInfo ();
    $this->visual_graph_color = "#18F3AD";
    $this->visual_background_color = "#000000";
    $this->visual_grid_color = "#002C4A";
    $this->visual_border_color = "#A52421";
    $this->visual_grid = true;
    $this->visual_border = true;
    $this->visual_width = 600;
    }
    }
    ?>

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Achieving True Agility -- How process can change the behavior of your tools

    Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools.
    FREE! Go There Now!


    NEW! Develop Systems Software Assets with IBM Rational Asset Manager

    Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager.
    FREE! Go There Now!


    NEW! Did you say mainframe? e-kit

    Learn how you can extend modern application lifecycle management to IBM System z through the IBM Rational Software Delivery Platform (SDP). The Did you say mainframe? e-kit includes podcasts, webcasts, tutorials, white and red papers, demos, and articles designed to help ease the challenges of modernizing your enterprise. This complimentary kit for mainframe developers is a practical, how-to guide for making the most of an existing development environment, including the skills and infrastructure already in place at an established enterprise.
    FREE! Go There Now!


    NEW! Discovering the value of WebSphere Process Server

    WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies.
    FREE! Go There Now!


    NEW! Hello World: WebSphere Service Registry and Repository

    Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services.
    FREE! Go There Now!


    NEW! Info 2.0: Harnessing the power of Web 2.0 and Enterprise Mashups

    Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started.
    FREE! Go There Now!


    NEW! Webcast: Eclipse: Empowering the universal platform

    The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now.
    FREE! Go There Now!


    NEW! Webcast: Extreme transaction processing with WebSphere Extended Deployment

    In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications.
    FREE! Go There Now!


    NEW! Webcast: What is new in Viper 2 for developers?

    Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications.
    FREE! Go There Now!


    NEW! Whitepaper: Delivering SOA solutions: service lifecycle management

    The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...
    - Model Data and Validation Rules for a Generi...
    - Building a Generic Model for the CodeIgniter...
    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT