OpenTTD Source
20241108-master-g80f628063a
|
Mixing of sound samples. More...
#include "stdafx.h"
#include <mutex>
#include <atomic>
#include "core/math_func.hpp"
#include "framerate_type.h"
#include "mixer.h"
#include "settings_type.h"
#include "safeguards.h"
Go to the source code of this file.
Data Structures | |
struct | MixerChannel |
Functions | |
template<typename T > | |
static int | RateConversion (T *b, int frac_pos) |
Perform the rate conversion between the input and output. More... | |
template<typename T > | |
static void | mix_int16 (MixerChannel *sc, int16_t *buffer, uint samples, uint8_t effect_vol) |
static void | MxCloseChannel (uint8_t channel_index) |
void | MxCloseAllChannels () |
Close all mixer channels. More... | |
void | MxMixSamples (void *buffer, uint samples) |
MixerChannel * | MxAllocateChannel () |
void | MxSetChannelRawSrc (MixerChannel *mc, int8_t *mem, size_t size, uint rate, bool is16bit) |
void | MxSetChannelVolume (MixerChannel *mc, uint volume, float pan) |
Set volume and pan parameters for a sound. More... | |
void | MxActivateChannel (MixerChannel *mc) |
uint32_t | MxSetMusicSource (MxStreamCallback music_callback) |
Set source of PCM music. More... | |
bool | MxInitialize (uint rate) |
void | SetEffectVolume (uint8_t volume) |
Variables | |
static std::atomic< uint8_t > | _active_channels |
static std::atomic< uint8_t > | _stop_channels |
static MixerChannel | _channels [8] |
static uint32_t | _play_rate = 11025 |
static uint32_t | _max_size = UINT_MAX |
static MxStreamCallback | _music_stream = nullptr |
static std::mutex | _music_stream_mutex |
static std::atomic< uint8_t > | _effect_vol |
static const int | MAX_VOLUME = 32767 |
The theoretical maximum volume for a single sound sample. More... | |
Mixing of sound samples.
Definition in file mixer.cpp.
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 117 of file mixer.cpp.
Referenced by ChangeSoundSet().
void MxSetChannelVolume | ( | MixerChannel * | mc, |
uint | volume, | ||
float | pan | ||
) |
Set volume and pan parameters for a sound.
mc | MixerChannel to set |
volume | Volume level for sound, range is 0..16384 |
pan | Pan position for sound, range is 0..1 |
uint32_t MxSetMusicSource | ( | MxStreamCallback | music_callback | ) |
Set source of PCM music.
music_callback | Function that will be called to fill sample buffers with music data. |
Definition at line 229 of file mixer.cpp.
References lock.
Referenced by MusicDriver_FluidSynth::Start(), and MusicDriver_FluidSynth::Stop().
|
static |
Perform the rate conversion between the input and output.
b | the buffer to read the data from |
frac_pos | the position from the begin of the buffer till the next element |
T | the size of the buffer (8 or 16 bits) |
|
static |