Go to the documentation of this file.
16 #include "libavcodec/avcodec.h"
20 #define LOC QString("AOUtil: ")
22 #ifdef Q_PROCESSOR_X86
24 static inline bool sse2_check()
26 #ifdef Q_PROCESSOR_X86_64
29 static int has_sse2 = -1;
31 return (
bool)has_sse2;
37 "and $0x4000000, %%edx \n\t"
43 return (
bool)has_sse2;
46 #endif //Q_PROCESSOR_X86
54 #ifdef Q_PROCESSOR_X86
98 bool music,
bool upmix)
100 float g = volume / 100.0F;
101 auto *fptr = (
float *)buf;
119 #ifdef Q_PROCESSOR_X86
120 if (sse2_check() &&
samples >= 16)
126 "movss %2, %%xmm0 \n\t"
127 "punpckldq %%xmm0, %%xmm0 \n\t"
128 "punpckldq %%xmm0, %%xmm0 \n\t"
130 "movups (%0), %%xmm1 \n\t"
131 "movups 16(%0), %%xmm2 \n\t"
132 "mulps %%xmm0, %%xmm1 \n\t"
133 "movups 32(%0), %%xmm3 \n\t"
134 "mulps %%xmm0, %%xmm2 \n\t"
135 "movups 48(%0), %%xmm4 \n\t"
136 "mulps %%xmm0, %%xmm3 \n\t"
137 "movups %%xmm1, (%0) \n\t"
138 "mulps %%xmm0, %%xmm4 \n\t"
139 "movups %%xmm2, 16(%0) \n\t"
140 "movups %%xmm3, 32(%0) \n\t"
141 "movups %%xmm4, 48(%0) \n\t"
147 :
"xmm0",
"xmm1",
"xmm2",
"xmm3",
"xmm4"
150 #endif //Q_PROCESSOR_X86
155 template <
class AudioDataType>
156 void tMuteChannel(AudioDataType *buffer,
int channels,
int ch,
int frames)
158 AudioDataType *s1 = buffer + ch;
159 AudioDataType *s2 = buffer - ch + 1;
161 for (
int i = 0; i < frames; i++)
176 void *buffer,
int bytes)
178 int frames =
bytes / ((obits >> 3) * channels);
182 else if (obits == 16)
189 int channel,
int count,
int bits)
195 auto *samp16 = (int16_t*) frames;
196 auto *samp32 = (int32_t*) frames;
200 for(
int chn = 0 ; chn < channels; chn++)
206 static_cast<float>(0x03fffffff);
209 *samp16++ = qToLittleEndian<qint16>(ires >> 16);
211 *samp32++ = qToLittleEndian<qint32>(ires);
233 uint8_t *buffer,
int &data_size,
237 bool got_frame =
false;
242 return AVERROR(ENOMEM);
251 int ret = avcodec_receive_frame(ctx,frame);
254 if (ret == AVERROR(EAGAIN))
257 ret = avcodec_send_packet(ctx, pkt);
258 if (ret == AVERROR(EAGAIN))
263 LOG(VB_AUDIO, LOG_ERR,
LOC +
264 QString(
"audio decode error: %1 (%2)")
276 LOG(VB_AUDIO, LOG_DEBUG,
LOC +
277 QString(
"audio decode, no frame decoded (%1)").arg(ret));
281 auto format = (AVSampleFormat)frame->format;
283 data_size = frame->nb_samples * frame->ch_layout.nb_channels * av_get_bytes_per_sample(format);
285 if (av_sample_fmt_is_planar(format))
288 frame->ch_layout.nb_channels, buffer, (
const uint8_t **)frame->extended_data,
294 memcpy(buffer, frame->extended_data[0], data_size);
305 uint8_t *
output,
const uint8_t *input,
317 uint8_t *
output,
const uint8_t *
const *input,
328 uint8_t *
output,
const uint8_t *input,
static int toFloat(AudioFormat format, void *out, const void *in, int bytes)
Convert integer samples to floats.
static AudioFormat AVSampleFormatToFormat(AVSampleFormat format, int bits=0)
Return AVSampleFormat closest equivalent to AudioFormat.
static char * GeneratePinkFrames(char *frames, int channels, int channel, int count, int bits=16)
static int toFloat(AudioFormat format, void *out, const void *in, int bytes)
Convert integer samples to floats.
MythAVFrame little utility class that act as a safe way to allocate an AVFrame which can then be allo...
static int fromFloat(AudioFormat format, void *out, const void *in, int bytes)
Convert float samples to integers.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static void MonoToStereo(void *dst, const void *src, int samples)
Convert a mono stream to stereo by copying and interleaving samples.
static int DecodeAudio(AVCodecContext *ctx, uint8_t *buffer, int &data_size, const AVPacket *pkt)
DecodeAudio Decode an audio packet, and compact it if data is planar Return negative error code if an...
void DeinterleaveSamples(int channels, uint8_t *output, const uint8_t *input, int data_size)
void initialize_pink_noise(pink_noise_t *pink, int num_rows)
static void MonoToStereo(void *dst, const void *src, int samples)
Convert a mono stream to stereo by copying and interleaving samples.
void tMuteChannel(AudioDataType *buffer, int channels, int ch, int frames)
static void InterleaveSamples(AudioFormat format, int channels, uint8_t *output, const uint8_t *const *input, int data_size)
Interleave input samples Planar audio is contained in array of pointers Interleave audio samples (con...
static bool has_optimized_SIMD()
Returns true if the processor supports MythTV's optimized SIMD for AudioOutputUtil/AudioConvert.
static void AdjustVolume(void *buffer, int len, int volume, bool music, bool upmix)
Adjust the volume of samples.
float generate_pink_noise_sample(pink_noise_t *pink)
static void DeinterleaveSamples(AudioFormat format, int channels, uint8_t *output, const uint8_t *input, int data_size)
Deinterleave input samples Deinterleave audio samples and compact them.
void InterleaveSamples(int channels, uint8_t *output, const uint8_t *const *input, int data_size)
static int fromFloat(AudioFormat format, void *out, const void *in, int bytes)
Convert float samples to integers.
static const std::array< const uint64_t, 4 > samples
static void MuteChannel(int obits, int channels, int ch, void *buffer, int bytes)
Mute individual channels through mono->stereo duplication.
char * av_make_error_stdstring(std::string &errbuf, int errnum)
A C++ equivalent to av_make_error_string.