📄 autest.c
字号:
(void) sprintf(strchr(tmp,NULL), "hex\n\t read "); for (n = 0; n < regcount; n++) (void) sprintf(strchr(tmp,NULL), "%02x ", rreg.data[n]); (void) sprintf(strchr(tmp,NULL), "hex\n"); send_message(ERDATA, ERROR, tmp); } } } /* restore original register values */ savreg.control = reg; audioctl(fd, AUDIOSETREG, &savreg, s1);}/* * Function to play an audio tune from content of a file. */audio_play_test(){ int fdata, datalen; char *databuf; send_message(NULL,VDEBUG,"Audio play test"); /* open and read data file into buffer */ if ((fdata = open(audio_file, O_RDONLY)) < 0) { send_message(NULL, WARNING, er_datafile, audio_file); datalen = 0; } else { if ((datalen = (int) lseek(fdata, 0L, L_XTND)) < 0) send_message(ERSEEK, ERROR, er_seek, SYSMSG); if (lseek(fdata, 0L, L_SET) < 0) send_message(ERSEEK, ERROR, er_seek, SYSMSG); /* set limit on data size for quick test */ if (quick_test) { if (datalen > QUICKDATALEN) datalen = QUICKDATALEN; } if (!(databuf = malloc((u_int)datalen))) send_message(ERSYS, ERROR, er_mem, datalen, SYSMSG); if (read(fdata, databuf, datalen) != datalen) send_message(ERREAD, ERROR, er_readf, datalen, SYSMSG); (void) close(fdata); /* play the audio */ audio_play_data(databuf, datalen); /* free data buffer */ (void) free(databuf); }}/* * Function to play the audio data in buffer. */audio_play_data(databuf, datalen)char *databuf;int datalen;{ int count;#ifdef OS_4_0_3 int qsize, qbytes;#endif send_message(NULL, DEBUG, "Write %d bytes to audio device", datalen);#ifdef OS_4_1 /* write data to audio buffer then wait till buffer empty */ while (datalen) { if ((count = write(fd, databuf, datalen)) < 0) send_message(ERWRITE, ERROR, er_write, datalen, SYSMSG); databuf += count; datalen -= count; sleep(1); } audioctl(fd, AUDIO_DRAIN, NULL, "AUDIO_DRAIN");#else /* get size of queue */ audioctl(fd, AUDIOGETQSIZE, &qsize, "AUDIOGETQSIZE"); /* write data from buffer to audio device */ do { /* check the write queue */ audioctl(fd, AUDIOWRITEQ, &qbytes, "AUDIOWRITEQ"); /* write data to fill up the write queue */ count = (qsize - qbytes) > datalen ? datalen : (qsize - qbytes); if (count) { if (write(fd, databuf, count) != count) send_message(ERWRITE, ERROR, er_write, count, SYSMSG); databuf += count; datalen -= count; } sleep(1); } while (count || qbytes);#endif}/* * Function to test the audio recording and playback. * Note that it will try to record input from the jack, and likely there * will be quiet sound when play back. */audio_record_test(){ char *databuf; int datalen; send_message(NULL,VDEBUG,"Audio recording test"); /* get size of read queue */#ifdef OS_4_1 audioctl(fd, FIONREAD, &datalen, "FIONREAD");#else audioctl(fd, AUDIOREADQ, &datalen, "AUDIOREADQ");#endif send_message(NULL, DEBUG, "Read %d bytes from audio device", datalen); /* allocate memory */ if (!(databuf = malloc((u_int)datalen))) send_message(ERSYS, ERROR, er_mem, datalen, SYSMSG);#ifdef OS_4_1 /* flush old recording data */ audioctl(fd, I_FLUSH, FLUSHRW, "I_FLUSH"); sleep(1);#endif /* record new data */ if (read(fd, databuf, datalen) != datalen) send_message(ERREAD, ERROR, er_read, datalen, SYSMSG); /* play back */ audio_play_data(databuf, datalen); /* free memory */ (void) free(databuf);}/* * Function to test the audio internal loopback. */audio_inloop_test(){ u_char wpat, rpat; int i;#ifdef OS_4_0_3 int qsize, readq;#endif send_message(NULL,VDEBUG,"Audio internal loopback test"); audio_set_inloop();#ifdef OS_4_0_3 audioctl(fd, AUDIOREADQ, &qsize, "AUDIOREADQ");#endif wpat = quick_test ? MAXBYTE - 5 : 0; do { /* write a byte of data */#ifdef OS_4_1 audioctl(fd, I_FLUSH, FLUSHRW, "I_FLUSH");#endif if (write(fd, (u_char *)&wpat, 1) != 1) send_message(ERWRITE, ERROR, er_write, 1, SYSMSG); /* wait for data ready */#ifdef OS_4_1 audioctl(fd, I_FLUSH, FLUSHR, "I_FLUSH");#endif /* read back data */ if (read(fd, (u_char *)&rpat, 1) != 1) send_message(ERREAD, ERROR, er_read, 1, SYSMSG);#ifdef OS_4_0_3 do { audioctl(fd, AUDIOREADQ, &readq, "AUDIOREADQ"); } while (readq != qsize);#endif /* check data */ send_message(NULL, DEBUG, "Write %d, read %d", wpat, rpat); if (wpat != rpat) send_message(ERLOOP, ERROR, er_inloop, wpat, rpat); } while (++wpat);}/* * Function to set the audio chip in internal loopback mode. */audio_set_inloop(){ struct audio_ioctl ioreg; ioreg.control = AUDIO_MUX_MCR2; ioreg.data[0] = AUDIO_MUX_CONNECT(AUDIO_MUX_PORT_BB, AUDIO_MUX_PORT_BB); audioctl(fd, AUDIOSETREG, &ioreg, "AUDIOSETREG MCR2");}/* * Function to set the audio volume. */audio_set_volume(volume)int volume;{ struct audio_ioctl ioreg; /* set up GR, GER, and GX registers */ audio_set_gr(volume * MAX_GR_ENTRIES / MAX_VOLUME); audio_set_ger(volume * MAX_GER_ENTRIES / MAX_VOLUME); audio_set_gx(volume * MAX_GX_ENTRIES / MAX_VOLUME); /* load values from registers */ ioreg.control = AUDIO_MAP_MMR1; ioreg.data[0] = AUDIO_MMR1_BITS_LOAD_GX | AUDIO_MMR1_BITS_LOAD_GR | AUDIO_MMR1_BITS_LOAD_GER; audioctl(fd, AUDIOSETREG, &ioreg, "AUDIOSETREG MMR1");}/* * Function to set the audio output to either speaker or jack. */audio_set_output(where)int where;{ struct audio_ioctl ioreg; ioreg.control = AUDIO_MAP_MMR2; audioctl(fd, AUDIOGETREG, &ioreg, "AUDIOGETREG MMR2"); if (where == OUT_SPEAKER) ioreg.data[0] |= AUDIO_MMR2_BITS_LS; else ioreg.data[0] &= ~AUDIO_MMR2_BITS_LS; audioctl(fd, AUDIOSETREG, &ioreg, "AUDIOSETREG MMR2");}/* * Function to set the GER gain coefficient value by indexing to the table. */audio_set_ger(index)int index;{ struct audio_ioctl ioreg; ioreg.control = AUDIO_MAP_GER; ioreg.data[0] = ger_table[index][1]; ioreg.data[1] = ger_table[index][0]; audioctl(fd, AUDIOSETREG, &ioreg, "AUDIOSETREG GER");}/* * Function to set the GER gain coefficient value by indexing to the table. */audio_set_gr(index)int index;{ struct audio_ioctl ioreg; ioreg.control = AUDIO_MAP_GR; ioreg.data[0] = gr_gx_table[index][1]; ioreg.data[1] = gr_gx_table[index][0]; audioctl(fd, AUDIOSETREG, &ioreg, "AUDIOSETREG GR");}/* * Function to set the GER gain coefficient value by indexing to the table. */audio_set_gx(index)int index;{ struct audio_ioctl ioreg; ioreg.control = AUDIO_MAP_GX; ioreg.data[0] = gr_gx_table[index][1]; ioreg.data[1] = gr_gx_table[index][0]; audioctl(fd, AUDIOSETREG, &ioreg, "AUDIOSETREG GX");}/* * Function to issue an ioctl command and print error message upon failure. * (VARARGS1) */audioctl(desc, command, argp, cmd_name)int desc, command;caddr_t argp;char *cmd_name;{ if (ioctl(desc, command, argp) < 0) send_message(ERIOCTL, ERROR, er_ioctl, cmd_name, SYSMSG);}/* * Dummy clean up procedure. */clean_up(){}/******************************************************************************/#ifdef lintchar *device_name;char *versionid;int quick_test;int errno;/* (VARARGS3 & ARGSUSED) */void send_message(exitcode, msgtype, format)int exitcode, msgtype;char *format;{}#endif/******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -