1 | /* |
---|
2 | Audio File Library |
---|
3 | |
---|
4 | Copyright 1998, Michael Pruett <michael@68k.org> |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or |
---|
7 | modify it under the terms of the GNU General Public License as |
---|
8 | published by the Free Software Foundation; either version 2 of |
---|
9 | the License, or (at your option) any later version. |
---|
10 | |
---|
11 | This program is distributed in the hope that it will be |
---|
12 | useful, but WITHOUT ANY WARRANTY; without even the implied |
---|
13 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
---|
14 | PURPOSE. See the GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public |
---|
17 | License along with this program; if not, write to the Free |
---|
18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
19 | MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | /* |
---|
23 | printinfo.c |
---|
24 | |
---|
25 | This file contains the function used by the sf commands to print |
---|
26 | information regarding a file. |
---|
27 | */ |
---|
28 | |
---|
29 | #ifdef __USE_SGI_HEADERS__ |
---|
30 | #include <dmedia/audiofile.h> |
---|
31 | #else |
---|
32 | #include <audiofile.h> |
---|
33 | #endif |
---|
34 | |
---|
35 | #include <stdio.h> |
---|
36 | #include <stdlib.h> |
---|
37 | |
---|
38 | char *copyrightstring (AFfilehandle file); |
---|
39 | |
---|
40 | void printfileinfo (char *filename) |
---|
41 | { |
---|
42 | int version; |
---|
43 | AFfilehandle file; |
---|
44 | int sampleFormat, sampleWidth, byteOrder, compressionType; |
---|
45 | char *copyright, *formatstring, *labelstring; |
---|
46 | |
---|
47 | file = afOpenFile(filename, "r", NULL); |
---|
48 | |
---|
49 | if (file == NULL) |
---|
50 | return; |
---|
51 | |
---|
52 | formatstring = afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_DESC, |
---|
53 | afGetFileFormat(file, &version), 0, 0); |
---|
54 | labelstring = afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_LABEL, |
---|
55 | afGetFileFormat(file, &version), 0, 0); |
---|
56 | |
---|
57 | if (formatstring == NULL || labelstring == NULL) |
---|
58 | return; |
---|
59 | |
---|
60 | printf("File Name %s\n", filename); |
---|
61 | printf("File Format %s (%s)\n", formatstring, labelstring); |
---|
62 | |
---|
63 | afGetSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); |
---|
64 | byteOrder = afGetByteOrder(file, AF_DEFAULT_TRACK); |
---|
65 | |
---|
66 | printf("Data Format "); |
---|
67 | |
---|
68 | compressionType = afGetCompression(file, AF_DEFAULT_TRACK); |
---|
69 | |
---|
70 | if (compressionType == AF_COMPRESSION_NONE) |
---|
71 | { |
---|
72 | switch (sampleFormat) |
---|
73 | { |
---|
74 | case AF_SAMPFMT_TWOSCOMP: |
---|
75 | printf("%d-bit integer (2's complement, %s)", |
---|
76 | sampleWidth, |
---|
77 | byteOrder == AF_BYTEORDER_BIGENDIAN ? |
---|
78 | "big endian" : "little endian"); |
---|
79 | break; |
---|
80 | case AF_SAMPFMT_UNSIGNED: |
---|
81 | printf("%d-bit integer (unsigned, %s)", |
---|
82 | sampleWidth, |
---|
83 | byteOrder == AF_BYTEORDER_BIGENDIAN ? |
---|
84 | "big endian" : "little endian"); |
---|
85 | break; |
---|
86 | case AF_SAMPFMT_FLOAT: |
---|
87 | printf("single-precision (32-bit) floating point, %s", |
---|
88 | byteOrder == AF_BYTEORDER_BIGENDIAN ? |
---|
89 | "big endian" : "little endian"); |
---|
90 | break; |
---|
91 | case AF_SAMPFMT_DOUBLE: |
---|
92 | printf("double-precision (64-bit) floating point, %s", |
---|
93 | byteOrder == AF_BYTEORDER_BIGENDIAN ? |
---|
94 | "big endian" : "little endian"); |
---|
95 | break; |
---|
96 | default: |
---|
97 | printf("unknown"); |
---|
98 | break; |
---|
99 | } |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | char *compressionName; |
---|
104 | compressionName = afQueryPointer(AF_QUERYTYPE_COMPRESSION, |
---|
105 | AF_QUERY_NAME, compressionType, |
---|
106 | 0, 0); |
---|
107 | |
---|
108 | if (compressionName == NULL) |
---|
109 | printf("unknown compression"); |
---|
110 | else |
---|
111 | printf("%s compression", compressionName); |
---|
112 | } |
---|
113 | printf("\n"); |
---|
114 | |
---|
115 | printf("Audio Data %ld bytes begins at offset %ld (%lx hex)\n", |
---|
116 | afGetTrackBytes(file, AF_DEFAULT_TRACK), |
---|
117 | afGetDataOffset(file, AF_DEFAULT_TRACK), |
---|
118 | afGetDataOffset(file, AF_DEFAULT_TRACK)); |
---|
119 | printf(" %d channel%s, %ld frames\n", |
---|
120 | afGetChannels(file, AF_DEFAULT_TRACK), |
---|
121 | afGetChannels(file, AF_DEFAULT_TRACK) > 1 ? "s" : "", |
---|
122 | afGetFrameCount(file, AF_DEFAULT_TRACK)); |
---|
123 | |
---|
124 | printf("Sampling Rate %.2f Hz\n", afGetRate(file, AF_DEFAULT_TRACK)); |
---|
125 | |
---|
126 | printf("Duration %.2f seconds\n", |
---|
127 | afGetFrameCount(file, AF_DEFAULT_TRACK) / |
---|
128 | afGetRate(file, AF_DEFAULT_TRACK)); |
---|
129 | |
---|
130 | copyright = copyrightstring(file); |
---|
131 | if (copyright) |
---|
132 | { |
---|
133 | printf("Copyright %s\n", copyright); |
---|
134 | free(copyright); |
---|
135 | } |
---|
136 | |
---|
137 | afCloseFile(file); |
---|
138 | } |
---|
139 | |
---|
140 | char *copyrightstring (AFfilehandle file) |
---|
141 | { |
---|
142 | char *copyright = NULL; |
---|
143 | int *miscids; |
---|
144 | int i, misccount; |
---|
145 | |
---|
146 | misccount = afGetMiscIDs(file, NULL); |
---|
147 | miscids = malloc(sizeof (int) * misccount); |
---|
148 | afGetMiscIDs(file, miscids); |
---|
149 | |
---|
150 | for (i=0; i<misccount; i++) |
---|
151 | { |
---|
152 | char *data; |
---|
153 | int datasize; |
---|
154 | |
---|
155 | if (afGetMiscType(file, miscids[i]) != AF_MISC_COPY) |
---|
156 | continue; |
---|
157 | |
---|
158 | /* |
---|
159 | If this code executes, the miscellaneous chunk is a |
---|
160 | copyright chunk. |
---|
161 | */ |
---|
162 | datasize = afGetMiscSize(file, miscids[i]); |
---|
163 | data = malloc(datasize); |
---|
164 | afReadMisc(file, miscids[i], data, datasize); |
---|
165 | copyright = data; |
---|
166 | break; |
---|
167 | } |
---|
168 | |
---|
169 | free(miscids); |
---|
170 | |
---|
171 | return copyright; |
---|
172 | } |
---|