PCM data recorded with a microphone, 16bit, 48KHz, mono, and I would like to get the 16KHz sampling rate of the PCM data, then by reducing the sampling rate of the method to achieve 48000HZ to 16000HZ sample rate conversion.
The conversion principle is relatively simple, 48000HZ to 16000HZ, actually dropped 3 times times, in the same time unit interval, 48000HZ sampled 3 points, 16000HZ sampled a point, that is, from the 48000HZ file for each read 3 data, It will be based on these 3 data to calculate the 1 data, and this data corresponds to a 16000HZ file in a data.
The realization of the following C language is implemented concretely
#define Old_file_path "FILE.PCM"
#define Down_file_path "DOWNSAMPLE.PCM"
void Pcm_downsample (void)
{ Short
sread = 0;
Short tempsum = 0;
int size = 0;
int flag = 0;
FILE *FP = fopen (Old_file_path, "rb+");
FILE *fp_down = fopen (Down_file_path, "wb+");
while (!feof (FP))
{
size = Fread (&sread, 2, 1, FP);//Read two bytes at a time, 16bit
if (size>0)
{
TempSum = TempSum + sread; Sum
flag++;
if (flag = = 3) //If three points are taken
{
flag = 0;
TempSum = TEMPSUM/3; Average, you can modify according to their needs, not necessarily mean, you can directly take a point
fwrite (&tempsum, 2, 1, fp_down);
TempSum = 0;
}
}
Fclose (FP);
Fclose (Fp_down);
}
Here I will convert 3 points to 1 points of the algorithm, is the average algorithm, you can use other algorithms to convert also can, if you want to reduce to other sample rate, as long as the corresponding proportion to sample, you can. reference materials
1.PCM data format