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

Author Topic: Does SFML support playing realtime raw sample stream?  (Read 3501 times)

0 Members and 1 Guest are viewing this topic.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Does SFML support playing realtime raw sample stream?
« on: September 23, 2015, 02:18:59 pm »
I need to play raw sound stream which is produced in realtime.

Actually, I wrote some interactive engine which produces realtime raw audio & video streams.
The content is interactive, so buffering is possible for a very short time - 50-100 ms.
Currently I'm using Direct3D and DirectSound directly.
But it's hardly linked with Windows, and I want to porting it into Linux and iOS.

I tested SFML and its really simple and beautiful :)
So, I'm thinking about using SFML...
Does SFML support such functionality?
« Last Edit: September 23, 2015, 02:21:16 pm by mkalex777 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Does SFML support playing realtime raw sample stream?
« Reply #1 on: September 23, 2015, 02:23:23 pm »
What format are your streams in (no "raw" is not format)?

You can call update() on a texture with a RGBA pixel array and sf::Music is able to play from a stream that is correctly formatted for OpenAL.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Does SFML support playing realtime raw sample stream?
« Reply #2 on: September 23, 2015, 02:24:55 pm »
The sf::SoundStream class is what you're looking for, but it currently doesn't allow to change the buffer size (currently, 2 seconds of audio data).

Quote
sf::Music is able to play from a stream that is correctly formatted for OpenAL.
Leave OpenAL alone ;)
sf::Music plays audio files, not raw data.
« Last Edit: September 23, 2015, 02:26:47 pm by Laurent »
Laurent Gomila - SFML developer

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Does SFML support playing realtime raw sample stream?
« Reply #3 on: September 23, 2015, 02:56:45 pm »
Format is 16 bit stereo, engine has it's own resampler, and is able to produce stream with any sample rate supported by hardware. Higher sample rate is better, because sounds may contains complex sound effects with wide range frequencies (up to 115 kHz), usually I'm using 192 kHz.

Does SoundBuffer support loopback playing with notifications of current position?
I want to write at position just before sound card will read it.
Actually it's how I implemented it in DirectSound...
I used the folowing technique:
1) create surface with loopback buffer for 160 ms
2) set position notifications for each 20 ms segment
3) when notification is raised I read current  playback position, calculate current segment number and write next portion of samples into previous segment (which playback is just completed)

Can I use the same technique in SFML?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Does SFML support playing realtime raw sample stream?
« Reply #4 on: September 23, 2015, 03:29:56 pm »
The only solution to this problem with SFML is what I already told you:

Quote
The sf::SoundStream class is what you're looking for, but it currently doesn't allow to change the buffer size (currently, 2 seconds of audio data).

So, unless you tweak SFML itself a little bit, you won't be able to achieve exactly what you want. Suggestions for making the API more flexible are welcome though :)
Laurent Gomila - SFML developer