delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/05/04:54:49

From: Alex Demko <ademko AT mbnet DOT mb DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Importing WAVs into Grabber
Date: Sun, 05 Jan 1997 02:24:35 -0600
Organization: The University of Manitoba
Lines: 141
Message-ID: <32CF6543.5461@mbnet.mb.ca>
References: <32c80c47 DOT 21201245 AT ursa DOT smsu DOT edu> <32CF2F23 DOT 3E1E AT infocom DOT net>
NNTP-Posting-Host: ts1u-4.cc.umanitoba.ca
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

> > Doesn anyone know of a WAV recorder that Grabber likes?

Here is a msg I got from sean regarding this problem:

QUOTE BEGINS
============
Like I said before, all my windows programs can read the allegro
spl files, however ANY file that I save cannot be read by ex17.exe
(your example program). I'm using Sound Gadget (95), Sound Recorder (95)
and Wave Studio (comes with the SB16) to make the WAV files. I'll
uuencode them in the next message...

Aha! Got it. I was assuming the WAV file would only contain "fmt" and   
"data"
chunks, but your WAV's had some extra copyright and version information
that my parser didn't like. I fixed it, so it should now skip any
unknown
chunks rather than complaining.

Try changing the load_sample() function in sound.c to this:


/* load_sample:
 *  Reads a mono RIFF WAV format sample file, returning a SAMPLE   
structure,
 *  or NULL on error.
 */
SAMPLE *load_sample(char *filename)
{
   PACKFILE *f;
   char buffer[25];
   int i;
   int length, len;
   int freq = 22050;
   int bits = 8;
   signed short s;
   SAMPLE *spl = NULL;

   f = pack_fopen(filename, F_READ);
   if (!f)
      return NULL;

   pack_fread(buffer, 12, f);          /* check RIFF header */
   if (memcmp(buffer, "RIFF", 4) || memcmp(buffer+8, "WAVE", 4))
      goto getout;

   while (!pack_feof(f)) {
      if (pack_fread(buffer, 4, f) != 4)
  break;

      length = pack_igetl(f);          /* read chunk length */

      if (memcmp(buffer, "fmt ", 4) == 0) {
  i = pack_igetw(f);            /* should be 1 for PCM data */
  length -= 2;
  if (i != 1)
     goto getout;

  i = pack_igetw(f);            /* should be 1 for mono data */
  length -= 2;
  if (i != 1)
     goto getout;

  freq = pack_igetl(f);         /* sample frequency */
  length -= 4;

  pack_igetl(f);                /* skip six bytes */
  pack_igetw(f);
  length -= 6;

  bits = pack_igetw(f);         /* 8 or 16 bit data? */
  length -= 2;
  if ((bits != 8) && (bits != 16))
     goto getout;
      }
      else if (memcmp(buffer, "data", 4) == 0) {
  len = length;
  if (bits == 16)
     len /= 2;

  spl = malloc(sizeof(SAMPLE));

  if (spl) {                    /* initialise the sample struct */
     spl->bits = 8;
     spl->freq = freq;
     spl->len = len;

     spl->data = malloc(len);
     if (!spl->data) {
        free(spl);
        spl = NULL;
     }
     else {                     /* read the actual sample data */
        if (bits == 8) {
    pack_fread(spl->data, len, f);
    length -= len;
        }
        else {
    for (i=0; i<spl->len; i++) {
       s = pack_igetw(f);
       length -= 2;
       ((unsigned char *)spl->data)[i] = (s^0x8000) >> 8;
    }
        }
        if (errno) {
    free(spl->data);
    free(spl);
    spl = NULL;
        }
     }
  }
      }

      while (length > 0) {             /* skip the remainder of the
chunk   
*/
  if (pack_getc(f) == EOF)
     break;

  length--;
      }
   }

   getout:

   pack_fclose(f);

   if (spl)
      lock_sample(spl);

   return spl;
}
=======
QUOTE ENDS


-- 
====================================================================
Alex Demko (Alex_Demko AT mbnet DOT mb DOT ca) # Chaos Software Productions
Univ. of Manitoba Comp. Sci.        # Just released: Drip! (PC 386+)
C C++ Pascal Delphi Perl HTML Java  # http://www.mbnet.mb.ca/chaos

- Raw text -


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