mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Refactor uses of playMono16Sound
This commit is contained in:
parent
aac5fb87e6
commit
9163b73032
@ -35,6 +35,7 @@
|
||||
#include <QTimer>
|
||||
#include <QThread>
|
||||
#include <QMutexLocker>
|
||||
#include <QFile>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@ -364,6 +365,16 @@ void Audio::playMono16Sound(const QByteArray& data)
|
||||
alDeleteBuffers(1, &buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
Play a 44100Hz mono 16bit PCM sound from a file
|
||||
*/
|
||||
void Audio::playMono16Sound(const char *path)
|
||||
{
|
||||
QFile sndFile(path);
|
||||
sndFile.open(QIODevice::ReadOnly);
|
||||
playMono16Sound(sndFile.readAll());
|
||||
}
|
||||
|
||||
/**
|
||||
@brief May be called from any thread, will always queue a call to playGroupAudio.
|
||||
|
||||
|
@ -78,6 +78,7 @@ public:
|
||||
void startLoop();
|
||||
void stopLoop();
|
||||
void playMono16Sound(const QByteArray& data);
|
||||
void playMono16Sound(const char* path);
|
||||
bool tryCaptureSamples(int16_t *buf, int samples);
|
||||
|
||||
static void playAudioBuffer(ALuint alSource, const int16_t *data, int samples, unsigned channels, int sampleRate);
|
||||
|
@ -193,7 +193,6 @@ void Nexus::showMainGUI()
|
||||
|
||||
// Connections
|
||||
Core* core = profile->getCore();
|
||||
CoreAV* coreav = core->getAv();
|
||||
#ifdef Q_OS_ANDROID
|
||||
connect(core, &Core::connected, androidgui, &AndroidGUI::onConnected);
|
||||
connect(core, &Core::disconnected, androidgui, &AndroidGUI::onDisconnected);
|
||||
@ -232,7 +231,6 @@ void Nexus::showMainGUI()
|
||||
connect(core, &Core::groupTitleChanged, widget, &Widget::onGroupTitleChanged);
|
||||
connect(core, &Core::groupPeerAudioPlaying, widget, &Widget::onGroupPeerAudioPlaying);
|
||||
connect(core, &Core::emptyGroupCreated, widget, &Widget::onEmptyGroupCreated);
|
||||
connect(coreav, &CoreAV::avInvite, widget, &Widget::playRingtone);
|
||||
connect(core, &Core::friendTypingChanged, widget, &Widget::onFriendTypingChanged);
|
||||
|
||||
connect(core, &Core::messageSentResult, widget, &Widget::onMessageSendResult);
|
||||
|
@ -291,20 +291,9 @@ void ChatForm::onAvInvite(uint32_t FriendId, bool video)
|
||||
QDateTime::currentDateTime()));
|
||||
|
||||
Widget::getInstance()->newFriendMessageAlert(FriendId, false);
|
||||
|
||||
static QFile sndFile(":audio/ToxicIncomingCall.pcm");
|
||||
static QByteArray sndData;
|
||||
|
||||
if (sndData.isEmpty())
|
||||
{
|
||||
sndFile.open(QIODevice::ReadOnly);
|
||||
sndData = sndFile.readAll();
|
||||
sndFile.close();
|
||||
}
|
||||
|
||||
Audio& audio = Audio::getInstance();
|
||||
audio.startLoop();
|
||||
audio.playMono16Sound(sndData);
|
||||
audio.playMono16Sound(":audio/ToxicIncomingCall.pcm");
|
||||
}
|
||||
|
||||
void ChatForm::onAvStart(uint32_t FriendId, bool video)
|
||||
|
@ -1236,42 +1236,12 @@ bool Widget::newMessageAlert(QWidget* currentWindow, bool isActive, bool sound,
|
||||
}
|
||||
|
||||
if (Settings::getInstance().getNotifySound() && sound)
|
||||
{
|
||||
static QFile sndFile(":audio/notification.pcm");
|
||||
static QByteArray sndData;
|
||||
|
||||
if (sndData.isEmpty())
|
||||
{
|
||||
sndFile.open(QIODevice::ReadOnly);
|
||||
sndData = sndFile.readAll();
|
||||
sndFile.close();
|
||||
}
|
||||
|
||||
Audio::getInstance().playMono16Sound(sndData);
|
||||
}
|
||||
Audio::getInstance().playMono16Sound(":audio/notification.pcm");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Widget::playRingtone()
|
||||
{
|
||||
if (ui->statusButton->property("status").toString() == "busy")
|
||||
return;
|
||||
|
||||
// for whatever reason this plays slower/downshifted from what any other program plays the file as... but whatever
|
||||
static QFile sndFile1(":audio/ToxicIncomingCall.pcm");
|
||||
static QByteArray sndData1;
|
||||
if (sndData1.isEmpty())
|
||||
{
|
||||
sndFile1.open(QIODevice::ReadOnly);
|
||||
sndData1 = sndFile1.readAll();
|
||||
sndFile1.close();
|
||||
}
|
||||
|
||||
Audio::getInstance().playMono16Sound(sndData1);
|
||||
}
|
||||
|
||||
void Widget::onFriendRequestReceived(const QString& userId, const QString& message)
|
||||
{
|
||||
FriendRequestDialog dialog(this, userId, message);
|
||||
|
@ -134,7 +134,6 @@ public slots:
|
||||
void onGroupTitleChanged(int groupnumber, const QString& author, const QString& title);
|
||||
void onGroupPeerAudioPlaying(int groupnumber, int peernumber);
|
||||
void onGroupSendResult(int groupId, const QString& message, int result);
|
||||
void playRingtone();
|
||||
void onFriendTypingChanged(int friendId, bool isTyping);
|
||||
void nextContact();
|
||||
void previousContact();
|
||||
|
Loading…
x
Reference in New Issue
Block a user