OpenTTD
Data Structures | Functions | Variables
mixer.cpp File Reference

Mixing of sound samples. More...

#include "stdafx.h"
#include <math.h>
#include "core/math_func.hpp"
#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...
 
static void mix_int16 (MixerChannel *sc, int16 *buffer, uint samples)
 
static void mix_int8_to_int16 (MixerChannel *sc, int16 *buffer, uint samples)
 
static void MxCloseChannel (MixerChannel *mc)
 
void MxMixSamples (void *buffer, uint samples)
 
MixerChannelMxAllocateChannel ()
 
void MxSetChannelRawSrc (MixerChannel *mc, int8 *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)
 
bool MxInitialize (uint rate)
 

Variables

static MixerChannel _channels [8]
 
static uint32 _play_rate = 11025
 
static uint32 _max_size = UINT_MAX
 
static const int MAX_VOLUME = 128 * 128
 The theoretical maximum volume for a single sound sample. More...
 

Detailed Description

Mixing of sound samples.

Definition in file mixer.cpp.

Function Documentation

◆ 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 198 of file mixer.cpp.

◆ RateConversion()

template<typename T >
static int RateConversion ( T *  b,
int  frac_pos 
)
static

Perform the rate conversion between the input and output.

Parameters
bthe buffer to read the data from
frac_posthe position from the begin of the buffer till the next element
Template Parameters
Tthe size of the buffer (8 or 16 bits)
Returns
the converted value.

Definition at line 57 of file mixer.cpp.

Variable Documentation

◆ MAX_VOLUME

const int MAX_VOLUME = 128 * 128
static

The theoretical maximum volume for a single sound sample.

Multiple sound samples should not exceed this limit as it will sound too loud. It also stops overflowing when too many sounds are played at the same time, which causes an even worse sound quality.

Definition at line 47 of file mixer.cpp.