All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET:设置页面buffer引出来的问题_[Asp.Net教程]
PHP脚本的8个技巧(7)PHP和Java_php资料_编程技术
AspNetPager分页控件--使用方法_.net资料_编程技术
.NET
利用OpenSmtp.Net发送需要smtp验证的邮件_[Asp.Net教程]
用ASP.Net实现文件的在线压缩和解压缩_[Asp.Net教程]
页面根据不同Url显示不同Title以及不同的Mete_[Asp.Net教程]
Silverlight,2(beta1)数据操作(7)—调用FlickR,REST,APIs来询图片_[Asp.Net教程]
Sql Server2005登录失败_[SQL Server教程]
解析在ASP.NET中调用存储过程的方法_[Asp.Net教程]
Reading number is top 10 pictures
Sora aoi on twitter1
The real super beauty13
住院一星期,检测费两万
Look for from human art net, is good--3
两个妞在等世界上最短的火车
妹子最好别玩单反
Most cow mistress ZhaoGongXia face exposure
恶搞漫画2
Look for from human art net, is good--2
奇趣的世界记录3
Download software ranking
Tram sex maniac 2 (H) rar bag8
Tram sex maniac 2 (H) rar bag5
Boxer Classic video3
Boxer's Top ten classic battle2
linux初级教程
WebService在.NET中的实战应用教学视频 → 第5集
Boxer's Top ten classic battle4
SQL2000 For 4IN1
都市狐狸姑娘传
Rio big adventure
aaa published in(发表于) 2013/12/24 5:49:10 Edit(编辑)
PHP分析.wav文件并绘制png格式的波形图_php资料_编程技术

PHP分析.wav文件并绘制png格式的波形图_php资料_编程技术

PHP分析.wav文件并绘制png格式的波形图_php资料_编程技术-你的首页-uuhomepage.com

  用Php分析并绘制音频文件的波形图,网上还是很少见到。其实只要根据wav文件的规范,用Php的fseek,fopen,fopen,pack/unpack等函数,以及强大的gd图形库,这些都是很容易的。很多人可能对pack/unpack函数不熟悉;这其实是Php借用perl的,他们提供了使用脚本语言访问复杂二进制数据结构的方法。我的这段简化的程序只能处理PCM格式的RIFF音频文件(这也是最常见的wav格式) ,不限声道,但是比特率(BitsPerSample)最好是16。

  这里有wave file format 和 MicroSoft wave soundfile format可以参考。这里是一个实际的例子(下载放大看)


  1   2

  3 function wav_graph($file, $f=0, $w=0)

  4 {

  5 global $DATA_DIR;

  6

  7 if(!is_file($file)) return 0;

  8 $fp = fopen($DATA_DIR.$file, 'r');

  9 $raw = fread($fp, 36);

  10 $str = '';

  11 $header = unpack('A4Riff/VSize/A4Wav/A4Head/VHeadSize/vPCM/vChannels/VSampleRate/VByteRate/vBlockAlign/vSampleBits', $raw);

  12 foreach($header as $k=>$v)

  13 $str .= $k.': '. $v.' ';

  14 fseek($fp, 36 + $header['HeadSize'] - 16);

  15 $raw = fread($fp, 8);

  16 $data = unpack('A4Data/VDataSize', $raw);

  17 foreach($data as $k=>$v)

  18 $str .= $k.': '. $v.' ';

  19

  20 $b = $header['SampleBits'];

  21 $c = $header['Channels'];

  22 $l = $b * $c / 8; // sample frame length in bytes

  23 $s = $data['DataSize'] / $l; // total number of samples

  24 $r = $header['SampleRate'];

  25 if($f) $h = pow(2, $b) / $f;

  26 else { $h = 200; $f = pow(2, $b - 1) / $h; }

  27 if($w == 0) $w = round($r / 1000); // default to show 1k sample frames per minute

  28

  29 header("Content-type: image/png");

  30 $im = imagecreate($s / $w, $h * $c * 2);

  31 imagecolorallocate($im, 0xff, 0xff, 0xff); // white bg

  32 $color = imagecolorallocate($im, 0, 0, 255); // black

  33 //imagestring($im, 5, 5, 5, $str, $color);

  34

  35 $x=0; $y = array(); $yn = array();

  36 for($i = 0; $i < $c; $i++) $y[$i] = $h * $i + $h;

  37 $n = $l * $w;

  38 while(1)

  39 {

  40 if($s == 0) break;

  41 if($s < $n) $n = $s;

  42 $samples = fread($fp, 1000 * $n);

  43 if($samples === FALSE) break;

  44 $packed = unpack("s*", $samples);

  45 foreach($packed as $k=>$v)

  46 {

  47 $cnt = ($k-1) % ($w * $l) ;

  48 if( $cnt > $c - 1) continue;

  49 $yn[$cnt] = $h * $cnt + $h - $v / $f;

  50 imageline($im, $x, $y[$cnt], $x+1, $yn[$cnt], $color);

  51 $y[$cnt] = $yn[$cnt];

  52 $x++;

  53 }

  54 $s -= $n;

  55 }

  56

  57 imagepng($im);

  58 imagedestroy($im);

  59 }

  60

  61 //wav_graph('audio2.wav');

  62 ?>





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.