假设你的int16数组已经是整理好的左右声道得数据了。那么用下面这段代码,直接就可以完成数组到pcm文件得转换了。
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define BUFFSIZE xxxx
#define FRAME_NUM xxx
const int16_t audio[] = {
417, 363, 326, 14, 47, 6, 43, -4, 33, -82, -1397, -214, -1621, -706, -1549, -448, -1598, -495, -1518, -744, -2016, -1141, -2359, -1421, -2677, -1495, -2256, -1262, -2152, -976, -2076, -1192, -1973, -1119, -2300, -1264, -1996, -1281, -1910, -1048, -1758, -925, -1385, -900, -1791, -776, -1483, -981, -1448, -924, -1657, -854, -1207, -448, -1311, -191, -1001, -621, -1122, -527, -1526, -824, -1418
};
int main() {
// FILE *fin;
FILE *fout;
int16_t *tmp = (int16_t *)malloc(sizeof(int16_t));
// fin = fopen("record_fpga.raw", "rb");
// if (fin == NULL) {
// /* code */
// printf("file in error!\n");
// exit(0);
// }
fout = fopen("data.pcm", "w+");
if (fout == NULL) {
printf("file out error!\n");
exit(0);
}
int i = 0;
while (i < BUFFSIZE * FRAME_NUM) {
// fread(tmp, sizeof(int16_t), 1, fin);
printf("%d,", audio[i]);
fwrite(&audio[i], sizeof(int16_t), 1, fout);
i++;
}
printf("\n end ... ..\n");
// fclose(fin);
fclose(fout);
}