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

Author Topic: Does my recording pause when calling onProcessSamples?  (Read 5502 times)

0 Members and 2 Guests are viewing this topic.

alexdupond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Does my recording pause when calling onProcessSamples?
« on: November 16, 2016, 11:16:31 am »
Hello World

I have a question about the onProcessSamples function in the Recorder Class. I im trying to process data real time, but im having trouble finding out if the capturing of data is paused then running onProcessSamples.

It says that returning true at the end will continue the capture, but i can't figure out if that means start capturing again.

Best Regards
Alexander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Does my recording pause when calling onProcessSamples?
« Reply #1 on: November 16, 2016, 12:49:52 pm »
It is of course not paused, if it was the case you'd have a tiny gap in your recorded data for each call to onProcessSamples.
Laurent Gomila - SFML developer

alexdupond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Does my recording pause when calling onProcessSamples?
« Reply #2 on: November 17, 2016, 01:49:04 pm »
That was what i thought, but i just wanted to be sure.

Thanks for the reply.

alexdupond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Does my recording pause when calling onProcessSamples?
« Reply #3 on: November 17, 2016, 08:41:39 pm »
And is there some way to make the sample count more stable on the OnProcessSamples? There seems to be some spikes, when sampling at a curtain rate.

The samplerate i stable most of the time, but after 5-6 OnProcessSamples call, the sample count spikes to about double of the expected samples count.  :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Does my recording pause when calling onProcessSamples?
« Reply #4 on: November 17, 2016, 08:48:32 pm »
Can you provide a complete and minimal code that reproduces the problem?
Laurent Gomila - SFML developer

alexdupond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Does my recording pause when calling onProcessSamples?
« Reply #5 on: November 29, 2016, 12:37:03 pm »
Sorry for the late reply. This is my CustomRecorder.cpp

#include "CustomRecorder.h"

CustomRecorder::CustomRecorder()
{
}

bool CustomRecorder::onStart() {

    setProcessingInterval(sf::milliseconds(10));
    return true;

}

bool CustomRecorder::onProcessSamples(const sf::Int16 *samples, std::size_t sampleCount) {

    cout << sampleCount << endl;
    return true;
}

void CustomRecorder::onStop() {

}

CustomRecorder::~CustomRecorder()
{
    stop();
}
 
The samplesRate is 4048 in this examples, and this i my samples count for at curtain area of time:

47
47
47
47
47
47
47
47
47
47
47
94
94
47
47
47
47
47
47
47
47
« Last Edit: November 29, 2016, 12:58:42 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Does my recording pause when calling onProcessSamples?
« Reply #6 on: November 29, 2016, 01:01:36 pm »
This code is not complete. I can't copy-paste it, compile it and run it to reproduce your problem.

By the way, formatted output in the console takes time, you'd better not use that to check small timings.
Laurent Gomila - SFML developer

alexdupond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Does my recording pause when calling onProcessSamples?
« Reply #7 on: November 29, 2016, 01:15:04 pm »
#include "SFML/Audio.hpp"
#include <iostream>

using namespace std;





class CustomRecorder : public sf::SoundRecorder {

public:
    CustomRecorder();

    bool onStart();

    bool onProcessSamples(const sf::Int16 *samples, std::size_t sampleCount);

    void onStop();

    ~CustomRecorder();
};

CustomRecorder::CustomRecorder()
{
}

bool CustomRecorder::onStart() {

    setProcessingInterval(sf::milliseconds(10));
    return true;

}

bool CustomRecorder::onProcessSamples(const sf::Int16 *samples, std::size_t sampleCount) {

    cout << sampleCount << endl;
    return true;
}

void CustomRecorder::onStop() {

}

CustomRecorder::~CustomRecorder()
{
    stop();
}


int main() {

    CustomRecorder recorder;
    recorder.start(4048);

    while(1){

    }

    recorder.stop();

    return 0;
}

alexdupond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Does my recording pause when calling onProcessSamples?
« Reply #8 on: November 29, 2016, 01:17:02 pm »
This is a simple program. Im running on a macOS. Don't know if it has something to do with the OpenAL for mac.

I have just tested the program on windows, and it seem to be more stable.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Does my recording pause when calling onProcessSamples?
« Reply #9 on: November 29, 2016, 04:00:28 pm »
You should put a sleep in your infinite loop, so that the main thread doesn't eat all the CPU.

And yes, there's a chance that the problem is specific to your environment, and there may be nothing to do about it.
Laurent Gomila - SFML developer

alexdupond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Does my recording pause when calling onProcessSamples?
« Reply #10 on: November 29, 2016, 05:26:35 pm »
I have tried it now on different computers, and the problem seems to wary from OS to OS.

On windows the lowest number of samples (with a sampling rate of 4096) is 128 samples, with a processing interval of 1 ms. On MacOS the lowest number of samples (with a sampling rate of 4096) is 47 samples, with a processing interval of 1 ms.

Does it mean the the OnProccesingSamples isn't called every 1 ms, but instead every:

128/4096 = 31 ms for windows
47/4096 = 11 ms for mac

Im just trying to understand what is causing this problem (Processor, architecture, etc.), and find the lowest processing interval as possible, for my program to run on both Windows and Mac.

Im new to both programming and SFML, so im having some trouble understanding this.  :)

alexdupond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Does my recording pause when calling onProcessSamples?
« Reply #11 on: November 29, 2016, 07:02:05 pm »
The problem with the sample count changing only occurs when sampling with a higher processing interval then the one specified above (11 ms for mac, and 31 for windows).

If the processing interval depends on the OS or the CPU power available, maybe there is some way to specify the needed sample count, instead of the processing interval in milliseconds?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Does my recording pause when calling onProcessSamples?
« Reply #12 on: November 29, 2016, 07:58:03 pm »
The recording interval is implemented with a call to sf::sleep, which is not accurate. It depends on the OS, and especially its internal scheduler. You shouldn't rely on this feature if you need really precise timing.
Laurent Gomila - SFML developer

alexdupond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Does my recording pause when calling onProcessSamples?
« Reply #13 on: November 30, 2016, 01:02:24 pm »
Precession isn't that important, but the time between every onProcessSamples call needs to be the same for both mac and windows. And im not sure if the sampleCount i reliable.

If the sample count is "actually caught samples", when the processingInterval is not 1 ms, but instead the 31 ms for Windows. So i need to find out if i set the sample rate, and get the sample count, is the processingInterval reliable?

Eks:
4096 sample rate - i get 150 sample count - then the processing interval is actually 150 / 4096 = 0.036 s = 36 ms

Hope that makes sense :)
« Last Edit: November 30, 2016, 09:25:12 pm by alexdupond »

 

anything