aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/sound/pcm/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/sound/pcm/buffer.c')
-rw-r--r--sys/dev/sound/pcm/buffer.c199
1 files changed, 17 insertions, 182 deletions
diff --git a/sys/dev/sound/pcm/buffer.c b/sys/dev/sound/pcm/buffer.c
index de535ec2dcba..eb2cbe667bf3 100644
--- a/sys/dev/sound/pcm/buffer.c
+++ b/sys/dev/sound/pcm/buffer.c
@@ -5,6 +5,10 @@
* Portions Copyright (c) Ryan Beasley <ryan.beasley@gmail.com> - GSoC 2006
* Copyright (c) 1999 Cameron Grant <cg@FreeBSD.org>
* All rights reserved.
+ * Copyright (c) 2025 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Christos Margiolis
+ * <christos@FreeBSD.org> under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -41,13 +45,12 @@
#include "snd_fxdiv_gen.h"
struct snd_dbuf *
-sndbuf_create(device_t dev, char *drv, char *desc, struct pcm_channel *channel)
+sndbuf_create(struct pcm_channel *channel, const char *desc)
{
struct snd_dbuf *b;
b = malloc(sizeof(*b), M_DEVBUF, M_WAITOK | M_ZERO);
- snprintf(b->name, SNDBUF_NAMELEN, "%s:%s", drv, desc);
- b->dev = dev;
+ snprintf(b->name, SNDBUF_NAMELEN, "%s:%s", channel->name, desc);
b->channel = channel;
return b;
@@ -60,19 +63,13 @@ sndbuf_destroy(struct snd_dbuf *b)
free(b, M_DEVBUF);
}
-bus_addr_t
-sndbuf_getbufaddr(struct snd_dbuf *buf)
-{
- return (buf->buf_addr);
-}
-
static void
sndbuf_setmap(void *arg, bus_dma_segment_t *segs, int nseg, int error)
{
struct snd_dbuf *b = (struct snd_dbuf *)arg;
if (snd_verbose > 3) {
- device_printf(b->dev, "sndbuf_setmap %lx, %lx; ",
+ printf("sndbuf_setmap %lx, %lx; ",
(u_long)segs[0].ds_addr, (u_long)segs[0].ds_len);
printf("%p -> %lx\n", b->buf, (u_long)segs[0].ds_addr);
}
@@ -147,7 +144,7 @@ sndbuf_free(struct snd_dbuf *b)
} else
free(b->buf, M_DEVBUF);
}
- seldrain(sndbuf_getsel(b));
+ seldrain(&b->sel);
b->tmpbuf = NULL;
b->shadbuf = NULL;
@@ -277,16 +274,10 @@ sndbuf_clear(struct snd_dbuf *b, unsigned int length)
length = b->bufsize;
data = sndbuf_zerodata(b->fmt);
-
i = sndbuf_getfreeptr(b);
- p = sndbuf_getbuf(b);
- while (length > 0) {
- p[i] = data;
- length--;
- i++;
- if (i >= b->bufsize)
- i = 0;
- }
+ p = b->buf;
+ for (; length > 0; length--, i++)
+ p[i % b->bufsize] = data;
}
/**
@@ -298,7 +289,7 @@ void
sndbuf_fillsilence(struct snd_dbuf *b)
{
if (b->bufsize > 0)
- memset(sndbuf_getbuf(b), sndbuf_zerodata(b->fmt), b->bufsize);
+ memset(b->buf, sndbuf_zerodata(b->fmt), b->bufsize);
b->rp = 0;
b->rl = b->bufsize;
}
@@ -307,7 +298,7 @@ void
sndbuf_fillsilence_rl(struct snd_dbuf *b, u_int rl)
{
if (b->bufsize > 0)
- memset(sndbuf_getbuf(b), sndbuf_zerodata(b->fmt), b->bufsize);
+ memset(b->buf, sndbuf_zerodata(b->fmt), b->bufsize);
b->rp = 0;
b->rl = min(b->bufsize, rl);
}
@@ -344,12 +335,6 @@ sndbuf_reset(struct snd_dbuf *b)
sndbuf_clearshadow(b);
}
-u_int32_t
-sndbuf_getfmt(struct snd_dbuf *b)
-{
- return b->fmt;
-}
-
int
sndbuf_setfmt(struct snd_dbuf *b, u_int32_t fmt)
{
@@ -359,60 +344,12 @@ sndbuf_setfmt(struct snd_dbuf *b, u_int32_t fmt)
return 0;
}
-unsigned int
-sndbuf_getspd(struct snd_dbuf *b)
-{
- return b->spd;
-}
-
void
sndbuf_setspd(struct snd_dbuf *b, unsigned int spd)
{
b->spd = spd;
}
-unsigned int
-sndbuf_getalign(struct snd_dbuf *b)
-{
- return (b->align);
-}
-
-unsigned int
-sndbuf_getblkcnt(struct snd_dbuf *b)
-{
- return b->blkcnt;
-}
-
-void
-sndbuf_setblkcnt(struct snd_dbuf *b, unsigned int blkcnt)
-{
- b->blkcnt = blkcnt;
-}
-
-unsigned int
-sndbuf_getblksz(struct snd_dbuf *b)
-{
- return b->blksz;
-}
-
-void
-sndbuf_setblksz(struct snd_dbuf *b, unsigned int blksz)
-{
- b->blksz = blksz;
-}
-
-unsigned int
-sndbuf_getbps(struct snd_dbuf *b)
-{
- return b->bps;
-}
-
-void *
-sndbuf_getbuf(struct snd_dbuf *b)
-{
- return b->buf;
-}
-
void *
sndbuf_getbufofs(struct snd_dbuf *b, unsigned int ofs)
{
@@ -422,24 +359,6 @@ sndbuf_getbufofs(struct snd_dbuf *b, unsigned int ofs)
}
unsigned int
-sndbuf_getsize(struct snd_dbuf *b)
-{
- return b->bufsize;
-}
-
-unsigned int
-sndbuf_getmaxsize(struct snd_dbuf *b)
-{
- return b->maxsize;
-}
-
-unsigned int
-sndbuf_getallocsize(struct snd_dbuf *b)
-{
- return b->allocsize;
-}
-
-unsigned int
sndbuf_runsz(struct snd_dbuf *b)
{
return b->dl;
@@ -451,19 +370,6 @@ sndbuf_setrun(struct snd_dbuf *b, int go)
b->dl = go? b->blksz : 0;
}
-struct selinfo *
-sndbuf_getsel(struct snd_dbuf *b)
-{
- return &b->sel;
-}
-
-/************************************************************/
-unsigned int
-sndbuf_getxrun(struct snd_dbuf *b)
-{
- return b->xrun;
-}
-
void
sndbuf_setxrun(struct snd_dbuf *b, unsigned int xrun)
{
@@ -471,18 +377,6 @@ sndbuf_setxrun(struct snd_dbuf *b, unsigned int xrun)
}
unsigned int
-sndbuf_gethwptr(struct snd_dbuf *b)
-{
- return b->hp;
-}
-
-void
-sndbuf_sethwptr(struct snd_dbuf *b, unsigned int ptr)
-{
- b->hp = ptr;
-}
-
-unsigned int
sndbuf_getready(struct snd_dbuf *b)
{
KASSERT((b->rl >= 0) && (b->rl <= b->bufsize), ("%s: b->rl invalid %d", __func__, b->rl));
@@ -521,38 +415,13 @@ sndbuf_getblocks(struct snd_dbuf *b)
return b->total / b->blksz;
}
-u_int64_t
-sndbuf_getprevblocks(struct snd_dbuf *b)
-{
- return b->prev_total / b->blksz;
-}
-
-u_int64_t
-sndbuf_gettotal(struct snd_dbuf *b)
-{
- return b->total;
-}
-
-u_int64_t
-sndbuf_getprevtotal(struct snd_dbuf *b)
-{
- return b->prev_total;
-}
-
-void
-sndbuf_updateprevtotal(struct snd_dbuf *b)
-{
- b->prev_total = b->total;
-}
-
unsigned int
sndbuf_xbytes(unsigned int v, struct snd_dbuf *from, struct snd_dbuf *to)
{
if (from == NULL || to == NULL || v == 0)
return 0;
- return snd_xbytes(v, sndbuf_getalign(from) * sndbuf_getspd(from),
- sndbuf_getalign(to) * sndbuf_getspd(to));
+ return snd_xbytes(v, from->align * from->spd, to->align * to->spd);
}
u_int8_t
@@ -592,7 +461,7 @@ sndbuf_acquire(struct snd_dbuf *b, u_int8_t *from, unsigned int count)
b->total += count;
if (from != NULL) {
while (count > 0) {
- l = min(count, sndbuf_getsize(b) - sndbuf_getfreeptr(b));
+ l = min(count, b->bufsize - sndbuf_getfreeptr(b));
bcopy(from, sndbuf_getbufofs(b, sndbuf_getfreeptr(b)), l);
from += l;
b->rl += l;
@@ -628,7 +497,7 @@ sndbuf_dispose(struct snd_dbuf *b, u_int8_t *to, unsigned int count)
KASSERT((b->rl >= 0) && (b->rl <= b->bufsize), ("%s: b->rl invalid %d", __func__, b->rl));
if (to != NULL) {
while (count > 0) {
- l = min(count, sndbuf_getsize(b) - sndbuf_getreadyptr(b));
+ l = min(count, b->bufsize - sndbuf_getreadyptr(b));
bcopy(sndbuf_getbufofs(b, sndbuf_getreadyptr(b)), to, l);
to += l;
b->rl -= l;
@@ -673,7 +542,7 @@ sndbuf_feed(struct snd_dbuf *from, struct snd_dbuf *to, struct pcm_channel *chan
if (sndbuf_getfree(to) < count)
return (EINVAL);
- maxfeed = SND_FXROUND(SND_FXDIV_MAX, sndbuf_getalign(to));
+ maxfeed = SND_FXROUND(SND_FXDIV_MAX, to->align);
do {
cnt = FEEDER_FEED(feeder, channel, to->tmpbuf,
@@ -695,40 +564,6 @@ sndbuf_feed(struct snd_dbuf *from, struct snd_dbuf *to, struct pcm_channel *chan
return (0);
}
-/************************************************************/
-
-void
-sndbuf_dump(struct snd_dbuf *b, char *s, u_int32_t what)
-{
- printf("%s: [", s);
- if (what & 0x01)
- printf(" bufsize: %d, maxsize: %d", b->bufsize, b->maxsize);
- if (what & 0x02)
- printf(" dl: %d, rp: %d, rl: %d, hp: %d", b->dl, b->rp, b->rl, b->hp);
- if (what & 0x04)
- printf(" total: %ju, prev_total: %ju, xrun: %d", (uintmax_t)b->total, (uintmax_t)b->prev_total, b->xrun);
- if (what & 0x08)
- printf(" fmt: 0x%x, spd: %d", b->fmt, b->spd);
- if (what & 0x10)
- printf(" blksz: %d, blkcnt: %d, flags: 0x%x", b->blksz, b->blkcnt, b->flags);
- printf(" ]\n");
-}
-
-/************************************************************/
-u_int32_t
-sndbuf_getflags(struct snd_dbuf *b)
-{
- return b->flags;
-}
-
-void
-sndbuf_setflags(struct snd_dbuf *b, u_int32_t flags, int on)
-{
- b->flags &= ~flags;
- if (on)
- b->flags |= flags;
-}
-
/**
* @brief Clear the shadow buffer by filling with samples equal to zero.
*