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