Go to the documentation of this file.
5 #include "mythconfig.h"
13 #include "libavcodec/avcodec.h"
17 #define LOC QString("AOUtil: ")
19 #define ISALIGN(x) (((unsigned long)(x) & 0xf) == 0)
22 static int has_sse2 = -1;
25 static inline bool sse_check()
28 return (
bool)has_sse2;
38 "and $0x4000000, %%edx \n\t"
48 return (
bool)has_sse2;
102 bool music,
bool upmix)
104 float g = volume / 100.0F;
105 auto *fptr = (
float *)buf;
124 if (sse_check() &&
samples >= 16)
130 "movss %2, %%xmm0 \n\t"
131 "punpckldq %%xmm0, %%xmm0 \n\t"
132 "punpckldq %%xmm0, %%xmm0 \n\t"
134 "movups (%0), %%xmm1 \n\t"
135 "movups 16(%0), %%xmm2 \n\t"
136 "mulps %%xmm0, %%xmm1 \n\t"
137 "movups 32(%0), %%xmm3 \n\t"
138 "mulps %%xmm0, %%xmm2 \n\t"
139 "movups 48(%0), %%xmm4 \n\t"
140 "mulps %%xmm0, %%xmm3 \n\t"
141 "movups %%xmm1, (%0) \n\t"
142 "mulps %%xmm0, %%xmm4 \n\t"
143 "movups %%xmm2, 16(%0) \n\t"
144 "movups %%xmm3, 32(%0) \n\t"
145 "movups %%xmm4, 48(%0) \n\t"
151 :
"xmm0",
"xmm1",
"xmm2",
"xmm3",
"xmm4"
159 template <
class AudioDataType>
160 void tMuteChannel(AudioDataType *buffer,
int channels,
int ch,
int frames)
162 AudioDataType *s1 = buffer + ch;
163 AudioDataType *s2 = buffer - ch + 1;
165 for (
int i = 0; i < frames; i++)
180 void *buffer,
int bytes)
182 int frames =
bytes / ((obits >> 3) * channels);
186 else if (obits == 16)
193 #define LE_SHORT(v) bswap_16(v)
194 #define LE_INT(v) bswap_32(v)
196 #define LE_SHORT(v) (v)
197 #define LE_INT(v) (v)
201 int channel,
int count,
int bits)
207 auto *samp16 = (int16_t*) frames;
208 auto *samp32 = (int32_t*) frames;
212 for(
int chn = 0 ; chn < channels; chn++)
218 static_cast<float>(0x03fffffff);
245 uint8_t *buffer,
int &data_size,
249 bool got_frame =
false;
254 return AVERROR(ENOMEM);
263 int ret = avcodec_receive_frame(ctx,frame);
266 if (ret == AVERROR(EAGAIN))
269 ret = avcodec_send_packet(ctx, pkt);
270 if (ret == AVERROR(EAGAIN))
275 LOG(VB_AUDIO, LOG_ERR,
LOC +
276 QString(
"audio decode error: %1 (%2)")
286 LOG(VB_AUDIO, LOG_DEBUG,
LOC +
287 QString(
"audio decode, no frame decoded (%1)").
arg(ret));
291 auto format = (AVSampleFormat)frame->format;
293 data_size = frame->nb_samples * frame->channels * av_get_bytes_per_sample(format);
295 if (av_sample_fmt_is_planar(format))
298 frame->channels, buffer, (
const uint8_t **)frame->extended_data,
304 memcpy(buffer, frame->extended_data[0], data_size);
315 uint8_t *
output,
const uint8_t *input,
327 uint8_t *
output,
const uint8_t *
const *input,
338 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 void error(const char *str,...)
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...
arg(title).arg(filename).arg(doDelete))
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)
static bool has_hardware_fpu()
Returns true if platform has an FPU.
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 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)