|
[A5] Getting a SAMPLE_INSTANCE* from a SAMPLE_ID |
X-G
Member #856
December 2000
|
Simple question: Given an ALLEGRO_SAMPLE_ID from al_play_sample, how do I get its corresponding ALLEGRO_SAMPLE_INSTANCE* so I can adjust its volume, etc.? EDIT: Also, what is the difference between al_sample_stop_sample_instance and al_set_sample_instance_playing(false) ? -- |
Matthew Leverton
Supreme Loser
January 1999
|
It's been a while since I used A5's sound routines. X-G said: Given an ALLEGRO_SAMPLE_ID from al_play_sample, how do I get its corresponding ALLEGRO_SAMPLE_INSTANCE* so I can adjust its volume, etc.? I'm not sure that you can. (That's not to say it wouldn't be nice to be able to get the sample instance from an ID.) I think in that case you have to use the more "advanced" API: ALLEGRO_SAMPLE_INSTANCE* sample_inst = al_create_sample_instance(sample); al_play_sample_instance(sample_inst); /* make changes to that sample_inst ... */ You can create multiple instances of the same sample. Note that the API you're currently using via al_reserve_samples() is basically just a shortcut for the above. Quote: Also, what is the difference between al_sample_stop_sample_instance and al_set_sample_instance_playing(false) ? Nothing, as far as I know. Could be wrong. But I think a long, long time ago there was some internal back-and-forth between having one or two abstract property getter and setters vs having unique functions, and perhaps there's still some (unintended?) multiple ways of doing things. |
X-G
Member #856
December 2000
|
Yeah, looks like it. I'll do it the "manually created sample instance" way, but it seems such a shame to have convenience functions in the library and then not allow you to use any of the functions you actually want to use on the result (aside from stop). Personally I kinda feel that al_play_sample should return an ALLEGRO_SAMPLE_INSTANCE* rather than that ID thing. Maybe. Could be some internal reason why it shouldn't. Either way... -- |
Evert
Member #794
November 2000
|
X-G said: Personally I kinda feel that al_play_sample should return an ALLEGRO_SAMPLE_INSTANCE* rather than that ID thing. Maybe. Could be some internal reason why it shouldn't. I think that it may have done that at one point in the past. I don't remember the reasons for changing that though, but it could have something to do with the persistance of the ALLEGRO_SAMPLE_INSTANCE pointer. |
X-G
Member #856
December 2000
|
Could be, but then at least there needs to be an al_get_sample_instance_from_id(). Basically what I'm trying to do is the equivalent of adjust_sample from A4... which does exist in the form of sample_instance_set*, but if I can't get an instance... -- |
Matthew Leverton
Supreme Loser
January 1999
|
Evert said: I think that it may have done that at one point in the past. I don't remember the reasons for changing that though, but it could have something to do with the persistance of the ALLEGRO_SAMPLE_INSTANCE pointer. Originally ALLEGRO_SAMPLE was ALLEGRO_SAMPLE_DATA and ALLEGRO_SAMPLE_INSTANCE was ALLEGRO_SAMPLE. I switched it around to the way it was now in order to make the "simple" mode the default. (i.e., To work more like Allegro 4.) I'd have to look at the source to refresh myself, but I'm thinking that if the actual instance were returned, you could completely mess up future al_play_sample calls if you did things like destroyed that sample instance. Edit: It seems like the advantage of the current setup is that you never have to al_destroy_sample_instance() when doing an al_play_sample(). When it's done playing, it's lost, and it can be reused. I think we could introduce an ALLEGRO_SAMPLE_ID to ALLEGRO_SAMPLE_INSTANCE function if:
While ALLEGRO_SAMPLE_ID would not be strictly necessary if it were impossible to destroy the reserved instances, I think it would still be useful so you know whether or not you're dealing with the same instance as you think you are. |
Evert
Member #794
November 2000
|
Matthew Leverton said: I think we could introduce an ALLEGRO_SAMPLE_ID to ALLEGRO_SAMPLE_INSTANCE function if: * it returned NULL if the sample has expired (finished playing) the call to al_destroy_sample_instance() returned false if you tried to destroy a reserved sample Agreed. The documentation should also come with a big fat warning to use the returned sample immediately and not store it. Even then there is a chance that by the time you use it the sample has expired. |
|