-
Notifications
You must be signed in to change notification settings - Fork 2
/
audioformat.cpp
87 lines (70 loc) · 1.65 KB
/
audioformat.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "audioformat.h"
#include <QString>
AudioFormat::AudioFormat()
{
this->codec = "audio/pcm";
}
void AudioFormat::setChannelCount(const int channels)
{
this->channelsCount = channels;
}
void AudioFormat::setSampleRate(const int sampleRate)
{
this->sampleRate = sampleRate;
}
void AudioFormat::setSampleSize(const int sampleSize)
{
this->sampleSize = sampleSize;
}
int AudioFormat::getChannelsCount()
{
return channelsCount;
}
int AudioFormat::getSampleRate()
{
return sampleRate;
}
int AudioFormat::getSampleSize()
{
return sampleSize;
}
quint64 AudioFormat::getBitrate()
{
return sampleRate * sampleSize * channelsCount / 8;
}
void AudioFormat::setCodec(const QString codec)
{
this->codec = codec;
}
bool AudioFormat::isValid()
{
return true;
}
QString AudioFormat::getCodec()
{
return codec;
}
quint64 AudioFormat::getBytesSizeForDuration(const int msecs)
{
if (msecs <= 0) return 0;
return this->getBitrate() / 1000 * msecs;
}
const QString AudioFormat::getFormatTextInfo()
{
return QString("samplesize:" + QString::number(sampleSize) + " samplerate:" + QString::number(sampleRate) + " channels:" + QString::number(channelsCount));
}
bool AudioFormat::setFormat(AudioFormat *format)
{
if (!format) return false;
sampleRate = format->getSampleRate();
sampleSize = format->getSampleSize();
codec = format->getCodec();
channelsCount = format->getChannelsCount();
return true;
}
QList<int> AudioFormat::getCommonSamplesRates()
{
QList<int> rates;
rates << 8000 << 11025 << 16000 << 22050 << 32000 << 44100 << 48000 << 96000 << 88200 << 176400 << 192000 << 384000;
return rates;
}