|
is a SAMPLE playing? |
Mark Oates
Member #1,146
March 2001
|
I like having self-contained code, so I'm trying to figure out a way to prevent a sample from playing if it's already playing. The way the code works, if the player is inside a "hint zone" then the sample plays looped. I want to avoid triggering the sample once, instead using a function like this: int play_sound(SAMPLE *s, bool looped=false) { if (!s) return 0; else if (****SAMPLE_IS_NOT_PLAYING****) { play_sample(s, 255, 128, 1000, looped); } return 1; } I searched the forums and found info about voice allocation. it seemed complicated and required external variables. Is there a simple way to do this? -- |
Billybob
Member #3,136
January 2003
|
There's a way to do it, but from my research you're going to need that external variable. Anyway you need to store the voice returned by play_sample. Then run voice_check on that value and see if it == the SAMPLE. If it does, the sample is playing. EDIT: I can't find a place where SAMPLE::param is used. Does Allegro ever use it? If not you can store the voice in there, that way you won't have to make a CSample or something to contain it. will only work if sizeof(void *) == sizeof(int)
|
Thomas Fjellstrom
Member #476
June 2000
|
or instead of wrapping SAMPLE, just wrap a voice.. thats all play_sample does. This way you get greater controll over your sounds. -- |
Mark Oates
Member #1,146
March 2001
|
It works, but it's ghetto:
[edit]reply for cookies -- |
Billybob
Member #3,136
January 2003
|
Better than nothin'.
|
Neil Walker
Member #210
April 2000
|
[edit]Ignore this, I spewed out a whole set of code for using the voice functions and managing them via timers, etc without realising that wasn't the question. So I've deleted it. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Mark Oates
Member #1,146
March 2001
|
Neil: What was the code all about? I'm interested. -- |
Neil Walker
Member #210
April 2000
|
You'll have to fill in the gaps yourself and ignore the class prefix, but... and maybe this somewhere: install_int(TimerDigiPurgeNow,TIMER_DIGIPURGETIME); void TimerDigiPurgeNow() { //music handler for purging stuff //automatically deallocates sounds that have stopped playing //called every 5 seconds, which seems reasonable to me TimerDigiPurge=true; } END_OF_FUNCTION(TimerDigiPurgeNow);
Then in your timer looper say,
Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
|