delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/16/21:22:36

From: "Seunghwan Ji" <shjee AT nexgen DOT co DOT kr>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Sound with allegro
Date: Mon, 16 Aug 1999 21:44:30 +0900
Organization: Korea Telecom
Lines: 75
Message-ID: <7p90q0$oj1$1@news2.kornet.net>
References: <rrekvqaqoqs14 AT corp DOT supernews DOT com> <37B76C37 DOT 43A AT ns DOT sympatico DOT ca> <rrfe9tapoqs60 AT corp DOT supernews DOT com>
NNTP-Posting-Host: 210.113.220.61
X-Newsreader: Microsoft Outlook Express 4.72.3610.0100
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3610.0100
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I think your problem is....
    play_sample() function doesn't wait until the wav file finish playing..
    Instead it return immediatley after the internal voice allocation and
settings..
    Refer to the source code of allegro below...

/* play_sample:
 *  Triggers a sample at the specified volume, pan position, and frequency.
 *  The volume and pan range from 0 (min/left) to 255 (max/right), although
 *  the resolution actually used by the playback routines is likely to be
 *  less than this. Frequency is relative rather than absolute: 1000
 *  represents the frequency that the sample was recorded at, 2000 is
 *  twice this, etc. If loop is true the sample will repeat until you call
 *  stop_sample(), and can be manipulated while it is playing by calling
 *  adjust_sample().
 */
int play_sample(SAMPLE *spl, int vol, int pan, int freq, int loop)
{
   int voice = allocate_voice(spl);

   if (voice >= 0) {
      voice_set_volume(voice, vol);
      voice_set_pan(voice, pan);
      voice_set_frequency(voice, absolute_freq(freq, spl));
      voice_set_playmode(voice, (loop ? PLAYMODE_LOOP : PLAYMODE_PLAY));
      voice_start(voice);
      release_voice(voice);
   }

   return voice;
}
END_OF_FUNCTION(play_sample);

And.. I corrected your source..

#include <allegro.h>
#include <iostream.h>

void main()
{
    int voice;
    SAMPLE *amazing;

    allegro_init();
    install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);

    amazing = load_wav("c:\\amazing.wav");


    voice = allocate_voice(amazing);
    if (voice >= 0) {
        voice_set_volume(voice, 255);
        voice_set_pan(voice, 128);
        voice_set_playmode(voice, PLAYMODE_PLAY);
        voice_start(voice);
        while (1) {
            if (!voice_check(voice)) break;
            if (voice_get_position(voice) < 0) break;
        }
        deallocate_voice(voice);
    }

    if (amazing) destroy_sample(amazing);

    allegro_exit();
}


Or.. you can simply put rest(...) function between play_sample() and
allegro_exit()..

Seunghwan Ji



- Raw text -


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