1
Audio / Memory problem with buffer
« on: July 12, 2009, 02:20:41 am »
I have to synchronize both audio and video That's why I am using Pthreads. I dont have any idea abt the SFML threads. btw I have solved the problem. Thanks
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#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);
}
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;
}
}
bool flag =True;
while( true){
if(flag is True)
flag = false
Recorder.Start(SampleRate);
if( timeInterval is 5 minutes )
then
flag = true
Recorder.stop() //stop the recorder
//Obtain the buffer and the write it into a file
sf::SoundBuffer Buffer = Recorder->GetBuffer();
Buffer.SaveToFile(SomeAudioFile.wav)
}