delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/02/16:03:13

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro: allocate_voice, voice_start, check_voice ...
Date: Mon, 2 Feb 1998 20:31:42 +0000
Organization: None
Distribution: world
Message-ID: <tXD4RnAu0i10EwkN@talula.demon.co.uk>
References: <6b5545$d8$1 AT news DOT interlog DOT com>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 46
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Adam Christopher Lawrence writes:
>    tmp = allocate_voice(qfile[Clue].dat); // Clue is the datafile sample
>    voice_start(tmp);
>    do
>    {
>        test = check_voice(tmp); // test is a previously defined sample
>    } while (test != NULL);
>    voice_stop(tmp);
>    // carry on execution here, (hopefully) once sample is concluded
>
>    It plays the sample fine, but never breaks out of the Do loop.

Use the voice_get_position() function instead of voice_check(). It will
return -1 when the sound has finished.

Don't forget to call deallocate_voice() at the end of your routine!

btw. please be careful when giving example code: the function is
voice_check() and not check_voice().

>    According to the Allegro docs (it's ver 3.0 by the way), 
>check_voice returns a sample if the voice is in use "or NULL if the 
>voice is inactive."

The voice_check() routine returns the allocation status of the voice,
which isn't always the same thing as whether it is currently playing.
When you allocate a voice it becomes yours, and will remain yours until
you explicitly free it. Even though it has reached the end of the
sample, it is still possible for you to restart the sound and play it
over again, so it is really only paused rather than truly stopped. In
order for voice_check() to return NULL, the channel must have been
freed, which is generally only something that you would want to check
after you have called the release_voice() function.

This isn't very well explained in the docs: I will revise that for the
next version.

>I don't want to have to add a sample length parameter to every datafile 

The length of the sound is contained in the SAMPLE structure, if you
ever need to access this.


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Pigs use it for a tambourine" - Frank Zappa

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019