qt can play the blips just fine

This commit is contained in:
stonedDiscord 2019-03-12 19:53:06 +01:00
parent 6e93d6e1be
commit 0b6f376f8f
2 changed files with 106 additions and 6 deletions

View File

@ -1,13 +1,19 @@
#ifndef AOBLIPPLAYER_H #ifndef AOBLIPPLAYER_H
#define AOBLIPPLAYER_H #define AOBLIPPLAYER_H
#if defined(BASSAUDIO)
#include "bass.h" #include "bass.h"
#elif defined(QTAUDIO)
#include <QSoundEffect>
#endif
#include "aoapplication.h" #include "aoapplication.h"
#include <QWidget> #include <QWidget>
#include <string.h> #include <string.h>
#include <QDebug> #include <QDebug>
#if defined(BASSAUDIO)
class AOBlipPlayer class AOBlipPlayer
{ {
public: public:
@ -26,5 +32,41 @@ private:
int m_volume; int m_volume;
HSTREAM m_stream_list[5]; HSTREAM m_stream_list[5];
}; };
#elif defined(QTAUDIO)
class AOBlipPlayer
{
public:
AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app);
void set_blips(QString p_sfx);
void blip_tick();
void set_volume(int p_volume);
int m_cycle = 0;
private:
QSoundEffect m_blips;
QWidget *m_parent;
AOApplication *ao_app;
int m_volume;
//HSTREAM m_stream_list[5];
};
#else
class AOBlipPlayer
{
public:
AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app);
void set_blips(QString p_sfx);
void blip_tick();
void set_volume(int p_volume);
private:
QWidget *m_parent;
AOApplication *ao_app;
};
#endif
#endif // AOBLIPPLAYER_H #endif // AOBLIPPLAYER_H

View File

@ -1,5 +1,6 @@
#include "aoblipplayer.h" #include "aoblipplayer.h"
#if defined(BASSAUDIO) //Using bass.dll for the blips
AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app)
{ {
m_parent = parent; m_parent = parent;
@ -12,11 +13,9 @@ void AOBlipPlayer::set_blips(QString p_sfx)
for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) for (int n_stream = 0 ; n_stream < 5 ; ++n_stream)
{ {
#ifdef BASSAUDIO
BASS_StreamFree(m_stream_list[n_stream]); BASS_StreamFree(m_stream_list[n_stream]);
m_stream_list[n_stream] = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE); m_stream_list[n_stream] = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE);
#endif
} }
set_volume(m_volume); set_volume(m_volume);
@ -30,11 +29,9 @@ void AOBlipPlayer::blip_tick()
m_cycle = 0; m_cycle = 0;
HSTREAM f_stream = m_stream_list[f_cycle]; HSTREAM f_stream = m_stream_list[f_cycle];
#ifdef BASSAUDIO
if (ao_app->get_audio_output_device() != "default") if (ao_app->get_audio_output_device() != "default")
BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); BASS_ChannelSetDevice(f_stream, BASS_GetDevice());
BASS_ChannelPlay(f_stream, false); BASS_ChannelPlay(f_stream, false);
#endif
} }
void AOBlipPlayer::set_volume(int p_value) void AOBlipPlayer::set_volume(int p_value)
@ -45,8 +42,69 @@ void AOBlipPlayer::set_volume(int p_value)
for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) for (int n_stream = 0 ; n_stream < 5 ; ++n_stream)
{ {
#ifdef BASSAUDIO
BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume); BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume);
#endif
} }
} }
#elif defined(QTAUDIO) //Using Qt's QSoundEffect class
AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app)
{
m_parent = parent;
ao_app = p_ao_app;
}
void AOBlipPlayer::set_blips(QString p_sfx)
{
QString f_path = ao_app->get_sounds_path(p_sfx);
for (int n_stream = 0 ; n_stream < 5 ; ++n_stream)
{
m_blips.setSource(QUrl::fromLocalFile(f_path));
}
set_volume(m_volume);
}
void AOBlipPlayer::blip_tick()
{
int f_cycle = m_cycle++;
if (m_cycle == 5)
m_cycle = 0;
//HSTREAM f_stream = m_stream_list[f_cycle];
//if (ao_app->get_audio_output_device() != "default")
//BASS_ChannelSetDevice(f_stream, BASS_GetDevice());
//BASS_ChannelPlay(f_stream, false);
m_blips.play();
}
void AOBlipPlayer::set_volume(int p_value)
{
m_volume = p_value;
float volume = p_value / 100.0f;
m_blips.setVolume(volume);
}
#else //No audio
AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app)
{
m_parent = parent;
ao_app = p_ao_app;
}
void AOBlipPlayer::set_blips(QString p_sfx)
{
}
void AOBlipPlayer::blip_tick()
{
}
void AOBlipPlayer::set_volume(int p_value)
{
}
#endif