|
ginnOS
The reference: libc, the libraries and the kernel
|
#include "audio.h"#include "soundcard.h"#include "arch/arch.h"#include "common/memory.h"#include "common/string.h"#include "kernel/device/device.h"#include "kernel/errno.h"#include "kernel/klog/klog.h"#include "kernel/process/process.h"#include "kernel/signal/signal.h"#include "kernel/sync/spinlock.h"#include "kernel/sync/wait_queue.h"#include "kernel/time/timer.h"#include "kernel/usermode/uaccess.h"#include "kernel/vfs/file.h"#include "kernel/vfs/poll.h"#include "kernel/vfs/stat.h"#include "kernel/memory/heap.h"Macros | |
| #define | RING_BYTES 32768u |
| the sound output core (see audio.h). | |
| #define | FRAME_BYTES 4u |
| #define | STREAMS_MAX 8u |
| #define | DRAIN_TIMEOUT_MS 2000u |
| #define | DEFAULT_VOLUME (75u | (75u << 8)) |
Functions | |
| void | audio_mix_add (int32_t *sums, const uint8_t *frames, uint32_t samples) |
| add 16-bit little-endian samples to sums (the mixing of the streams). | |
| void | audio_mix_out (uint8_t *out, const int32_t *sums, uint32_t samples) |
| write sums as 16-bit little-endian samples, clipped to the 16-bit range. | |
| uint32_t | audio_pull (audio_device_t *dev, void *dst, uint32_t bytes) |
| fill a DMA period from the ring buffer, with silence after the data. | |
| bool | audio_register (audio_device_t *dev) |
| register the sound device (one, the first one wins) and make /dev/dsp and /dev/mixer. | |
| void | audio_status (audio_status_t *status) |
| #define RING_BYTES 32768u |
the sound output core (see audio.h).
each opener of /dev/dsp has a stream: a ring buffer of sound in the device format, 4 bytes per frame (left and right, signed 16-bit little endian). write() converts the program's format into it; audio_pull (the driver interrupt) adds the playing streams together, with clipping. the program's byte counts (GETOSPACE, GETODELAY) are given in its format.
a stream plays when its ring holds enough sound for all the device's periods and one more, and stops when the program closes /dev/dsp (after the queued sound has played), on SNDCTL_DSP_SYNC, and on SNDCTL_DSP_RESET. the device runs while a stream plays. all streams use the device's rate: only a program that is alone can change it.
locking: one spinlock (with interrupts off) for the streams and the state, shared with the driver interrupt. the driver's start and stop run without it, in process context.
| #define FRAME_BYTES 4u |
| #define STREAMS_MAX 8u |
| #define DRAIN_TIMEOUT_MS 2000u |
| #define DEFAULT_VOLUME (75u | (75u << 8)) |
add 16-bit little-endian samples to sums (the mixing of the streams).
write sums as 16-bit little-endian samples, clipped to the 16-bit range.
| uint32_t audio_pull | ( | audio_device_t * | dev, |
| void * | dst, | ||
| uint32_t | bytes ) |
fill a DMA period from the ring buffer, with silence after the data.
call it from the driver interrupt (or from start).
| dst | the period. |
| bytes | its size (a multiple of 4). |
| bool audio_register | ( | audio_device_t * | dev | ) |
register the sound device (one, the first one wins) and make /dev/dsp and /dev/mixer.
| void audio_status | ( | audio_status_t * | status | ) |