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.
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # You should have received a copy of the GNU General Public License along
13 # with this program. If not, see <http://www.gnu.org/licenses/>.
19 raw96cdconv - converts between different formats of CD raw images
23 B<raw96cdconv> B<--version>
25 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> ]>
32 Getopt
::Long
::Configure
('bundling', 'no_auto_abbrev', 'auto_version', 'auto_help');
34 $main::VERSION
= "1.1";
36 my ($verbose, $no_act, $force, $swab, $subchan, $fullraw);
41 die Getopt
::Long
::HelpMessage
(128)
43 'v|verbose!' => \
$verbose,
44 'quiet' => sub { $verbose = 0 },
45 'n|no-act!' => \
$no_act,
46 'f|force!' => \
$force,
48 'sector-size=i' => \
$raw_sect,
49 'iso' => sub { $raw_sect = 2048; $raw = ".iso" },
50 'c|subchan!' => \
$subchan,
51 'r|fullraw!' => \
$fullraw,
53 'C|subch=s' => \
$subch,
54 'R|raw96=s' => \
$raw96,
56 $verbose++ if $no_act;
59 my $raw96_sect = $raw_sect + $subch_sect;
62 print "Reading filenames from STDIN\n" if $verbose;
69 my $src = $_ .(($fullraw) ?
$raw : $raw96);
70 my $in_sect = ($fullraw) ?
$raw_sect : $raw96_sect;
71 my $dst = $_ .(($fullraw) ?
$raw96 : (($subchan) ?
$subch : $raw));
72 unless ($force or !-e
$dst) {
73 warn "Skipping '$_' because '$dst' already exists\n" if $verbose;
76 unless (open SRC
, "<", $src) {
77 warn "ERROR Cannot open file '$src' for reading: $!\n";
81 unless ($no_act or open DST
, ">", $dst) {
82 warn "ERROR Cannot open file '$dst' for writing: $!\n";
85 binmode DST
unless $no_act;
87 unless (open SUBCH
, "<", $_ .$subch) {
88 warn "ERROR Cannot open file '$_$subch' for reading: $!\n";
95 SECTOR
: while (my $n = read SRC
, $buf, $in_sect) {
96 unless ($n == $in_sect) {
97 warn "ERROR Partial sector of size $n/$in_sect found in '$src'\n";
101 $buf = pack '(v)*', unpack('(n)*', $buf) if ($swab);
102 print DST
$buf unless $no_act;
103 my $m = read SUBCH
, $buf, $subch_sect;
104 unless ($m == $subch_sect) {
105 warn "ERROR Partial sub-channel block of size $m/$subch_sect found in '$_$subch'\n";
108 print DST
$buf unless $no_act;
110 print DST
substr($buf, $raw_sect) unless $no_act;
112 $buf = pack '(v)*', unpack('(n)*', substr($buf, 0, $raw_sect)) if ($swab);
113 print DST
substr($buf, 0, $raw_sect) unless $no_act;
117 print "$count sectors from '$src' written in '$dst'\n" if $verbose;
119 close SRC
; close DST
; close SUBCH
if ($fullraw);
121 print "There was $rc errors.\n" if $verbose and $rc;
128 C<raw96cdconv> generates a raw file by extracting raw CD sectors (made up either
129 of audio data or of raw data sectors) from a file made up of chunks containing
130 both raw data and sub-channel data (RAW+96). By default F<.raw> is appended to
131 the given file names to obtain the corresponding generated file name. If no
132 filenames are given on the command line, filenames will be read via standard
135 It is also possible to generate a file containing only sub-channel data or to
136 re-generate the full RAW+96 file containing both the raw and the sub-channel
137 data. The default extension for sub-channel files is F<.subch>.
139 The sector size of raw data is 2352 bytes; the corresponding sub-channel data
140 is 96 bytes long, so that the full RAW+96 file is made of chunks of 2448 bytes.
142 C<raw96cdconv> also works with images containing only data sectors (2048 bytes
143 long) and sub-channel data.
148 Options can be negated by prefixing them with "--no-" instead of "--".
154 Print the version information and exit.
156 =item B<-v>, B<--verbose>
158 Verbose: print the names of the files successfully generated as well as their
159 number of sectors, print the names of the files completely skipped and at the
160 end print the number of files that caused an error.
162 =item B<-n>, B<--no-act>
164 No Action: test the reading of files and show what files would have been
167 =item B<-f>, B<--force>
169 Force: overwrite existing files.
171 =item B<-S>, B<--swab>
173 Swap byte: swap the byte order of the raw data; it works for both normal mode
174 (raw data extraction) and full raw data mode. Use it with readcd(1) images
175 that contain little endian audio data.
177 =item B<--sector-size>
179 By default 2352, which corresponds to audio data (or to a raw sector of any
180 data). Use 2048 for error corrected data sectors.
184 Same as `B<--raw> .iso B<--sector-size> 2048'.
186 =item B<-c>, B<--subchan>
188 Sub-channel mode: generate a file containing only sub-channel data from the
191 =item B<-r>, B<--fullraw>
193 Full raw data mode: (re-)generate a RAW+96 file containing both raw and
194 sub-channel data from the raw file and the sub-channel data file.
196 =item B<-D>, B<--raw> I<ext>
198 =item B<-C>, B<--subch> I<ext>
200 =item B<-R>, B<--raw96> I<ext>
202 Extension: file name extensions appended to the name given on the command line;
203 the first one is for raw files (default: F<.raw>); the second one is for
204 sub-channel data files (default: F<.subch>); the third one is for RAW+96 data
205 files (default: empty extension).
212 No environment variables are used.
217 For example, to generate both a raw file F<image.raw> and a sub-channel file
223 To re-generate F<image> from F<image.raw> and F<image.subch>:
227 To generate F<image.raw96> instead of F<image>:
229 raw96cdconv -R .raw96 -r image
231 To extract an iso image F<image.iso> from F<image> that contains both (error
232 corrected) data sectors and sub-channel data:
234 raw96cdconv --iso image
236 If F<image> contains the image of a CDDA, it is more appropriate to extract to
239 raw96cdconv -A .cdda image
241 To convert the extracted raw audio to WAV, you can use sox(1):
243 sox -t .cdda image.cdda image.wav
245 To convert the extracted 2352b/s raw data to ISO, you can use ccd2iso(1):
247 ccd2iso image.raw image.iso
252 No bugs or limitations are known.
254 See also the CDimg|tools distribution file F<BUGS>.
262 L<cdrdao(1)>, L<readcd(1)>, L<soxformat(7)>, L<ccd2iso(1)>