openMSX
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members
openmsx::SoundDevice Class Referenceabstract

#include <SoundDevice.hh>

Inheritance diagram for openmsx::SoundDevice:
Inheritance graph
[legend]

Public Types

using VolumeType = FixedPoint< MSXMixer::AMP_BITS >
 

Public Member Functions

const std::string & getName () const
 Get the unique name that identifies this sound device. More...
 
const std::string & getDescription () const
 Gets a description of this sound device, to be presented to the user. More...
 
bool isStereo () const
 Is this a stereo device? This is set in the constructor and cannot be changed anymore. More...
 
std::pair< VolumeType, VolumeTypegetAmplificationFactor () const
 Gets this device its 'amplification factor'. More...
 
void setSoftwareVolume (VolumeType volume, EmuTime::param time)
 Change the 'software volume' of this sound device. More...
 
void setSoftwareVolume (VolumeType left, VolumeType right, EmuTime::param time)
 
void recordChannel (unsigned channel, const Filename &filename)
 
void muteChannel (unsigned channel, bool muted)
 
virtual void setOutputRate (unsigned sampleRate)=0
 When a SoundDevice registers itself with the Mixer, the Mixer sets the required sampleRate through this method. More...
 
virtual bool updateBuffer (unsigned length, int *buffer, EmuTime::param time)=0
 Generate sample data. More...
 

Static Public Attributes

static const unsigned MAX_CHANNELS = 24
 

Protected Member Functions

 SoundDevice (MSXMixer &mixer, string_view name, string_view description, unsigned numChannels, bool stereo=false)
 Constructor. More...
 
 ~SoundDevice ()
 
virtual int getAmplificationFactorImpl () const
 Get extra amplification factor for this device. More...
 
void registerSound (const DeviceConfig &config)
 Registers this sound device with the Mixer. More...
 
void unregisterSound ()
 Unregisters this sound device with the Mixer. More...
 
void updateStream (EmuTime::param time)
 
void setInputRate (unsigned sampleRate)
 
unsigned getInputRate () const
 
virtual void generateChannels (int **buffers, unsigned num)=0
 Abstract method to generate the actual sound data. More...
 
bool mixChannels (int *dataOut, unsigned num)
 Calls generateChannels() and combines the output to a single channel. More...
 
const DynamicClockgetHostSampleClock () const
 See MSXMixer::getHostSampleClock(). More...
 
double getEffectiveSpeed () const
 

Static Protected Member Functions

static void addFill (int *&buffer, int value, unsigned num)
 Adds a number of samples that all have the same value. More...
 

Detailed Description

Definition at line 17 of file SoundDevice.hh.

Member Typedef Documentation

◆ VolumeType

Definition at line 20 of file SoundDevice.hh.

Constructor & Destructor Documentation

◆ SoundDevice()

openmsx::SoundDevice::SoundDevice ( MSXMixer mixer,
string_view  name,
string_view  description,
unsigned  numChannels,
bool  stereo = false 
)
protected

Constructor.

Parameters
mixerThe Mixer object
nameName for this device, will be made unique
descriptionDescription for this sound device
numChannelsThe number of channels for this device
stereoIs this a stereo device

Definition at line 92 of file SoundDevice.cc.

References MAX_CHANNELS, and ~SoundDevice().

Referenced by getAmplificationFactor().

◆ ~SoundDevice()

openmsx::SoundDevice::~SoundDevice ( )
protecteddefault

Member Function Documentation

◆ addFill()

void openmsx::SoundDevice::addFill ( int *&  buffer,
int  value,
unsigned  num 
)
staticprotected

Adds a number of samples that all have the same value.

Can be used to synthesize the high half of a square wave cycle.

Parameters
bufferPointer to the position in a sample buffer where the samples should be added. This pointer is updated to the position right after the written samples.
valueSample value (amplitude).
numThe number of samples.

Definition at line 43 of file SoundDevice.cc.

Referenced by getInputRate(), openmsx::SN76489::write(), and openmsx::AY8910::writeRegister().

◆ generateChannels()

virtual void openmsx::SoundDevice::generateChannels ( int **  buffers,
unsigned  num 
)
protectedpure virtual

Abstract method to generate the actual sound data.

Parameters
buffersAn array of pointer to buffers. Each buffer must be big enough to hold 'num' samples.
numThe number of samples.

This method should fill each buffer with sound data that corresponds to one channel of the sound device. The same channel should each time be written to the same buffer (needed for record).

If a certain channel is muted it is allowed to set the buffer pointer to nullptr. This has exactly the same effect as filling the buffer completely with zeros, but it can be more efficient.

Implemented in openmsx::CassettePlayer, and openmsx::SN76489.

Referenced by getInputRate(), and mixChannels().

◆ getAmplificationFactor()

std::pair<VolumeType, VolumeType> openmsx::SoundDevice::getAmplificationFactor ( ) const
inline

Gets this device its 'amplification factor'.

Each sample generated by the 'updateBuffer' method will get multiplied by this factor during mixing (see MSXMixer).

This factor is the combination of:

  • a fixed per device factor (see getAmplificationFactorImpl()).
  • a MSX software controlled volume setting (e.g. used in Carnivore2 emulation). The influence of the different volume settings is not part of this factor.

Definition at line 50 of file SoundDevice.hh.

References getAmplificationFactorImpl(), muteChannel(), recordChannel(), registerSound(), setSoftwareVolume(), SoundDevice(), unregisterSound(), updateStream(), and ~SoundDevice().

Referenced by mixChannels().

◆ getAmplificationFactorImpl()

int openmsx::SoundDevice::getAmplificationFactorImpl ( ) const
protectedvirtual

Get extra amplification factor for this device.

Normally the outputBuffer() method should scale the output to the range [-32768,32768]. Some devices can be emulated slightly faster to produce another output range. In later stages the output is anyway still multiplied by some factor. This method tells which factor should be used to scale the output to the correct range. The default implementation returns 1.

Definition at line 120 of file SoundDevice.cc.

Referenced by getAmplificationFactor().

◆ getDescription()

const std::string& openmsx::SoundDevice::getDescription ( ) const
inline

Gets a description of this sound device, to be presented to the user.

Definition at line 31 of file SoundDevice.hh.

References isStereo().

Referenced by openmsx::MSXMixer::findDevice().

◆ getEffectiveSpeed()

double openmsx::SoundDevice::getEffectiveSpeed ( ) const
protected

Definition at line 381 of file SoundDevice.cc.

Referenced by openmsx::ResampledSoundDevice::createResampler(), and getInputRate().

◆ getHostSampleClock()

const DynamicClock & openmsx::SoundDevice::getHostSampleClock ( ) const
protected

◆ getInputRate()

unsigned openmsx::SoundDevice::getInputRate ( ) const
inlineprotected

◆ getName()

const std::string& openmsx::SoundDevice::getName ( ) const
inline

Get the unique name that identifies this sound device.

Used to create setting names.

Definition at line 26 of file SoundDevice.hh.

Referenced by openmsx::MSXMixer::registerSound(), and openmsx::MSXMixer::unregisterSound().

◆ isStereo()

bool openmsx::SoundDevice::isStereo ( ) const

Is this a stereo device? This is set in the constructor and cannot be changed anymore.

Definition at line 115 of file SoundDevice.cc.

Referenced by openmsx::ResampledSoundDevice::createResampler(), getDescription(), and mixChannels().

◆ mixChannels()

bool openmsx::SoundDevice::mixChannels ( int *  dataOut,
unsigned  num 
)
protected

Calls generateChannels() and combines the output to a single channel.

Parameters
dataOutOutput buffer, must be big enough to hold 'num' samples
numThe number of samples
Returns
true iff at least one channel was unmuted

Note: To enable various optimizations (like SSE), this method can fill the output buffer with up to 3 extra samples. Those extra samples should be ignored, though the caller must make sure the buffer has enough space to hold them.

Definition at line 223 of file SoundDevice.cc.

References generateChannels(), getAmplificationFactor(), isStereo(), and VLA.

Referenced by openmsx::ResampledSoundDevice::generateInput(), getInputRate(), and openmsx::DACSound16S::writeDAC().

◆ muteChannel()

void openmsx::SoundDevice::muteChannel ( unsigned  channel,
bool  muted 
)

Definition at line 217 of file SoundDevice.cc.

Referenced by getAmplificationFactor().

◆ recordChannel()

void openmsx::SoundDevice::recordChannel ( unsigned  channel,
const Filename filename 
)

Definition at line 189 of file SoundDevice.cc.

References openmsx::Filename::empty().

Referenced by getAmplificationFactor().

◆ registerSound()

void openmsx::SoundDevice::registerSound ( const DeviceConfig config)
protected

◆ setInputRate()

void openmsx::SoundDevice::setInputRate ( unsigned  sampleRate)
inlineprotected

◆ setOutputRate()

virtual void openmsx::SoundDevice::setOutputRate ( unsigned  sampleRate)
pure virtual

When a SoundDevice registers itself with the Mixer, the Mixer sets the required sampleRate through this method.

All sound devices share a common sampleRate.

Implemented in openmsx::ResampledSoundDevice.

Referenced by getInputRate(), and openmsx::MSXMixer::registerSound().

◆ setSoftwareVolume() [1/2]

void openmsx::SoundDevice::setSoftwareVolume ( VolumeType  volume,
EmuTime::param  time 
)

Change the 'software volume' of this sound device.

Some devices like 'Carnivore2' include sound chips (e.g. SCC and fm-pac) and allow the MSX software to configure the volume of those chips. To be clear: these are not the regular per channel volume registers of the SCC/YM2413 sound chips, but another register that controls the total output of those chips.

This method allows to change that per-chip volume.

Definition at line 176 of file SoundDevice.cc.

Referenced by getAmplificationFactor(), openmsx::YMF278::setMixLevel(), openmsx::YMF262::setMixLevel(), and openmsx::Carnivore2::writeMem().

◆ setSoftwareVolume() [2/2]

void openmsx::SoundDevice::setSoftwareVolume ( VolumeType  left,
VolumeType  right,
EmuTime::param  time 
)

Definition at line 181 of file SoundDevice.cc.

References updateStream().

◆ unregisterSound()

void openmsx::SoundDevice::unregisterSound ( )
protected

◆ updateBuffer()

virtual bool openmsx::SoundDevice::updateBuffer ( unsigned  length,
int *  buffer,
EmuTime::param  time 
)
pure virtual

Generate sample data.

Parameters
lengthThe number of required samples
bufferThis buffer should be filled
timecurrent time
Returns
false iff the output is empty. IOW filling the buffer with zeros or returning false has the same effect, but the latter can be more efficient

This method is regularly called from the Mixer, it should return a pointer to a buffer filled with the required number of samples. Samples are always ints, later they are converted to the systems native format (e.g. 16-bit signed).

Note: To enable various optimizations (like SSE), this method can fill the output buffer with up to 3 extra samples. Those extra samples should be ignored, though the caller must make sure the buffer has enough space to hold them.

Implemented in openmsx::ResampledSoundDevice.

Referenced by getInputRate().

◆ updateStream()

void openmsx::SoundDevice::updateStream ( EmuTime::param  time)
protected

Member Data Documentation

◆ MAX_CHANNELS

const unsigned openmsx::SoundDevice::MAX_CHANNELS = 24
static

Definition at line 21 of file SoundDevice.hh.

Referenced by getInputRate(), and SoundDevice().


The documentation for this class was generated from the following files: