Changeset 5894

Show
Ignore:
Timestamp:
07/03/08 13:11:15 (3 months ago)
Author:
ethans
Message:

Per discussion with Philippe:

I am commiting this because I am leaving for vacation. The changes in here remove the option of transcoding a wav to mp3 (why?) and
force transcoding of mp3s to wavs and transcoding of wavs to acceptable wavs. As discussed with Philippe, this requires sox and
mpg123 to be installed, so there should be a amportal.conf configuration for disabling this functionality if the user doesn't have or
doesn't want to install mpg123 (should be rare).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.5/music/page.music.php

    r5658 r5894  
    174174} 
    175175 
    176 function process_mohfile($mohfile,$onlywav=false
     176function process_mohfile($mohfile,$onlywav=false,$volume=false
    177177{ 
    178178        global $path_to_dir; 
    179179        $output = 0; 
    180180        $returncode = 0; 
    181  
    182181        $origmohfile=$path_to_dir."/orig_".$mohfile; 
    183         $newname = strtr($mohfile,"&", "_"); 
    184         if(strstr($newname,".mp3")) { 
    185                 $onlywav = false; 
    186         } 
    187         if(!$onlywav) { 
    188                 $newmohfile=$path_to_dir."/". ((strpos($newname,'.mp3') === false) ? $newname.".mp3" : $newname); 
    189                 $lamecmd="lame --cbr -m m -t -F \"".$origmohfile."\" \"".$newmohfile."\" 2>&1 "; 
    190                 if (strpos($newmohfile,'.mp3') !== false)  
    191                         exec($lamecmd, $output, $returncode); 
    192                 } else { 
    193                         $newmohfile = $path_to_dir."/wav_".$newname; 
    194                         $soxcmd = "sox \"".$origmohfile."\" -r 8000 -c 1 \"".$newmohfile."\" "; 
    195                         $soxresample = "resample -ql "; 
    196                         exec($soxcmd.$soxresample."2>&1", $output, $returncode); 
    197                         if ($returncode != 0) { 
    198                                 // try it again without the resample in case the input sample rate was the same 
    199                                 // 
    200                                 exec("rm -rf \"".$newmohfile."\""); 
    201                                 exec($soxcmd."2>&1", $output, $returncode); 
    202                         } 
    203                 } 
     182        if($onlywav) { 
     183                $newname = substr($mohfile,0,strrpos($mohfile,".")); 
     184 
     185                // If we are dealing with an MP3, we need to decode it to a wav file 
     186                if (strpos($origmohfile,'.mp3') !== false)  {  
     187                        //$lamecmd="lame --cbr -m m -t -F --decode \"".$origmohfile."\" \"".substr($origmohfile,0,strrpos($origmohfile,".")).".wav\" 2>&1 "; 
     188                       // exec($lamecmd, $output, $returncode); 
     189                        $mpg123cmd = "mpg123 -w \"".substr($origmohfile,0,strrpos($origmohfile,".")).".wav\" \"".$origmohfile."\" 2>&1 "; 
     190                        exec($mpg123cmd, $output, $returncode); 
     191                } 
     192                $newmohfile = $path_to_dir."/wav_".$newname.".wav"; 
     193                //asdf 
     194                $soxcmd = "sox \"".substr($origmohfile,0,strrpos($origmohfile,".")).".wav\""; 
     195                if($volume) 
     196                  $soxcmd .= " -v ".$volume; 
     197                $soxcmd .= " -r 8000 -c 1 \"".$newmohfile."\" "; 
     198                $soxresample = "resample -ql "; 
     199                exec($soxcmd.$soxresample."2>&1", $output, $returncode); 
     200                if ($returncode != 0) { 
     201                        // try it again without the resample in case the input sample rate was the same 
     202                        // 
     203                        exec("rm -rf \"".$newmohfile."\""); 
     204                        exec($soxcmd."2>&1", $output, $returncode); 
     205                } 
     206        } 
    204207        if ($returncode != 0) { 
    205208                return join("<br>\n", $output); 
     
    207210        $rmcmd="rm -f \"". $origmohfile."\""; 
    208211        exec($rmcmd); 
     212        // If this started as an mp3, we converted it to a wav and then transcoded it from there, so we have two "original" files to delete 
     213        if (strpos($origmohfile,'.mp3') !== false)  { 
     214                $rmcmd="rm -f \"". substr($origmohfile,0,strrpos($origmohfile,".")).".wav\""; 
     215                exec($rmcmd); 
     216 
     217        } 
     218 
    209219        return null; 
    210220} 
     
    280290                <input type="button" value="<?php echo _("Upload")?>" onclick="document.upload.submit(upload);alert('<?php echo addslashes(_("Please wait until the page loads. Your file is being processed."))?>');"/> 
    281291                <br /> 
    282                 <input type="checkbox" name="onlywav" checked="checked"><small><?php echo _("Do not encode wav to mp3"); ?></small> 
     292                <select name="volume"> 
     293                        <option value="1.50">Volume 150%</option> 
     294                        <option value="1.25">Volume 125%</option> 
     295                        <option value="" selected>Volume 100%</option> 
     296                        <option value=".75">Volume 75%</option> 
     297                        <option value=".5">Volume 50%</option> 
     298                        <option value=".25">Volume 25%</option> 
     299                        <option value=".1">Volume 10%</option> 
     300                </select> 
     301                <small><?php echo _("Volume adjustments are done linearly, therefore 50% will not be exactly 'half volume'"); ?></small> 
    283302        </form> 
    284303        <br /> 
     
    306325                //echo $_FILES['mohfile']['name']." uploaded OK"; 
    307326                move_uploaded_file($_FILES['mohfile']['tmp_name'], $path_to_dir."/orig_".$_FILES['mohfile']['name']); 
    308  
    309                 $process_err = process_mohfile($_FILES['mohfile']['name'],($_REQUEST['onlywav'] != '')); 
     327                $process_err = process_mohfile($_FILES['mohfile']['name'],true,$_REQUEST['volume']); 
    310328 
    311329                if (isset($process_err)) { 
Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads