Re: [AD] voice_stop() and voice_start() on Linux

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> I can't reproduce the problem with the *current* CVS (the timer sync code
> is now disabled). Could you check with the modified exstream.c attached to
> this message ?

Your version of exstream.c works fine.

In my game, I'm calling get_audio_stream_buffer() even when the stream is 
paused. I've attached a further modified exstream.c which does the same 
thing. (I also made it not use text*_ex(), so it would compile with Allegro 
4.0.0.) This one doesn't work properly on my computer, even with the very 
latest CVS (checked out after I received your message). It works fine with 
Allegro 4.0.0.

Any clues as to what might have changed to cause this to stop working? I may 
shortly play with the CVS browser and see what's changed in src/stream.c...

Ben
/*
 *    Example program for the Allegro library, by Shawn Hargreaves.
 *
 *    This program shows how to use the audio stream functions to transfer
 *    large blocks of sample data to the soundcard.
 */


#include "allegro.h"



#define BUFFER_SIZE  1024



int main()
{
   AUDIOSTREAM *stream;
   unsigned char *p;
   int updates = 0;
   int pitch = 0;
   int val = 0;
   int i,c ;
   int stopped = 0;

   if (allegro_init() != 0)
      return 1;
   install_keyboard();
   install_timer();

   if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
	 return 1;
      }
   }

   set_palette(desktop_palette);
   clear_to_color(screen, makecol(255, 255, 255));

   /* install a digital sound driver */
   if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) != 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error initialising sound system\n%s\n", allegro_error);
      return 1;
   }

   /* create an audio stream */
   stream = play_audio_stream(BUFFER_SIZE, 8, FALSE, 22050, 255, 128);
   if (!stream) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error creating audio stream!\n");
      return 1;
   }

   text_mode(makecol(255, 255, 255));
   textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/3, makecol(0, 0, 0), "Audio stream is now playing...");
   textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/3+24, makecol(0, 0, 0), "Driver: %s", digi_driver->name);
   textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/3+48, makecol(0, 0, 0), "Press [space] to stop/resume");

   while (TRUE) {
      if (keypressed()) {
	 c = readkey();
	 if ((c >> 8) == KEY_SPACE) {
	    if (stopped) {
	       voice_start(stream->voice);
	       stopped = 0;
	    } else {
	       voice_stop(stream->voice);
	       stopped = 1;
	    }
	 }
	 else if ((c >> 8) == KEY_ESC)
	    break;
      }

      /* does the stream need any more data yet? */
      p = get_audio_stream_buffer(stream);

      if (p) {
	 /* if so, generate a bit more of our waveform... */
	 textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H*2/3, makecol(0, 0, 0), "update #%d", updates++);

	 for (i=0; i<BUFFER_SIZE; i++) {
	    /* this is just a sawtooth wave that gradually increases in
	     * pitch. Obviously you would want to do something a bit more
	     * interesting here, for example you could fread() the next
	     * buffer of data in from a disk file...
	     */
	    p[i] = (val >> 16) & 0xFF;
	    val += pitch;
	    pitch++;
	    if (pitch > 0x40000)
	       pitch = 0x10000;
	 }

	 free_audio_stream_buffer(stream);
      }
   }

 End:
   stop_audio_stream(stream);

   return 0;
}

END_OF_MAIN();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/