Hi
WHAT I WANT TO DO
I have been trying to create some cool audio Panning effects for a game im working on.
It would work by setting the Pan of a sample to -100 or 100 ( as it plays ) depending on how far it is from the center of the screen, like this:
If Bomb collides with Ground
- Play Sample BOOM
- Set Pan of BOOM to BombX - ( FrameXright - FrameXleft )/2
- Bomb destroy
...
THE PROBLEM
Problem is if multiple Bombs hit Ground making the BOOM Samples overlap, the 'Set Pan' action only ever referrs to the first Sample it finds in the Channel list ( 'Set Sample Volume' also works like this, maybe 'Set Sample Position' too ).
So for example, if i drop 3 bombs across the screen ( 1 at the left side, 1 in the middle, 1 at the right side ), i would expect something like this:
C#1: BOOM, Pan -100
C#2: BOOM, Pan 0
C#3: BOOM, Pan 100
But istead, since the Set Pan of BOOM allways only referrs to the first BOOM Sample it can find, i end up with this:
C#1: BOOM, Pan 100
C#2: BOOM, Pan 0
C#3: BOOM, Pan 0
...
THE PROBLEM IN DETAIL
In detail what happens is:
FIRST BOMB
If Bomb collides with Ground
- Play Sample BOOM ( plays in first empty Channel, Channel#1 )
- Set Pan of BOOM ( Sets Pan of first BOOM sample it finds in Channel list, sets pan of Channel#1 ), -100
- Bomb destroy
SECOND BOMB
If Bomb collides with Ground
- Play Sample BOOM ( plays in first empty Channel, Channel#2 )
- Set Pan of BOOM ( Sets Pan of first BOOM sample it finds in Channel list, sets pan of Channel#1 ), 0
- Bomb destroy
THIRD BOMB
If Bomb collides with Ground
- Play Sample BOOM ( plays in first empty Channel, Channel#3 )
- Set Pan of BOOM ( Sets Pan of first BOOM sample it finds in Channel list, sets pan of Channel#1 ), 100
- Bomb destroy
...
THE SOLUTION
The solution for this is very simple in theory.
What is needed is a 'Channel Index Pointer' which, as soon as a Sample plays, changes to the Channel# the Sample is played on.
EXAMPLE A
Lets take the Bomb example from above and see if this solution will get the job done:
So for example, if i drop 3 bombs across the screen ( 1 at the left side, 1 in the middle, 1 at the right side )
FIRST BOMB
If Bomb collides with Ground
- Play Sample BOOM ( plays in first empty Channel, Channel#1. 'Channel Index Pointer' is set to 1 )
- Set Pan of Channel#<Channel Index Pointer value> ( Sets Pan of Channel#1 ), -100
- Bomb destroy
SECOND BOMB
If Bomb collides with Ground
- Play Sample BOOM ( plays in first empty Channel, Channel#2. 'Channel Index Pointer' is set to 2 )
- Set Pan of Channel#<Channel Index Pointer value> ( Sets Pan of Channel#2 ), -100
- Bomb destroy
SECOND BOMB
If Bomb collides with Ground
- Play Sample BOOM ( plays in first empty Channel, Channel#3. 'Channel Index Pointer' is set to 3 )
- Set Pan of Channel#<Channel Index Pointer value> ( Sets Pan of Channel#3 ), -100
- Bomb destroy
RESULTS
C#1: BOOM, Pan -100
C#2: BOOM, Pan 0
C#3: BOOM, Pan 100
Amazing , it works!
...
EXAMPLE B
With this 'Channel Index Pointer' solution, i can create 3 different Samples and Pan them correctly according to their origins in a single event
Start of frame
- Set Origin to -100
- Play Sample BOOM
- Set Pan of Channel#<Channel Index Pointer value> to Origin
- Set Origin to 0
- Play Sample BOOM
- Set Pan of Channel#<Channel Index Pointer value> to Origin
- Set Origin to 100
- Play Sample BOOM
- Set Pan of Channel#<Channel Index Pointer value> to Origin
With a 'Channel Index Pointer' you are allways able to referr to the Sample being played, regradless of there being other Instances of the Smaple in play at the time.
Remember, this also applies to and fixes same issues with 'Set Sample Volume' and 'Set Sample Position'.
So what do you think?
Im not expecting or demanding anything, but this cant be that hard to do right?
As it is right now its impossible for me, and you, to create flawless consisten stereo panning in Apps or Games ( that is, if your design allows for multiple Sample Instances to play at the same time ) without going out of your way by creating your own or using alternative audio Objects/ Extencions/ Engines.











Reply With Quote





