#7 Some soundcards cannot set exact sample rate.

closed
nobody
None
5
2015-03-03
2000-02-01
Paul Fenwick
No

Some soundcards under Linux cannot do set the sample rate exactly to 16000Hz, but rather something close to it (eg, 16036). This causes sphinx to die with an error, however if this test is skip no real harm is caused. The test occurs in the ad_i386_linux.c file.

The following changes enables a tolerance' on the sample rate, allowing soundcards which areclose' to pass the test, but soundcards which have completely goofed it to still fail. Will happily check these changes into CVS if appropriate blessings are given. :)

include/ad.h 2000/01/28 23:42:14 1.2
--- include/ad.h 2000/02/01 05:52:21
***
62,67 ****
--- 62,68 ----

#define AD_SAMPLE_SIZE (sizeof(int16))
#define DEFAULT_SAMPLES_PER_SEC 16000
+ #define SAMPLERATE_TOLERANCE 0.10

/ Return codes /
#define AD_OK 0

src/libsphinx2/ad_i386_linux.c 2000/01/31 21:37:30 1.2
--- src/libsphinx2/ad_i386_linux.c 2000/02/01 05:52:21
***
142,150 ****
return NULL;
}
if (sampleRate != sps) {
! E_ERROR("Audio ioctl(SPEED): %d, expected: %d\n", sampleRate, sps);
! close (dspFD);
! return NULL;
}

  if (ioctl (dspFD, SNDCTL_DSP_NONBLOCK, &nonBlocking) < 0) {

--- 142,155 ----
return NULL;
}
if (sampleRate != sps) {
! if (abs(sampleRate - sps) <= (sampleRate * SAMPLERATE_TOLERANCE)) {
! E_ERROR("Audio ioctl(SPEED) not perfect, but is acceptable. "
! "(Wanted %d, but got %d)\n",sampleRate, sps);
! } else {
! E_ERROR("Audio ioctl(SPEED): %d, expected: %d\n", sampleRate, sps);
! close(dspFD);
! return NULL;
! }
}

  if (ioctl (dspFD, SNDCTL_DSP_NONBLOCK, &amp;nonBlocking) &lt; 0) {

Discussion

  • Paul Fenwick
    Paul Fenwick
    2000-02-01

    Patch applied to the CVS tree. Bug should now be fixed.