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

Author Topic: Stereo recording  (Read 3233 times)

0 Members and 1 Guest are viewing this topic.

hack006

  • Newbie
  • *
  • Posts: 5
    • View Profile
Stereo recording
« on: April 03, 2011, 01:01:58 am »
Hi there. Because I am developing dualchannel "jack" scope I of course need stereo recording. Problem is that in SoundRecorder.hpp the predefined record type is set as AL_FORMAT_MONO16. I have started to solve this problem with overriding void SoundRecorder::Start(unsigned int SampleRate = 44100); but I am not sure if it's the best solution. If I try to compile, I get a lot of compile errors:
Quote
../libjop/jop_signalcatcher.cpp: In member function ‘void MyRecorder::Start(unsigned int)’:
../libjop/jop_signalcatcher.cpp:111: error: ‘CaptureDevice’ was not declared in this scope
../libjop/jop_signalcatcher.cpp:120: error: ‘CaptureDevice’ was not declared in this scope
../libjop/jop_signalcatcher.cpp:120: error: ‘AL_FORMAT_STEREO16’ was not declared in this scope
../libjop/jop_signalcatcher.cpp:120: error: ‘alcCaptureOpenDevice’ was not declared in this scope
../libjop/jop_signalcatcher.cpp:122: error: ‘CaptureDevice’ was not declared in this scope
../libjop/jop_signalcatcher.cpp:122: error: ‘AL_FORMAT_MONO16’ was not declared in this scope
../libjop/jop_signalcatcher.cpp:122: error: ‘alcCaptureOpenDevice’ was not declared in this scope
../libjop/jop_signalcatcher.cpp:124: error: ‘CaptureDevice’ was not declared in this scope
/usr/include/SFML/Audio/SoundRecorder.hpp:141: error: ‘unsigned int sf::SoundRecorder::mySampleRate’ is private
../libjop/jop_signalcatcher.cpp:134: error: within this context
/usr/include/SFML/Audio/SoundRecorder.hpp:100: error: ‘virtual bool sf::SoundRecorder::OnStart()’ is private
../libjop/jop_signalcatcher.cpp:137: error: within this context
/usr/include/SFML/Audio/SoundRecorder.hpp:100: error: ‘virtual bool sf::SoundRecorder::OnStart()’ is private
../libjop/jop_signalcatcher.cpp:137: error: within this context
../libjop/jop_signalcatcher.cpp:140: error: ‘CaptureDevice’ was not declared in this scope
../libjop/jop_signalcatcher.cpp:140: error: ‘alcCaptureStart’ was not declared in this scope
/usr/include/SFML/Audio/SoundRecorder.hpp:142: error: ‘bool sf::SoundRecorder::myIsCapturing’ is private
../libjop/jop_signalcatcher.cpp:143: error: within this context
/usr/include/SFML/System/Unix/Thread.hpp:69: error: ‘void sf::Thread::Launch()’ is inaccessible
../libjop/jop_signalcatcher.cpp:144: error: within this context
/usr/include/SFML/System/Unix/Thread.hpp:69: error: ‘void sf::Thread::Launch()’ is inaccessible
../libjop/jop_signalcatcher.cpp:144: error: within this context
../libjop/jop_signalcatcher.cpp:144: error: ‘sf::Thread’ is not an accessible base of ‘MyRecorder’

I have found that in SoundRecorder.cpp are defined following includes:
Quote
00028 #include <SFML/Audio/SoundRecorder.hpp>
00029 #include <SFML/Audio/AudioDevice.hpp>
00030 #include <SFML/Audio/OpenAL.hpp>
00031 #include <SFML/System/Sleep.hpp>
00032 #include <iostream>

The problem is AudioDevice.hpp and OpenAL.hpp are not found, if I try to include them in the file with my new SoundRecorder::Start(...) definition .. I know it is ok because these headers aren't located in  /usr/include/SFML/Audio. These libraries are located only in sfml source. So how can I get rid of these errors? Will I have to add sfml sources to my project?? Or if my solution is bad please suggest cleaner solution. I believe I have described my problem enough. Thanks in advance for any solutions or suggestions :wink:

For a better explanation I included my sources:
 JOP_Signal_Catcher.h
Code: [Select]
#ifndef JOP_SIGNALCATCHER_H
#define JOP_SIGNALCATCHER_H

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


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

private:
    bool loop;

public:
    MyRecorder(int myLimit, bool loop);
    MyRecorder();
    virtual bool OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount);
    // predefinovani defaultni funkce start -> uprava pro spusteni stereo nahravani
    void Start(unsigned int SampleRate);
    std::vector<sf::Int16> mySamples;
    std::size_t myLimit;

signals:
    void processFinished();
};


JOP_Signal_Catcher.cpp
Code: [Select]
#include "jop_signalcatcher.h"
#include <SFML/Audio/SoundRecorder.hpp>
#include <SFML/Audio/SoundRecorder.hpp>
#include <SFML/Audio/AudioDevice.hpp> // error, not found
#include <SFML/Audio/OpenAL.hpp> // error, not found
#include <SFML/System/Sleep.hpp>
#include <iostream>

// copied from sfml, changed only capture mod (AL_FORMAT_MONO16 ->AL_FORMAT_STEREO16)
void MyRecorder::Start(unsigned int SampleRate)
 {
     // Check if the device can do audio capture
     if (!CanCapture())
     {
         std::cerr << "Failed to start capture : your system cannot capture audio data (call SoundRecorder::CanCapture to check it)" << std::endl;
         return;
     }

     // Check that another capture is not already running
     if (CaptureDevice)
     {
         std::cerr << "Trying to start audio capture, but another capture is already running" << std::endl;
         return;
     }

     // Open the capture device for capturing 16 bits MONO or STEREO samples
     // -> depends on [bool] loop (modificated)
     if(this->loop)
        CaptureDevice = alcCaptureOpenDevice(NULL, SampleRate, AL_FORMAT_STEREO16, SampleRate);
     else
         CaptureDevice = alcCaptureOpenDevice(NULL, SampleRate, AL_FORMAT_MONO16, SampleRate);

     if (!CaptureDevice)
     {
         std::cerr << "Failed to open the audio capture device" << std::endl;
         return;
     }

     // Clear the sample array
     mySamples.clear();

     // Store the sample rate
     mySampleRate = SampleRate;

     // Notify derived class
     if (OnStart())
     {
         // Start the capture
         alcCaptureStart(CaptureDevice);

         // Start the capture in a new thread, to avoid blocking the main thread
         myIsCapturing = true;
         Launch();
     }
 }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Stereo recording
« Reply #1 on: April 03, 2011, 10:33:53 am »
The cleanest solution for you would be to fix this directly inside SFML and recompile it.
Laurent Gomila - SFML developer

hack006

  • Newbie
  • *
  • Posts: 5
    • View Profile
RE: Laurent
« Reply #2 on: April 03, 2011, 12:54:06 pm »
Firstly, thank you for reply. Ok it could be good solution. Unfortunately if I want to share my program I will have also share recompiled SFML, won't I.
Please if I am wrong correct me.
Quote

1) I won't be able to use libsfml-audio from repos
2) I will have to include fixed version of SFML in my sources
3) Suggestion: Isn't simpler and maybe cleaner to create own Recorder class implementing OpenAL's capture function
 


Thank you very much for any help and of course your freetime

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Stereo recording
« Reply #3 on: April 03, 2011, 01:10:45 pm »
Quote
1) I won't be able to use libsfml-audio from repos

Right, but you can simply distribute your modified version of it (together with the program that uses it) instead of relying on the official one.

Quote
2) I will have to include fixed version of SFML in my sources

Right, same answer as above.

Quote
3) Suggestion: Isn't simpler and maybe cleaner to create own Recorder class implementing OpenAL's capture function

Simpler? I don't think so, because you won't be able to reuse anything from SFML, this will be pure OpenAL.

Even simpler would be to make a feature request on the task tracker (for stereo recording) and wait until I implement it ;)
Laurent Gomila - SFML developer

hack006

  • Newbie
  • *
  • Posts: 5
    • View Profile
Stereo recording
« Reply #4 on: April 03, 2011, 01:25:27 pm »
Ok. Thank you very much Laurent.  And definitely I will make a feature request on the task tracker (for stereo recording). I think there should by an optional parameter through which the recording format (at least AL_FORMAT_STEREO16 and AL_FORMAT_MONO_16) can be passed.

 

anything