delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/13/14:31:49

From: epsilonbeta AT geocities DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: ALLEGRO: play_audio_stream
Date: Mon, 13 Apr 1998 18:39:18 GMT
Organization: EUnet Belgium, Leuven, Belgium
Lines: 128
Message-ID: <35325bd2.21122243@news.ping.be>
NNTP-Posting-Host: idialup217.antwerp.eunet.be
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi Evry1,

I'm trying to use the play_audio_stream-function of Allegro (3.0 + wip
of 12apr) to play back any wav-file.

Until now, I managed allready to play back a HUGE (+- 21MEG) 8-bit
mono wav.

What I can't play are
16-bit mono,
8-bit stereo,
16-bit stereo wav-files.

The program doesn't crash or so, I only get noise (kind of a very
short echo).

Since I wan't to be able to play very big samples I can't use the
regular play_sample-stuff (which is working nice BTW for small wavs of
all kinds).

Hereby I send you the routine which is causing the trouble.

/*---------------------------------------------------------------------------*/
#define BUFFER_SIZE 4096

/* s is the filename of the sample */
void play_stereo(char s[256])
{
  int i;
  ushr nchannels, wbitspersample;
  uint data_size, len, navgbytespersec, nbytes, nsamplespersec;
  FILE *fp;
  AUDIOSTREAM *stream;

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

  fp = fopen(s, "rb");

  fseek(fp, 22, SEEK_SET);
  nchannels = fgetc_ushr_l(fp); /* reads a 16-bit value LSB first */

  fseek(fp, 24, SEEK_SET);
  nsamplespersec = fgetc_uint_l(fp); /* 32-bit value */

  fseek(fp, 28, SEEK_SET);
  navgbytespersec = fgetc_uint_l(fp);

  fseek(fp, 34, SEEK_SET);
  wbitspersample = fgetc_ushr_l(fp);

  fseek(fp, 40, SEEK_SET);
  data_size = fgetc_uint_l(fp);

/* until here everything ok */

  if (nchannels == 2) /* stereo */
    {
      printf("stereo-sample\n");
      stream = play_audio_stream(BUFFER_SIZE, wbitspersample, TRUE,
				 nsamplespersec, 255, 128);
    }
  else /* mono */
    {
      printf("mono-sample\n");
      stream = play_audio_stream(BUFFER_SIZE, wbitspersample, FALSE,
				 nsamplespersec, 255, 128);
    }

  if (!stream)
    {
      printf("error:\n");
      printf("(play_stereo) !stream\n");
      exit(1);
    }

  printf("%i-bits\n", wbitspersample);
  printf("%i Hz\n", nsamplespersec);
  printf("%i samples\n", data_size);

  len = data_size;
  fseek(fp, 44, SEEK_SET);
  while (!keypressed() && (len > 0))
    {
      uchr* p = get_audio_stream_buffer(stream);

      if (p)
	{
	  nbytes = (len > BUFFER_SIZE) ? BUFFER_SIZE : len;

	  if (nbytes == BUFFER_SIZE)
	    {
	      for (i = 0; i < BUFFER_SIZE; i++)
		{
		  p[i] = fgetc_uchr(fp); /* 8-bit value */
		}
	    }
	  else
	    {
	      printf ("filling up rest of buffer with 0's\n");
	      for (i = 0; i < nbytes; i++)
		{
		  p[i] = fgetc_uchr(fp);
		}
	      for (i = nbytes; i < BUFFER_SIZE; i++)
		{
		  p[i] = 0;
		}
	    }
	  len -= nbytes;
	  free_audio_stream_buffer(stream);
	}
    }

  stop_audio_stream(stream);
  fclose(fp);
}
/*---------------------------------------------------------------------------*/

Thanks for any help,


Edward Boone (alias Epsilon Beta)
epsilonbeta AT geocities DOT com
http://www.geocities.com/SiliconValley/Vista/6617/index.html
/* Only nothing seems to be what it looks like */

- Raw text -


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