mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-05-31 00:30:57 +00:00
[audio] Rework alsa to use a pull model
This brings the alsa driver in line with the jack render (progress towards #16), but breaks most of the other drivers (for now: one step at a time). The idea is that once the pull model is working for at least one other target, the jack renderer can become just another target like it should have been in the first place (but I needed to get the pull model working first, then forgot about it). Correct state checking is not done yet, but testsound does produce what seems to be fairly good sound when it starts up correctly (part of the state checking (or lack thereof), I imagine).
This commit is contained in:
parent
c9319966ce
commit
fc907e232f
13 changed files with 506 additions and 331 deletions
|
@ -30,23 +30,15 @@
|
|||
#include <QF/plugin.h>
|
||||
#include <QF/qtypes.h>
|
||||
|
||||
/*
|
||||
All sound plugins must export these functions
|
||||
*/
|
||||
typedef volatile struct dma_s *(*P_S_O_Init) (void);
|
||||
typedef void (*P_S_O_Shutdown) (void);
|
||||
typedef int (*P_S_O_GetDMAPos) (void);
|
||||
typedef void (*P_S_O_Submit) (void);
|
||||
typedef void (*P_S_O_BlockSound) (void);
|
||||
typedef void (*P_S_O_UnblockSound) (void);
|
||||
struct snd_s;
|
||||
|
||||
typedef struct snd_output_funcs_s {
|
||||
P_S_O_Init pS_O_Init;
|
||||
P_S_O_Shutdown pS_O_Shutdown;
|
||||
P_S_O_GetDMAPos pS_O_GetDMAPos;
|
||||
P_S_O_Submit pS_O_Submit;
|
||||
P_S_O_BlockSound pS_O_BlockSound;
|
||||
P_S_O_UnblockSound pS_O_UnblockSound;
|
||||
int (*init) (struct snd_s *snd);
|
||||
void (*shutdown) (struct snd_s *snd);
|
||||
int (*get_dma_pos) (struct snd_s *snd);
|
||||
void (*submit) (struct snd_s *snd);
|
||||
void (*block_sound) (struct snd_s *snd);
|
||||
void (*unblock_sound) (struct snd_s *snd);
|
||||
} snd_output_funcs_t;
|
||||
|
||||
typedef struct snd_output_data_s {
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
typedef struct sfx_s sfx_t;
|
||||
struct sfx_s
|
||||
{
|
||||
struct snd_s *snd; //!< ownding snd_t instance
|
||||
const char *name;
|
||||
sfx_t *owner;
|
||||
|
||||
|
|
|
@ -67,6 +67,11 @@ QF_ALSA_NEED (int, snd_pcm_sw_params_set_stop_threshold, (snd_pcm_t *pcm, snd_pc
|
|||
QF_ALSA_NEED (size_t, snd_pcm_sw_params_sizeof, (void))
|
||||
QF_ALSA_NEED (const char *, snd_strerror, (int errnum))
|
||||
|
||||
QF_ALSA_NEED (int, snd_async_add_pcm_handler, (snd_async_handler_t **handler, snd_pcm_t *pcm, snd_async_callback_t callback, void *private_data))
|
||||
QF_ALSA_NEED (snd_pcm_t *, snd_async_handler_get_pcm, (snd_async_handler_t *handler))
|
||||
QF_ALSA_NEED (void *, snd_async_handler_get_callback_private, (snd_async_handler_t *handler))
|
||||
QF_ALSA_NEED (int, snd_async_del_handler, (snd_async_handler_t *handler))
|
||||
|
||||
#ifdef UNDEF_QF_ALSA_NEED
|
||||
#undef QF_ALSA_NEED
|
||||
#undef UNDEF_QF_ALSA_NEED
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
#include "QF/zone.h"
|
||||
|
||||
typedef struct portable_samplepair_s portable_samplepair_t;
|
||||
typedef struct dma_s dma_t;
|
||||
typedef struct snd_s snd_t;
|
||||
typedef struct wavinfo_s wavinfo_t;
|
||||
typedef struct channel_s channel_t;
|
||||
typedef struct sfxbuffer_s sfxbuffer_t;
|
||||
|
@ -70,7 +70,7 @@ struct portable_samplepair_s {
|
|||
|
||||
/** communication structure between output drivers and renderer
|
||||
*/
|
||||
struct dma_s {
|
||||
struct snd_s {
|
||||
int speed; //!< sample rate
|
||||
int samplebits; //!< bits per sample
|
||||
int channels; //!< number of output channels
|
||||
|
@ -84,7 +84,8 @@ struct dma_s {
|
|||
\param count The number of sample to transfer.
|
||||
\param volume The gain for the samples.
|
||||
*/
|
||||
void (*xfer) (portable_samplepair_t *paintbuffer, int count,
|
||||
void (*xfer) (struct snd_s *snd,
|
||||
portable_samplepair_t *paintbuffer, int count,
|
||||
float volume);
|
||||
/** Optional data for the xfer function.
|
||||
*/
|
||||
|
@ -229,8 +230,6 @@ extern struct cvar_s *snd_volume;
|
|||
extern struct cvar_s *snd_interp;
|
||||
extern struct cvar_s *snd_stereo_phase_separation;
|
||||
|
||||
extern volatile dma_t *snd_shm;
|
||||
|
||||
extern snd_render_data_t snd_render_data;
|
||||
#define PAINTBUFFER_SIZE 512
|
||||
extern portable_samplepair_t snd_paintbuffer[PAINTBUFFER_SIZE * 2];
|
||||
|
@ -279,16 +278,16 @@ void SND_SFX_StreamClose (sfx_t *sfx);
|
|||
/** Pre-load a sound into the cache.
|
||||
\param sample name of sound to precache
|
||||
*/
|
||||
sfx_t *SND_PrecacheSound (const char *sample);
|
||||
sfx_t *SND_PrecacheSound (snd_t *snd, const char *sample);
|
||||
|
||||
/** Pre-load a sound.
|
||||
\param name name of sound to load
|
||||
*/
|
||||
sfx_t *SND_LoadSound (const char *name);
|
||||
sfx_t *SND_LoadSound (snd_t *snd, const char *name);
|
||||
|
||||
/** Initialize the sfx sub-subsystem
|
||||
*/
|
||||
void SND_SFX_Init (void);
|
||||
void SND_SFX_Init (snd_t *snd);
|
||||
|
||||
///@}
|
||||
|
||||
|
@ -312,29 +311,29 @@ extern int snd_total_channels; //!< number of active channels
|
|||
|
||||
/** Allocate a sound channel that can be used for playing sounds.
|
||||
*/
|
||||
struct channel_s *SND_AllocChannel (void);
|
||||
struct channel_s *SND_AllocChannel (snd_t *snd);
|
||||
|
||||
/** Stop a channel from playing.
|
||||
\param chan the channel to stop
|
||||
*/
|
||||
void SND_ChannelStop (channel_t *chan);
|
||||
void SND_ChannelStop (snd_t *snd, channel_t *chan);
|
||||
|
||||
/** Scan channels looking for stopped channels.
|
||||
\param wait if true, wait for the channels to be done. if false, force the
|
||||
channels to be done. true is for threaded, false for
|
||||
non-threaded.
|
||||
*/
|
||||
void SND_ScanChannels (int wait);
|
||||
void SND_ScanChannels (snd_t *snd, int wait);
|
||||
|
||||
/** Disable ambient sounds.
|
||||
\todo not used, remove?
|
||||
*/
|
||||
void SND_AmbientOff (void);
|
||||
void SND_AmbientOff (snd_t *snd);
|
||||
|
||||
/** Enable ambient sounds.
|
||||
\todo not used, remove?
|
||||
*/
|
||||
void SND_AmbientOn (void);
|
||||
void SND_AmbientOn (snd_t *snd);
|
||||
|
||||
/** Update the sound engine with the client's position and orientation and
|
||||
render some sound.
|
||||
|
@ -345,17 +344,17 @@ void SND_AmbientOn (void);
|
|||
\param ambient_sound_level Pointer to 4 bytes indicating the levels at
|
||||
which to play the ambient sounds.
|
||||
*/
|
||||
void SND_SetListener (const vec3_t origin, const vec3_t v_forward,
|
||||
void SND_SetListener (snd_t *snd, const vec3_t origin, const vec3_t v_forward,
|
||||
const vec3_t v_right, const vec3_t v_up,
|
||||
const byte *ambient_sound_level);
|
||||
|
||||
/** Stop all sounds from playing.
|
||||
*/
|
||||
void SND_StopAllSounds(void);
|
||||
void SND_StopAllSounds (snd_t *snd);
|
||||
|
||||
/** Initialize the channels sub-subsystem
|
||||
*/
|
||||
void SND_Channels_Init (void);
|
||||
void SND_Channels_Init (snd_t *snd);
|
||||
|
||||
/** Start a sound playing.
|
||||
\param entnum index of entity the sound is associated with.
|
||||
|
@ -370,8 +369,8 @@ void SND_Channels_Init (void);
|
|||
\param fvol absolute volume of the sound
|
||||
\param attenuation rate of volume dropoff vs distance
|
||||
*/
|
||||
void SND_StartSound (int entnum, int entchannel, sfx_t *sfx, const vec3_t origin,
|
||||
float fvol, float attenuation);
|
||||
void SND_StartSound (snd_t *snd, int entnum, int entchannel, sfx_t *sfx,
|
||||
const vec3_t origin, float fvol, float attenuation);
|
||||
|
||||
/** Create a sound generated by the world.
|
||||
\param sfx sound to play
|
||||
|
@ -379,18 +378,18 @@ void SND_StartSound (int entnum, int entchannel, sfx_t *sfx, const vec3_t origin
|
|||
\param vol absolute volume of the sound
|
||||
\param attenuation rate of volume dropoff vs distance
|
||||
*/
|
||||
void SND_StaticSound (sfx_t *sfx, const vec3_t origin, float vol,
|
||||
float attenuation);
|
||||
void SND_StaticSound (snd_t *snd, sfx_t *sfx, const vec3_t origin, float vol,
|
||||
float attenuation);
|
||||
/** Stop an entity's sound.
|
||||
\param entnum index of entity the sound is associated with.
|
||||
\param entchannel channel to silence
|
||||
*/
|
||||
void SND_StopSound (int entnum, int entchannel);
|
||||
void SND_StopSound (snd_t *snd, int entnum, int entchannel);
|
||||
|
||||
/** Start a sound local to the client view.
|
||||
\param s name of sound to play
|
||||
*/
|
||||
void SND_LocalSound (const char *s);
|
||||
void SND_LocalSound (snd_t *snd, const char *s);
|
||||
///@}
|
||||
|
||||
|
||||
|
@ -405,11 +404,11 @@ extern unsigned snd_paintedtime;
|
|||
/** Mix all active channels into the output buffer.
|
||||
\param endtime sample time until when to mix
|
||||
*/
|
||||
void SND_PaintChannels(unsigned int endtime);
|
||||
void SND_PaintChannels(snd_t *snd, unsigned int endtime);
|
||||
|
||||
/** Initialize the scale table for painting of 8 bit samples.
|
||||
*/
|
||||
void SND_InitScaletable (void);
|
||||
void SND_InitScaletable (snd_t *snd);
|
||||
|
||||
/** Set the paint function of the sfxbuffer
|
||||
\param sc sfxbuffer to set.
|
||||
|
@ -447,8 +446,8 @@ void SND_Resample (sfxbuffer_t *sc, float *data, int length);
|
|||
\param channels number of channels per frame
|
||||
\param width bytes per channel
|
||||
*/
|
||||
void SND_Convert (byte *idata, float *fdata, int frames, int channels,
|
||||
int width);
|
||||
void SND_Convert (byte *idata, float *fdata, int frames,
|
||||
int channels, int width);
|
||||
///@}
|
||||
|
||||
|
||||
|
@ -492,7 +491,7 @@ int SND_LoadWav (QFile *file, sfx_t *sfx, char *realname);
|
|||
\param realname path of sound file should it need to be re-opened
|
||||
\return 0 if ok, -1 on error
|
||||
*/
|
||||
int SND_LoadMidi (QFile *file, sfx_t *sfx, char *realname);
|
||||
int SND_LoadMidi (snd_t *snd, QFile *file, sfx_t *sfx, char *realname);
|
||||
///@}
|
||||
|
||||
/** \defgroup sound_render_cache_stream Cache/Stream Functions.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue