📄 audbri_tests.c
字号:
close(audiofd); if (gen_file) { fclose(deb_fp); } TRACE_OUT return(0);}/* * Crystal Test * * Verify that the timing of the audio channel is correct at * each of the sample rates. */int audbri_crystal(){ audio_info_t ai; short *play_sig; int i, size, duration_usec, tolerance; int upper_limit, lower_limit; int time; func_name = "audbri_crystal"; TRACE_IN /* * calculate upper and lower limits for timing */ duration_usec = (duration * 1000000); tolerance = nint(aucrystal_tol * (double) duration_usec); upper_limit = duration_usec + tolerance; lower_limit = duration_usec - tolerance; /* * initialize audio parameters */ AUDIO_INITINFO(&ai); ai.play.port = AUDIO_SPEAKER; ai.monitor_gain = AUDIO_MIN_GAIN; /* * open audio device and set parameters */ play_open(&ai); /* * test timing for each frequency */ for (i = 0; crystal_audata[i].sample_rate != NULL; i++) { send_message(0, DEBUG, sr_msg, crystal_audata[i].sample_rate); /* * generate a signal to play */ if (!(size = gensig(&crystal_audata[i], &play_sig, duration))) { close(audiofd); TRACE_OUT return(1); } /* * set play audio parameters */ AUDIO_INITINFO(&ai); ai.play.sample_rate = crystal_audata[i].sample_rate; ai.play.channels = crystal_audata[i].channels; ai.play.precision = crystal_audata[i].precision; ai.play.encoding = crystal_audata[i].encoding; ai.play.gain = crystal_audata[i].cal_pgain_max; if (ioctl(audiofd, AUDIO_SETINFO, &ai) < 0) { send_message(ERSYS, ERROR, er_ioctl, "AUDIO_SETINFO", SYSMSG); } /* * play a signal and time it */ time = play(play_sig, size, crystal_audata[i].precision); free(play_sig); /* all done with the signal */ /* * verify crystal tolerance */ if (time < lower_limit || time > upper_limit) { close(audiofd); TRACE_OUT send_message(ERAUDIO, ERROR, er_aucrystal, crystal_audata[i].sample_rate, time); } else { send_message(0, VERBOSE+DEBUG, crystal_msg, crystal_audata[i].sample_rate, time); } } close(audiofd); TRACE_OUT return(0);}/* * SIGPOLL handler used by audbri_controls() */sigpollhandler(sig, code, scp, addr)int sig, code;struct sigcontext *scp;char *addr;{ audio_info_t ai; func_name = "sigpollhandler"; TRACE_IN /* * get audio state */ if (ioctl(audioctlfd, AUDIO_GETINFO, &ai) < 0) { send_message(ERSYS, ERROR, er_ioctl, "AUDIO_GETINFO", SYSMSG); } switch (dc_flag) { case 0: /* * If volume went down, tell the user to press volume up */ if (ai.play.gain < audio_info.play.gain) { audio_info = ai; dc_flag = 1; send_message(0, DEBUG+VERBOSE, vup_msg); } break; case 1: /* * If volume went up, tell the user to press mute */ if (ai.play.gain > audio_info.play.gain) { audio_info = ai; dc_flag = 2; send_message(0, DEBUG+VERBOSE, mute_msg); } break; case 2: /* * If mute is on, tell user to press it "unmute" */ if (ai.speaker_muted) { audio_info = ai; dc_flag = 3; send_message(0, DEBUG+VERBOSE, unmute_msg); } break; case 3: /* * If mute is off, control test passed */ if (!ai.speaker_muted) { audio_info = ai; dc_flag = 4; send_message(0, DEBUG+VERBOSE, ctlpass_msg); } break; } TRACE_OUT}/* * Controls Test * * Determine */int audbri_controls(){ audio_info_t ai; short *play_sig; struct itimerval time; int fd, precision; struct stat statbuf; Audio_filehdr *ah; func_name = "audbri_controls"; TRACE_IN /* * open the music file, get it's size and map it */ if ((fd = open(music_file, O_RDONLY)) == -1 ) { send_message(ERSYS, ERROR, er_open, music_file, SYSMSG); } if (fstat(fd, &statbuf) == -1) { send_message(ERSYS, ERROR, er_stat, SYSMSG); } if ((ah = (Audio_filehdr *)mmap((caddr_t) 0, statbuf.st_size, PROT_READ, MAP_SHARED, fd, (off_t) 0)) == (Audio_filehdr *) -1) { send_message(ERSYS, ERROR, er_mmap, SYSMSG); } close(fd); /* * Make sure it's a valid audio file. */ if (ah->magic != AUDIO_FILE_MAGIC) { send_message(ERAUDIO, ERROR, er_afile); } /* * set play and monitor gain, open audio device */ AUDIO_INITINFO(&ai); ai.play.channels = ah->channels; switch(ah->encoding) { case AUDIO_FILE_ENCODING_MULAW_8: ai.play.precision = 8; ai.play.encoding = AUDIO_ENCODING_ULAW; break; case AUDIO_FILE_ENCODING_LINEAR_16: ai.play.precision = 16; ai.play.encoding = AUDIO_ENCODING_LINEAR; break; default: send_message(ERAUDIO, ERROR, er_afile); break; } precision = ai.play.precision; ai.play.gain = music_gain; ai.play.port = AUDIO_SPEAKER; ai.play.sample_rate = ah->sample_rate; ai.monitor_gain = AUDIO_MIN_GAIN; play_open(&ai); /* * get current audio state */ if (ioctl(audioctlfd, AUDIO_GETINFO, &audio_info) < 0) { send_message(ERSYS, ERROR, er_ioctl, "AUDIO_GETINFO", SYSMSG); } /* * initialize controls test "state" flag */ dc_flag = 0; /* * set up to catch volume change and mute */ signal(SIGPOLL, sigpollhandler); if (ioctl(audioctlfd, I_SETSIG, S_MSG) < 0) { send_message(ERSYS, ERROR, er_ioctl, "I_SETSIG", SYSMSG); } /* * tell user to press volume down */ send_message(0, DEBUG+VERBOSE, vdown_msg); /* * play the file's data */ play_sig = (short *) ((caddr_t) ah + ah->hdr_size); (void) play(play_sig, ah->data_size, precision); /* * unmap */ (void) munmap(ah, statbuf.st_size); close(audiofd); close(audioctlfd); if (dc_flag == 4) { TRACE_OUT return(0); } else { TRACE_OUT return(1); }}/* * Music Test * */int audbri_music(){ audio_info_t ai; short *play_sig; struct itimerval time; int fd, precision; struct stat statbuf; Audio_filehdr *ah; func_name = "audbri_music"; TRACE_IN /* * open the music file, get it's size and map it */ if ((fd = open(music_file, O_RDONLY)) == -1 ) { send_message(ERSYS, ERROR, er_open, music_file, SYSMSG); } if (fstat(fd, &statbuf) == -1) { send_message(ERSYS, ERROR, er_stat, SYSMSG); } if ((ah = (Audio_filehdr *)mmap((caddr_t) 0, statbuf.st_size, PROT_READ, MAP_SHARED, fd, (off_t) 0)) == (Audio_filehdr *) -1) { send_message(ERSYS, ERROR, er_mmap, SYSMSG); } close(fd); /* * Make sure it's a valid audio file. */ if (ah->magic != AUDIO_FILE_MAGIC) { send_message(ERAUDIO, ERROR, er_afile); } /* * set play and monitor gain, open audio device */ AUDIO_INITINFO(&ai); ai.play.channels = ah->channels; switch(ah->encoding) { case AUDIO_FILE_ENCODING_MULAW_8: ai.play.precision = 8; ai.play.encoding = AUDIO_ENCODING_ULAW; break; case AUDIO_FILE_ENCODING_LINEAR_16: ai.play.precision = 16; ai.play.encoding = AUDIO_ENCODING_LINEAR; break; default: send_message(ERAUDIO, ERROR, er_afile); break; } precision = ai.play.precision; ai.play.gain = music_gain; ai.play.port = AUDIO_SPEAKER; ai.play.sample_rate = ah->sample_rate; ai.monitor_gain = AUDIO_MIN_GAIN; play_open(&ai); /* * play the file's data */ play_sig = (short *) ((caddr_t) ah + ah->hdr_size); (void) play(play_sig, ah->data_size, precision); /* * unmap */ (void) munmap(ah, statbuf.st_size); close(audiofd); close(audioctlfd); TRACE_OUT return(0);}/* * This function is called just before executing * some critical part of the code. The SIGINT * signal when/if received while executing this * part of the code will be temporarily blocked * and serviced at a later stage(in exit_critical()). */enter_critical(){ int oldmask=0; oldmask = sigblock(sigmask(SIGINT)); return(oldmask);} /* * This function is called just after executing * some critical part of the code. The SIGINT * signal will be unblocked and the old signal * mask will be restored, so that the interrupts * may be serviced as originally intended. */exit_critical(omask)int omask;{ (void) sigsetmask(omask);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -