Public Member Functions | |
__construct ($numChannelsOrFileName=null, $sampleRateOrReadData=null, $bitsPerSample=null) | |
__clone () | |
__toString () | |
getActualSize () | |
getChunkSize () | |
getFmtChunkSize () | |
getFmtExtendedSize () | |
getFactChunkSize () | |
getDataSize () | |
getDataOffset () | |
getAudioFormat () | |
getAudioSubFormat () | |
getNumChannels () | |
setNumChannels ($numChannels) | |
getChannelMask () | |
setChannelMask ($channelMask=self::SPEAKER_DEFAULT) | |
getSampleRate () | |
setSampleRate ($sampleRate) | |
getBitsPerSample () | |
setBitsPerSample ($bitsPerSample) | |
getValidBitsPerSample () | |
getBlockAlign () | |
getNumBlocks () | |
getByteRate () | |
getSamples () | |
setSamples (&$samples= '') | |
getMinAmplitude () | |
getZeroAmplitude () | |
getMaxAmplitude () | |
makeHeader () | |
getDataSubchunk () | |
save ($filename) | |
openWav ($filename, $readData=true) | |
closeWav () | |
setWavData (&$data, $free=true) | |
readWavData ($dataOffset=0, $dataSize=null) | |
getSampleBlock ($blockNum) | |
setSampleBlock ($sampleBlock, $blockNum) | |
getSampleValue ($blockNum, $channelNum) | |
setSampleValue ($sampleFloat, $blockNum, $channelNum) | |
filter ($filters, $blockOffset=0, $numBlocks=null) | |
appendWav (WavFile $wav) | |
mergeWav (WavFile $wav, $normalizeThreshold=null) | |
insertSilence ($duration=1.0) | |
degrade ($quality=1.0) | |
generateNoise ($duration=1.0, $percent=100) | |
convertBitsPerSample ($bitsPerSample) | |
displayInfo () |
Static Public Member Functions | |
static | unpackSample ($sampleBinary, $bitDepth=null) |
static | packSample ($sample, $bitDepth) |
static | unpackSampleBlock ($sampleBlock, $bitDepth, $numChannels=null) |
static | packSampleBlock ($samples, $bitDepth) |
static | normalizeSample ($sampleFloat, $threshold) |
Public Attributes | |
const | FILTER_MIX = 0x01 |
const | FILTER_NORMALIZE = 0x02 |
const | FILTER_DEGRADE = 0x04 |
const | MAX_CHANNEL = 18 |
const | MAX_SAMPLERATE = 192000 |
const | SPEAKER_DEFAULT = 0x000000 |
const | SPEAKER_FRONT_LEFT = 0x000001 |
const | SPEAKER_FRONT_RIGHT = 0x000002 |
const | SPEAKER_FRONT_CENTER = 0x000004 |
const | SPEAKER_LOW_FREQUENCY = 0x000008 |
const | SPEAKER_BACK_LEFT = 0x000010 |
const | SPEAKER_BACK_RIGHT = 0x000020 |
const | SPEAKER_FRONT_LEFT_OF_CENTER = 0x000040 |
const | SPEAKER_FRONT_RIGHT_OF_CENTER = 0x000080 |
const | SPEAKER_BACK_CENTER = 0x000100 |
const | SPEAKER_SIDE_LEFT = 0x000200 |
const | SPEAKER_SIDE_RIGHT = 0x000400 |
const | SPEAKER_TOP_CENTER = 0x000800 |
const | SPEAKER_TOP_FRONT_LEFT = 0x001000 |
const | SPEAKER_TOP_FRONT_CENTER = 0x002000 |
const | SPEAKER_TOP_FRONT_RIGHT = 0x004000 |
const | SPEAKER_TOP_BACK_LEFT = 0x008000 |
const | SPEAKER_TOP_BACK_CENTER = 0x010000 |
const | SPEAKER_TOP_BACK_RIGHT = 0x020000 |
const | SPEAKER_ALL = 0x03FFFF |
const | WAVE_FORMAT_PCM = 0x0001 |
const | WAVE_FORMAT_IEEE_FLOAT = 0x0003 |
const | WAVE_FORMAT_EXTENSIBLE = 0xFFFE |
const | WAVE_SUBFORMAT_PCM = "0100000000001000800000aa00389b71" |
const | WAVE_SUBFORMAT_IEEE_FLOAT = "0300000000001000800000aa00389b71" |
Protected Member Functions | |
setActualSize ($actualSize=null) | |
setChunkSize ($chunkSize=null) | |
setFmtChunkSize ($fmtChunkSize=null) | |
setFmtExtendedSize ($fmtExtendedSize=null) | |
setFactChunkSize ($factChunkSize=null) | |
setDataSize ($dataSize=null) | |
setDataOffset ($dataOffset=null) | |
setAudioFormat ($audioFormat=null) | |
setAudioSubFormat ($audioSubFormat=null) | |
setValidBitsPerSample ($validBitsPerSample=null) | |
setBlockAlign ($blockAlign=null) | |
setNumBlocks ($numBlocks=null) | |
setByteRate ($byteRate=null) | |
readWav ($readData=true) | |
readWavHeader () |
Static Protected Attributes | |
static | $LOOKUP_LOGBASE |
Definition at line 66 of file WavFile.php.
WavFile::__construct | ( | $numChannelsOrFileName = null , |
|
$sampleRateOrReadData = null , |
|||
$bitsPerSample = null |
|||
) |
WavFile Constructor.
$wav1 = new WavFile(2, 44100, 16); // new wav with 2 channels, at 44100 samples/sec and 16 bits per sample $wav2 = new WavFile('./audio/sound.wav'); // open and read wav file
string | int | $numChannelsOrFileName | (Optional) If string, the filename of the wav file to open. The number of channels otherwise. Defaults to 1. |
int | bool | $sampleRateOrReadData | (Optional) If opening a file and boolean, decides whether to read the data chunk or not. Defaults to true. The sample rate in samples per second otherwise. 8000 = standard telephone, 16000 = wideband telephone, 32000 = FM radio and 44100 = CD quality. Defaults to 8000. |
int | $bitsPerSample | (Optional) The number of bits per sample. Has to be 8, 16 or 24 for PCM audio or 32 for IEEE FLOAT audio. 8 = telephone, 16 = CD and 24 or 32 = studio quality. Defaults to 8. |
WavFormatException | |
WavFileException |
Definition at line 218 of file WavFile.php.
References openWav(), and SPEAKER_DEFAULT.
WavFile::__toString | ( | ) |
Output the wav file headers and data.
Definition at line 266 of file WavFile.php.
References getDataSubchunk(), and makeHeader().
WavFile::appendWav | ( | WavFile | $wav | ) |
Append a wav file to the current wav.
The wav files must have the same sample rate, number of bits per sample, and number of channels.
WavFile | $wav | (Required) The wav file to append. |
WavFileException |
Definition at line 1675 of file WavFile.php.
WavFile::closeWav | ( | ) |
Close a with openWav() previously opened wav file or free the buffer of setWavData(). Not necessary if the data has been read (readData = true) already.
Definition at line 950 of file WavFile.php.
Referenced by openWav(), readWav(), readWavData(), and setWavData().
WavFile::convertBitsPerSample | ( | $bitsPerSample | ) |
Convert sample data to different bits per sample.
int | $bitsPerSample | (Required) The new number of bits per sample; |
WavFileException |
Definition at line 1776 of file WavFile.php.
WavFile::degrade | ( | $quality = 1.0 | ) |
Degrade the quality of the wav file by introducing random noise.
float | quality (Optional) The quality relative to the amplitude. 1 = no noise, 0 = max. noise. |
Definition at line 1733 of file WavFile.php.
References filter().
WavFile::displayInfo | ( | ) |
Output information about the wav object.
Definition at line 1803 of file WavFile.php.
WavFile::filter | ( | $filters, | |
$blockOffset = 0 , |
|||
$numBlocks = null |
|||
) |
Run samples through audio processing filters.
$wav->filter( array( WavFile::FILTER_MIX => array( // Filter for mixing 2 WavFile instances. 'wav' => $wav2, // (Required) The WavFile to mix into this WhavFile. If no optional arguments are given, can be passed without the array. 'loop' => true, // (Optional) Loop the selected portion (with warping to the beginning at the end). 'blockOffset' => 0, // (Optional) Block number to start mixing from. 'numBlocks' => null // (Optional) Number of blocks to mix in or to select for looping. Defaults to the end or all data for looping. ), WavFile::FILTER_NORMALIZE => 0.6, // (Required) Normalization of (mixed) audio samples - see threshold parameter for normalizeSample(). WavFile::FILTER_DEGRADE => 0.9 // (Required) Introduce random noise. The quality relative to the amplitude. 1 = no noise, 0 = max. noise. ), 0, // (Optional) The block number of this WavFile to start with. null // (Optional) The number of blocks to process. );
array | $filters | (Required) An array of 1 or more audio processing filters. |
int | $blockOffset | (Optional) The block number to start precessing from. |
int | $numBlocks | (Optional) The maximum number of blocks to process. |
WavFileException |
Definition at line 1568 of file WavFile.php.
References getSampleValue(), normalizeSample(), and setSampleValue().
Referenced by degrade(), and mergeWav().
WavFile::generateNoise | ( | $duration = 1.0 , |
|
$percent = 100 |
|||
) |
Generate noise at the end of the wav for the specified duration and volume.
float | $duration | (Optional) Number of seconds of noise to generate. |
float | $percent | (Optional) The percentage of the maximum amplitude to use. 100 = full amplitude. |
Definition at line 1746 of file WavFile.php.
WavFile::getDataSubchunk | ( | ) |
Construct wav DATA chunk.
Definition at line 881 of file WavFile.php.
Referenced by __toString(), and save().
WavFile::getSampleBlock | ( | $blockNum | ) |
Return a single sample block from the file.
int | $blockNum | (Required) The sample block number. Zero based. |
Definition at line 1316 of file WavFile.php.
WavFile::getSampleValue | ( | $blockNum, | |
$channelNum | |||
) |
Get a float sample value for a specific sample block and channel number.
int | $blockNum | (Required) The sample block number to fetch. Zero based. |
int | $channelNum | (Required) The channel number within the sample block to fetch. First channel is 1. |
WavFileException |
Definition at line 1386 of file WavFile.php.
Referenced by filter().
WavFile::insertSilence | ( | $duration = 1.0 | ) |
Add silence to the wav file.
float | $duration | (Optional) How many seconds of silence. If negative, add to the beginning of the file. Defaults to 1s. |
Definition at line 1711 of file WavFile.php.
WavFile::makeHeader | ( | ) |
Construct a wav header from this object. Includes "fact" chunk in necessary. http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/wave.html
Definition at line 837 of file WavFile.php.
Referenced by __toString(), and save().
WavFile::mergeWav | ( | WavFile | $wav, |
$normalizeThreshold = null |
|||
) |
Mix 2 wav files together.
Both wavs must have the same sample rate and same number of channels.
WavFile | $wav | (Required) The WavFile to mix. |
float | $normalizeThreshold | (Optional) See normalizeSample for an explanation. |
WavFileException |
Definition at line 1699 of file WavFile.php.
References filter().
|
static |
Normalizes a float audio sample. Maximum input range assumed for compression is [-2, 2]. See http://www.voegler.eu/pub/audio/ for more information.
float | $sampleFloat | (Required) The float sample to normalize. |
float | $threshold | (Required) The threshold or gain factor for normalizing the amplitude.
|
Definition at line 416 of file WavFile.php.
Referenced by filter().
WavFile::openWav | ( | $filename, | |
$readData = true |
|||
) |
Reads a wav header and data from a file.
string | $filename | (Required) The path to the wav file to read. |
bool | $readData | (Optional) If true, also read the data chunk. |
WavFormatException | |
WavFileException |
Definition at line 924 of file WavFile.php.
References closeWav(), and readWav().
Referenced by __construct().
|
static |
Packs a single numeric sample to binary.
int | float | $sample | (Required) The sample to encode. Has to be within valid range for $bitDepth. Float values only for 32 bits. |
int | $bitDepth | (Required) The bits per sample to encode with. |
Definition at line 329 of file WavFile.php.
Referenced by packSampleBlock().
|
static |
Packs an array of numeric channel samples to a binary sample block.
array | $samples | (Required) The array of channel sample values. Expects float values for 32 bits and integer otherwise. |
int | $bitDepth | (Required) The bits per sample to encode with. |
Definition at line 389 of file WavFile.php.
References packSample().
|
protected |
Read wav file from a stream.
$readData | (Optional) If true, also read the data chunk. |
WavFormatException | |
WavFileException |
Definition at line 994 of file WavFile.php.
References closeWav(), readWavData(), and readWavHeader().
Referenced by openWav(), and setWavData().
WavFile::readWavData | ( | $dataOffset = 0 , |
|
$dataSize = null |
|||
) |
Read the wav data from the file into the buffer.
$dataOffset | (Optional) The byte offset to skip before starting to read. Must be a multiple of BlockAlign. |
$dataSize | (Optional) The size of the data to read in bytes. Must be a multiple of BlockAlign. Defaults to all data. |
WavFileException |
Definition at line 1275 of file WavFile.php.
References closeWav().
Referenced by readWav().
|
protected |
Parse a wav header. http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/wave.html
WavFormatException | |
WavFileException |
Definition at line 1019 of file WavFile.php.
Referenced by readWav().
WavFile::save | ( | $filename | ) |
Save the wav data to a file.
string | $filename | (Required) The file path to save the wav to. |
WavFileException |
Definition at line 902 of file WavFile.php.
References getDataSubchunk(), and makeHeader().
WavFile::setSampleBlock | ( | $sampleBlock, | |
$blockNum | |||
) |
Set a single sample block.
Allows to append a sample block.
string | $sampleBlock | (Required) The binary sample block (all channels). |
int | $blockNum | (Required) The sample block number. Zero based. |
WavFileException |
Definition at line 1341 of file WavFile.php.
WavFile::setSampleValue | ( | $sampleFloat, | |
$blockNum, | |||
$channelNum | |||
) |
Sets a float sample value for a specific sample block number and channel.
Converts float values to appropriate integer values and clips properly.
Allows to append samples (in order).
float | $sampleFloat | (Required) The float sample value to set. Converts float values and clips if necessary. |
int | $blockNum | (Required) The sample block number to set or append. Zero based. |
int | $channelNum | (Required) The channel number within the sample block to set or append. First channel is 1. |
WavFileException |
Definition at line 1450 of file WavFile.php.
Referenced by filter().
WavFile::setWavData | ( | & | $data, |
$free = true |
|||
) |
Set the wav file data and properties from a wav file in a string.
string | $data | (Required) The wav file data. Passed by reference. |
bool | $free | (Optional) True to free the passed $data after copying. |
WavFormatException | |
WavFileException |
Definition at line 964 of file WavFile.php.
References closeWav(), and readWav().
|
static |
Unpacks a single binary sample to numeric value.
string | $sampleBinary | (Required) The sample to decode. |
int | $bitDepth | (Optional) The bits per sample to decode. If omitted, derives it from the length of $sampleBinary. |
Definition at line 283 of file WavFile.php.
Referenced by unpackSampleBlock().
|
static |
Unpacks a binary sample block to numeric values.
string | $sampleBlock | (Required) The binary sample block (all channels). |
int | $bitDepth | (Required) The bits per sample to decode. |
int | $numChannels | (Optional) The number of channels to decode. If omitted, derives it from the length of $sampleBlock and $bitDepth. |
Definition at line 367 of file WavFile.php.
References unpackSample().
|
staticprotected |
Definition at line 130 of file WavFile.php.
const WavFile::SPEAKER_DEFAULT = 0x000000 |
Channel Locations for ChannelMask
Definition at line 87 of file WavFile.php.
Referenced by __construct().