-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoundplayer.cpp
49 lines (42 loc) · 1.59 KB
/
soundplayer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "soundplayer.h"
#include <QDebug>
#include <QTextCodec>
#include <QFile>
#include "settingsdialog.h"
SoundPlayer::SoundPlayer(QString path, QObject *parent) :
QThread(parent),
path(path)
{
qDebug() << "SoundPlayer: init" << LOG_DATA;
this->device = SettingsDialog::getInstance()->getOutputDevice();
if (!this->device) return;
qDebug() << "SoundPlayer: init output device " << QString::fromLocal8Bit(this->device->name) << LOG_DATA;
initAudioOutputDevice(this->device);
if(!isAudioOk){
qDebug() << "SoundPlayer: FAIL init output device " << QString::fromLocal8Bit(this->device->name) << LOG_DATA;
return;
}
qDebug() << "SoundPlayer: open wav file " << path << LOG_DATA;
QFile file(path);
file.open(QIODevice::ReadOnly);
this->waveFile = waveOpenHFile(file.handle());
}
SoundPlayer::~SoundPlayer()
{
qDebug() << "~SoundPlayer" << LOG_DATA;
freeAudioOutputDevice(this->device);
waveCloseFile(waveFile);
}
void SoundPlayer::run()
{
qDebug() << "SoundPlayer: run" << LOG_DATA;
playSound(
this->device,
this->waveFile->dataChunk->waveformData,
littleEndianBytesToUInt32(this->waveFile->dataChunk->chunkDataSize),
littleEndianBytesToUInt16(this->waveFile->formatChunk->numberOfChannels),
littleEndianBytesToUInt16(this->waveFile->formatChunk->significantBitsPerSample),
littleEndianBytesToUInt32(this->waveFile->formatChunk->sampleRate));
emit finished();
this->deleteLater();
}