forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AudioResampler.cpp
199 lines (166 loc) · 4.75 KB
/
AudioResampler.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
* This file is part of QtAV
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include "QtAV/AudioResampler.h"
#include "QtAV/AudioFormat.h"
#include "QtAV/private/AudioResampler_p.h"
#include "QtAV/private/factory.h"
#include "QtAV/private/mkid.h"
#include "utils/Logger.h"
namespace QtAV {
FACTORY_DEFINE(AudioResampler)
AudioResamplerId AudioResamplerId_FF = mkid::id32base36_6<'F', 'F', 'm', 'p', 'e', 'g'>::value;
AudioResamplerId AudioResamplerId_Libav = mkid::id32base36_5<'L', 'i', 'b', 'a', 'v'>::value;
extern bool RegisterAudioResamplerFF_Man();
extern bool RegisterAudioResamplerLibav_Man();
void AudioResampler::registerAll()
{
static bool done = false;
if (done)
return;
done = true;
#if QTAV_HAVE(SWRESAMPLE)
RegisterAudioResamplerFF_Man();
#endif
#if QTAV_HAVE(AVRESAMPLE)
RegisterAudioResamplerLibav_Man();
#endif
}
AudioResampler::AudioResampler(AudioResamplerPrivate& d):DPTR_INIT(&d)
{
}
AudioResampler::~AudioResampler()
{
}
QByteArray AudioResampler::outData() const
{
return d_func().data_out;
}
bool AudioResampler::prepare()
{
if (!inAudioFormat().isValid()) {
qWarning("src audio parameters 'channel layout(or channels), sample rate and sample format must be set before initialize resampler");
return false;
}
return true;
}
bool AudioResampler::convert(const quint8 **data)
{
Q_UNUSED(data);
return false;
}
void AudioResampler::setSpeed(qreal speed)
{
DPTR_D(AudioResampler);
if (d.speed == speed)
return;
d.speed = speed;
prepare();
}
qreal AudioResampler::speed() const
{
return d_func().speed;
}
void AudioResampler::setInAudioFormat(const AudioFormat& format)
{
DPTR_D(AudioResampler);
if (d.in_format == format)
return;
d.in_format = format;
prepare();
}
AudioFormat& AudioResampler::inAudioFormat()
{
return d_func().in_format;
}
const AudioFormat& AudioResampler::inAudioFormat() const
{
return d_func().in_format;
}
void AudioResampler::setOutAudioFormat(const AudioFormat& format)
{
DPTR_D(AudioResampler);
if (d.out_format == format)
return;
d.out_format = format;
prepare();
}
AudioFormat& AudioResampler::outAudioFormat()
{
return d_func().out_format;
}
const AudioFormat& AudioResampler::outAudioFormat() const
{
return d_func().out_format;
}
void AudioResampler::setInSampesPerChannel(int samples)
{
d_func().in_samples_per_channel = samples;
}
int AudioResampler::outSamplesPerChannel() const
{
return d_func().out_samples_per_channel;
}
//channel count can be computed by av_get_channel_layout_nb_channels(chl)
void AudioResampler::setInSampleRate(int isr)
{
AudioFormat af(d_func().in_format);
af.setSampleRate(isr);
setInAudioFormat(af);
}
void AudioResampler::setOutSampleRate(int osr)
{
AudioFormat af(d_func().out_format);
af.setSampleRate(osr);
setOutAudioFormat(af);
}
void AudioResampler::setInSampleFormat(int isf)
{
AudioFormat af(d_func().in_format);
af.setSampleFormatFFmpeg(isf);
setInAudioFormat(af);
}
void AudioResampler::setOutSampleFormat(int osf)
{
AudioFormat af(d_func().out_format);
af.setSampleFormatFFmpeg(osf);
setOutAudioFormat(af);
}
void AudioResampler::setInChannelLayout(qint64 icl)
{
AudioFormat af(d_func().in_format);
af.setChannelLayoutFFmpeg(icl);
setInAudioFormat(af);
}
void AudioResampler::setOutChannelLayout(qint64 ocl)
{
AudioFormat af(d_func().out_format);
af.setChannelLayoutFFmpeg(ocl);
setOutAudioFormat(af);
}
void AudioResampler::setInChannels(int channels)
{
AudioFormat af(d_func().in_format);
af.setChannels(channels);
setInAudioFormat(af);
}
void AudioResampler::setOutChannels(int channels)
{
AudioFormat af(d_func().out_format);
af.setChannels(channels);
setOutAudioFormat(af);
}
} //namespace QtAV