1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-17 10:26:15 +00:00

make the feederchain builder work for recording. this has not been tested

extensively as none of my testboxes have speakers or an audio source at
present, but the chains built look correct and reading /dev/audio (ulaw,
translated from signed 16 bit little-endian) gives values within the
expected range for silence.
This commit is contained in:
Cameron Grant 2002-01-23 05:10:56 +00:00
parent f6126456ef
commit 79e6a82b48
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=89686
3 changed files with 64 additions and 19 deletions

View File

@ -997,7 +997,7 @@ chn_buildfeeder(struct pcm_channel *c)
{
struct feeder_class *fc;
struct pcm_feederdesc desc;
u_int32_t tmp[2], type, flags;
u_int32_t tmp[2], type, flags, hwfmt;
CHN_LOCKASSERT(c);
while (chn_removefeeder(c) == 0);
@ -1072,14 +1072,22 @@ chn_buildfeeder(struct pcm_channel *c)
}
}
if (!fmtvalid(c->feeder->desc->out, chn_getcaps(c)->fmtlist)) {
if (chn_fmtchain(c, chn_getcaps(c)->fmtlist) == 0) {
DEB(printf("can't build fmtchain from %x\n", c->feeder->desc->out));
return EINVAL;
if (fmtvalid(c->feeder->desc->out, chn_getcaps(c)->fmtlist)) {
hwfmt = c->feeder->desc->out;
} else {
if (c->direction == PCMDIR_REC) {
tmp[0] = c->format;
tmp[1] = NULL;
hwfmt = chn_fmtchain(c, tmp);
} else {
hwfmt = chn_fmtchain(c, chn_getcaps(c)->fmtlist);
}
DEB(printf("built fmtchain from %x\n", c->feeder->desc->out));
}
if (hwfmt == 0)
return EINVAL;
sndbuf_setfmt(c->bufhard, hwfmt);
return 0;
}

View File

@ -267,25 +267,60 @@ feeder_fmtchain(u_int32_t *to, struct pcm_feeder *source, struct pcm_feeder *sto
u_int32_t
chn_fmtchain(struct pcm_channel *c, u_int32_t *to)
{
struct pcm_feeder *try, *stop;
int max;
struct pcm_feeder *try, *del, *stop;
u_int32_t tmpfrom[2], best, *from;
int i, max, bestmax;
KASSERT(c != NULL, ("c == NULL"));
KASSERT(c->feeder != NULL, ("c->feeder == NULL"));
KASSERT(to != NULL, ("to == NULL"));
KASSERT(to[0] != 0, ("to[0] == 0"));
/* we're broken for recording currently, reject attempts */
if (c->direction == PCMDIR_REC)
return EINVAL;
stop = c->feeder;
try = NULL;
max = 0;
while (try == NULL && max < 8) {
try = feeder_fmtchain(to, c->feeder, stop, max);
max++;
if (c->direction == PCMDIR_REC && c->feeder->desc->type == FEEDER_ROOT) {
from = chn_getcaps(c)->fmtlist;
} else {
tmpfrom[0] = c->feeder->desc->out;
tmpfrom[1] = 0;
from = tmpfrom;
}
i = 0;
best = 0;
bestmax = 100;
while (from[i] != 0) {
c->feeder->desc->out = from[i];
try = NULL;
max = 0;
while (try == NULL && max < 8) {
try = feeder_fmtchain(to, c->feeder, stop, max);
if (try == NULL)
max++;
}
if (try != NULL && max < bestmax) {
bestmax = max;
best = from[i];
}
while (try != NULL && try != stop) {
del = try;
try = try->source;
feeder_destroy(del);
}
i++;
}
if (best == 0)
return 0;
c->feeder->desc->out = best;
try = feeder_fmtchain(to, c->feeder, stop, bestmax);
if (try == NULL)
return 0;
c->feeder = try;
c->align = 0;
#ifdef FEEDER_DEBUG
printf("chain: ");
printf("\n\nchain: ");
#endif
while (try && (try != stop)) {
#ifdef FEEDER_DEBUG
@ -293,6 +328,8 @@ chn_fmtchain(struct pcm_channel *c, u_int32_t *to)
if (try->source)
printf(" -> ");
#endif
if (try->source)
try->source->parent = try;
if (try->align > 0)
c->align += try->align;
else if (try->align < 0 && c->align < -try->align)
@ -302,7 +339,7 @@ chn_fmtchain(struct pcm_channel *c, u_int32_t *to)
#ifdef FEEDER_DEBUG
printf("%s [%d]\n", try->class->name, try->desc->idx);
#endif
return c->feeder->desc->out;
return (c->direction == PCMDIR_REC)? best : c->feeder->desc->out;
}
/*****************************************************************************/

View File

@ -46,7 +46,7 @@ struct pcm_feeder {
struct pcm_feederdesc *desc;
void *data;
struct feeder_class *class;
struct pcm_feeder *source;
struct pcm_feeder *source, *parent;
};
void feeder_register(void *p);