#include<iostream>
#include <SFML/Audio.hpp>
#include<pthread.h>
#include<cstdlib>
using namespace std;
void* SoundCapture(void *unncessary){
string AudioName;
int SampleRate = 44100;bool z=1;int FileCount =1;
sf::SoundBufferRecorder *Recorder=new sf::SoundBufferRecorder;
time_t sec1,sec2;
time(&sec1);
while(1)
{
time(&sec2);
if(z ){
Recorder->Start(SampleRate);z =0;
}
if(sec2-sec1==30)
{
sec1=sec2;
z=1;
Recorder->Stop();
char arr[100];
sprintf(arr,"%d",FileCount);
FileCount++;
string temp=arr;
AudioName ="Audio_"+temp+".wav";
const sf::SoundBuffer &B = Recorder->GetBuffer();
B.SaveToFile(AudioName);
free(Recorder);
Recorder = new sf::SoundBufferRecorder;
}
}
}
main(){
pthread_t t;
int a;
//pthread_create(&t[0],NULL,CaptureVideo,(void *)a[0]);
pthread_create(&t,NULL,SoundCapture,(void *)a);
void *status;
pthread_join(t,&status);
pthread_exit(NULL);
}
I need to use Threads in my code because I need to record Video simultaneously for my application
to compile dont forget add -lpthread
While the code is running we can infer its memory requirements from top command
i Linux