获取自1970年以来的时间,精确到毫秒
#include1.2 简单打印时间差// 获取时间,精确到毫秒 unsigned int _OsCounterGetMs(void) { struct timeval t1; gettimeofday(&t1, NULL); unsigned int T = ((1000000 * t1.tv_sec) + t1.tv_usec) / 1000; return T; } #define D_frame_LEN 128 #define D_SAMPLE_RATE 16000 int main(int argc, char *argv[]) { int total_count = 10 * D_SAMPLE_RATE; int total_frames = (int)(total_count / D_frame_LEN); unsigned int time_begin_ms = _OsCounterGetMs(); // 起始时刻 for (int i = 0; i < total_frames; i++) { unsigned int time_now_ms = _OsCounterGetMs(); int ms_to_sleep = (int)(i * D_frame_LEN * 1000 / D_SAMPLE_RATE) - (time_now_ms - time_begin_ms); if (ms_to_sleep > 0) { usleep(ms_to_sleep * 1000); } } }
#include2. 打印数组至文件clock_t time0 = clock(); clock_t time1 = clock(); printf("[%s %d] interval: (%f) msn", __FUNCTION__, __LINE__, (double)((time1-time0))/CLOCKS_PER_SEC * 1000);
#includeFILE *fp0 = fopen("aaa_meldb.txt", "w"); for (int j = 0; j < D_TOTAL_frameS; j++) { for (int k = 0; k < D_TOTAL_FEATS; k++) { fprintf(fp0, "%f ", afFeatures[j][k]); } fprintf(fp0, "n"); } fclose(fp0);



