sox: Patch for Psion .prc format
Silas S. Brown <ssb22 <at> cam.ac.uk>
2006-10-11 12:30:57 GMT
Hi,
Apologies if I sent this to the wrong place.
The following patch fixes a small bug in sox's
writing of .prc files, and there's also a
workaround for the Psion 7 "click" problem.
The existing code writes the length field as a
2-byte word. It is actually a 4-byte double
word. If you treat it as a 2-byte word then any
sound longer than 8.2 seconds is truncated to an
arbitrary length less than that (because EPOC
ignores any bytes in the file after the length).
This patch gets sox to write the correct 4-byte
length field, so that longer sounds can work.
-----------cut here--------------------------
--- old-prc.c 2006-10-11 12:24:44.000000000 +0100
+++ sox-12.18.2/src/prc.c 2006-10-11 12:27:40.000000000 +0100
<at> <at> -198,16 +198,15 <at> <at>
static void prcwriteheader(ft_t ft)
{
- char nullbuf[15];
+ char nullbuf[12];
prc_t p = (prc_t ) ft->priv;
st_report("Final length=%d",p->length);
- memset(nullbuf,0,14);
+ memset(nullbuf,0,12);
st_writebuf(ft, header, 1, sizeof(header));
- st_writew(ft, p->length);
- st_writebuf(ft, nullbuf,1,14);
- st_writew(ft, p->length);
- st_writebuf(ft, nullbuf,1,2);
+ st_writedw(ft, p->length);
+ st_writebuf(ft, nullbuf,1,12);
+ st_writedw(ft, p->length);
}
/* Psion .prc */
-----------cut here--------------------------
(Note that it is not necessary to dimension
'nullbuf' to 1 more than the number of bytes you
want, as it is not a string with a terminator.)
On the subject of Psion .PRC files, the Psion
Series 7 is famous for making spurious "click"
noises at the end of sounds and between repeats.
(This bug is not present in the Psion Revo.)
I have found by experimenting that these "click"
noises can be eliminated by adding 8 samples of
absolute silence to the end of the file. (Fewer
than 8 sometimes works too, but 8 always works.)
Below is a Python function to (a) fix incorrect
length fields in any PRC file and (b) optionally
add the 8 samples of silence if not already present.
(This is nothing to do with sox, but I might as
well mention it. If you use it, you won't need
the above patch.)
-----------cut here--------------------------
def fix_prc_length(filename, also_fix_psion7_click = True):
d=open(filename).read()
if also_fix_psion7_click:
while not d.endswith('\xd5'*8): d+='\xd5'
l=len(d)-72; l=chr(l&0xFF)+chr(l>>8&0xFF)+chr(l>>16&0xFF)+chr(l>>24&0xFF)
open(filename,'wb').write(d[:52]+l+d[56:68]+l+d[72:])
-----------cut here--------------------------
Best wishes. Silas
--
--
Silas S Brown, Computer Lab Cambridge UK http://www.cus.cam.ac.uk/~ssb22
"He that is wise keeps it calm to the last." - Proverbs 29:11
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642