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

Show Posts

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.


Messages - desperado

Pages: [1]
1
Audio / 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;
}
 


Pages: [1]