Looping SFX system - Defined this way:

[SoundL]
sfx-roar = 1
This commit is contained in:
Crystalwarrior 2019-09-15 17:44:47 +03:00
parent a2f9df4042
commit e94640b349
6 changed files with 97 additions and 14 deletions

View File

@ -151,6 +151,9 @@ public:
//Returns true if blank blips is enabled in config.ini and false otherwise
bool get_blank_blip();
//Returns true if looping sound effects are enabled in the config.ini
bool get_looping_sfx();
//Returns true if stop music on objection is enabled in the config.ini
bool objection_stop_music();

View File

@ -18,19 +18,24 @@ class AOSfxPlayer
public:
AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app);
void play(QString p_sfx, QString p_char = "", QString shout = "");
void stop();
void clear();
void loop_clear();
void play(QString p_sfx, QString p_char = "", QString shout = "", int channel=-1);
void stop(int channel=-1);
void set_volume(qreal p_volume);
void set_looping(bool toggle, int channel=-1);
int m_channel = 0;
private:
QWidget *m_parent;
AOApplication *ao_app;
qreal m_volume = 0;
bool m_looping = true;
void set_volume_internal(qreal p_volume);
#if defined(BASSAUDIO)
HSTREAM m_stream;
const int m_channelmax = 5;
HSTREAM m_stream_list[5];
#elif defined(QTAUDIO)
QSoundEffect m_sfx;
#endif

View File

@ -67,26 +67,34 @@ void AOCharMovie::load_image(QString p_char, QString p_emote, QString emote_pref
movie_effects.resize(max_frames);
for (int e_frame = 0; e_frame < max_frames; ++e_frame)
{
#ifdef DEBUG_CHARMOVIE
qDebug() << p_char << p_emote << e_frame;
#endif
QString effect = ao_app->get_screenshake_frame(p_char, emote_prefix + p_emote, e_frame);
if (effect != "")
{
movie_effects[e_frame].append("shake");
#ifdef DEBUG_CHARMOVIE
qDebug() << e_frame << "shake";
#endif
}
effect = ao_app->get_flash_frame(p_char, emote_prefix + p_emote, e_frame);
if (effect != "")
{
movie_effects[e_frame].append("flash");
#ifdef DEBUG_CHARMOVIE
qDebug() << e_frame << "flash";
#endif
}
effect = ao_app->get_sfx_frame(p_char, emote_prefix + p_emote, e_frame);
if (effect != "")
{
movie_effects[e_frame].append("sfx^"+effect);
#ifdef DEBUG_CHARMOVIE
qDebug() << e_frame << effect;
#endif
}
}
#ifdef DEBUG_CHARMOVIE
@ -138,20 +146,26 @@ void AOCharMovie::play_frame_effect(int frame)
if(effect == "shake")
{
shake();
#ifdef DEBUG_CHARMOVIE
qDebug() << "Attempting to play shake on frame" << frame;
#endif
}
if(effect == "flash")
{
flash();
#ifdef DEBUG_CHARMOVIE
qDebug() << "Attempting to play flash on frame" << frame;
#endif
}
if(effect.startsWith("sfx^"))
{
QString sfx = effect.section("^", 1);
play_sfx(sfx);
#ifdef DEBUG_CHARMOVIE
qDebug() << "Attempting to play sfx" << sfx << "on frame" << frame;
#endif
}
}
}

View File

@ -8,9 +8,35 @@ AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app)
ao_app = p_ao_app;
}
void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout)
void AOSfxPlayer::clear()
{
BASS_ChannelStop(m_stream);
for (int n_stream = 0 ; n_stream < m_channelmax ; ++n_stream)
{
BASS_ChannelStop(m_stream_list[n_stream]);
}
set_volume_internal(m_volume);
}
void AOSfxPlayer::loop_clear()
{
for (int n_stream = 0 ; n_stream < m_channelmax ; ++n_stream)
{
if((BASS_ChannelFlags(m_stream_list[n_stream], 0, 0)&BASS_SAMPLE_LOOP))
BASS_ChannelStop(m_stream_list[n_stream]);
}
set_volume_internal(m_volume);
}
void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout, int channel)
{
if (channel == -1)
{
if (m_stream_list[channel] != NULL)
m_channel = (m_channel + 1) % m_channelmax;
channel = m_channel;
}
BASS_ChannelStop(m_stream_list[channel]);
QString misc_path = "";
QString char_path = "";
@ -30,18 +56,22 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout)
else
f_path = sound_path;
m_stream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE);
m_stream_list[channel] = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE);
set_volume_internal(m_volume);
if (ao_app->get_audio_output_device() != "default")
BASS_ChannelSetDevice(m_stream, BASS_GetDevice());
BASS_ChannelPlay(m_stream, false);
BASS_ChannelSetDevice(m_stream_list[m_channel], BASS_GetDevice());
BASS_ChannelPlay(m_stream_list[m_channel], false);
}
void AOSfxPlayer::stop()
void AOSfxPlayer::stop(int channel)
{
BASS_ChannelStop(m_stream);
if (channel == -1)
{
channel = m_channel;
}
BASS_ChannelStop(m_stream_list[channel]);
}
void AOSfxPlayer::set_volume(qreal p_value)
@ -52,8 +82,30 @@ void AOSfxPlayer::set_volume(qreal p_value)
void AOSfxPlayer::set_volume_internal(qreal p_value)
{
float volume = p_value;
BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume);
float volume = static_cast<float>(p_value);
for (int n_stream = 0 ; n_stream < m_channelmax ; ++n_stream)
{
BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume);
}
}
void AOSfxPlayer::set_looping(bool toggle, int channel)
{
if (channel == -1)
{
channel = m_channel;
}
m_looping = toggle;
if (BASS_ChannelFlags(m_stream_list[channel], 0, 0) & BASS_SAMPLE_LOOP)
{
if (m_looping == false)
BASS_ChannelFlags(m_stream_list[channel], 0, BASS_SAMPLE_LOOP); // remove the LOOP flag
}
else
{
if (m_looping == true)
BASS_ChannelFlags(m_stream_list[channel], BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set the LOOP flag
}
}
#elif defined(QTAUDIO) //Using Qt's QSoundEffect class
AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app)

View File

@ -1425,7 +1425,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
default:
qDebug() << "W: Logic error in objection switch statement!";
}
sfx_player->clear(); //Objection played! Cut all sfx.
int emote_mod = m_chatmessage[EMOTE_MOD].toInt();
if (emote_mod == 0)
@ -1444,6 +1444,8 @@ void Courtroom::handle_chatmessage_2()
{
ui_vp_speedlines->stop();
ui_vp_player_char->stop();
//Clear all looping sfx to prevent obnoxiousness
sfx_player->loop_clear();
if (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked())
{
@ -2470,6 +2472,7 @@ void Courtroom::play_sfx()
return;
sfx_player->play(ao_app->get_sfx_suffix(sfx_name));
sfx_player->set_looping(ao_app->get_sfx_looping(current_char, sfx_name)!="0");
}
void Courtroom::set_scene()

View File

@ -638,6 +638,12 @@ bool AOApplication::get_blank_blip()
return result.startsWith("true");
}
bool AOApplication::get_looping_sfx()
{
QString result = configini->value("looping_sfx", "true").value<QString>();
return result.startsWith("true");
}
bool AOApplication::objection_stop_music()
{
QString result = configini->value("objection_stop_music", "false").value<QString>();