In: Electrical Engineering
In audio processing (e.g., PyAudio), when and how is the frame rate different than the sampling rate?
- What is the precise meaning of WIDTH in the following Python code? What values are usually used for WIDTH? Why?
wf = wave.open(file_name, 'w')
wf.setsampwidth(WIDTH)
ANS: Sample rate is defined as number of bytes per sample. While frame rate is defined as number of frames per second.
sample rate = number of bytes / sample .
Frame rate = number of frames / second
Audio files have number of parameters in PyAudio. Actually the sampling rate or frame rate is same for some condition that is the number of times per second the sound is sampled.
The number of channels indicate if the audio is mono, sterio or quadro. Each frame consist of one sample per channel. The sample size is the size in bytes of each sample. Thus a frame consist of sample size bytes and a seconds worth of audio consist frame rate bytes.
for example CD quality audio has a sample size of two bytes (16 bits) uses two channels and has a frame rate of 44100 frame per second. This gives a frame size of four bytes and seconds worth occupies 2*2*44100 bytes.
WIDTH : in this program WIDTH indicate number of bits required to represent the value on a storage medium.
WIDTH > 1 and it must be signed integer.
WIDTH = 1 ................used as one byte or 8-bit resolution
WIDTH = 2 .................used as two byte or 16-bit resolution and so on