Обрезать аудиофайл с меткой времени c ++ - PullRequest
0 голосов
/ 15 декабря 2018

Итак, у меня есть программа, которая записывает фрагменты аудио на массив микрофонов, а затем ставит метки времени окончания файла.Моя проблема в том, что процесс запуска программы занимает случайное количество времени, поэтому звук имеет произвольную длину.Мне нужен способ прочитать размер файла (в килобайтах), а затем обрезать файл на определенное количество килобайт, чтобы записи всегда были одинаковой длины.

#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);


}
}
...