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

Add stereo option to webform generate. #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions Waveform.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ public function getDuration()
* @param int $width Width of the image file in pixels
* @param int $height Height of the image file in pixels
* @param bool $onePhase `true` to get positive values only, `false` to get both phases
* @param bool $stereo `true` to generate 2 waveforms, `false` to a single 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;
Expand Down Expand Up @@ -149,6 +150,9 @@ public function getWaveform($filename, $width, $height, $onePhase = false)
}

// Drawing channel 1
if (!$stereo) {
$center1 = $height / 2;
}
for ($i = 0; $i < count($lines1); $i += 2) {
$x = $i / 2 / self::$linesPerPixel;
if ($onePhase) {
Expand All @@ -161,21 +165,23 @@ public function getWaveform($filename, $width, $height, $onePhase = false)
}
}
// 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) {
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);
}
}
}

// Axis
imageline($img, 0, $center1, $width - 1, $center1, $axis);
if ($center2 !== null) {
if ($stereo && $center2 !== null) {
imageline($img, 0, $center2, $width - 1, $center2, $axis);
}

Expand Down