FreeBSD kernel sound device code
buffer.c File Reference
#include <dev/sound/pcm/sound.h>
#include "feeder_if.h"
#include "snd_fxdiv_gen.h"
Include dependency graph for buffer.c:

Go to the source code of this file.

Macros

#define SND_USE_FXDIV
 
#define SND_DECLARE_FXDIV
 
#define SNDBUF_CACHE_SHIFT   5
 

Functions

 SND_DECLARE_FILE ("$FreeBSD$")
 
struct snd_dbufsndbuf_create (device_t dev, char *drv, char *desc, struct pcm_channel *channel)
 
void sndbuf_destroy (struct snd_dbuf *b)
 
bus_addr_t sndbuf_getbufaddr (struct snd_dbuf *buf)
 
static void sndbuf_setmap (void *arg, bus_dma_segment_t *segs, int nseg, int error)
 
int sndbuf_alloc (struct snd_dbuf *b, bus_dma_tag_t dmatag, int dmaflags, unsigned int size)
 
int sndbuf_setup (struct snd_dbuf *b, void *buf, unsigned int size)
 
void sndbuf_free (struct snd_dbuf *b)
 
int sndbuf_resize (struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz)
 
int sndbuf_remalloc (struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz)
 
void sndbuf_clear (struct snd_dbuf *b, unsigned int length)
 Zero out space in buffer free area. More...
 
void sndbuf_fillsilence (struct snd_dbuf *b)
 Zap buffer contents, resetting "ready area" fields. More...
 
void sndbuf_fillsilence_rl (struct snd_dbuf *b, u_int rl)
 
void sndbuf_softreset (struct snd_dbuf *b)
 Reset buffer w/o flushing statistics. More...
 
void sndbuf_reset (struct snd_dbuf *b)
 
u_int32_t sndbuf_getfmt (struct snd_dbuf *b)
 
int sndbuf_setfmt (struct snd_dbuf *b, u_int32_t fmt)
 
unsigned int sndbuf_getspd (struct snd_dbuf *b)
 
void sndbuf_setspd (struct snd_dbuf *b, unsigned int spd)
 
unsigned int sndbuf_getalign (struct snd_dbuf *b)
 
unsigned int sndbuf_getblkcnt (struct snd_dbuf *b)
 
void sndbuf_setblkcnt (struct snd_dbuf *b, unsigned int blkcnt)
 
unsigned int sndbuf_getblksz (struct snd_dbuf *b)
 
void sndbuf_setblksz (struct snd_dbuf *b, unsigned int blksz)
 
unsigned int sndbuf_getbps (struct snd_dbuf *b)
 
void * sndbuf_getbuf (struct snd_dbuf *b)
 
void * sndbuf_getbufofs (struct snd_dbuf *b, unsigned int ofs)
 
unsigned int sndbuf_getsize (struct snd_dbuf *b)
 
unsigned int sndbuf_getmaxsize (struct snd_dbuf *b)
 
unsigned int sndbuf_getallocsize (struct snd_dbuf *b)
 
unsigned int sndbuf_runsz (struct snd_dbuf *b)
 
void sndbuf_setrun (struct snd_dbuf *b, int go)
 
struct selinfo * sndbuf_getsel (struct snd_dbuf *b)
 
unsigned int sndbuf_getxrun (struct snd_dbuf *b)
 
void sndbuf_setxrun (struct snd_dbuf *b, unsigned int xrun)
 
unsigned int sndbuf_gethwptr (struct snd_dbuf *b)
 
void sndbuf_sethwptr (struct snd_dbuf *b, unsigned int ptr)
 
unsigned int sndbuf_getready (struct snd_dbuf *b)
 
unsigned int sndbuf_getreadyptr (struct snd_dbuf *b)
 
unsigned int sndbuf_getfree (struct snd_dbuf *b)
 
unsigned int sndbuf_getfreeptr (struct snd_dbuf *b)
 
u_int64_t sndbuf_getblocks (struct snd_dbuf *b)
 
u_int64_t sndbuf_getprevblocks (struct snd_dbuf *b)
 
u_int64_t sndbuf_gettotal (struct snd_dbuf *b)
 
u_int64_t sndbuf_getprevtotal (struct snd_dbuf *b)
 
void sndbuf_updateprevtotal (struct snd_dbuf *b)
 
unsigned int sndbuf_xbytes (unsigned int v, struct snd_dbuf *from, struct snd_dbuf *to)
 
u_int8_t sndbuf_zerodata (u_int32_t fmt)
 
int sndbuf_acquire (struct snd_dbuf *b, u_int8_t *from, unsigned int count)
 Acquire buffer space to extend ready area. More...
 
int sndbuf_dispose (struct snd_dbuf *b, u_int8_t *to, unsigned int count)
 Dispose samples from channel buffer, increasing size of ready area. More...
 
int sndbuf_feed (struct snd_dbuf *from, struct snd_dbuf *to, struct pcm_channel *channel, struct pcm_feeder *feeder, unsigned int count)
 
void sndbuf_dump (struct snd_dbuf *b, char *s, u_int32_t what)
 
u_int32_t sndbuf_getflags (struct snd_dbuf *b)
 
void sndbuf_setflags (struct snd_dbuf *b, u_int32_t flags, int on)
 
void sndbuf_clearshadow (struct snd_dbuf *b)
 Clear the shadow buffer by filling with samples equal to zero. More...
 

Macro Definition Documentation

◆ SND_DECLARE_FXDIV

#define SND_DECLARE_FXDIV

Definition at line 40 of file buffer.c.

◆ SND_USE_FXDIV

#define SND_USE_FXDIV

Definition at line 39 of file buffer.c.

◆ SNDBUF_CACHE_SHIFT

#define SNDBUF_CACHE_SHIFT   5

Definition at line 161 of file buffer.c.

Function Documentation

◆ SND_DECLARE_FILE()

SND_DECLARE_FILE ( "$FreeBSD$"  )

◆ sndbuf_acquire()

int sndbuf_acquire ( struct snd_dbuf b,
u_int8_t *  from,
unsigned int  count 
)

Acquire buffer space to extend ready area.

This function extends the ready area length by count bytes, and may optionally copy samples from another location stored in from. The counter snd_dbuf::total is also incremented by count bytes.

Parameters
baudio buffer
fromsample source (optional)
countnumber of bytes to acquire
Return values
0Unconditional

Definition at line 618 of file buffer.c.

References b, snd_dbuf::bufsize, count, snd_dbuf::rl, sndbuf_getbufofs(), sndbuf_getfree(), sndbuf_getfreeptr(), sndbuf_getsize(), and snd_dbuf::total.

Referenced by chn_dmaupdate(), chn_sync(), chn_wrfeed(), chn_write(), dsp_ioctl(), feed_mixer_feed(), feed_mixer_rec(), and sndbuf_feed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_alloc()

◆ sndbuf_clear()

void sndbuf_clear ( struct snd_dbuf b,
unsigned int  length 
)

Zero out space in buffer free area.

This function clears a chunk of length bytes in the buffer free area (i.e., where the next write will be placed).

Parameters
bbuffer context
lengthnumber of bytes to blank

Definition at line 270 of file buffer.c.

References b, snd_dbuf::bufsize, data, snd_dbuf::fmt, sndbuf_getbuf(), sndbuf_getfreeptr(), and sndbuf_zerodata().

Referenced by chn_sync(), sndbuf_reset(), and sndbuf_softreset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_clearshadow()

void sndbuf_clearshadow ( struct snd_dbuf b)

Clear the shadow buffer by filling with samples equal to zero.

Parameters
bbuffer to clear

Definition at line 770 of file buffer.c.

References b, snd_dbuf::fmt, snd_dbuf::shadbuf, snd_dbuf::sl, and sndbuf_zerodata().

Referenced by sndbuf_reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_create()

struct snd_dbuf * sndbuf_create ( device_t  dev,
char *  drv,
char *  desc,
struct pcm_channel channel 
)

Definition at line 46 of file buffer.c.

References b, snd_dbuf::channel, channel, desc, snd_dbuf::dev, dev, snd_dbuf::name, and SNDBUF_NAMELEN.

Referenced by chn_init().

Here is the caller graph for this function:

◆ sndbuf_destroy()

void sndbuf_destroy ( struct snd_dbuf b)

Definition at line 59 of file buffer.c.

References b, free, and sndbuf_free().

Referenced by chn_init(), and chn_kill().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_dispose()

int sndbuf_dispose ( struct snd_dbuf b,
u_int8_t *  to,
unsigned int  count 
)

Dispose samples from channel buffer, increasing size of ready area.

This function discards samples from the supplied buffer by advancing the ready area start pointer and decrementing the ready area length. If to is not NULL, then the discard samples will be copied to the location it points to.

Parameters
bPCM channel sound buffer
todestination buffer (optional)
countnumber of bytes to discard
Returns
0 unconditionally

Definition at line 655 of file buffer.c.

References b, snd_dbuf::bufsize, count, snd_dbuf::rl, snd_dbuf::rp, sndbuf_getbufofs(), sndbuf_getready(), sndbuf_getreadyptr(), and sndbuf_getsize().

Referenced by chn_dmaupdate(), chn_rdfeed(), chn_read(), dsp_ioctl(), feed_mixer_rec(), and feed_root().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_dump()

◆ sndbuf_feed()

int sndbuf_feed ( struct snd_dbuf from,
struct snd_dbuf to,
struct pcm_channel channel,
struct pcm_feeder feeder,
unsigned int  count 
)

Definition at line 691 of file buffer.c.

References channel, count, feeder, sndbuf_acquire(), sndbuf_getalign(), sndbuf_getfree(), and snd_dbuf::tmpbuf.

Referenced by chn_rdfeed(), and chn_wrfeed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_fillsilence()

void sndbuf_fillsilence ( struct snd_dbuf b)

Zap buffer contents, resetting "ready area" fields.

Parameters
bbuffer context

Definition at line 299 of file buffer.c.

References b, snd_dbuf::bufsize, snd_dbuf::fmt, snd_dbuf::rl, snd_dbuf::rp, sndbuf_getbuf(), and sndbuf_zerodata().

Referenced by dsp_ioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_fillsilence_rl()

void sndbuf_fillsilence_rl ( struct snd_dbuf b,
u_int  rl 
)

Definition at line 308 of file buffer.c.

References b, snd_dbuf::bufsize, snd_dbuf::fmt, snd_dbuf::rl, snd_dbuf::rp, sndbuf_getbuf(), and sndbuf_zerodata().

Referenced by chn_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_free()

void sndbuf_free ( struct snd_dbuf b)

◆ sndbuf_getalign()

◆ sndbuf_getallocsize()

unsigned int sndbuf_getallocsize ( struct snd_dbuf b)

Definition at line 447 of file buffer.c.

References snd_dbuf::allocsize, and b.

◆ sndbuf_getblkcnt()

unsigned int sndbuf_getblkcnt ( struct snd_dbuf b)

Definition at line 391 of file buffer.c.

References b, and snd_dbuf::blkcnt.

Referenced by atiixp_chan_setfragments(), chn_resizebuf(), chn_sync(), dsp_ioctl(), eschan_setfragments(), hdaa_channel_setfragments(), ich_filldtbl(), and via8233chan_setfragments().

Here is the caller graph for this function:

◆ sndbuf_getblksz()

unsigned int sndbuf_getblksz ( struct snd_dbuf b)

◆ sndbuf_getblocks()

u_int64_t sndbuf_getblocks ( struct snd_dbuf b)

Definition at line 541 of file buffer.c.

References b, snd_dbuf::blksz, SNDBUF_LOCKASSERT, and snd_dbuf::total.

Referenced by dsp_ioctl().

Here is the caller graph for this function:

◆ sndbuf_getbps()

unsigned int sndbuf_getbps ( struct snd_dbuf b)

Definition at line 415 of file buffer.c.

References b, and snd_dbuf::bps.

◆ sndbuf_getbuf()

void * sndbuf_getbuf ( struct snd_dbuf b)

Definition at line 421 of file buffer.c.

References b, and snd_dbuf::buf.

Referenced by audio_soc_chan_free(), emupchan_free(), feed_mixer_feed(), nmchan_init(), sndbuf_clear(), sndbuf_fillsilence(), and sndbuf_fillsilence_rl().

Here is the caller graph for this function:

◆ sndbuf_getbufaddr()

◆ sndbuf_getbufofs()

void * sndbuf_getbufofs ( struct snd_dbuf b,
unsigned int  ofs 
)

Definition at line 427 of file buffer.c.

References b, snd_dbuf::buf, and snd_dbuf::bufsize.

Referenced by chn_read(), chn_write(), dsp_mmap_single(), sndbuf_acquire(), and sndbuf_dispose().

Here is the caller graph for this function:

◆ sndbuf_getflags()

u_int32_t sndbuf_getflags ( struct snd_dbuf b)

Definition at line 751 of file buffer.c.

References b, and snd_dbuf::flags.

Referenced by sndbuf_dma(), sndbuf_dmabounce(), sndbuf_dmaptr(), and sndbuf_dmasetdir().

Here is the caller graph for this function:

◆ sndbuf_getfmt()

u_int32_t sndbuf_getfmt ( struct snd_dbuf b)

Definition at line 349 of file buffer.c.

References b, and snd_dbuf::fmt.

Referenced by chn_setparam(), and feed_root().

Here is the caller graph for this function:

◆ sndbuf_getfree()

unsigned int sndbuf_getfree ( struct snd_dbuf b)

◆ sndbuf_getfreeptr()

unsigned int sndbuf_getfreeptr ( struct snd_dbuf b)

Definition at line 531 of file buffer.c.

References b, snd_dbuf::bufsize, snd_dbuf::rl, snd_dbuf::rp, and SNDBUF_LOCKASSERT.

Referenced by buffer_copy(), chn_write(), dsp_ioctl(), envy24_r16sl(), envy24_r32sl(), envy24ht_r16sl(), envy24ht_r32sl(), sndbuf_acquire(), and sndbuf_clear().

Here is the caller graph for this function:

◆ sndbuf_gethwptr()

unsigned int sndbuf_gethwptr ( struct snd_dbuf b)

Definition at line 488 of file buffer.c.

References b, snd_dbuf::hp, and SNDBUF_LOCKASSERT.

Referenced by chn_dmaupdate(), and dsp_ioctl().

Here is the caller graph for this function:

◆ sndbuf_getmaxsize()

unsigned int sndbuf_getmaxsize ( struct snd_dbuf b)

◆ sndbuf_getprevblocks()

u_int64_t sndbuf_getprevblocks ( struct snd_dbuf b)

Definition at line 549 of file buffer.c.

References b, snd_dbuf::blksz, snd_dbuf::prev_total, and SNDBUF_LOCKASSERT.

◆ sndbuf_getprevtotal()

u_int64_t sndbuf_getprevtotal ( struct snd_dbuf b)

Definition at line 565 of file buffer.c.

References b, snd_dbuf::prev_total, and SNDBUF_LOCKASSERT.

Referenced by chn_polltrigger().

Here is the caller graph for this function:

◆ sndbuf_getready()

◆ sndbuf_getreadyptr()

unsigned int sndbuf_getreadyptr ( struct snd_dbuf b)

Definition at line 513 of file buffer.c.

References b, snd_dbuf::bufsize, snd_dbuf::rp, and SNDBUF_LOCKASSERT.

Referenced by buffer_copy(), chn_read(), dsp_ioctl(), envy24_p16sl(), envy24_p32sl(), envy24_p8u(), envy24ht_p16sl(), envy24ht_p32sl(), envy24ht_p8u(), and sndbuf_dispose().

Here is the caller graph for this function:

◆ sndbuf_getsel()

struct selinfo * sndbuf_getsel ( struct snd_dbuf b)

Definition at line 465 of file buffer.c.

References b, and snd_dbuf::sel.

Referenced by chn_poll(), and chn_wakeup().

Here is the caller graph for this function:

◆ sndbuf_getsize()

◆ sndbuf_getspd()

unsigned int sndbuf_getspd ( struct snd_dbuf b)

Definition at line 373 of file buffer.c.

References b, and snd_dbuf::spd.

Referenced by atiixp_chan_trigger(), chn_resizebuf(), chn_setparam(), chn_start(), chn_sync(), feeder_chain(), sndbuf_xbytes(), via8233chan_trigger(), and via_poll_ticks().

Here is the caller graph for this function:

◆ sndbuf_gettotal()

u_int64_t sndbuf_gettotal ( struct snd_dbuf b)

Definition at line 557 of file buffer.c.

References b, SNDBUF_LOCKASSERT, and snd_dbuf::total.

Referenced by chn_polltrigger(), and dsp_ioctl().

Here is the caller graph for this function:

◆ sndbuf_getxrun()

unsigned int sndbuf_getxrun ( struct snd_dbuf b)

Definition at line 472 of file buffer.c.

References b, SNDBUF_LOCKASSERT, and snd_dbuf::xrun.

◆ sndbuf_remalloc()

int sndbuf_remalloc ( struct snd_dbuf b,
unsigned int  blkcnt,
unsigned int  blksz 
)

Definition at line 214 of file buffer.c.

References snd_dbuf::allocsize, b, blkcnt, snd_dbuf::blkcnt, blksz, snd_dbuf::blksz, buf, snd_dbuf::buf, snd_dbuf::bufsize, snd_dbuf::channel, CHN_LOCK, CHN_UNLOCK, free, snd_dbuf::maxsize, snd_dbuf::shadbuf, snd_dbuf::sl, snd_verbose, SNDBUF_CACHE_SHIFT, sndbuf_reset(), and snd_dbuf::tmpbuf.

Referenced by chn_resizebuf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_reset()

void sndbuf_reset ( struct snd_dbuf b)

Definition at line 334 of file buffer.c.

References b, snd_dbuf::buf, snd_dbuf::bufsize, snd_dbuf::dl, snd_dbuf::hp, snd_dbuf::prev_total, snd_dbuf::rl, snd_dbuf::rp, sndbuf_clear(), sndbuf_clearshadow(), snd_dbuf::total, and snd_dbuf::xrun.

Referenced by chn_resetbuf(), sndbuf_remalloc(), and sndbuf_resize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_resize()

◆ sndbuf_runsz()

unsigned int sndbuf_runsz ( struct snd_dbuf b)

Definition at line 453 of file buffer.c.

References b, and snd_dbuf::dl.

Referenced by ad1816_intr(), mss_intr(), opti931_intr(), sb_intr(), sndbuf_dmaptr(), trrchan_setformat(), and trrchan_trigger().

Here is the caller graph for this function:

◆ sndbuf_setblkcnt()

void sndbuf_setblkcnt ( struct snd_dbuf b,
unsigned int  blkcnt 
)

Definition at line 397 of file buffer.c.

References b, blkcnt, and snd_dbuf::blkcnt.

◆ sndbuf_setblksz()

void sndbuf_setblksz ( struct snd_dbuf b,
unsigned int  blksz 
)

Definition at line 409 of file buffer.c.

References b, blksz, and snd_dbuf::blksz.

Referenced by chn_resizebuf().

Here is the caller graph for this function:

◆ sndbuf_setflags()

void sndbuf_setflags ( struct snd_dbuf b,
u_int32_t  flags,
int  on 
)

Definition at line 757 of file buffer.c.

References b, and snd_dbuf::flags.

Referenced by sndbuf_dmasetup().

Here is the caller graph for this function:

◆ sndbuf_setfmt()

int sndbuf_setfmt ( struct snd_dbuf b,
u_int32_t  fmt 
)

Definition at line 355 of file buffer.c.

References AFMT_16BIT, AFMT_24BIT, AFMT_32BIT, AFMT_ALIGN, AFMT_BPS, AFMT_CHANNEL, snd_dbuf::align, b, snd_dbuf::bps, fmt, and snd_dbuf::fmt.

Referenced by chn_init(), and feeder_chain().

Here is the caller graph for this function:

◆ sndbuf_sethwptr()

void sndbuf_sethwptr ( struct snd_dbuf b,
unsigned int  ptr 
)

Definition at line 496 of file buffer.c.

References b, snd_dbuf::hp, and SNDBUF_LOCKASSERT.

Referenced by chn_dmaupdate().

Here is the caller graph for this function:

◆ sndbuf_setmap()

static void sndbuf_setmap ( void *  arg,
bus_dma_segment_t *  segs,
int  nseg,
int  error 
)
static

Definition at line 72 of file buffer.c.

References b, snd_dbuf::buf, snd_dbuf::buf_addr, snd_dbuf::dev, error, and snd_verbose.

Referenced by sndbuf_alloc().

Here is the caller graph for this function:

◆ sndbuf_setrun()

void sndbuf_setrun ( struct snd_dbuf b,
int  go 
)

Definition at line 459 of file buffer.c.

References b, snd_dbuf::blksz, snd_dbuf::dl, and go.

Referenced by chn_abort(), chn_flush(), and chn_start().

Here is the caller graph for this function:

◆ sndbuf_setspd()

void sndbuf_setspd ( struct snd_dbuf b,
unsigned int  spd 
)

Definition at line 379 of file buffer.c.

References b, snd_dbuf::spd, and spd.

Referenced by chn_init(), chn_setparam(), feeder_chain(), and vchan_sync().

Here is the caller graph for this function:

◆ sndbuf_setup()

int sndbuf_setup ( struct snd_dbuf b,
void *  buf,
unsigned int  size 
)

Definition at line 123 of file buffer.c.

References b, buf, snd_dbuf::buf, snd_dbuf::bufsize, snd_dbuf::flags, snd_dbuf::maxsize, size, SNDBUF_F_MANAGED, and sndbuf_resize().

Referenced by audio_soc_chan_init(), chn_init(), emu_vinit(), envy24chan_init(), envy24htchan_init(), hdspechan_init(), nmchan_init(), uaudio_chan_init(), and uaudio_chan_set_param_blocksize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_setxrun()

void sndbuf_setxrun ( struct snd_dbuf b,
unsigned int  xrun 
)

Definition at line 480 of file buffer.c.

References b, SNDBUF_LOCKASSERT, and snd_dbuf::xrun.

◆ sndbuf_softreset()

void sndbuf_softreset ( struct snd_dbuf b)

Reset buffer w/o flushing statistics.

This function just zeroes out buffer contents and sets the "ready length" to zero. This was originally to facilitate minimal playback interruption (i.e., dropped samples) in SNDCTL_DSP_SILENCE/SKIP ioctls.

Parameters
bbuffer context

Definition at line 326 of file buffer.c.

References b, snd_dbuf::buf, snd_dbuf::bufsize, snd_dbuf::rl, and sndbuf_clear().

Referenced by dsp_ioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_updateprevtotal()

void sndbuf_updateprevtotal ( struct snd_dbuf b)

Definition at line 573 of file buffer.c.

References b, snd_dbuf::prev_total, SNDBUF_LOCKASSERT, and snd_dbuf::total.

Referenced by chn_pollreset().

Here is the caller graph for this function:

◆ sndbuf_xbytes()

unsigned int sndbuf_xbytes ( unsigned int  v,
struct snd_dbuf from,
struct snd_dbuf to 
)

Definition at line 581 of file buffer.c.

References snd_xbytes(), sndbuf_getalign(), and sndbuf_getspd().

Referenced by chn_resizebuf(), chn_start(), chn_sync(), and chn_wrfeed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndbuf_zerodata()

u_int8_t sndbuf_zerodata ( u_int32_t  fmt)

Definition at line 591 of file buffer.c.

References AFMT_PASSTHROUGH, AFMT_SIGNED, and fmt.

Referenced by feed_mixer_feed(), feed_root(), sndbuf_clear(), sndbuf_clearshadow(), sndbuf_fillsilence(), sndbuf_fillsilence_rl(), and z_resampler_setup().

Here is the caller graph for this function: