-
Notifications
You must be signed in to change notification settings - Fork 45
BufferUtility
<utilities/bufferutility.h>
Utility to provide several time related calculations where musical concepts are translated into buffer units and vice versa.
int bufferToMilliseconds( int bufferSize, int sampleRate )
Returns the time in milliseconds a buffer of given bufferSize lasts for given sampleRate.
int millisecondsToBuffer( int milliSeconds, int sampleRate )
The reverse of bufferToMilliseconds. Calculates the required buffer size to represent given milliSeconds at given sampleRate.
float bufferToSeconds( int bufferSize, int sampleRate )
Returns the time in seconds a buffer of given bufferSize lasts for given sampleRate.
int secondsToBuffer( float seconds, int sampleRate )
The reverse of bufferToSeconds. Calculates the required buffer size to represent given seconds at given sampleRate.
int getBitRate( int sampleRate, int bitDepth, int channels )
Returns the bit rate for an audio stream at given sampleRate, bitDepth and channel amount.
int calculateBufferLength( SAMPLE_RATE minRate )
Calculates the amount of samples a single cycle of a waveform will require at given minRate (in Hertz), for the current engine sample rate.
int calculateBufferLength( int milliSeconds );
Calculates the amount of samples necessary to represent given time in milliSeconds, for the current engine sample rate.
int calculateSamplesPerBeatDivision( int sampleRate, double tempo, int subdivision )
Calculates the amount of samples necessary to render audio at the duration of requested subdivision at the current sampleRate and tempo, where subdivision is a number by which to divide a measure (e.g. 1 = full meausure, 2 = half measure, 4 = quaver, 8 = eight note, etc.)
int getSamplesPerBeat( int sampleRate, double tempo )
Calculates the amount of samples necessary to render audio lasting a single beat for the given tempo at the given sampleRate.
getSamplesPerBar( int sampleRate, double tempo, int beatAmount, int beatUnit )
Calculates the amount of samples necessary to render audio lasting a single measure for the given tempo at the given sampleRate.
double getBPMbyLength( double length, int amountOfBars )
When given length represents a length in milliseconds and amountOfBars represents the known amount of measures the snippet represents, the resulting value is the tempo in BPM.
double getBPMbySamples( int length, int amountOfBars, int sampleRate )
The same as getBPMbyLength() except that given length represents the size of a buffer in samples and sampleRate the known sampe rate of the snippet.
std::vector<SAMPLE_TYPE*>* createSampleBuffers( int amountOfChannels, int bufferSize )
Returns a vector of given amountOfChannels in size, containing silent audio buffers at given bufferSize in length.
SAMPLE_TYPE* generateSilentBuffer( int bufferSize )
Creates a silent audio (0.0f) buffer at given bufferSize in length.
void bufferToFile( const char* fileName, SAMPLE_TYPE* buffer, int bufferLength )
Writes the contents of given buffer onto storage under given fileName. The result is a comma separated list of SAMPLE_TYPE values.