Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why create 2 wave forms #8

Open
priteshmahajan1806 opened this issue Jul 29, 2020 · 6 comments
Open

Why create 2 wave forms #8

priteshmahajan1806 opened this issue Jul 29, 2020 · 6 comments

Comments

@priteshmahajan1806
Copy link

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

@maximal
Copy link
Owner

maximal commented Jan 27, 2022

@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.

@DrMickArtisan
Copy link

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);
+                }
             }
         } 

@maximal
Copy link
Owner

maximal commented Dec 22, 2023

@DrMickArtisan, I think it needs to be configurable, otherwise we’ll break the current intended behaviour.

@webdobe
Copy link

webdobe commented Dec 22, 2023

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.

@webdobe
Copy link

webdobe commented Dec 22, 2023

The posted patch doesn't account for the 2nd axis line though...

@webdobe
Copy link

webdobe commented Dec 22, 2023

Added this pull request: #9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants