Incorporate patches against the "Audio read error" problem.
PR: 58227 Submitted by: Andriy Gapon of Cybervision Also chase soundcard.h.
This commit is contained in:
parent
4256ce416f
commit
13aa24cbba
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=92030
@ -16,17 +16,15 @@ MAINTAINER= trevor@FreeBSD.org
|
||||
COMMENT= Speech recognition system
|
||||
|
||||
DEST= ${WRKSRC}/src/libsphinx2/
|
||||
USE_LIBTOOL= yes
|
||||
GNU_CONFIGURE= yes
|
||||
INSTALLS_SHLIB= yes
|
||||
PKGMESSAGE= ${WRKDIR}/pkg-message
|
||||
USE_GMAKE= yes
|
||||
|
||||
IGNORE= "audio read error"
|
||||
|
||||
# contains i386 sound code
|
||||
ONLY_FOR_ARCHS= i386
|
||||
|
||||
do-patch:
|
||||
post-patch:
|
||||
.for ii in CM_funcs.c hash.c linklist.c list.c salloc.c
|
||||
${MV} ${DEST}${ii} ${DEST}${ii}.orig
|
||||
${SED} -e "s:<malloc.h>:<stdlib.h>:g" < ${DEST}${ii}.orig > ${DEST}${ii}
|
||||
|
14
audio/sphinx/files/patch-src_examples_tty-continuous.c
Normal file
14
audio/sphinx/files/patch-src_examples_tty-continuous.c
Normal file
@ -0,0 +1,14 @@
|
||||
$FreeBSD$
|
||||
|
||||
author: Andriy Gapon
|
||||
|
||||
--- src/examples/tty-continuous.c.orig Thu Dec 13 21:11:15 2001
|
||||
+++ src/examples/tty-continuous.c Mon Oct 20 12:12:58 2003
|
||||
@@ -175,7 +175,6 @@ static void utterance_loop()
|
||||
* listening until current utterance completely decoded
|
||||
*/
|
||||
ad_stop_rec (ad);
|
||||
- while (ad_read (ad, adbuf, 4096) >= 0);
|
||||
cont_ad_reset (cont);
|
||||
|
||||
printf ("Stopped listening, please wait...\n"); fflush (stdout);
|
211
audio/sphinx/files/patch-src_libsphinx2ad_ad_oss_bsd.c
Normal file
211
audio/sphinx/files/patch-src_libsphinx2ad_ad_oss_bsd.c
Normal file
@ -0,0 +1,211 @@
|
||||
$FreeBSD$
|
||||
|
||||
author: Andriy Gapon
|
||||
|
||||
--- src/libsphinx2ad/ad_oss_bsd.c.orig Thu Dec 13 21:11:27 2001
|
||||
+++ src/libsphinx2ad/ad_oss_bsd.c Fri Oct 24 04:11:22 2003
|
||||
@@ -61,7 +61,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
-#include <machine/soundcard.h>
|
||||
+#include <sys/soundcard.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "s2types.h"
|
||||
@@ -72,14 +72,11 @@
|
||||
|
||||
#define SPS_EPSILON 200
|
||||
|
||||
-#ifndef SNDCTL_DSP_SETDUPLEX
|
||||
-#define SNDCTL_DSP_SETDUPLEX -1
|
||||
-#endif
|
||||
|
||||
ad_rec_t *ad_open_sps (int32 sps) {
|
||||
ad_rec_t *handle;
|
||||
int32 dspFD, mixerFD;
|
||||
- int32 nonBlocking=1, sourceMic=1, inputGain=INPUT_GAIN;
|
||||
+ int32 sourceMic=1, inputGain=INPUT_GAIN;
|
||||
int32 audioFormat=AUDIO_FORMAT;
|
||||
int32 dspCaps=0;
|
||||
int32 sampleRate;
|
||||
@@ -96,7 +93,6 @@
|
||||
}
|
||||
sampleRate = sps;
|
||||
|
||||
- /* Used to have O_NDELAY. */
|
||||
if((dspFD = open ("/dev/dsp", O_RDONLY))<0){
|
||||
if (errno == EBUSY)
|
||||
fprintf(stderr, "Audio device busy\n");
|
||||
@@ -105,18 +101,6 @@
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- if (ioctl (dspFD, SNDCTL_DSP_SYNC, 0) < 0){
|
||||
- fprintf(stderr, "Audio ioctl(SYNC) failed: %s\n", strerror(errno));
|
||||
- close (dspFD);
|
||||
- return NULL;
|
||||
- }
|
||||
-
|
||||
- if (ioctl (dspFD, SNDCTL_DSP_RESET, 0) < 0){
|
||||
- fprintf(stderr, "Audio ioctl(RESET) failed: %s\n", strerror(errno));
|
||||
- close (dspFD);
|
||||
- return NULL;
|
||||
- }
|
||||
-
|
||||
if (ioctl (dspFD, SNDCTL_DSP_SETFMT, &audioFormat) < 0){
|
||||
fprintf(stderr, "Audio ioctl(SETFMT 0x%x) failed: %s\n", audioFormat, strerror(errno));
|
||||
close (dspFD);
|
||||
@@ -139,12 +123,6 @@
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- if (ioctl (dspFD, SNDCTL_DSP_NONBLOCK, &nonBlocking) < 0) {
|
||||
- fprintf(stderr, "ioctl(NONBLOCK) failed: %s\n", strerror(errno));
|
||||
- close (dspFD);
|
||||
- return NULL;
|
||||
- }
|
||||
-
|
||||
if (ioctl (dspFD, SNDCTL_DSP_GETCAPS, &dspCaps) < 0) {
|
||||
fprintf(stderr, "ioctl(GETCAPS) failed: %s\n", strerror(errno));
|
||||
close (dspFD);
|
||||
@@ -161,8 +139,6 @@
|
||||
printf("DSP %s memory map capability.\n", (dspCaps&DSP_CAP_MMAP)?"has":"does not have");
|
||||
#endif
|
||||
|
||||
- if ((dspCaps & DSP_CAP_DUPLEX) && (ioctl (dspFD, SNDCTL_DSP_SETDUPLEX, 0) < 0))
|
||||
- fprintf(stderr, "ioctl(SETDUPLEX) failed: %s\n", strerror(errno));
|
||||
|
||||
/* Patched by N. Roy (nickr@ri.cmu.edu), 99/7/23.
|
||||
Previously, mixer was set through dspFD. This is incorrect. Should
|
||||
@@ -210,10 +186,10 @@
|
||||
}
|
||||
|
||||
handle->dspFD = dspFD;
|
||||
- handle->recording = 0;
|
||||
handle->sps = sps;
|
||||
handle->bps = sizeof(int16);
|
||||
-
|
||||
+ handle->recording = 1;
|
||||
+
|
||||
return(handle);
|
||||
}
|
||||
|
||||
@@ -224,15 +200,10 @@
|
||||
|
||||
int32 ad_close (ad_rec_t *handle)
|
||||
{
|
||||
- if (handle->dspFD < 0)
|
||||
- return AD_ERR_NOT_OPEN;
|
||||
-
|
||||
if (handle->recording) {
|
||||
- if (ad_stop_rec (handle) < 0)
|
||||
- return AD_ERR_GEN;
|
||||
+ ad_stop_rec (handle);
|
||||
}
|
||||
|
||||
- close (handle->dspFD);
|
||||
free(handle);
|
||||
|
||||
return(0);
|
||||
@@ -240,48 +211,62 @@
|
||||
|
||||
int32 ad_start_rec (ad_rec_t *handle)
|
||||
{
|
||||
- if (handle->dspFD < 0)
|
||||
- return AD_ERR_NOT_OPEN;
|
||||
-
|
||||
- if (handle->recording)
|
||||
- return AD_ERR_GEN;
|
||||
+
|
||||
+ if (!handle->recording) {
|
||||
+
|
||||
+ int32 dspFD;
|
||||
+ int32 audioFormat=AUDIO_FORMAT;
|
||||
+ int32 sampleRate=handle->sps;
|
||||
+
|
||||
+ if((dspFD = open ("/dev/dsp", O_RDONLY))<0){
|
||||
+ if (errno == EBUSY)
|
||||
+ fprintf(stderr, "Audio device busy\n");
|
||||
+ else
|
||||
+ fprintf(stderr, "Failed to open audio device: %s\n", strerror(errno));
|
||||
+ return AD_ERR_GEN;
|
||||
+ }
|
||||
|
||||
- /* Sample rate, format, input mix settings, &c. are configured
|
||||
- * with ioctl(2) calls under Linux. It makes more sense to handle
|
||||
- * these at device open time and consider the state of the device
|
||||
- * to be fixed until closed.
|
||||
- */
|
||||
+ if (ioctl (dspFD, SNDCTL_DSP_SETFMT, &audioFormat) < 0){
|
||||
+ fprintf(stderr, "Audio ioctl(SETFMT 0x%x) failed: %s\n", audioFormat, strerror(errno));
|
||||
+ close (dspFD);
|
||||
+ return AD_ERR_GEN;
|
||||
+ }
|
||||
+ if (audioFormat != AUDIO_FORMAT) {
|
||||
+ fprintf(stderr, "Audio ioctl(SETFMT): 0x%x, expected: 0x%x\n", audioFormat, AUDIO_FORMAT);
|
||||
+ close (dspFD);
|
||||
+ return AD_ERR_GEN;
|
||||
+ }
|
||||
|
||||
- handle->recording = 1;
|
||||
-
|
||||
- /* rkm@cs: This doesn't actually do anything. How do we turn recording on/off? */
|
||||
+ if (ioctl (dspFD, SNDCTL_DSP_SPEED, &sampleRate) < 0) {
|
||||
+ fprintf(stderr, "Audio ioctl(SPEED %d) failed %s\n", sampleRate, strerror(errno));
|
||||
+ close (dspFD);
|
||||
+ return AD_ERR_GEN;
|
||||
+ }
|
||||
+ if (sampleRate != handle->sps) {
|
||||
+ fprintf(stderr, "Audio ioctl(SPEED): %d, expected: %d\n", sampleRate, handle->sps);
|
||||
+ close (dspFD);
|
||||
+ return AD_ERR_GEN;
|
||||
+ }
|
||||
+ handle->dspFD = dspFD;
|
||||
+ handle->recording = 1;
|
||||
+ }
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
int32 ad_stop_rec (ad_rec_t *handle)
|
||||
{
|
||||
- if (handle->dspFD < 0)
|
||||
- return AD_ERR_NOT_OPEN;
|
||||
-
|
||||
- if (! handle->recording)
|
||||
- return AD_ERR_GEN;
|
||||
-
|
||||
- if (ioctl (handle->dspFD, SNDCTL_DSP_SYNC, 0) < 0) {
|
||||
- fprintf(stderr, "Audio ioctl(SYNC) failed: %s\n", strerror(errno));
|
||||
- return AD_ERR_GEN;
|
||||
- }
|
||||
-
|
||||
- handle->recording = 0;
|
||||
-
|
||||
+ if (handle->recording) {
|
||||
+ close (handle->dspFD);
|
||||
+ handle->dspFD = -1;
|
||||
+ handle->recording = 0;
|
||||
+ }
|
||||
return (0);
|
||||
}
|
||||
|
||||
int32 ad_read (ad_rec_t *handle, int16 *buf, int32 max)
|
||||
{
|
||||
- int32 length;
|
||||
-
|
||||
- length = max * handle->bps; /* #samples -> #bytes */
|
||||
+ int32 length = max * handle->bps; /* #samples -> #bytes */
|
||||
|
||||
if ((length = read (handle->dspFD, buf, length)) > 0) {
|
||||
#if 0
|
||||
@@ -292,7 +277,7 @@
|
||||
}
|
||||
|
||||
if (length < 0) {
|
||||
- fprintf(stderr, "Audio read error\n");
|
||||
+ perror("Audio read error");
|
||||
return AD_ERR_GEN;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user