Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/boyhagemann/Waveform

A php package that can generate waveforms based on a WAV file
https://github.com/boyhagemann/Waveform

Last synced: 7 days ago
JSON representation

A php package that can generate waveforms based on a WAV file

Awesome Lists containing this project

README

        

Waveform
========

This package creates a waveform, based on the [BoyHagemann\Wave](http://github.com/boyhagemann/Wave) class. It will have several generators to present the waveform.

![An example of a generated waveform](https://raw.github.com/boyhagemann/Waveform/master/data/waveform-example.png)
## Install

You can install with composer using the following lines in your composer.json file:
```json
"minimum-stability": "dev",
"require": {
"boyhagemann/waveform": "dev-master"
}
```

## How to use

The most basic way to generate a waveform is like this. It has a default width of 500 pixels and a height of 200 pixels.
```php
setGenerator(new Generator\Png)
->setWidth(960)
->setHeight(400);

// Will display the image, including setting the read image/png header
echo $waveform->generate();
```

### Generate a html/css based waveform

```php
setGenerator(new Generator\Html)
->setWidth(960)
->setHeight(400);

$waveformHtml = $waveform->generate();

?>


#waveform {
float: left;
position: relative;
height: 400px;
width: 960px;
}
span {
position: absolute;
display: block;
width: 1px;
background: #ddd;
float: left;
bottom: 0;
}









```

### Generate an svg based waveform
```php
setGenerator(new Generator\Svg)

$waveformSvg = $waveform->generate();

\\do something, e.g. save it to a file
file_put_contents ('the/path/to/result/file.svg', $waveformSvg);

```

## Maximize
By default, the wave amplitude data is maximized to match the height you set for the waveform.
This means that if you set the height to 200, then the waveform is maximized to 200 pixels.
The result is a nice looking waveform regardless of the overall loudness.
Don't want this nifty feature? You can change the behaviour with one simple line of code:
```php
$waveform->setMaximized(false); // defaults to true
```

## Get wave metadata

You have access to all the wave metadata.
The only thing you have to do is retrieving the original Wave object and get the desired information.
Form more detailed information see [BoyHagemann\Wave documentation](https://github.com/boyhagemann/Wave/blob/master/README.md).
```php
$wave = $waveform->getWave();
$metadata = $wave->getMetadata();
$metadata->getSampleRate();
$metadata->getBitsPerSample();
```

## To do

- [X] Add png generator
- [ ] Add svg generator
- [ ] Allow different bits per sample (8, 16, 24, 32)