修剪标有时间戳c ++

时间:2018-12-15 03:41:11

标签: c++ audio-recording

所以我有一个程序,可以在麦克风阵列上记录音频片段,然后为文件的结束时间加上时间戳。我的问题是程序开始录制的过程需要花费随机的时间来开始,因此音频是随机的。我想要一种方法来读取文件的大小(千字节),然后将文件修剪一定数量的千字节,以使记录的长度始终相同。

#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include<signal.h>
#include<unistd.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include "zlib.h"


long long int rem;
long long int ms1;
long long int unixtime;
using namespace std;
const char* Filenames;

int main(void) {

        int system(const char *command);
        int x;
        struct timeval tp1;

        rem = 5;
while (rem != 0) {
        gettimeofday(&tp1, NULL);
        ms1 = tp1.tv_sec * 1000ll  + tp1.tv_usec / 1000ll;
        rem  = ms1 % 10000;
}

for (x=0; x<3; x++){
        pid_t pid=fork();

if (pid==0){
        execl("/home/pi/odas/bin/odaslive", "/home/pi/odas/bin/odaslive", "-vc", "/home/pi/odas/config/odaslive/matrix_creator.cfg", (char *)NULL);
        exit(127);

} else {
        std::this_thread::sleep_for(std::chrono::milliseconds(15000));
        kill(pid, SIGINT);
}
        gettimeofday(&tp1, NULL);
        unixtime = tp1.tv_sec  + tp1.tv_usec / 1000000ll;

        std::string name1 = "/home/pi/matrix_creator_explore/postfiltered/postfiltered1_";
        std::string name2 = ".raw";
        std::string result1;
        result1 = name1 + std::to_string(unixtime) + name2;
        const char *cstr = result1.c_str();
        rename ("/home/pi/matrix_creator_explore/postfiltered.raw", cstr);

        std::string name3 = "/home/pi/matrix_creator_explore/tracked/tracked1_";
        std::string name4 = ".raw";
        std::string result2;
        result2 = name3 + std::to_string(unixtime) + name4;
        const char *cstr1 = result2.c_str();
        rename ("/home/pi/matrix_creator_explore/tracked.raw", cstr1);

     
        struct stat buf;
        stat( cstr,&buf);
        printf ("\n %i \n", buf.st_size);


}
}

0 个答案:

没有答案