## FANDOM

8 Pages

UtilFunction provides functions that are used in multiple modules. In the module you can find functions that solve different needs which are all listed below.

## Power of two checking Edit

This function check if a number is power of two. This function is from sms-tools package.

This function read a sound file (in .wav) and convert it in to a normalized floating point array. it returns to the sampling rate of file. This function is from sms-tools package.

## Wav Playing Edit

This function plays a sound file (in .wav) using OS calls. This function is from sms-tools package.

## Wav Writing Edit

This function write a sound file (in .wav) from an array with the sound and the sampling rate. This function is from sms-tools package.

## Peak Detection Edit

This function detects the location of spectral peaks of a frame. It needs the spectrum of a signal and a threshold. This function is from sms-tools package.

## Length of File Edit

This function return the length of a file in kbits.

## File Writing Edit

This function writes a variable to a file using the bits designed. It is intended to work in a similar way to MATLAB's 'fwrite' function.

This function reads values a determined bit-length from a file. It is intended to work in a similar way to MATLAB's 'fread' function.

## Open Stream Edit

This function initializes the Stream as a BitString BitStream.

## Flush Stream Edit

This function flushes whatever is left in the global stream. Therefore if there were non-Byteable bits, it zero-pad them to Byteable and write them to the file.

## Signal to Noise Ratio Edit

This function calculates the total Signal to Noise Ratio (SNR) of the input and que output and a graph of SNR over time using a window determined.

## Bark Edit

This function convert a lineal frequency specified in hertz to bark scale.

## Bin to Bark Edit

This function convert the fft bin to bark scale, it uses the fft length and the sampling frequency. This function uses the function BARK.

## Schroeder Edit

This function calculates the masking spectrum for a given frequency and SPL with Schroeder function.

$10log_{10} F(dz) = 15.81 + 75(dz + 0.474) - 75(1+(dz + 0.474)^2)^{1/2}$

It uses the sampling frequency, the frame length, the frequency peak location in hertz and the difference between the peak and the mask levels in dB.  This function uses the function BARK.

This function quantize a signal in number of levels that we assign. it uses the signal and the number of bits that we want to use.

This function is a more advanced function based in Midtread quantizer. It can quantize arrays and also check if there has been overlab (therefore some normalisation should be made).

This function dequantize a signal quantized in number of levels that we assign. it uses the signal and the number of bits that we want to use.

## Modified Discrete Cosine Transform Edit

This function returns the Modified Discrete Cosine Transform of a signal. It needs a vector of a signal.

## Inverse Modified Discrete Cosine Transform Edit

This function returns the Inverse of Discrete Cosine Transform of a signal. It needs a vector of Discrete Cosine Transform of a signal.

## Bitpool Encoder Edit

This function quantizes the MDCT of a frame with the bits indicated at the 'bit_alloc'. It uses the MDCT of a frame, the sampling frequency, the frame length and bit_alloc (an array containing the bits designed for each band). It returns the quantized gain and the quantized MDCT.

## Enframe Edit

This function split a signal in to frames. We can choose a type of window to enframe each frame and the overlapping.

## Bit allocation Edit

This function allocates bits to each band given a certain bitrate (from which a bitpool will be generated). It is based on the SPL 'y' which for the perceptual model is the SMR. For Bands is just the signal SPL.