--- vplay.c.orig Thu Dec 31 00:15:52 1998 +++ vplay.c Thu Dec 31 00:57:21 1998 @@ -35,6 +35,9 @@ int timelimit = 0, dsp_speed = DEFAULT_DSP_SPEED, dsp_stereo = 0; int samplesize = 8; int quiet_mode = 0; +int accurate_mode = 0; +char one_chn = 0; +char to_8 = 0; int verbose_mode = 0; int convert = 0; int record_type = VOC_FMT; @@ -60,6 +63,7 @@ void end_wave_raw (int fd); void end_snd (int fd); u_long calc_count (); +void set_dsp_param(void); struct fmt_record { void (*start) (int fd, u_long count); @@ -91,8 +95,14 @@ exit (1); } - while ((c = getopt (argc, argv, "aqs:St:b:vrwd")) != EOF) + while ((c = getopt (argc, argv, "EAaqs:St:b:vrwd")) != EOF) switch (c) { + case 'A': + accurate_mode = 2; + break; + case 'E': + accurate_mode = 1; + break; case 'S': dsp_stereo = raw_info.dsp_stereo = 1; break; @@ -128,7 +138,7 @@ break; default: fprintf (stderr, - "Usage: %s [-qvwraS] [-t secs] [-s Hz] [-b 8|12|16] [filename]\n", command); + "Usage: %s [-AEqvwraS] [-t secs] [-s Hz] [-b 8|12|16] [filename]\n", command); exit (-1); } @@ -307,11 +317,19 @@ /* setting the speed for output */ void set_dsp_speed (int *dsp_speed) { - if (ioctl(audio, SNDCTL_DSP_SPEED, dsp_speed) < 0) { + int speed = *dsp_speed; + + if (ioctl(audio, SNDCTL_DSP_SPEED, &speed) < 0) { fprintf (stderr, "%s: unable to set audio speed\n", command); perror (AUDIO); exit (-1); } + if (accurate_mode > 0 && speed != *dsp_speed){ + fprintf (stderr, "%s: set speed %d Hz but actual speed is %d Hz\n", + command, *dsp_speed, speed); + *dsp_speed = speed; + if (accurate_mode == 2) exit (-1); + } } /* if to_mono: @@ -695,48 +713,7 @@ { int l, real_l; u_long c; - char one_chn = 0; - char to_8 = 0; - int tmps; - sync_dsp(); - tmps = samplesize; - ioctl(audio, SNDCTL_DSP_SAMPLESIZE, &tmps); - if (tmps != samplesize) { - fprintf (stderr, "%s: unable to set %d bit sample size", - command, samplesize); - if (samplesize == 16) { - samplesize = 8; - ioctl(audio, SNDCTL_DSP_SAMPLESIZE, &samplesize); - if (samplesize != 8) { - fprintf(stderr, "%s: unable to set 8 bit sample size!\n", command); - exit (-1); - } - fprintf (stderr, "; playing 8 bit\n"); - to_8 = 1; - } - else { - fprintf (stderr, "\n"); - exit (-1); - } - } -#ifdef SOUND_VERSION - if (ioctl (audio, SNDCTL_DSP_STEREO, &dsp_stereo) < 0) { -#else - if (dsp_stereo != ioctl (audio, SNDCTL_DSP_STEREO, dsp_stereo) ) { -#endif - if (direction == PLAY) { - fprintf (stderr, "%s: can't play in Stereo; playing only one channel\n", - command); - dsp_stereo = MODE_MONO; - one_chn = 1; - } - else { - fprintf (stderr, "%s: can't record in Stereo\n", command); - exit (-1); - } - } - set_dsp_speed (&dsp_speed); if (!quiet_mode) { fprintf (stderr, "%s %s : ", (direction == PLAY) ? "Playing" : "Recording", @@ -827,9 +804,10 @@ /* read SND-header */ read (fd, (char *)audiobuf, sizeof(SndHeader) ); - if ( test_sndfile(audiobuf, fd) >= 0 ) + if ( test_sndfile(audiobuf, fd) >= 0 ){ + set_dsp_param(); recplay(fd, 0, count, SND_FMT, name); - + } else { /* read VOC-Header */ read (fd, (char *)audiobuf + sizeof(SndHeader), @@ -841,12 +819,15 @@ /* read bytes for WAVE-header */ read (fd, (char *)audiobuf + sizeof(VocHeader), sizeof(WaveHeader) - sizeof(VocHeader) ); - if (test_wavefile (audiobuf) >= 0) + if (test_wavefile (audiobuf) >= 0){ + set_dsp_param(); recplay (fd, 0, count, WAVE_FMT, name); + } else { /* should be raw data */ init_raw_data(); count = calc_count(); + set_dsp_param(); recplay (fd, sizeof(WaveHeader), count, RAW_DATA, name); } } @@ -866,6 +847,7 @@ } } count = calc_count() & 0xFFFFFFFE; + set_dsp_param(); /* WAVE-file should be even (I'm not sure), but wasting one byte isn't a problem (this can only be in 8 bit mono) */ if (fmt_rec_table[record_type].start) @@ -874,4 +856,49 @@ fmt_rec_table[record_type].end(fd); } } + +void set_dsp_param(void) +{ + int tmps; + + sync_dsp(); + tmps = samplesize; + ioctl(audio, SNDCTL_DSP_SAMPLESIZE, &tmps); + if (tmps != samplesize) { + fprintf (stderr, "%s: unable to set %d bit sample size", + command, samplesize); + if (samplesize == 16) { + samplesize = 8; + ioctl(audio, SNDCTL_DSP_SAMPLESIZE, &samplesize); + if (samplesize != 8) { + fprintf(stderr, "%s: unable to set 8 bit sample size!\n", command); + exit (-1); + } + fprintf (stderr, "; playing 8 bit\n"); + to_8 = 1; + } + else { + fprintf (stderr, "\n"); + exit (-1); + } + } +#ifdef SOUND_VERSION + if (ioctl (audio, SNDCTL_DSP_STEREO, &dsp_stereo) < 0) { +#else + if (dsp_stereo != ioctl (audio, SNDCTL_DSP_STEREO, dsp_stereo) ) { +#endif + if (direction == PLAY) { + fprintf (stderr, "%s: can't play in Stereo; playing only one channel\n", + command); + dsp_stereo = MODE_MONO; + one_chn = 1; + } + else { + fprintf (stderr, "%s: can't record in Stereo\n", command); + exit (-1); + } + } + set_dsp_speed (&dsp_speed); +} +