Skip to content

Commit 76cd6b8

Browse files
committed
Added docs about one-phase (positive only) mode (#4)
1 parent 8a87e52 commit 76cd6b8

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

Waveform.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
namespace maximal\audio;
1818

19+
/**
20+
* Waveform class allows you to get waveform data and images from audio files
21+
* @package maximal\audio
22+
*/
1923
class Waveform
2024
{
2125
protected $filename;
@@ -105,6 +109,15 @@ public function getDuration()
105109
return $this->duration;
106110
}
107111

112+
/**
113+
* Get waveform from the audio file.
114+
* @param string $filename Audio file name
115+
* @param int $width Width of the image file in pixels
116+
* @param int $height Height of the image file in pixels
117+
* @param bool $onePhase `true` to get positive values only, `false` to get both phases
118+
* @return bool Returns `true` on success or `false` on failure.
119+
* @throws \Exception
120+
*/
108121
public function getWaveform($filename, $width, $height, $onePhase = false)
109122
{
110123
// Calculating parameters
@@ -169,6 +182,13 @@ public function getWaveform($filename, $width, $height, $onePhase = false)
169182
return imagepng($img, $filename);
170183
}
171184

185+
/**
186+
* Get waveform data from the audio file.
187+
* @param int $width Desired width of the image file in pixels
188+
* @param bool $onePhase `true` to get positive values only, `false` to get both phases
189+
* @return array
190+
* @throws \Exception
191+
*/
172192
public function getWaveformData($width, $onePhase = false)
173193
{
174194
// Calculating parameters

one-phase-mono.png

6.53 KB
Loading

one-phase-stereo.png

12.7 KB
Loading

readme.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ $waveform = new Waveform('track.mp3');
4848
$success = $waveform->getWaveform('thumbnail.png', 1024, 512);
4949
```
5050

51+
### One Phase
52+
To get positive waveform only (i.e. one phase) pass `onePhase` parameter set to `true`:
53+
```php
54+
$waveform->getWaveform('one-phase.png', 800, 400, true);
55+
```
56+
57+
Stereo source:
58+
59+
![One phase stereo](one-phase-stereo.png)
60+
61+
Mono source:
62+
63+
![One phase stereo](one-phase-mono.png)
64+
5165

5266
## Settings
5367

@@ -116,6 +130,12 @@ $data = $waveform->getWaveformData($width);
116130
// $data['lines1'] and $data['lines2'] now have the waveform data for channels 1 and 2
117131
```
118132

133+
To get positive values only (i.e. one phase) pass `onePhase` parameter set to `true`:
134+
135+
```php
136+
$data = $waveform->getWaveformData($width, true);
137+
```
138+
119139

120140
## Contact the author
121141

0 commit comments

Comments
 (0)