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

Author Topic: I need to limit the number of recorded samples  (Read 7650 times)

0 Members and 1 Guest are viewing this topic.

LuckyNeo

  • Newbie
  • *
  • Posts: 9
    • View Profile
I need to limit the number of recorded samples
« Reply #15 on: March 15, 2011, 11:02:56 pm »
When I pasted this line:
Code: [Select]
sf::SoundBufferRecorder::OnProcessSamples(Samples, this->samplesCount);

I got this error:
‘virtual bool sf::SoundBufferRecorder::OnProcessSamples(const sf::Int16*, size_t)’ is private

How to fix it without editing SoundBufferRecorder.hpp?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
I need to limit the number of recorded samples
« Reply #16 on: March 16, 2011, 08:04:16 am »
Oh... sorry I didn't realize that. So forget about this code.

Well, do you need to stop the recorder exactly after a certain amount of samples, or is it acceptable to let it run slightly longer and adjust the number of samples later, in the returned sound buffer?
Laurent Gomila - SFML developer

LuckyNeo

  • Newbie
  • *
  • Posts: 9
    • View Profile
I need to limit the number of recorded samples
« Reply #17 on: March 16, 2011, 04:09:50 pm »
Of course, it can run slightly longer. It shouldn't affect the measurement, only increase a wait time of analyzing. And it also brings noticeable delay when I will use AUDIO IN as an oscilloscope.
Stop recording sooner would be perfect, unless it is difficult to implement.

I made this code yesterday:

Code: [Select]
bool MyRecorder::OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount) {
    buffer.LoadFromSamples(Samples, this->samplesCount, 1, 44100);
    return false;
}


Did you mean it this way? Only imperfection is that it takes minimally one second.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
I need to limit the number of recorded samples
« Reply #18 on: March 16, 2011, 04:32:18 pm »
Quote
Did you mean it this way?

More or less. The idea is to write your own recorder (not derived from sf::SoundBufferRecorder, but from sf::SoundRecorder directly) so that you can control how many samples you process.

Code: [Select]
class MyRecorder : public sf::SoundRecorder
{
    bool OnProcessSamples(const Int16* Samples, std::size_t SamplesCount)
    {
        bool ok = true;
        if (mySamples.size() + SamplesCount > myLimit)
        {
            ok = false;
            SamplesCount = myLimit - mySamples.size();
        }

        std::copy(Samples, Samples + SamplesCount, std::back_inserter(mySamples));

        return ok;
    }

    std::size_t myLimit;
    std::vector<sf::Int16> mySamples;
};

Since you're using the collected samples to perform analysis, I don't think you need to store the samples in a sf::SoundBuffer; an array should be better.

Now, concerning the "lag", SFML calls OnProcessSamples every 100 ms so you should have a delay of 1 second.
Laurent Gomila - SFML developer