Hello all,
I am trying to unpack big wav file (more than 10 mb), because i want to generate Visualization of an wav file, for smaller files (less than 2 mb) it works fine, but for bigger files it gives Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 35 bytes) in /var/www/phptest/mp3processor/thescript.php on line 64
I am pesting the code below
PLEASE HELP
==================== - <?
-
class wavVisualization{
-
var $afiles = array();
-
var $arrData = array();
-
var $wavs = array();
-
-
function wavVisualization(){}
-
-
function loadFile($filenam){
-
$content = file_get_contents($filenam) or die("HALT");
-
$this->getStructure($content);
-
$this->afiles['structure'] = $this->wavs;
-
$this->unpackData($this->wavs['Data']);
-
}
-
-
//== Get structure of wav file ==//
-
function getStructure($binstr){
-
$this->wavs['ChunkID'] = substr($binstr,0,4);
-
$this->wavs['ChunkSize'] = $this->unpackHeader(substr($binstr,4,4));
-
$this->wavs['Format'] = substr($binstr,8,4);
-
$this->wavs['Subchunk1ID'] = substr($binstr,12,4);
-
$this->wavs['SubChunk1Size'] = $this->unpackHeader(substr($binstr,16,4));
-
$this->wavs['AudioFormat'] = $this->unpackHeader(substr($binstr,20,2));
-
$this->wavs['NumChannels'] = $this->unpackHeader(substr($binstr,22,2));
-
$this->wavs['SampleRate'] = $this->unpackHeader(substr($binstr,24,4));
-
$this->wavs['ByteRate'] = $this->unpackHeader(substr($binstr,28,4));
-
$this->wavs['BlockAlign'] = $this->unpackHeader(substr($binstr,32,2));
-
$this->wavs['BitsPerSample'] = $this->unpackHeader(substr($binstr,34,2));
-
-
//check extra format bytes
-
if($this->wavs['SubChunk1Size']==16){
-
$this->wavs['Subchunk2ID'] = substr($binstr,36,4);
-
$this->wavs['SubChunk2Size'] = $this->unpackHeader(substr($binstr,40,4));
-
$this->wavs['Data']= substr($binstr,44,strlen($binstr));
-
}
-
elseif($this->wavs['SubChunk1Size']==18){
-
$this->wavs['ExtraFormatBytes'] = substr($binstr,36,2);
-
$this->wavs['Subchunk2ID'] = substr($binstr,38,4);
-
$this->wavs['SubChunk2Size'] = $this->unpackHeader(substr($binstr,42,4));
-
$this->wavs['Data']= substr($binstr,46,strlen($binstr));
-
}
-
$this->wavs['NumberSamples']= ($this->wavs['SubChunk2Size']*8)/($this->wavs['NumChannels']*$this->wavs['BitsPerSample']);
-
}
-
-
-
//== Get Decimal Values ==//
-
function unpackHeader($str,$opt=""){
-
if(strlen($str)>2){
-
$arr = unpack("V*",$str);
-
}
-
else{
-
$arr = unpack("v*",$str);
-
}
-
return $arr[1];
-
}
-
-
-
//== unpackData ==//
-
function unpackData($strbin){
-
if($this->wavs['BlockAlign']==1){
-
return unpack("C*",$strbin); //unsign Character
-
}
-
else{
-
return unpack("s*",$strbin); //sign int16 //error occuring here//
-
}
-
}
-
}
-
?>
-
<?php
-
$srcaudio="temp_audio_store/lal_1192620354.wav"; //==An WAV file more than 10 mb==//
-
$audViz = new wavVisualization();
-
$audViz->loadFile($srcaudio);
-
?>
1 1759
Heya, santrooper. Welcome to TSDN!
You're getting an out-of-memory error.
Probably the best way to circumvent this would be to load the file in 2 MB chunks using the fread() function.
Of course, in order to avoid out-of-memory errors, you'll also need to keep writing your temporary data to a file as you process. This will slow down your script significantly, so be sure to check the size of the file first.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Penn Markham |
last post by:
Hello all,
I am writing a script where I need to use the system() function to call
htpasswd. I can do this just fine on the command line...works great
(see attached file, test.php). When my...
|
by: Geoffrey |
last post by:
Hope someone can help.
I am trying to read data from a file binary file and then unpack the
data into python variables. Some of the data is store like this;
xbuffer:...
|
by: grant |
last post by:
Hi All,
I am pretty new to python and am having a problem
intepreting binary data using struct.unpack.
I am reading a file containing binary packed data
using open with "rb". All the values are...
|
by: Elezar Simeon Papo |
last post by:
Hello All,
I have a tab separated input file (data.txt) in text format - the file
looks like this
SCHOOL DEPART1 DEPART2 DEPART3
Harvard Economics Mathematics Physics...
|
by: Andrew Robert |
last post by:
Hey everyone,
Maybe you can see something I don't.
I need to convert a working piece of perl code to python.
The perl code is:
sub ParseTrig {
|
by: f rom |
last post by:
----- Forwarded Message ----
From: Josiah Carlson <jcarlson@uci.edu>
To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org
Sent: Monday, December 4, 2006 10:03:28 PM
Subject: Re: ...
|
by: Ping Zhao |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I am writing a small program to decode MS bitmap image. When I use statements as follow, it works fine:
header = str(struct.unpack('2s',...
|
by: JRough |
last post by:
I have used this function to create a string called $headers:
function GetHeaders($file_name){
return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th>
<th><a...
|
by: JRough |
last post by:
I have used this function to create a string called $headers:
function GetHeaders($file_name){
return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th>
<th><a href='"....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |