Revert "- don't let the Timidity++ player directly access the CVARs."

This reverts commit 8f7a503561.

# Conflicts:
#	src/sound/timiditypp/playmidi.cpp

Something in here wasn't working as intended, and since it needs better synchronization let's redo it entirely.
This commit is contained in:
Christoph Oelckers 2018-02-26 09:19:10 +01:00
parent 36e8358763
commit 47dbbeb65a
7 changed files with 31 additions and 79 deletions

View file

@ -101,24 +101,6 @@ CUSTOM_CVAR (Int, timidity_frequency, 44100, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
self = 65000; self = 65000;
} }
// These two need a music restart.
CUSTOM_CVAR(Bool, timidity_surround_chorus, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (currSong != nullptr && currSong->GetDeviceType() == MDEV_TIMIDITY)
{
MIDIDeviceChanged(-1, true);
}
}
CUSTOM_CVAR(Bool, timidity_modulation_envelope, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (currSong != nullptr && currSong->GetDeviceType() == MDEV_TIMIDITY)
{
MIDIDeviceChanged(-1, true);
}
}
//========================================================================== //==========================================================================
// //
// TimidityPPMIDIDevice Constructor // TimidityPPMIDIDevice Constructor

View file

@ -183,27 +183,27 @@ void Effect::effect_left_right_delay(int32_t *buff, int32_t count)
void Effect::do_effect(int32_t *buf, int32_t count) void Effect::do_effect(int32_t *buf, int32_t count)
{ {
int32_t nsamples = count * 2; int32_t nsamples = count * 2;
int reverb_level = (reverb->timidity_reverb < 0) int reverb_level = (timidity_reverb < 0)
? -reverb->timidity_reverb & 0x7f : DEFAULT_REVERB_SEND_LEVEL; ? -timidity_reverb & 0x7f : DEFAULT_REVERB_SEND_LEVEL;
/* for static reverb / chorus level */ /* for static reverb / chorus level */
if (reverb->timidity_reverb == 2 || reverb->timidity_reverb == 4 if (timidity_reverb == 2 || timidity_reverb == 4
|| (reverb->timidity_reverb < 0 && !(reverb->timidity_reverb & 0x80)) || (timidity_reverb < 0 && !(timidity_reverb & 0x80))
|| timidity_chorus < 0) || timidity_chorus < 0)
{ {
reverb->set_dry_signal(buf, nsamples); reverb->set_dry_signal(buf, nsamples);
/* chorus sounds horrible /* chorus sounds horrible
* if applied globally on top of channel chorus * if applied globally on top of channel chorus
*/ */
if (reverb->timidity_reverb == 2 || reverb->timidity_reverb == 4 if (timidity_reverb == 2 || timidity_reverb == 4
|| (reverb->timidity_reverb < 0 && !(reverb->timidity_reverb & 0x80))) || (timidity_reverb < 0 && !(timidity_reverb & 0x80)))
reverb->set_ch_reverb(buf, nsamples, reverb_level); reverb->set_ch_reverb(buf, nsamples, reverb_level);
reverb->mix_dry_signal(buf, nsamples); reverb->mix_dry_signal(buf, nsamples);
/* chorus sounds horrible /* chorus sounds horrible
* if applied globally on top of channel chorus * if applied globally on top of channel chorus
*/ */
if (reverb->timidity_reverb == 2 || reverb->timidity_reverb == 4 if (timidity_reverb == 2 || timidity_reverb == 4
|| (reverb->timidity_reverb < 0 && !(reverb->timidity_reverb & 0x80))) || (timidity_reverb < 0 && !(timidity_reverb & 0x80)))
reverb->do_ch_reverb(buf, nsamples); reverb->do_ch_reverb(buf, nsamples);
} }
/* L/R Delay */ /* L/R Delay */

View file

@ -26,12 +26,9 @@ class Effect
Reverb *reverb; Reverb *reverb;
public: public:
int timidity_chorus; Effect(Reverb *_reverb)
Effect(Reverb *_reverb, int chorus)
{ {
reverb = _reverb; reverb = _reverb;
timidity_chorus = chorus;
init_effect(); init_effect();
} }

View file

@ -52,11 +52,17 @@ CVAR(Bool, timidity_portamento, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
* reverb=4 "global" new reverb 4 * reverb=4 "global" new reverb 4
* reverb=4,n set reverb level to n (-1 to -127) - 384 * reverb=4,n set reverb level to n (-1 to -127) - 384
*/ */
CVAR(Int, timidity_reverb, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) static bool mustinitreverb;
CUSTOM_CVAR(Int, timidity_reverb, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
mustinitreverb = true; // this needs to reallocate some buffers
}
CVAR(Int, timidity_chorus, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Int, timidity_chorus, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, timidity_surround_chorus, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, timidity_channel_pressure, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, timidity_channel_pressure, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Int, timidity_lpf_def, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Int, timidity_lpf_def, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, timidity_temper_control, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, timidity_temper_control, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, timidity_modulation_envelope, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, timidity_overlap_voice_allow, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, timidity_overlap_voice_allow, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, timidity_drum_effect, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, timidity_drum_effect, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, timidity_pan_delay, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, timidity_pan_delay, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
@ -114,6 +120,7 @@ Player::Player(int freq, Instruments *instr)
const int CONTROLS_PER_SECOND = 1000; const int CONTROLS_PER_SECOND = 1000;
const int MAX_CONTROL_RATIO = 255; const int MAX_CONTROL_RATIO = 255;
mustinitreverb = false;
memset(this, 0, sizeof(*this)); memset(this, 0, sizeof(*this));
playback_rate = freq; playback_rate = freq;
@ -131,9 +138,9 @@ Player::Player(int freq, Instruments *instr)
new_midi_file_info(); new_midi_file_info();
init_mblock(&playmidi_pool); init_mblock(&playmidi_pool);
reverb = new Reverb(timidity_reverb); reverb = new Reverb;
reverb->init_effect_status(play_system_mode); reverb->init_effect_status(play_system_mode);
effect = new Effect(reverb, timidity_chorus); effect = new Effect(reverb);
mixer = new Mixer(this); mixer = new Mixer(this);
@ -5015,31 +5022,12 @@ void Player::do_compute_data(int32_t count)
int Player::compute_data(float *buffer, int32_t count) int Player::compute_data(float *buffer, int32_t count)
{ {
if (count == 0) return RC_OK; if (count == 0) return RC_OK;
if (mustinitreverb)
timidity_modulation_wheel = ::timidity_modulation_wheel;
timidity_portamento = ::timidity_portamento;
timidity_chorus = ::timidity_chorus;
timidity_channel_pressure = ::timidity_chorus;
timidity_lpf_def = ::timidity_lpf_def;
timidity_temper_control = ::timidity_temper_control;
timidity_overlap_voice_allow = ::timidity_overlap_voice_allow;
timidity_drum_effect = ::timidity_drum_effect;
timidity_pan_delay = ::timidity_pan_delay;
timidity_drum_power = ::timidity_drum_power;
timidity_key_adjust = ::timidity_key_adjust;
timidity_tempo_adjust = ::timidity_tempo_adjust;
std::atomic_thread_fence(std::memory_order_acq_rel);
effect->timidity_chorus = timidity_chorus;
if (::timidity_reverb != timidity_reverb)
{ {
timidity_reverb = ::timidity_reverb;
std::atomic_thread_fence(std::memory_order_acq_rel);
reverb->timidity_reverb = timidity_reverb;
// If the reverb mode has changed some buffers need to be reallocated before doing any sound generation. // If the reverb mode has changed some buffers need to be reallocated before doing any sound generation.
reverb->free_effect_buffers(); reverb->free_effect_buffers();
reverb->init_reverb(); reverb->init_reverb();
mustinitreverb = false;
} }
buffer_pointer = common_buffer; buffer_pointer = common_buffer;

View file

@ -512,24 +512,6 @@ class Effect;
class Player class Player
{ {
public: public:
bool timidity_modulation_wheel = true;
bool timidity_portamento = true;
int timidity_reverb = 0;
int timidity_chorus = 0;
bool timidity_surround_chorus = false;
bool timidity_channel_pressure = false;
bool timidity_temper_control = true;
bool timidity_modulation_envelope = true;
bool timidity_overlap_voice_allow = true;
bool timidity_drum_effect = false;
bool timidity_pan_delay = false;
int timidity_lpf_def = true;
float timidity_drum_power = 1.0;
int timidity_key_adjust = 0;
float timidity_tempo_adjust = 1;
Channel channel[MAX_CHANNELS]; Channel channel[MAX_CHANNELS];
Voice voice[max_voices]; Voice voice[max_voices];
ChannelBitMask default_drumchannel_mask; ChannelBitMask default_drumchannel_mask;

View file

@ -692,16 +692,13 @@ class Reverb
void do_xg_auto_wah_od(int32_t *buf, int32_t count, EffectList *ef); void do_xg_auto_wah_od(int32_t *buf, int32_t count, EffectList *ef);
public: public:
int timidity_reverb; Reverb()
Reverb(int reverb)
{ {
// Make sure that this starts out with all zeros. // Make sure that this starts out with all zeros.
memset(this, 0, sizeof(*this)); memset(this, 0, sizeof(*this));
REV_INP_LEV = 1.0; REV_INP_LEV = 1.0;
direct_bufsize = sizeof(direct_buffer); direct_bufsize = sizeof(direct_buffer);
reverb_effect_bufsize = sizeof(reverb_effect_buffer); reverb_effect_bufsize = sizeof(reverb_effect_buffer);
timidity_reverb = reverb;
} }

View file

@ -28,7 +28,6 @@
#ifndef TIMIDITY_H_INCLUDED #ifndef TIMIDITY_H_INCLUDED
#define TIMIDITY_H_INCLUDED 1 #define TIMIDITY_H_INCLUDED 1
#include <stdint.h>
#include "c_cvars.h" #include "c_cvars.h"
#include "controls.h" #include "controls.h"
#include "mblock.h" #include "mblock.h"
@ -37,9 +36,16 @@
#pragma warning(disable:4244) // double->float truncation occurs so often in here that it's pointless to fix it all. #pragma warning(disable:4244) // double->float truncation occurs so often in here that it's pointless to fix it all.
#endif #endif
EXTERN_CVAR(Bool, timidity_surround_chorus)
EXTERN_CVAR(Bool, timidity_modulation_envelope)
EXTERN_CVAR(Bool, timidity_modulation_wheel)
EXTERN_CVAR(Bool, timidity_portamento)
EXTERN_CVAR(Int, timidity_reverb)
EXTERN_CVAR(Int, timidity_chorus)
EXTERN_CVAR(Bool, timidity_surround_chorus)
EXTERN_CVAR(Bool, timidity_channel_pressure)
EXTERN_CVAR(Int, timidity_lpf_def)
EXTERN_CVAR(Bool, timidity_temper_control)
EXTERN_CVAR(Bool, timidity_modulation_envelope)
/* /*