change the package "pretty name" to CDimg|tools
[cdimgtools.git] / raw96cdconv
blob1c8ef7f3308ba3d05f95f1a314186564e4070604
1 #!/usr/bin/perl -w
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
10 # for more details.
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/>.
15 =encoding utf-8
17 =head1 NAME
19 raw96cdconv - converts between different formats of CD raw images
21 =head1 SYNOPSIS
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> ]>
27 =cut
29 use strict;
31 use Getopt::Long;
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);
37 my $raw_sect = 2352;
38 my $raw = '.raw';
39 my $subch = '.subch';
40 my $raw96 = '';
41 die Getopt::Long::HelpMessage(128)
42 unless GetOptions(
43 'v|verbose!' => \$verbose,
44 'quiet' => sub { $verbose = 0 },
45 'n|no-act!' => \$no_act,
46 'f|force!' => \$force,
47 'S|swab!' => \$swab,
48 'sector-size=i' => \$raw_sect,
49 'iso' => sub { $raw_sect = 2048; $raw = ".iso" },
50 'c|subchan!' => \$subchan,
51 'r|fullraw!' => \$fullraw,
52 'D|raw=s' => \$raw,
53 'C|subch=s' => \$subch,
54 'R|raw96=s' => \$raw96,
56 $verbose++ if $no_act;
58 my $subch_sect = 96;
59 my $raw96_sect = $raw_sect + $subch_sect;
61 if (!@ARGV) {
62 print "Reading filenames from STDIN\n" if $verbose;
63 @ARGV = <STDIN>;
64 chomp(@ARGV);
67 my $rc = 0;
68 FILE: for (@ARGV) {
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;
74 $rc++; next FILE;
76 unless (open SRC, "<", $src) {
77 warn "ERROR Cannot open file '$src' for reading: $!\n";
78 $rc++; next FILE;
80 binmode SRC;
81 unless ($no_act or open DST, ">", $dst) {
82 warn "ERROR Cannot open file '$dst' for writing: $!\n";
83 $rc++; next FILE;
85 binmode DST unless $no_act;
86 if ($fullraw) {
87 unless (open SUBCH, "<", $_ .$subch) {
88 warn "ERROR Cannot open file '$_$subch' for reading: $!\n";
89 $rc++; next FILE;
91 binmode SUBCH;
93 my $count = 0;
94 my $buf;
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";
98 $rc++; last SECTOR;
100 if ($fullraw) {
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";
106 $rc++; last SECTOR;
108 print DST $buf unless $no_act;
109 } elsif ($subchan) {
110 print DST substr($buf, $raw_sect) unless $no_act;
111 } else {
112 $buf = pack '(v)*', unpack('(n)*', substr($buf, 0, $raw_sect)) if ($swab);
113 print DST substr($buf, 0, $raw_sect) unless $no_act;
115 $count++;
117 print "$count sectors from '$src' written in '$dst'\n" if $verbose;
118 } continue {
119 close SRC; close DST; close SUBCH if ($fullraw);
121 print "There was $rc errors.\n" if $verbose and $rc;
122 exit 1 if $rc;
124 __END__
126 =head1 DESCRIPTION
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
133 input.
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.
146 =head1 OPTIONS
148 Options can be negated by prefixing them with "--no-" instead of "--".
150 =over 8
152 =item B<--version>
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
165 generated.
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.
182 =item B<--iso>
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
189 RAW+96 data file.
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).
207 =back
210 =head1 ENVIRONMENT
212 No environment variables are used.
215 =head1 EXAMPLES
217 For example, to generate both a raw file F<image.raw> and a sub-channel file
218 F<image.subch>:
220 raw96cdconv image
221 raw96cdconv -c image
223 To re-generate F<image> from F<image.raw> and F<image.subch>:
225 raw96cdconv -r image
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
237 F<image.cdda>:
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
250 =head1 BUGS
252 No bugs or limitations are known.
254 See also the CDimg|tools distribution file F<BUGS>.
256 =head1 AUTHOR
258 G.raud Meyer
260 =head1 SEE ALSO
262 L<cdrdao(1)>, L<readcd(1)>, L<soxformat(7)>, L<ccd2iso(1)>
264 =cut