*** sound.c.orig	Fri Nov  1 13:04:46 1996
--- sound.c	Fri Nov  1 15:08:05 1996
***************
*** 980,985 ****
--- 980,986 ----
  	double rate;
  	int channels;
  	int bits;
+ 	char id[5];
  	char *p;
  
  	p = buf + 4;
***************
*** 992,1045 ****
  	}
  	p += 4;
  
  	for (;;)
  	{
! 	    if (memcmp (p, "fmt ", 4) == 0)
! 	    {
! 		p += 4;
! 		break;
! 	    }
! 
  	    p += 4;
  
  	    chunk_size = little_long (p);
  	    p += 4;
- 	    p += chunk_size;
- 	}
  
! 	chunk_size = little_long (p);
! 	p += 4;
! 
! 	chunk_type = little_short (p);
! 	p += 2;
! 	/*
! 	 * Only one wave format is supported.
! 	 */
! 	if (chunk_type == 0x0001)
! 	{
! 	    channels = little_short (p); p += 2;
! 	    rate = little_long (p); p += 4;
! 	    p += 4;		/* bytes/second ? */
! 	    p += 2;		/* block align ? */
! 	    bits = little_short (p); p += 2;
  	}
- 	else
- 	{
- 	    report (REPORT_ERROR, "unknown wave chunk `%x'\n", chunk_type);
- 	    return -1;
- 	}
  
- 	if (memcmp (p, "data", 4) != 0)
- 	{
- 	    report (REPORT_ERROR, "unexpected wave chunk\n");
- 	    return -1;
- 	}
- 	p += 4;
- 
- 	/* size */
- 	sound_chunk_size = little_long (p);
- 	p += 4;
- 
  	s->offset = p - buf;
  	s->sample_rate = rate;
  	s->input_precision = bits;
--- 993,1061 ----
  	}
  	p += 4;
  
+ 	/*
+ 	 * Scan the chunks.
+ 	 */
  	for (;;)
  	{
! 	    /*
! 	     * Chunk id.
! 	     */
! 	    memcpy (id, p, 4);
! 	    id[4] = '\0';
  	    p += 4;
  
+ 	    /*
+ 	     * Chunk size.
+ 	     */
  	    chunk_size = little_long (p);
  	    p += 4;
  
! 	    /*
! 	     * 'fmt ' Chunk.
! 	     */
! 	    if (memcmp (id, "fmt ", 4) == 0)
! 	    {
! 		chunk_type = little_short (p);
! 		p += 2;
! 		/*
! 		 * Only one wave format is supported.
! 		 */
! 		if (chunk_type == 0x0001)
! 		{
! 		    channels = little_short (p); p += 2;
! 		    rate = little_long (p); p += 4;
! 		    p += 4;		/* bytes/second ? */
! 		    p += 2;		/* block align ? */
! 		    bits = little_short (p); p += 2;
! 		}
! 	    }
! 	    /*
! 	     * data Chunk.
! 	     */
! 	    else if (memcmp (id, "data", 4) == 0)
! 	    {
! 		/* size */
! 		sound_chunk_size = chunk_size;
! 		p += 4;
! 		break;
! 	    }
! 	    /*
! 	     * Ignore other chunks.
! 	     */
! 	    else
! 	    {
! 		report (REPORT_DEBUG, "ignoring chunk - %s (%d)\n",
! 			id, chunk_size);
! 		p += chunk_size;
! 		/*
! 		 * skip the pad byte, if necessary
! 		 */
! 		if (chunk_size % 2 == 1)
! 		    p++;
! 	    }
  	}
  
  	s->offset = p - buf;
  	s->sample_rate = rate;
  	s->input_precision = bits;



