Open priteshmahajan1806 opened 4 years ago
@priteshmahajan1806, you’re working with the stereo signal, that’s why you have two channels in the generated waveform. Those are left and right channels.
Hi, I run in the same problem, and I just modify the getWaveform() method to only have first channel in stereo mode :
--- a/Waveform.php
+++ b/Waveform.php
@@ -119,7 +119,7 @@ class Waveform
* @return bool Returns `true` on success or `false` on failure.
* @throws \Exception
*/
- public function getWaveform($filename, $width, $height, $onePhase = false)
+ public function getWaveform($filename, $width, $height, $onePhase = false, $stereo = true)
{
// Calculating parameters
$needChannels = $this->getChannels() > 1 ? 2 : 1;
@@ -148,8 +148,9 @@ class Waveform
$center1 = $needChannels === 2 ? ($height / 2 - 1) / 2 : $height / 2;
$center2 = $needChannels === 2 ? $height - $center1 : null;
}
-
- // Drawing channel 1
+ if (!$stereo) {
+ $center1 = $height / 2;
+ }
for ($i = 0; $i < count($lines1); $i += 2) {
$x = $i / 2 / self::$linesPerPixel;
if ($onePhase) {
@@ -161,16 +162,18 @@ class Waveform
imageline($img, $x, $center1 - $min * $center1, $x, $center1 - $max * $center1, $color);
}
}
- // Drawing channel 2
- for ($i = 0; $i < count($lines2); $i += 2) {
- $x = $i / 2 / self::$linesPerPixel;
- if ($onePhase) {
- $max = max($lines2[$i], $lines2[$i + 1]);
- imageline($img, $x, $center2, $x, $center2 - $max * $center1, $color);
- } else {
- $min = $lines2[$i];
- $max = $lines2[$i + 1];
- imageline($img, $x, $center2 - $min * $center1, $x, $center2 - $max * $center1, $color);
+ if ($stereo) {
+ // Drawing channel 2
+ for ($i = 0; $i < count($lines2); $i += 2) {
+ $x = $i / 2 / self::$linesPerPixel;
+ if ($onePhase) {
+ $max = max($lines2[$i], $lines2[$i + 1]);
+ imageline($img, $x, $center2, $x, $center2 - $max * $center1, $color);
+ } else {
+ $min = $lines2[$i];
+ $max = $lines2[$i + 1];
+ imageline($img, $x, $center2 - $min * $center1, $x, $center2 - $max * $center1, $color);
+ }
}
}
@DrMickArtisan, I think it needs to be configurable, otherwise we’ll break the current intended behaviour.
Doesn't the line: public function getWaveform($filename, $width, $height, $onePhase = false, $stereo = true) make it configureable? I literally just started using this and we are actively talking about it.
The posted patch doesn't account for the 2nd axis line though...
Added this pull request: https://github.com/maximal/audio-waveform-php/pull/9
I am using this code. This code will create 2 wave form in single image Please check screenshot.
Created : https://prnt.sc/tqkmdp I need only : https://prnt.sc/tqklds
I have passed required params as well but still create 2 images