• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2    iecdump - dump IEC958 status bits on ALSA
3    Copyright (C) 2003 by Takashi Iwai <tiwai@suse.de>
4 
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License
7    as published by the Free Software Foundation; either version 2
8    of the License, or (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #include <stdio.h>
21 #include <alsa/asoundlib.h>
22 
23 struct category_str {
24 	int val;
25 	const char *name;
26 };
27 
28 static const struct category_str con_category[] = {
29 	{ IEC958_AES1_CON_GENERAL, "general" },
30 
31 	{ IEC958_AES1_CON_IEC908_CD, "CD" },
32 	{ IEC958_AES1_CON_NON_IEC908_CD, "non-IEC908 CD" },
33 	{ IEC958_AES1_CON_MINI_DISC, "Mini-Disc" },
34 	{ IEC958_AES1_CON_DVD, "DVD" },
35 
36 	{ IEC958_AES1_CON_PCM_CODER, "PCM coder" },
37 	{ IEC958_AES1_CON_MIXER, "digital signal mixer" },
38 	{ IEC958_AES1_CON_RATE_CONVERTER, "rate converter" },
39 	{ IEC958_AES1_CON_SAMPLER, "sampler" },
40 	{ IEC958_AES1_CON_DSP, "digital sound processor" },
41 
42 	{ IEC958_AES1_CON_DAT, "DAT" },
43 	{ IEC958_AES1_CON_VCR, "VCR" },
44 	{ IEC958_AES1_CON_DCC, "DCC" },
45 	{ IEC958_AES1_CON_MAGNETIC_DISC, "magnetic disc" },
46 
47 	{ IEC958_AES1_CON_DAB_JAPAN, "digital audio broadcast (Japan)" },
48 	{ IEC958_AES1_CON_DAB_EUROPE, "digital audio broadcast (Europe)" },
49 	{ IEC958_AES1_CON_DAB_USA, "digital audio broadcast (USA)" },
50 	{ IEC958_AES1_CON_SOFTWARE, "software delivery" },
51 
52 	{ IEC958_AES1_CON_SYNTHESIZER, "synthesizer" },
53 	{ IEC958_AES1_CON_MICROPHONE, "microphone" },
54 
55 	{ IEC958_AES1_CON_ADC, "ADC without copyright information" },
56 
57 	{ IEC958_AES1_CON_ADC_COPYRIGHT, "ADC with copyright information" },
58 
59 	{ IEC958_AES1_CON_SOLIDMEM_DIGITAL_RECORDER_PLAYER, "flash memory recorder/player" },
60 
61 	{ IEC958_AES1_CON_EXPERIMENTAL, "experimental" },
62 };
63 
64 
65 #define ARRAY_SIZE(x) (int)(sizeof(x)/sizeof(x[0]))
66 
dump_iec958(snd_aes_iec958_t * iec)67 void dump_iec958(snd_aes_iec958_t *iec)
68 {
69 	int i;
70 
71 	if (! (iec->status[0] & IEC958_AES0_PROFESSIONAL)) {
72 		/* consumer */
73 		printf("Mode: consumer\n");
74 		printf("Data: ");
75 		if (!(iec->status[0] & IEC958_AES0_NONAUDIO)) {
76 			printf("audio\n");
77 		} else {
78 			printf("non-audio\n");
79 		}
80 		printf("Rate: ");
81 		switch (iec->status[3] & IEC958_AES3_CON_FS) {
82 		case IEC958_AES3_CON_FS_22050:
83 			printf("22050 Hz\n");
84 			break;
85 		case IEC958_AES3_CON_FS_24000:
86 			printf("24000 Hz\n");
87 			break;
88 		case IEC958_AES3_CON_FS_32000:
89 			printf("32000 Hz\n");
90 			break;
91 		case IEC958_AES3_CON_FS_44100:
92 			printf("44100 Hz\n");
93 			break;
94 		case IEC958_AES3_CON_FS_48000:
95 			printf("48000 Hz\n");
96 			break;
97 		case IEC958_AES3_CON_FS_88200:
98 			printf("88200 Hz\n");
99 			break;
100 		case IEC958_AES3_CON_FS_96000:
101 			printf("96000 Hz\n");
102 			break;
103 		case IEC958_AES3_CON_FS_176400:
104 			printf("176400 Hz\n");
105 			break;
106 		case IEC958_AES3_CON_FS_192000:
107 			printf("192000 Hz\n");
108 			break;
109 		case IEC958_AES3_CON_FS_768000:
110 			printf("768000 Hz\n");
111 			break;
112 		case IEC958_AES3_CON_FS_NOTID:
113 			printf("not indicated\n");
114 			break;
115 		default:
116 			printf("unknown\n");
117 			break;
118 		}
119 		printf("Copyright: ");
120 		if (iec->status[0] & IEC958_AES0_CON_NOT_COPYRIGHT) {
121 			printf("permitted\n");
122 		} else {
123 			printf("protected\n");
124 		}
125 		printf("Emphasis: ");
126 		if ((iec->status[0] & IEC958_AES0_CON_EMPHASIS) != IEC958_AES0_CON_EMPHASIS_5015) {
127 			printf("none\n");
128 		} else {
129 			printf("50/15us\n");
130 		}
131 		printf("Category: ");
132 		for (i = 0; i < ARRAY_SIZE(con_category); i++) {
133 			if ((iec->status[1] & IEC958_AES1_CON_CATEGORY) == con_category[i].val) {
134 				printf("%s\n", con_category[i].name);
135 				break;
136 			}
137 		}
138 		if (i >= ARRAY_SIZE(con_category)) {
139 			printf("unknown 0x%x\n", iec->status[1] & IEC958_AES1_CON_CATEGORY);
140 		}
141 		printf("Original: ");
142 		if (iec->status[1] & IEC958_AES1_CON_ORIGINAL) {
143 			printf("original\n");
144 		} else {
145 			printf("1st generation\n");
146 		}
147 		printf("Clock: ");
148 		switch (iec->status[3] & IEC958_AES3_CON_CLOCK) {
149 		case IEC958_AES3_CON_CLOCK_1000PPM:
150 			printf("1000 ppm\n");
151 			break;
152 		case IEC958_AES3_CON_CLOCK_50PPM:
153 			printf("50 ppm\n");
154 			break;
155 		case IEC958_AES3_CON_CLOCK_VARIABLE:
156 			printf("variable pitch\n");
157 			break;
158 		default:
159 			printf("unknown\n");
160 			break;
161 		}
162 	} else {
163 		printf("Mode: professional\n");
164 		printf("Data: ");
165 		if (!(iec->status[0] & IEC958_AES0_NONAUDIO)) {
166 			printf("audio\n");
167 		} else {
168 			printf("non-audio\n");
169 		}
170 		printf("Rate: ");
171 		switch (iec->status[0] & IEC958_AES0_PRO_FS) {
172 		case IEC958_AES0_PRO_FS_44100:
173 			printf("44100 Hz\n");
174 			break;
175 		case IEC958_AES0_PRO_FS_48000:
176 			printf("48000 Hz\n");
177 			break;
178 		case IEC958_AES0_PRO_FS_32000:
179 			printf("32000 Hz\n");
180 			break;
181 		default:
182 			printf("unknown\n");
183 			break;
184 		}
185 		printf("Rate Locked: ");
186 		if (iec->status[0] & IEC958_AES0_PRO_FREQ_UNLOCKED)
187 			printf("no\n");
188 		else
189 			printf("yes\n");
190 		printf("Emphasis: ");
191 		switch (iec->status[0] & IEC958_AES0_PRO_EMPHASIS) {
192 		case IEC958_AES0_PRO_EMPHASIS_CCITT:
193 			printf("CCITT J.17\n");
194 			break;
195 		case IEC958_AES0_PRO_EMPHASIS_NONE:
196 			printf("none\n");
197 			break;
198 		case IEC958_AES0_PRO_EMPHASIS_5015:
199 			printf("50/15us\n");
200 			break;
201 		case IEC958_AES0_PRO_EMPHASIS_NOTID:
202 		default:
203 			printf("unknown\n");
204 			break;
205 		}
206 		printf("Stereophonic: ");
207 		if ((iec->status[1] & IEC958_AES1_PRO_MODE) == IEC958_AES1_PRO_MODE_STEREOPHONIC) {
208 			printf("stereo\n");
209 		} else {
210 			printf("not indicated\n");
211 		}
212 		printf("Userbits: ");
213 		switch (iec->status[1] & IEC958_AES1_PRO_USERBITS) {
214 		case IEC958_AES1_PRO_USERBITS_192:
215 			printf("192bit\n");
216 			break;
217 		case IEC958_AES1_PRO_USERBITS_UDEF:
218 			printf("user-defined\n");
219 			break;
220 		default:
221 			printf("unknown\n");
222 			break;
223 		}
224 		printf("Sample Bits: ");
225 		switch (iec->status[2] & IEC958_AES2_PRO_SBITS) {
226 		case IEC958_AES2_PRO_SBITS_20:
227 			printf("20 bit\n");
228 			break;
229 		case IEC958_AES2_PRO_SBITS_24:
230 			printf("24 bit\n");
231 			break;
232 		case IEC958_AES2_PRO_SBITS_UDEF:
233 			printf("user defined\n");
234 			break;
235 		default:
236 			printf("unknown\n");
237 			break;
238 		}
239 		printf("Word Length: ");
240 		switch (iec->status[2] & IEC958_AES2_PRO_WORDLEN) {
241 		case IEC958_AES2_PRO_WORDLEN_22_18:
242 			printf("22 bit or 18 bit\n");
243 			break;
244 		case IEC958_AES2_PRO_WORDLEN_23_19:
245 			printf("23 bit or 19 bit\n");
246 			break;
247 		case IEC958_AES2_PRO_WORDLEN_24_20:
248 			printf("24 bit or 20 bit\n");
249 			break;
250 		case IEC958_AES2_PRO_WORDLEN_20_16:
251 			printf("20 bit or 16 bit\n");
252 			break;
253 		default:
254 			printf("unknown\n");
255 			break;
256 		}
257 	}
258 }
259 
260