From orc@pell.portland.or.us  Wed Nov 20 18:26:53 2002
Return-Path: <orc@pell.portland.or.us>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 8BE0B37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 20 Nov 2002 18:26:53 -0800 (PST)
Received: from pell.portland.or.us (pell.portland.or.us [192.156.98.250])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 7E15E43E91
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 20 Nov 2002 18:26:52 -0800 (PST)
	(envelope-from orc@pell.portland.or.us)
Received: (from orc@localhost)
	by pell.portland.or.us (8.8.5/8.8.5) id RAA22252
	for FreeBSD-gnats-submit@freebsd.org; Wed, 20 Nov 2002 17:12:07 -0800
Message-Id: <200211210112.RAA22252@pell.portland.or.us>
Date: Wed, 20 Nov 2002 17:12:07 -0800
From: david parsons <orc@pell.portland.or.us>
Reply-To: david parsons <orc@pell.portland.or.us>
To: FreeBSD-gnats-submit@freebsd.org
Subject: a patch to make burncd handle .wav files.
X-Send-Pr-Version: 3.113

>Number:         45547
>Category:       bin
>Synopsis:       [patch] make burncd(8) handle .wav files.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 20 18:30:02 PST 2002
>Closed-Date:    Thu Feb 17 13:22:56 UTC 2011
>Last-Modified:  Thu Feb 17 13:22:56 UTC 2011
>Originator:     david parsons
>Release:        FreeBSD 4.7-RELEASE i386
>Organization:
n/a
>Environment:
System: FreeBSD india.pell.portland.or.us 4.7-RELEASE FreeBSD 4.7-RELEASE #2: Thu Oct 24 14:43:00 PDT 2002 root@india.pell.portland.or.us:/usr/src/sys/compile/PACIFIC i386


>Description:
	burncd writes out .wav headers when recording audio, creating
	annoying clicks at the start of each track.
>How-To-Repeat:
	burn an audio cd.
>Fix:
Apply this patch (i386 only, I guess)

*** burncd.c~	Mon Nov 18 17:46:37 2002
--- burncd.c	Wed Nov 20 00:36:13 2002
***************
*** 48,53 ****
--- 48,54 ----
  	int	file;
  	char	*file_name;
  	u_int	file_size;
+ 	off_t	file_start;
  	int	block_size;
  	int	block_type;
  	int	pregap;
***************
*** 283,288 ****
--- 284,326 ----
  }
  
  void
+ get_info(int fd, int block_type, struct stat *sb, struct track_info *trk)
+ {
+ 	off_t pos = lseek(fd, 0, SEEK_CUR);
+ 
+ 	struct riff_hdr {
+ 		char magic[4];
+ 		unsigned long size;
+ 	} header;
+ 	char wave[4];
+ 
+ #define RD_HDR()	(read(fd, &header, sizeof header) == sizeof header)
+ #define GETHDR(s)	(RD_HDR() && memcmp(header.magic, s, 4) == 0)
+ 
+ 	/* special handling for .wav audio files */
+ 
+ 	if (block_type == CDR_DB_RAW && GETHDR("RIFF")
+                                      && read(fd, wave, 4) == 4
+                                      && memcmp(wave, "WAVE", 4) == 0 ) {
+ 
+ 		while (RD_HDR()) {
+ 			/* return a pointer to the first "data" chunk */
+ 			if (memcmp(header.magic, "data", 4) == 0) {
+ 				trk->file_start = lseek(fd, 0, SEEK_CUR);
+ 				trk->file_size = header.size;
+ 				return;
+ 			}
+ 			else
+ 				lseek(fd, header.size, SEEK_CUR);
+ 		}
+ 	}
+ 	/* everything else is just a bytestream */
+ 	trk->file_size = sb->st_size;
+ 	trk->file_start = 0;
+ 	lseek(fd, pos, SEEK_SET);
+ }
+ 
+ void
  add_track(char *name, int block_size, int block_type, int nogap)
  {
  	struct stat sb;
***************
*** 299,312 ****
  	}
  	else if ((file = open(name, O_RDONLY, 0)) < 0)
  		err(EX_NOINPUT, "open(%s)", name);
  	if (fstat(file, &sb) < 0)
  		err(EX_IOERR, "fstat(%s)", name);
  	tracks[notracks].file = file;
  	tracks[notracks].file_name = name;
! 	if (file == STDIN_FILENO)
  		tracks[notracks].file_size = -1;
  	else
! 		tracks[notracks].file_size = sb.st_size;
  	tracks[notracks].block_size = block_size;
  	tracks[notracks].block_type = block_type;
  
--- 337,353 ----
  	}
  	else if ((file = open(name, O_RDONLY, 0)) < 0)
  		err(EX_NOINPUT, "open(%s)", name);
+ 
  	if (fstat(file, &sb) < 0)
  		err(EX_IOERR, "fstat(%s)", name);
+ 
  	tracks[notracks].file = file;
  	tracks[notracks].file_name = name;
! 	if (isatty(file))
  		tracks[notracks].file_size = -1;
  	else
! 		get_info(file, block_type, &sb, &tracks[notracks]);
! 
  	tracks[notracks].block_size = block_size;
  	tracks[notracks].block_type = block_type;
  
***************
*** 466,471 ****
--- 507,513 ----
  	char buf[2352*BLOCKS];
  	static int tot_size = 0;
  
+ 	lseek(track_info->file, track_info->file_start, SEEK_SET);
  	filesize = track_info->file_size / 1024;
  
  	if (ioctl(fd, CDRIOCSETBLOCKSIZE, &track_info->block_size) < 0)
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->sos 
Responsible-Changed-By: njl 
Responsible-Changed-When: Sat Nov 23 15:57:23 PST 2002 
Responsible-Changed-Why:  
Over to burncd(8) maintainer.  Patch looks like it could need some cleaning 
up (i.e. unnecessary one-use macros, definition of a struct for a single 
use).  Try to minimize your diff size by doing things like reading 8 bytes 
and comparing to "RIFFWAVE" instead of doing it separately.  Also you need 
a little endian conversion for the length field. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=45547 
State-Changed-From-To: open->suspended 
State-Changed-By: sos 
State-Changed-When: Sun May 4 03:11:53 PDT 2003 
State-Changed-Why:  
Use the UNIX way of things, same argument as in pr29292. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=45547 

From: Stewart Heitmann <stewart@heitmann.id.au>
To: freebsd-gnats-submit@FreeBSD.org, orc@pell.portland.or.us
Cc:  
Subject: Re: bin/45547: a patch to make burncd handle .wav files.
Date: Fri, 6 Feb 2004 23:28:03 +1100

 Just like to add two things:
 1) I applied this patch to my src/usr.sbin/burncd/burncd.c,
     v 1.10.2.7 2003/08/02 11:02:53 and while I had to manually
     edit the changes (patch didnt work due to line number differences)
     the resulting program did drop the heavy click from the start of
     the wav files. So the patch works.
 2) However, there is still an audible click on the transition between
     audio tracks when they are burnt with no gaps between them
     (ie using the burncd -n option).
     That is probably not a wave header issue but an issue related
     to smooth transitioning across wav files (my guess anyway).
 -- 
 Stewart Heitmann <stewart@heitmann.id.au>
 
Responsible-Changed-From-To: sos->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon May 11 21:45:47 UTC 2009 
Responsible-Changed-Why:  
sos@ is not actively working on ATA-related PRs. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=45547 
State-Changed-From-To: suspended->closed 
State-Changed-By: arundel 
State-Changed-When: Thu Feb 17 13:21:28 UTC 2011 
State-Changed-Why:  
Burncd(1) perfectly handles raw wave files. It is not intended to provide 
funcionality to strip away wave headers. Thus close this PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=45547 
>Unformatted:
