auto const epoch = clock();
static double now()
{
return (clock() - epoch);
};
template static double bench(const FN &fn)
{
auto took = -now();
return (fn(), took + now()) / 1000;
}
//写wav文件
void wavWrite_int16(char* filename, int16_t* buffer, int sampleRate, uint32_t totalSampleCount, int channels = 1) {
FILE* fp = fopen(filename, "wb");
if (fp == NULL) {
printf("文件打开失败.\n");
return;
}
//修正写入的buffer长度
totalSampleCount *= sizeof(int16_t)*channels;
int nbit = 16;
int FORMAT_PCM = 1;
int nbyte = nbit / 8;
char text[4] = { ‘R‘, ‘I‘, ‘F‘, ‘F‘ };
uint32_t long_number = 36 + totalSampleCount;
fwrite(text, 1, 4, fp);
fwrite(&long_number, 4, 1, fp);
text[0] = ‘W‘;
text[1] = ‘A‘;
text[2] = ‘V‘;
text[3] = ‘E‘;
fwrite(text, 1, 4, fp);
text[0] = ‘f‘;
text[1] = ‘m‘;
text[2] = ‘t‘;
text[3] = ‘ ‘;
fwrite(text, 1, 4, fp);
long_number = 16;
fwrite(&long_number, 4, 1, fp);
int16_t short_number = FORMAT_PCM;//默认音频格式
fwrite(&short_number, 2, 1, fp);
short_nu