2 # Copyright © 2012 Géraud Meyer <graud@gmx.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation.
11 raw96cdconv - converts between different formats of CD raw images
15 B<raw96cdconv> S<[ B<-v> ]> S<[ B<-n> ]> S<[ B<-f> ]> S<[ B<-c> | B<-r> ]> S<[ B<-S> ]> S<[ B<-I<C>> I<ext> ]> S<[ I<files> ]>
22 Getopt
::Long
::Configure
('bundling', 'no_auto_abbrev', 'auto_version', 'auto_help');
24 $main::VERSION
= "1.1";
26 my ($verbose, $no_act, $force, $swab, $subchan, $fullraw);
31 die Getopt
::Long
::HelpMessage
(128)
33 'v|verbose!' => \
$verbose,
34 'quiet' => sub { $verbose = 0 },
35 'n|no-act!' => \
$no_act,
36 'f|force!' => \
$force,
38 'sector-size=i' => \
$raw_sect,
39 'iso' => sub { $raw_sect = 2048; $raw = ".iso" },
40 'c|subchan!' => \
$subchan,
41 'r|fullraw!' => \
$fullraw,
43 'C|subch=s' => \
$subch,
44 'R|raw96=s' => \
$raw96,
46 $verbose++ if $no_act;
49 my $raw96_sect = $raw_sect + $subch_sect;
52 print "Reading filenames from STDIN\n" if $verbose;
59 my $src = $_ .(($fullraw) ?
$raw : $raw96);
60 my $in_sect = ($fullraw) ?
$raw_sect : $raw96_sect;
61 my $dst = $_ .(($fullraw) ?
$raw96 : (($subchan) ?
$subch : $raw));
62 unless ($force or !-e
$dst) {
63 warn "Skipping '$_' because '$dst' already exists\n" if $verbose;
66 unless (open SRC
, "<", $src) {
67 warn "ERROR Cannot open file '$src' for reading: $!\n";
71 unless ($no_act or open DST
, ">", $dst) {
72 warn "ERROR Cannot open file '$dst' for writing: $!\n";
75 binmode DST
unless $no_act;
77 unless (open SUBCH
, "<", $_ .$subch) {
78 warn "ERROR Cannot open file '$_$subch' for reading: $!\n";
85 SECTOR
: while (my $n = read SRC
, $buf, $in_sect) {
86 unless ($n == $in_sect) {
87 warn "ERROR Partial sector of size $n/$in_sect found in '$src'\n";
91 $buf = pack '(v)*', unpack('(n)*', $buf) if ($swab);
92 print DST
$buf unless $no_act;
93 my $m = read SUBCH
, $buf, $subch_sect;
94 unless ($m == $subch_sect) {
95 warn "ERROR Partial sub-channel block of size $m/$subch_sect found in '$_$subch'\n";
98 print DST
$buf unless $no_act;
100 print DST
substr($buf, $raw_sect) unless $no_act;
102 $buf = pack '(v)*', unpack('(n)*', substr($buf, 0, $raw_sect)) if ($swab);
103 print DST
substr($buf, 0, $raw_sect) unless $no_act;
107 print "$count sectors from '$src' written in '$dst'\n" if $verbose;
109 close SRC
; close DST
; close SUBCH
if ($fullraw);
111 print "There was $rc errors.\n" if $verbose and $rc;
118 C<raw96cdconv> generates a raw file by extracting raw CD sectors (made up either
119 of audio data or of raw data sectors) from a file made up of chunks containing
120 both raw data and sub-channel data (RAW+96). By default F<.raw> is appended to
121 the given file names to obtain the corresponding generated file name. If no
122 filenames are given on the command line, filenames will be read via standard
125 It is also possible to generate a file containing only sub-channel data or to
126 re-generate the full RAW+96 file containing both the raw and the sub-channel
127 data. The default extension for sub-channel files is F<.subch>.
129 The sector size of raw data is 2352 bytes; the corresponding sub-channel data
130 is 96 bytes long, so that the full RAW+96 file is made of chunks of 2448 bytes.
132 C<raw96cdconv> also works with images containing only data sectors (2048 bytes
133 long) and sub-channel data.
137 For example, to generate both a raw file F<image.raw> and a sub-channel file
143 To re-generate F<image> from F<image.raw> and F<image.subch>:
147 To generate F<image.raw96> instead of F<image>:
149 raw96cdconv -R .raw96 -r image
151 To extract an iso image F<image.iso> from F<image> that contains both (error
152 corrected) data sectors and sub-channel data:
154 raw96cdconv --iso image
156 If F<image> contains the image of a CDDA, it is more appropriate to extract to
159 raw96cdconv -A .cdda image
161 To convert the extracted raw audio to WAV, you may use sox(1):
163 sox -t .cdda image.cdda image.wav
165 To convert the extracted 2352b/s raw data to ISO, you may use ccd2iso(1):
167 ccd2iso <image.raw >image.iso
171 Options may be negated by prefixing them with "--no-" instead of "--".
175 =item B<-v>, B<--verbose>
177 Verbose: print the names of the files successfully generated as well as their
178 number of sectors, print the names of the files completely skipped and at the
179 end print the number of files that caused an error.
181 =item B<-n>, B<--no-act>
183 No Action: test the reading of files and show what files would have been
186 =item B<-f>, B<--force>
188 Force: overwrite existing files.
190 =item B<-S>, B<--swab>
192 Swap byte: swap the byte order of the raw data; it works for both normal mode
193 (raw data extraction) and full raw data mode. Use it with readcd(1) images
194 that contain little endian audio data.
196 =item B<--sector-size>
198 By default 2352, which corresponds to audio data (or to a raw sector of any
199 data). Use 2048 for error corrected data sectors.
203 Same as `B<--raw> .iso B<--sector-size> 2048'.
205 =item B<-c>, B<--subchan>
207 Sub-channel mode: generate a file containing only sub-channel data from the
210 =item B<-r>, B<--fullraw>
212 Full raw data mode: (re-)generate a RAW+96 file containing both raw and
213 sub-channel data from the raw file and the sub-channel data file.
215 =item B<-D>, B<--raw> I<ext>
217 =item B<-C>, B<--subch> I<ext>
219 =item B<-R>, B<--raw96> I<ext>
221 Extension: file name extensions; the first one is for raw files (default:
222 F<.raw>); the second one is for sub-channel data files (default: F<.subch>);
223 the third one is for RAW+96 data files (default: empty extension).
229 No environment variables are used.
233 G.raud <graud@gmx.com>
237 L<cdrdao(1)>, L<readcd(1)>, L<soxformat(7)>, L<ccd2iso(1)>