Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Capture data recorded every 0.010 sec and process in Real Time  (Read 2666 times)

0 Members and 1 Guest are viewing this topic.

desperado

  • Newbie
  • *
  • Posts: 1
    • View Profile
Capture data recorded every 0.010 sec and process in Real Time
« on: November 03, 2016, 10:27:16 pm »
Hello to all,
I'm working on processing audio data in Real Time, using windows 8.1 and visual studio 2015n SFML 2.4.0, everything work fine, i can record and save in .wav file, i changed Fs from 44100 Hz to 8000 Hz, in my work the data must be bufferise to 0.01 second in Time (so 80 Samples in ones frame), the problem is i want to read (get data or samples recorded) to process them, something like this:
- start record
- every 0.01 read 80 samples
- store them in a vector[80]
- myfunction(vector[80])
- choosing a time_to_record as a condition to stop the record.
* i tried with the function "onProcessSamples" but every time i get a different result.
Do you have a solution for this issue ? or suggest me another thing that i can record and process in Real time.

my code:

// soundStreamSFML_test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/audio.hpp>
using namespace std;
// flux audio qui joue un buffer déjà chargé

sf::Int16 myBuff[16000];
long int j = 0;
class ch : public sf::SoundRecorder
{
        virtual bool onStart() { return true; }
        virtual void onStop() {}
        virtual bool onProcessSamples(const sf::Int16* samples, std::size_t sampleCount)
        {
                unsigned long int count_samples = 0;
                // int sample_count = 80;
                // long int myBuff[79];

                //cout << "sampleCount = " << sampleCount << endl;
                cout << "sample_count = " << sampleCount << endl;
                for (int i=0;i<sampleCount;i++)
                {      
                        if (i % 1 == 0)
                        {

                                cout << i <<"\t"<< samples[i] << endl;
                        }
                       
                        //myBuff[j++] = samples[i];
                        // cout <<i << " "<< samples[i] << endl;
                        //printf("\n%d\t%d", i, samples[i]);
                        //count_samples = count_samples + 1;
                }
                /*
                if (count_samples + 1 % 80 == 0)
                {
                        count_samples = 0;
                        return false;
                }
                */

                return false;
        }

};

int main()
{
        // chargement d'un buffer audio à partir d'un fichier
        //sf::SoundBuffer buffer;
        //buffer.loadFromFile("1234_recorded.wav");

        ch sbr;
        //sbr.setChannelCount(0);
        sbr.start();
        //
        sf::sleep(sf::seconds(10.0f));
        //cout << sbr.getChannelCount() << endl;
        // initialisation et lecture de notre flux
        //wait(1000,0);
        sbr.stop();

        system("pause");

        return 0;
}
 


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Capture data recorded every 0.010 sec and process in Real Time
« Reply #1 on: November 03, 2016, 10:52:27 pm »
Quote
i tried with the function "onProcessSamples" but every time i get a different result.
You don't really explain what your problem is. You'll have to give more details if you want to get relevant replies.
Laurent Gomila - SFML developer