![]() |
|
Control multiple versions of the same sound |
DavyKager
Member #8,299
February 2007
|
Hi! I am building an audiogame based on Allegro, but I encounter some problems during the process. As I've said before, I'm an absolute beginner, so excuse me for asking this stupid things. I'd like to have multiple versions of the same sound playing, which I can control seperately. The last is possible with Voice Control, but I need to specify a voice so I can adjust it. So, I have to obtain the voice where the sound is playing with allocate_voice, but at the same time I already need this voicenumber, because it should be my ID. I know this is not very common, but does someone get my point and maybe can provide some help? |
Tobias Dammers
Member #2,604
August 2002
![]() |
First allocate, then adjust. Store the ID in a member var of your object. --- |
DavyKager
Member #8,299
February 2007
|
I just don't know how to do this in another way. My problem is that I want to make multiple objects at the same time. And if Allegro gives me a voicenumber, and I store that, and then build up a new object (from the same function) it'll override the original one, isn't it? |
Tobias Dammers
Member #2,604
August 2002
![]() |
No. --- |
gnolam
Member #2,030
March 2002
![]() |
Quote: So, I have to obtain the voice where the sound is playing with allocate_voice Or just use the value returned by play_sample(). -- |
DavyKager
Member #8,299
February 2007
|
So you think it's possible to place objets (stones, cars, whatever) with just one function which will manage all the objects simultaniously? |
ImLeftFooted
Member #3,935
October 2003
![]() |
Better to allow only 1 instance of a sound to play at once. The more sounds you play the lower the sound quality. If you get too many playing at once it will sound awful and you lose the point of playing sounds in the first place. Also remember the old saying KISS, Keep It Simple, Stupid. |
DavyKager
Member #8,299
February 2007
|
Alright, but this is going to be an audiogame... Tomorrow I'll try classes and arrays (good practice!). |
Audric
Member #907
January 2001
|
You don't select the voices number yourself... If you have any sound program running (Winamp), you could have ANY voices busy and unavailable to Allegro - and it probably won't be as simple as voices 0 and 1.
edit: argh, I just saw the word "classes" in your post.. I should have made it C++ instead of C++-like. |
DavyKager
Member #8,299
February 2007
|
I have made a class where a function runs that places objects. Now I'm able to do this: object ob1; I can play one object, and I think I can also make it adjust the sample. And this afternoon I'll try to make it working for multiple objects (won't be too hard using classes I hope). |
Richard Phipps
Member #1,632
November 2001
![]() |
There is a design flaw (IMHO) in Allegro's sound handling which makes it difficult to play a sample using a specific voice. You have to let Allegro find a voice and then manipulate that voice channel. |
Tobias Dammers
Member #2,604
August 2002
![]() |
This is not a design flaw, it's how the api works. It is similar to when you allocate a pointer or a handle: you will get whatever free space the memory allocation algorithm finds for you. You can't say, for example: int* p = new int at 0x00AA1234; Allegro's voices work exactly the same, only that the address space is "a little" smaller. --- |
DavyKager
Member #8,299
February 2007
|
By the way, am I right that adjust_sample(*spl); adjusts the first one that it finds. So, if you make two samples, the first one is always adjusted, even if you call adjust_sample() multiple times? |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Quote: Allegro's voices work exactly the same, only that the address space is "a little" smaller. If you want to keep a voice number, you can use reallocate_voice. Just make sure it isn't set to deallocate automatically. Then you also have to worry about running out of voices. Quote: the first one is always adjusted, even if you call adjust_sample() multiple times? It seems it might only modify the last one you played. Which seems to jive with the api, play_sample makes a voice that auto deallocates when finished, so you can't rely on the voice id existing and being usefull at all for any length of time. For more complex sound using games, you MUST use the voice functions and ignore the play_sample function all together. play_sample is a fire and forget type interface. edit: Actually play_sample returns the voice number for the voice it allocated, so you can use the voice functions with that if you wish. But its all the same really. -- |
DavyKager
Member #8,299
February 2007
|
If I play one sound with my own created class all is fine, but when I try to play two sounds, they're played at the far left side of the stereofield. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Maybe you're passing the pan value in wrong? -- |
DavyKager
Member #8,299
February 2007
|
The pan variable is currently declared in the function itself (which is declared in the class), but that seems to trouble. I know that this stuff isn't really common, although I hope to find a good solution quite soon. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Post the play_sample code you have. as well as some of the code arround it, so we can see how you're using it. -- |
DavyKager
Member #8,299
February 2007
|
I don't know if someone is able to understand it, but here we go... The class: class rock { public: int rock_x; int rock_y; rock(); ~rock(); void adjust_rock(void); };
|
Thomas Fjellstrom
Member #476
June 2000
![]() |
Please use the <code>code here</code> tags The only thing I can think at this point is the pan variable is getting to large or too small. try printf'ing or cout'ing the value of it when you modify it. -- |
DavyKager
Member #8,299
February 2007
|
One last question: Is it true that Allegro adjusts the volume when you pan a sound, and if so, can I prevent Allegro from doing that? |
GullRaDriel
Member #3,861
September 2003
![]() |
Do you really realize what pan mean ? "Code is like shit - it only smells if it is not yours" |
DavyKager
Member #8,299
February 2007
|
I meant: are there differences between the way adjust_sample and voice_set_pan works? Some programs/mixers/whatever boost the volume of the left channel when you pan to the left. But others just cut down the volume of the right side (which is better in my opinion). Edit: I found it! I needed set_volume_per_voice(). |
|