1 /* iffscan - Simple AIFF/RIFF chunk scanner
2 * Copyright (C) 2007 Josh Coalson
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #if defined _MSC_VER || defined __MINGW32__
27 #include <sys/types.h> /* for off_t */
28 #if _MSC_VER <= 1600 /* @@@ [2G limit] */
33 #include "foreign_metadata.h"
35 static FLAC__uint32
unpack32be_(const FLAC__byte
*b
)
37 return ((FLAC__uint32
)b
[0]<<24) + ((FLAC__uint32
)b
[1]<<16) + ((FLAC__uint32
)b
[2]<<8) + (FLAC__uint32
)b
[3];
40 static FLAC__uint32
unpack32le_(const FLAC__byte
*b
)
42 return (FLAC__uint32
)b
[0] + ((FLAC__uint32
)b
[1]<<8) + ((FLAC__uint32
)b
[2]<<16) + ((FLAC__uint32
)b
[3]<<24);
45 static FLAC__uint32
unpack32_(const FLAC__byte
*b
, foreign_block_type_t type
)
47 if(type
== FOREIGN_BLOCK_TYPE__AIFF
)
48 return unpack32be_(b
);
50 return unpack32le_(b
);
53 int main(int argc
, char *argv
[])
57 foreign_metadata_t
*fm
;
58 const char *fn
, *error
;
63 fprintf(stderr
, "usage: %s { file.wav | file.aif }\n", argv
[0]);
67 if(0 == (f
= fopen(fn
, "rb")) || fread(buf
, 1, 4, f
) != 4) {
68 fprintf(stderr
, "ERROR opening %s for reading\n", fn
);
72 if(0 == (fm
= flac__foreign_metadata_new(memcmp(buf
, "RIFF", 4)? FOREIGN_BLOCK_TYPE__AIFF
: FOREIGN_BLOCK_TYPE__RIFF
))) {
73 fprintf(stderr
, "ERROR: out of memory\n");
76 if(fm
->type
== FOREIGN_BLOCK_TYPE__AIFF
) {
77 if(!flac__foreign_metadata_read_from_aiff(fm
, fn
, &error
)) {
78 fprintf(stderr
, "ERROR reading chunks from %s: %s\n", fn
, error
);
83 if(!flac__foreign_metadata_read_from_wave(fm
, fn
, &error
)) {
84 fprintf(stderr
, "ERROR reading chunks from %s: %s\n", fn
, error
);
88 if(0 == (f
= fopen(fn
, "rb"))) {
89 fprintf(stderr
, "ERROR opening %s for reading\n", fn
);
92 for(i
= 0; i
< fm
->num_blocks
; i
++) {
93 if(fseeko(f
, fm
->blocks
[i
].offset
, SEEK_SET
) < 0) {
94 fprintf(stderr
, "ERROR seeking in %s\n", fn
);
97 if(fread(buf
, 1, 12, f
) != 12) {
98 fprintf(stderr
, "ERROR reading %s\n", fn
);
101 size
= unpack32_((const FLAC__byte
*)buf
+4, fm
->type
);
102 printf("block:[%c%c%c%c] size=%08x=(%10u)", buf
[0], buf
[1], buf
[2], buf
[3], size
, size
);
104 printf(" type:[%c%c%c%c]", buf
[8], buf
[9], buf
[10], buf
[11]);
105 else if(fm
->type
== FOREIGN_BLOCK_TYPE__AIFF
&& i
== fm
->audio_block
)
106 printf(" offset size=%08x=(%10u)", fm
->ssnd_offset_size
, fm
->ssnd_offset_size
);
110 flac__foreign_metadata_delete(fm
);