OpenTTD Source 20241224-master-gf74b0cf984
mixer.h File Reference

Functions to mix sound samples. More...

Go to the source code of this file.

Typedefs

typedef void(* MxStreamCallback) (int16_t *buffer, size_t samples)
 Type of callback functions for supplying PCM music.
 

Functions

bool MxInitialize (uint rate)
 
void MxMixSamples (void *buffer, uint samples)
 
MixerChannelMxAllocateChannel ()
 
void MxSetChannelRawSrc (MixerChannel *mc, const std::shared_ptr< std::vector< uint8_t > > &mem, uint rate, bool is16bit)
 
void MxSetChannelVolume (MixerChannel *mc, uint volume, float pan)
 Set volume and pan parameters for a sound.
 
void MxActivateChannel (MixerChannel *)
 
void MxCloseAllChannels ()
 Close all mixer channels.
 
uint32_t MxSetMusicSource (MxStreamCallback music_callback)
 Set source of PCM music.
 
void SetEffectVolume (uint8_t volume)
 

Detailed Description

Functions to mix sound samples.

Definition in file mixer.h.

Typedef Documentation

◆ MxStreamCallback

typedef void(* MxStreamCallback) (int16_t *buffer, size_t samples)

Type of callback functions for supplying PCM music.

A music decoder/renderer implements this function and installs it with MxSetMusicSource, which also returns the sample rate used.

Parameters
bufferPointer to interleaved 2-channel signed 16 bit PCM data buffer, guaranteed to be 0-initialized.
samplesnumber of samples that must be filled into buffer.

Definition at line 21 of file mixer.h.

Function Documentation

◆ MxActivateChannel()

void MxActivateChannel ( MixerChannel mc)

Definition at line 222 of file mixer.cpp.

◆ MxAllocateChannel()

MixerChannel * MxAllocateChannel ( )

Definition at line 170 of file mixer.cpp.

◆ MxCloseAllChannels()

void MxCloseAllChannels ( )

Close all mixer channels.

This signals to the mixer that each channel should be closed even if it has not played all remaining samples. This is safe (and designed) to be called from the main thread.

Definition at line 119 of file mixer.cpp.

Referenced by ChangeSoundSet().

◆ MxInitialize()

bool MxInitialize ( uint  rate)

Definition at line 242 of file mixer.cpp.

◆ MxMixSamples()

void MxMixSamples ( void *  buffer,
uint  samples 
)

Definition at line 124 of file mixer.cpp.

◆ MxSetChannelRawSrc()

void MxSetChannelRawSrc ( MixerChannel mc,
const std::shared_ptr< std::vector< uint8_t > > &  mem,
uint  rate,
bool  is16bit 
)

Definition at line 183 of file mixer.cpp.

◆ MxSetChannelVolume()

void MxSetChannelVolume ( MixerChannel mc,
uint  volume,
float  pan 
)

Set volume and pan parameters for a sound.

Parameters
mcMixerChannel to set
volumeVolume level for sound, range is 0..16384
panPan position for sound, range is 0..1

Definition at line 213 of file mixer.cpp.

◆ MxSetMusicSource()

uint32_t MxSetMusicSource ( MxStreamCallback  music_callback)

Set source of PCM music.

Parameters
music_callbackFunction that will be called to fill sample buffers with music data.
Returns
Sample rate of mixer, which the buffers supplied to the callback must be rendered at.

Definition at line 234 of file mixer.cpp.

References lock.

Referenced by MusicDriver_FluidSynth::Start(), and MusicDriver_FluidSynth::Stop().

◆ SetEffectVolume()

void SetEffectVolume ( uint8_t  volume)

Definition at line 251 of file mixer.cpp.