Date: Fri, 20 Sep 2002 09:22:20 +1000 (EST) From: Peter Jeremy <peter.jeremy@alcatel.com.au> To: FreeBSD-gnats-submit@FreeBSD.org, murbani@libero.it Subject: ports/42975: audio/dagrab generates corrupt mono .WAV files Message-ID: <200209192322.g8JNMKd7008450@gsmx07.alcatel.com.au>
next in thread | raw e-mail | index | archive | help
>Number: 42975 >Category: ports >Synopsis: audio/dagrab generates corrupt mono .WAV files >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-ports >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Sep 19 16:30:03 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Peter Jeremy >Release: FreeBSD 4.7-PRERELEASE i386 >Organization: Alcatel Australia Limited >Environment: System: FreeBSD server.c18609.belrs1.nsw.optusnet.com.au 4.7-PRERELEASE FreeBSD 4.7-PRERELEASE #4: Sat Sep 14 15:07:16 EST 2002 root@server.c18609.belrs1.nsw.optusnet.com.au:/usr/obj/usr/src/sys/server i386 dagrab-0.3.5 >Description: When generating mono .WAV files from a CD, dagrab generates an incorrect RIFF header and the last (partial) block is saved in stereo rather than mono. Also no error checking is performed on writes in mono mode. The problem in the header is that the total chunk size (Rlen) is not adjusted for mono data and always contains the size assuming stereo data. For the last (partial) block, there is no test whether the data is being saved as mono or stereo - the block is always written in stereo mode. >How-To-Repeat: Grab a track in mono mode and use a WAV file analyser (eg sndfile_info which is part of libsndfile) to validate the structure. >Fix: The following patch is relative to dagrab.c after the FreeBSD ports patch. The patches don't clash but the line numbers may be different. --- dagrab.c.old Thu Sep 19 18:27:00 2002 +++ dagrab.c Thu Sep 19 18:14:46 2002 @@ -206,16 +206,20 @@ struct Wavefile cd_newave(unsigned size) { - struct Wavefile dummy={{'R','I','F','F'},0x24+size,{'W','A','V','E'}, - {'f','m','t',' '},0x10,1,2,44100,4*44100,4,16, - {'d','a','t','a'},size }; - /*dummy.Dlen=size; - dummy.Rlen=0x24+size;*/ - dummy.sample_rate = opt_srate; - dummy.channel = 2 - opt_mono; - dummy.byte_rate = opt_srate << dummy.channel; - dummy.align = dummy.channel * dummy.sample >> 3; - dummy.Dlen >>= opt_mono; + struct Wavefile dummy={{'R','I','F','F'}, /* Rid */ + 0x24 + (size >> opt_mono), /* Rlen */ + {'W','A','V','E'}, /* Wid */ + {'f','m','t',' '}, /* Fid */ + 0x10, /* Flen */ + 1, /* tag */ + 2 - opt_mono, /* channel */ + opt_srate, /* sample_rate */ + opt_srate << (2 - opt_mono), /* byte_rate */ + 16 * (2 - opt_mono) >> 3, /* align */ + 16, /* sample */ + {'d','a','t','a'}, /* Did */ + size >> opt_mono /* Dlen */ + }; return dummy; } @@ -796,6 +800,7 @@ struct Wavefile header; int fd,bytes,i,n,q,space; int bcount, sc, missing, speed = 0, ldp, now; + ssize_t wlen; if(tn<tl->min || tn>tl->max) return (-1); space = ((tl->starts[tn-tl->min+1]-tl->starts[tn-tl->min]) * @@ -879,8 +884,10 @@ d = p1[c]; buf3[c] = ((short)(d&65535) + (short)(d>>16)) >> 1; } - write(fd,buf3,n>>1); - } else if(write(fd,p1,n)==-1){ + wlen = write(fd,buf3,n>>1); + } else + wlen = write(fd,p1,n); + if (wlen == -1){ fprintf(stderr,"%s: error writing wave file %s: %s\n", progname,nam,strerror(errno)); exit(1); @@ -896,7 +903,17 @@ /* dump last bytes */ if (bytes<(tl->starts[tn+1]-tl->starts[tn])*CD_FRAMESIZE_RAW){ n=(tl->starts[tn+1]-tl->starts[tn])*CD_FRAMESIZE_RAW-bytes; - if(write(fd,p1,n)==-1){ + if(opt_mono) { + register int c, d; + for(c = 0; c < (n>>2); c++) { + d = p1[c]; + buf3[c] = ((short)(d&65535) + (short)(d>>16)) >> 1; + } + wlen = write(fd,buf3,n>>1); + } else + wlen = write(fd,p1,n); + + if(wlen==-1){ fprintf(stderr,"%s: error writing wave file %s: %s\n",progname,nam,strerror(errno)); exit(1); }; >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209192322.g8JNMKd7008450>