openMSX
|
#include <SoundDevice.hh>
Classes | |
struct | AmplificationFactors |
Gets this device its 'amplification factor'. More... | |
Public Member Functions | |
SoundDevice (const SoundDevice &)=delete | |
SoundDevice (SoundDevice &&)=delete | |
SoundDevice & | operator= (const SoundDevice &)=delete |
SoundDevice & | operator= (SoundDevice &&)=delete |
const std::string & | getName () const |
Get the unique name that identifies this sound device. | |
std::string_view | getDescription () const |
Gets a description of this sound device, to be presented to the user. | |
unsigned | getNumChannels () const |
How many channels does this device have? | |
bool | hasStereoChannels () const |
Are the individual channels of this device stereo? | |
bool | isStereo () const |
Is the full output of this device stereo? | |
AmplificationFactors | getAmplificationFactor () const |
void | setSoftwareVolume (float volume, EmuTime::param time) |
Change the 'software volume' of this sound device. | |
void | setSoftwareVolume (float left, float right, EmuTime::param time) |
void | recordChannel (unsigned channel, const Filename &filename) |
void | muteChannel (unsigned channel, bool muted) |
std::span< const float > | getLastBuffer (unsigned channel) |
Query the last generated audio signal for a specific channel. | |
float | getNativeSampleRate () const |
The samples returned by 'getLastBuffer()' have this sample rate. | |
unsigned | getLastMonoBufferSize () const |
getLastBuffer() with return buffers containing this many samples. | |
unsigned | getLastBufferSize () const |
virtual void | setOutputRate (unsigned hostSampleRate, double speed)=0 |
When a SoundDevice registers itself with the Mixer, the Mixer sets the required sampleRate through this method. | |
virtual bool | updateBuffer (size_t length, float *buffer, EmuTime::param time)=0 |
Generate sample data. | |
Static Public Attributes | |
static constexpr unsigned | MAX_CHANNELS = 24 |
Protected Member Functions | |
SoundDevice (MSXMixer &mixer, std::string_view name, static_string_view description, unsigned numChannels, unsigned inputRate, bool stereo) | |
Constructor. | |
~SoundDevice () | |
virtual float | getAmplificationFactorImpl () const |
Get amplification/attenuation factor for this device. | |
void | registerSound (const DeviceConfig &config) |
Registers this sound device with the Mixer. | |
void | unregisterSound () |
Unregisters this sound device with the Mixer. | |
void | updateStream (EmuTime::param time) |
void | setInputRate (unsigned sampleRate) |
unsigned | getInputRate () const |
virtual void | generateChannels (std::span< float * > buffers, unsigned num)=0 |
Abstract method to generate the actual sound data. | |
bool | mixChannels (float *dataOut, size_t samples) |
Calls generateChannels() and combines the output to a single channel. | |
const DynamicClock & | getHostSampleClock () const |
See MSXMixer::getHostSampleClock(). | |
double | getEffectiveSpeed () const |
Static Protected Member Functions | |
static void | addFill (float *&buffer, float value, unsigned num) |
Adds a number of samples that all have the same value. | |
Definition at line 19 of file SoundDevice.hh.
|
delete |
|
delete |
|
protected |
Constructor.
mixer | The Mixer object |
name | Name for this device, will be made unique |
description | Description for this sound device |
numChannels | The number of channels for this device |
inputRate | The sample rate of this sound device |
stereo | Is this a stereo device |
Definition at line 47 of file SoundDevice.cc.
References ranges::fill(), MAX_CHANNELS, and setInputRate().
|
protecteddefault |
|
staticprotected |
Adds a number of samples that all have the same value.
Can be used to synthesize segments of a square wave.
buffer | Pointer 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. |
value | Sample value (amplitude). |
num | The number of samples. |
Definition at line 34 of file SoundDevice.cc.
|
protectedpure virtual |
Abstract method to generate the actual sound data.
buffers | An array of pointer to buffers. Each buffer must be big enough to hold 'num' samples. |
num | The 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 mixChannels().
|
inline |
Definition at line 71 of file SoundDevice.hh.
References getAmplificationFactorImpl().
Referenced by mixChannels().
|
protectedvirtual |
Get amplification/attenuation factor for this device.
Normally the outputBuffer() method should scale the output to the range [-1.0..+1.0]. But sometimes it's more convenient to generate 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.0 / 32768.0'.
Reimplemented in openmsx::CassettePlayer.
Definition at line 67 of file SoundDevice.cc.
Referenced by getAmplificationFactor().
|
inline |
Gets a description of this sound device, to be presented to the user.
Definition at line 37 of file SoundDevice.hh.
|
protected |
Definition at line 367 of file SoundDevice.cc.
Referenced by openmsx::ResampledSoundDevice::createResampler().
|
protected |
See MSXMixer::getHostSampleClock().
Definition at line 363 of file SoundDevice.cc.
Referenced by openmsx::ResampledSoundDevice::createResampler(), openmsx::DACSound16S::serialize(), and openmsx::DACSound16S::writeDAC().
|
inlineprotected |
Definition at line 167 of file SoundDevice.hh.
Referenced by openmsx::ResampledSoundDevice::createResampler().
std::span< const float > openmsx::SoundDevice::getLastBuffer | ( | unsigned | channel | ) |
Query the last generated audio signal for a specific channel.
The length of this buffer is fixed (for a specific sound device), see getLastBufferSize(). It's possible that no data is available yet. In that case an empty buffer will be returned. For example this will be the case the first time you call this method. Collecting this data is not free, so by default we don't do it. Requesting this data will automatically start the collecting-process. So, some time later, when you call this method again, there is a good chance that it will succeed. And similarly, if you stop calling this method for some time, we will automatically stop collecting this data. This method is meant to be used by the GUI. There it's acceptable that the first few frames no data is available yet.
Definition at line 174 of file SoundDevice.cc.
References getLastBufferSize().
|
inline |
Definition at line 122 of file SoundDevice.hh.
References getLastMonoBufferSize().
Referenced by getLastBuffer(), and mixChannels().
|
inline |
getLastBuffer() with return buffers containing this many samples.
This number depends on the native-sample-rate of the device. For all devices it will be (approximately) represent the same time duration.
Definition at line 117 of file SoundDevice.hh.
Referenced by getLastBufferSize().
|
inline |
Get the unique name that identifies this sound device.
Used to create setting names.
Definition at line 32 of file SoundDevice.hh.
Referenced by openmsx::MSXMixer::registerSound(), and openmsx::MSXMixer::unregisterSound().
|
inline |
The samples returned by 'getLastBuffer()' have this sample rate.
Definition at line 111 of file SoundDevice.hh.
|
inline |
How many channels does this device have?
Definition at line 41 of file SoundDevice.hh.
|
inline |
Are the individual channels of this device stereo?
Definition at line 45 of file SoundDevice.hh.
Referenced by isStereo().
|
inline |
Is the full output of this device stereo?
Definition at line 51 of file SoundDevice.hh.
References hasStereoChannels().
Referenced by openmsx::ResampledSoundDevice::createResampler(), and mixChannels().
|
protected |
Calls generateChannels() and combines the output to a single channel.
dataOut | Output buffer, must be big enough to hold 'samples' number of samples |
samples | The number of samples |
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 187 of file SoundDevice.cc.
References ranges::any_of(), ranges::fill(), generateChannels(), getAmplificationFactor(), getLastBufferSize(), isStereo(), and xrange().
Referenced by openmsx::ResampledSoundDevice::generateInput().
void openmsx::SoundDevice::muteChannel | ( | unsigned | channel, |
bool | muted | ||
) |
Definition at line 168 of file SoundDevice.cc.
|
delete |
|
delete |
void openmsx::SoundDevice::recordChannel | ( | unsigned | channel, |
const Filename & | filename | ||
) |
Definition at line 140 of file SoundDevice.cc.
References openmsx::Filename::empty().
|
protected |
Registers this sound device with the Mixer.
Call this method when the sound device is ready to start receiving calls to updateBuffer, so after all initialisation is done.
config | Configuration data for this sound device. |
Definition at line 72 of file SoundDevice.cc.
References openmsx::DeviceConfig::getChild(), openmsx::XMLElement::getChildData(), and StringOp::parseRange().
Referenced by openmsx::AY8910::AY8910(), openmsx::CassettePlayer::CassettePlayer(), openmsx::DACSound16S::DACSound16S(), openmsx::LaserdiscPlayer::LaserdiscPlayer(), openmsx::SamplePlayer::SamplePlayer(), openmsx::SCC::SCC(), openmsx::SN76489::SN76489(), openmsx::VLM5030::VLM5030(), openmsx::Y8950::Y8950(), openmsx::YM2151::YM2151(), openmsx::YM2413::YM2413(), openmsx::YMF262::YMF262(), and openmsx::YMF278::YMF278().
|
inlineprotected |
Definition at line 166 of file SoundDevice.hh.
Referenced by SoundDevice().
|
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 openmsx::MSXMixer::registerSound().
void openmsx::SoundDevice::setSoftwareVolume | ( | float | left, |
float | right, | ||
EmuTime::param | time | ||
) |
Definition at line 132 of file SoundDevice.cc.
References updateStream().
void openmsx::SoundDevice::setSoftwareVolume | ( | float | 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 127 of file SoundDevice.cc.
References setSoftwareVolume().
Referenced by openmsx::DACSound8U::DACSound8U(), openmsx::YMF262::setMixLevel(), openmsx::YMF278::setMixLevel(), setSoftwareVolume(), and openmsx::ReproCartridgeV2::setVolume().
|
protected |
Unregisters this sound device with the Mixer.
Call this method before any deallocation is done.
Definition at line 117 of file SoundDevice.cc.
Referenced by openmsx::AY8910::~AY8910(), openmsx::CassettePlayer::~CassettePlayer(), openmsx::DACSound16S::~DACSound16S(), openmsx::LaserdiscPlayer::~LaserdiscPlayer(), openmsx::SamplePlayer::~SamplePlayer(), openmsx::SCC::~SCC(), openmsx::SN76489::~SN76489(), openmsx::VLM5030::~VLM5030(), openmsx::Y8950::~Y8950(), openmsx::YM2151::~YM2151(), openmsx::YM2413::~YM2413(), openmsx::YMF262::~YMF262(), and openmsx::YMF278::~YMF278().
|
pure virtual |
Generate sample data.
length | The number of required samples |
buffer | This buffer should be filled |
time | current time |
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 floats, 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.
|
protected |
Definition at line 122 of file SoundDevice.cc.
Referenced by openmsx::VLM5030::getBSY(), openmsx::YM2413::pokeReg(), openmsx::Y8950::readReg(), openmsx::SN76489::reset(), openmsx::Y8950::reset(), openmsx::YM2413::reset(), openmsx::YMF278::reset(), openmsx::Y8950::setEnabled(), openmsx::LaserdiscPlayer::setMuting(), setSoftwareVolume(), openmsx::VLM5030::writeControl(), openmsx::SCC::writeMem(), openmsx::YM2413::writePort(), openmsx::YM2151::writeReg(), openmsx::YMF278::writeReg(), openmsx::Y8950::writeReg(), openmsx::YMF262::writeReg512(), and openmsx::AY8910::writeRegister().
|
staticconstexpr |
Definition at line 22 of file SoundDevice.hh.
Referenced by SoundDevice().