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

Author Topic: onProcessSamples called twice instead of once  (Read 2364 times)

0 Members and 1 Guest are viewing this topic.

Eran

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
onProcessSamples called twice instead of once
« on: March 02, 2014, 05:27:01 pm »
Hello,

I'm trying to capture audio and have encountered a strange behaviour.

Here is a simple code that demonstrates the issue: http://pastebin.com/AYhv20nm
I'm using Visual studio 2010 on Windows 7 to compile this.

Even though the onProcessSamples function always returns false, it is called twice.

Thanks in advance,
Eran
« Last Edit: March 02, 2014, 05:51:30 pm by Eran »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: onProcessSamples called twice instead of once
« Reply #1 on: March 02, 2014, 06:29:34 pm »
It looks like onProcessSamples should be continuously called as it's recording. Therefore, it calls when you play(), stops calling while it's sleeping, then calls again before you stop().

Edit: I may be wrong about continously. It could, however, just be interrupted by the sleep so processes it in two chunks.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: onProcessSamples called twice instead of once
« Reply #2 on: March 02, 2014, 09:00:22 pm »
During the time between the moment where you return false and the moment where the capture is actually stopped, there are still samples being captured, which are passed to onProcessSamples() again. But I agree that it would be more intuitive if returning false would result in an immediate stop, also because the documentation says returning false stops the capture.

The fix would be easy, I have to make sure that OpenAL doesn't require the sample buffer to be processed before cleaning up. Reading the OpenAL specification, it says
Quote from: Page 57
If the application doesn't need to capture more audio for an amount of time, they can halt the device without closing it via the alcCaptureStop entry point:
void alcCaptureStop(ALCdevice *device);

The implementation is encouraged to optimize for this case. The amount of audio samples available after restarting a stopped capture device is reset to zero. The application does not need to stop the capture device to read from it.
So it should be fine if the samples are discarded.

By the way, please use the embedded [code=cpp] [/code] tags for such short example codes.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: