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

Author Topic: Multiple audio channels that can be individually managed  (Read 10941 times)

0 Members and 1 Guest are viewing this topic.

Cyrano

  • Newbie
  • *
  • Posts: 19
    • View Profile
Multiple audio channels that can be individually managed
« on: April 22, 2010, 07:33:07 am »
I'm highly impressed with SFML, but I have some questions regarding its sound libraries:

How is a multi-channel sound que/array done? (Ex: Que has .wav1 & .wav2 stored in it. Channels A & B can have sounds sent from the que to them via, say a function in the application's code. In this way, sounds are loaded into a storage area for ease of reference within the program.)

Is there a built-in way to route sounds to different channels depending on situation? (Ex: A .wav1 normally plays on channel A, but .wav2 is currently playing on channel A. Can .wav be routed to channel B?)

Can individual channels be individually managed?
(Ex: Channel A is to be at 100% volume, channel B needs to be at 50%.)

I've heard that playing multiple sounds simultaneously lowers the volume in some circumstances. Can this be averted by using multiple audio channels? (Ex: .wav1 on channel A plays at 100%, .wav2 plays on channel B at 100%. Both need to sound like they do at full volume.)

Is it possible to give a "priority tag" to a sound, so as to determine what channel it plays on? (Ex: Channel A is at 100% volume, Channel B is at 50% volume. .wav1 has a rank of 5, so it outranks .wav2, which is a rank 2 sound. If both sounds try to play simultaneously, .wav1 will always get Channel A, the priority channel. However, if .wav1 is not playing, .wav2 can use Channel A.)


I do not have any source code at this time, but decided to post this to see if there are answers to my questions, before I get into a tangled programming mess.

Thanks in advance.

-Cyrano
– A cape? Forsooth! 'Tis a peninsula!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Multiple audio channels that can be individually managed
« Reply #1 on: April 22, 2010, 09:47:19 am »
What is a channel for you? SFML doesn't have such a notion.
Laurent Gomila - SFML developer

Cyrano

  • Newbie
  • *
  • Posts: 19
    • View Profile
Multiple audio channels that can be individually managed
« Reply #2 on: April 22, 2010, 03:55:33 pm »
Quote from: "Laurent"
What is a channel for you? SFML doesn't have such a notion.


A channel for me would be... something like a path for the sound to go through on its way to output. I had always thought of it as, say in an audio recording program where multiple tracks are layered together, and all still maintain the same volume/qualities they each had before they were mashed together. All I want is to be able to do that in real-time. I realize this may not be possible, if that is the case, so be it; I'll find a way to work around it.

Thanks again!

-Cyrano
– A cape? Forsooth! 'Tis a peninsula!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Multiple audio channels that can be individually managed
« Reply #3 on: April 22, 2010, 06:35:06 pm »
If you want channels you can design your own system, but the audio module of SFML doesn't work like that. The library already takes care of mixing sounds that are played simultaneously.
Laurent Gomila - SFML developer

Cyrano

  • Newbie
  • *
  • Posts: 19
    • View Profile
Multiple audio channels that can be individually managed
« Reply #4 on: April 22, 2010, 06:39:00 pm »
Quote from: "Laurent"
If you want channels you can design your own system, but the audio module of SFML doesn't work like that. The library already takes care of mixing sounds that are played simultaneously.


Oh!

Ok, I kind of figured that that was what I'd have to do in the end; I just wanted to see if such a system had already been implemented by someone else.

Another question (I'm full of them):
What do you mean by "mixing sounds"? Does that mean that they are all just mashed together in the same output stream/thing?
– A cape? Forsooth! 'Tis a peninsula!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Multiple audio channels that can be individually managed
« Reply #5 on: April 22, 2010, 10:23:25 pm »
Well, in the end you have only one set of speakers, so yes they end up being mixed in the same "tunnel" at some point.
Laurent Gomila - SFML developer

Cyrano

  • Newbie
  • *
  • Posts: 19
    • View Profile
Multiple audio channels that can be individually managed
« Reply #6 on: April 22, 2010, 10:53:28 pm »
Right, so that "tunnel"... would it be a mono or stereo output?

Also, if stereo, would that be a 2 channel system?

How does SFML decide how to mix the sounds together? (Ex: .wav1, .wav2, and .wav3 all want to play simultaneously from a mono channel.)
– A cape? Forsooth! 'Tis a peninsula!

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Multiple audio channels that can be individually managed
« Reply #7 on: April 23, 2010, 01:35:02 am »
Cyrano, you really are full of questions :D
Quote from: "Cyrano"
Right, so that "tunnel"... would it be a mono or stereo output?

Depends on what you tell SFML :) (SFML uses OpenAL, which can handle 1.0, 2.0, 2.1, 4.1, 5.1 and 7.1 ... or maybe I'm wrong, but I'm too lazy to look at it :D)
Quote from: "Cyrano"
Also, if stereo, would that be a 2 channel system?

Stereo does mean 2-channel, doesn't it? o.O

By the way. Maybe this is a stupid question. Let's imagine we have a 5.1 sound system. I want to send data only to the.... well, let's say, to the 4th channel. So far, i managed to do it by creating a sample array with the size of 6 * [sample number], filled with zeroes, and the fourth number of every six-number-packet is filled with the desired data. (I really hope this is understandable :D) But I find this very... I don't know which word is suitable here, so.. I find it wasteful. Is there a way to send data only to a selected channel, or this is the way how OpenAL works? Thanks for the answer :)

[EDIT]
I have a feeling that I just asked the same question that Cyrano did... :$

Cyrano

  • Newbie
  • *
  • Posts: 19
    • View Profile
Multiple audio channels that can be individually managed
« Reply #8 on: April 23, 2010, 05:40:47 am »
I'm new to multimedia programming, so of course I have a huge amount of questions. Some programmers don't like newbies and simply shove documentation links at the hapless fellows (not to say that those links aren't useful!). I'm glad to see that at least some are willing to put up with my periodically clueless questions.

Quote
Cyrano, you really are full of questions :D


That I am. I don't know the answer, so I ask. I think the worse sin on my part would be not to ask, but to code on in ignorance. THAT would be a sin. There is enough worthless code out there already (*cough* Google, wikipedia). I don't want to add to that refuse heap. My knowledge base is limited in several areas, so I ask the questions that seem most pertinent to the issues I have at hand.

Quote
Quote from: "Cyrano"
Also, if stereo, would that be a 2 channel system?

Stereo does mean 2-channel, doesn't it? o.O


Dumb question, I apologize. I had seen an issue where a guy basically had to make stereo sound by having dual mono channels outputting the same data...it's a long story.:?  Gave me the wrong impression, which led to a foolish question.

Quote
By the way. Maybe this is a stupid question. Let's imagine we have a 5.1 sound system. I want to send data only to the.... well, let's say, to the 4th channel. So far, i managed to do it by creating a sample array with the size of 6 * [sample number], filled with zeroes, and the fourth number of every six-number-packet is filled with the desired data. (I really hope this is understandable :D) But I find this very... I don't know which word is suitable here, so.. I find it wasteful. Is there a way to send data only to a selected channel, or this is the way how OpenAL works? Thanks for the answer :)

[EDIT]
I have a feeling that I just asked the same question that Cyrano did... :$


That is a far better way of phrasing it than I could have done. :!:  Not a dumb question at all. Thank you!

And yes, that is more or less what I was trying to articulate, if unsuccessfully. :roll:

I have my own reasons for wanting such a structure.

-Cyrano
– A cape? Forsooth! 'Tis a peninsula!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Multiple audio channels that can be individually managed
« Reply #9 on: April 23, 2010, 08:44:42 am »
Ok, so you're not just asking beginner questions, you're really looking for something very specific ;)

Currently, SFML doesn't allow to output a mono sound to a specific channel / speaker. I don't know if OpenAL allows that, but I don't think so.

I'm curious: why do you need to achieve that?
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Multiple audio channels that can be individually managed
« Reply #10 on: April 23, 2010, 12:37:54 pm »
I suppose he tries to compare with Fmod or something similar. It works with channels (channels are like sf::Sound, but you can apply effects of different channels).

BTW: Laurent, how will you do so you can apply effects to sounds in a future? sf::Sound::SetReverb for example?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Multiple audio channels that can be individually managed
« Reply #11 on: April 23, 2010, 04:40:08 pm »
Quote
I suppose he tries to compare with Fmod or something similar. It works with channels (channels are like sf::Sound, but you can apply effects of different channels).

The effects indeed add this notion of channels. At least in OpenAL (it's called "slots"), I don't know if I need to forward it in the SFML API.

Quote
BTW: Laurent, how will you do so you can apply effects to sounds in a future? sf::Sound::SetReverb for example?

I didn't think about it yet (it's planned for SFML 2.x, not 2.0 as it doesn't require to break the current audio API). But I think that I'll need to add a new class sf::SoundEffect, and something like sf::Sound::UseEffect(const sf::SoundEffect&).
Filters have a more limited API, so I probably can just add functions like Sound::EnableFilter(FilterType type, bool enable).
Laurent Gomila - SFML developer

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Multiple audio channels that can be individually managed
« Reply #12 on: April 23, 2010, 08:10:50 pm »
Quote from: "Cyrano"
I'm new to multimedia programming, so of course I have a huge amount of questions. Some programmers don't like newbies and simply shove documentation links at the hapless fellows (not to say that those links aren't useful!).

Woohooo... am I feeling right, that you are a bit upset? Sorry then, I didn't say that asking questions is wrong... I just made a neutral statement :) (Saying totally useless things is my habit... :D Btw, I am new to this topic, too... :))
Quote from: "Cyrano"
That I am. I don't know the answer, so I ask. I think the worse sin on my part would be not to ask, but to code on in ignorance. THAT would be a sin.

I agree.
Quote from: "Cyrano"
I had seen an issue where a guy basically had to make stereo sound by having dual mono channels outputting the same data...

In the current state, this can be solved by duplicating every data, and sending it to the two channels.

[EDIT] I found an interesting workaround for the single-channel problem:
http://opensource.creative.com/pipermail/openal/2005-January/008020.html

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Multiple audio channels that can be individually managed
« Reply #13 on: April 23, 2010, 08:55:59 pm »
Quote from: "Laurent"
I'm curious: why do you need to achieve that?


Well, if you're asking me, I'm developing a node-based audio tool (simila to SynthEdit), and for the node called "DAC" there will be a pin for every channel. If a user connects one of the pins to a source (let's say to an oscillator), then the program needs to send audio signals only to that channel (and by now, zeroes to the other channels). For example, if we have a DAC node with 2 pins, and I connect an oscillator to the second pin, the right speaker should play the audio coming from the oscillator, and the left speaker should remain silent. This is useful, if one wants to "slide" a sound from a channel to the other: there will be a mixer node, which will have 2 output pins, you just have to connect these two output pins to the DAC's two input pins, and you can just control the mixer node's controller to achive the effect. The sound will slide from one speaker to the other. (I tried that, and works :) Just wondered if there is a way to manage channels individually...)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Multiple audio channels that can be individually managed
« Reply #14 on: April 23, 2010, 09:16:11 pm »
Ok I see. That looks very interesting, don't hesitate to post in the "projects" forum when you have something to show :)

I think that the workaround involving the 3D position of the audio sources is the only solution with the current API (and probably with OpenAL).
Laurent Gomila - SFML developer

 

anything