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 - LuckyNeo

Pages: [1]
1
Audio / I need to limit the number of recorded samples
« 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.

2
Audio / I need to limit the number of recorded samples
« 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?

3
Audio / I need to limit the number of recorded samples
« on: March 15, 2011, 08:14:44 pm »
I think I get how you mean it. It is stopped when samplesCount exceeds the limit.
But firstly I use recorder for some electrical measurements which take less than a second (44100 samples) and secondly recorder's member variable "samplesCount" is the limit, it is amount of samples I want to record.
I think that your solution can control only whole seconds.
Is there a way to stop recording in less than one second, e.g. 1300 samples?

4
Audio / I need to limit the number of recorded samples
« on: March 15, 2011, 07:03:37 pm »
I only want to stop it after certain amount of samples

5
Audio / I need to limit the number of recorded samples
« on: March 15, 2011, 06:16:42 pm »
I realized that maybe I have to save Samples in OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount) manually to SoundBuffer using LoadFromSamples().
But I still don't know how to change number of processed samples, I've found out that default SamplesCount is 44096. How can I change this number?

6
Audio / I need to limit the number of recorded samples
« on: March 15, 2011, 05:38:36 pm »
Main window .cpp file (shortened)
Code: [Select]

...
void JOP::on_btnStartRec_clicked()
{
    cat = new SignalCatcher(&bufferCat, 12345, 44100);
    cat->start();
}

void JOP::on_btnStopRec_clicked()
{
    qDebug() << cat->cat_buffer.GetSamplesCount();
    delete cat;
}
...




jop_signalcatcher.h
Code: [Select]


#ifndef JOP_SIGNALCATCHER_H
#define JOP_SIGNALCATCHER_H

#include <SFML/Audio.hpp>
#include "jop_core.h"


class MyRecorder : public QObject, public sf::SoundBufferRecorder
{
    Q_OBJECT

private:
    int samplesCount;

public:
    MyRecorder(int samplesCount);
    MyRecorder();
    virtual bool OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount);

signals:
    void processFinished();
};

class SignalCatcher : public QObject
{
    Q_OBJECT

private:
     int sampleRate;
    const unsigned int samplesCount;

public:
    SignalCatcher(sf::SoundBuffer* snd_buffer, int samplesCount,  int samplerate);
    sf::SoundBuffer cat_buffer;
    void setSampleRate(int smprate);
    int getSampleRate();
    bool start();
    bool stop();
    MyRecorder *recorder;
    const sf::Int16* Samples;


public slots:
    virtual void onProcessFinished();
};

#endif // JOP_SIGNALCATCHER_H




jop_signalcatcher.cpp
Code: [Select]


#include "jop_signalcatcher.h"

SignalCatcher::SignalCatcher(sf::SoundBuffer* snd_buffer, int samplesCount,  int sampleRate = 44100): samplesCount(samplesCount)
{
    this->recorder = new MyRecorder(samplesCount);
    this->cat_buffer = *snd_buffer;
    this->sampleRate = sampleRate;

    QObject::connect(recorder, SIGNAL(processFinished()),
            this, SLOT(onProcessFinished()));
}

bool SignalCatcher::start()
{
    if (sf::SoundRecorder::CanCapture())
    {
        recorder->Start();
        return true;
    }
    else {
        return false;
    }
}

bool SignalCatcher::stop()
{
    recorder->Stop();
    this->cat_buffer = recorder->GetBuffer();
    qDebug() << "stopped";
    return true;
}

bool MyRecorder::OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount) {
    SamplesCount = this->samplesCount;
    emit processFinished();
    return true;
}

MyRecorder::MyRecorder(int samplesCount) {
    this->samplesCount = samplesCount;
}

MyRecorder::MyRecorder() {
    this->samplesCount = 44100;
}

void SignalCatcher::onProcessFinished() {
    qDebug() << "finished";
    this->stop();
}

void SignalCatcher::setSampleRate(int smprate)
{
    this->sampleRate = smprate;
}

int SignalCatcher::getSampleRate()
{
    return sampleRate;
}

7
Audio / I need to limit the number of recorded samples
« on: March 15, 2011, 07:10:57 am »
Code: [Select]



SignalCatcher::SignalCatcher(sf::SoundBuffer* snd_buffer, int samplesCount,  int sampleRate = 44100): samplesCount(samplesCount)
{
    this->recorder = new MyRecorder(samplesCount);
    this->cat_buffer = *snd_buffer;
    this->sampleRate = sampleRate;

    connect(recorder, SIGNAL(processFinished()),
            this, SLOT(onProcessFinished()));
}

bool SignalCatcher::start()
{
    if (sf::SoundRecorder::CanCapture())
    {
        recorder->Start();
        return true;
    }
    else {
        return false;
    }
}

bool SignalCatcher::stop()
{
    recorder->Stop();
    this->cat_buffer = recorder.GetBuffer();
    qDebug() << "stopped";
    return true;
}

bool MyRecorder::OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount) {
    SamplesCount = this->samplesCount;
    emit processFinished();
    return true;
}

void SignalCatcher::onProcessFinished() {
    qDebug() << "finished";
    this->stop();
}

8
Audio / I need to limit the number of recorded samples
« on: March 14, 2011, 11:51:54 am »
I have tried it, if you mean this one http://www.sfml-dev.org/tutorials/1.6/audio-capture.php
I changed value of SamplesCount within OnProcessSamples this way:
Code: [Select]
SamplesCount = 1300;
and then stopped through signal
Code: [Select]
emit ProcessFinished(), in slot there is
Code: [Select]
recorder->Stop() to stop recording after needed number of samples. But after I've copied buffer with GetBuffer() it showed zero samples when I called GetSamplesCount.
There must be something I've missed in OnProcessSamples, but I don't know what.

9
Audio / I need to limit the number of recorded samples
« on: March 13, 2011, 11:11:37 am »
Hi,
I need to start recording and after given number of samples stop recording. In doc, I've found OnProcessSamples, but I don't really know how to use it. Every time I do it, it don't record anything.
Do you have a clue?

Pages: [1]
anything