37 #define DST_MAX_CHANNELS 6
38 #define DST_MAX_ELEMENTS (2 * DST_MAX_CHANNELS)
40 #define DSD_FS44(sample_rate) (sample_rate * 8 / 44100)
42 #define DST_SAMPLES_PER_FRAME(sample_rate) (588 * DSD_FS44(sample_rate))
90 for (i = 0; i < avctx->
channels; i++)
116 memset(
map, 0,
sizeof(*
map) * DST_MAX_CHANNELS);
130 int coeff_bits,
int is_signed,
int offset)
135 dst[i] = (is_signed ?
get_sbits(gb, coeff_bits) :
get_bits(gb, coeff_bits)) + offset;
140 int length_bits,
int coeff_bits,
int is_signed,
int offset)
142 unsigned int i, j, k;
148 int method =
get_bits(gb, 2), lsb_size;
155 for (j = method + 1; j < t->
length[i]; j++) {
157 for (k = 0; k < method + 1; k++)
158 x += code_pred_coeff[method][k] * t->
coeff[i][j - k - 1];
179 unsigned int k = (ac->
a >> 8) | ((ac->
a >> 7) & 1);
180 unsigned int q = k * p;
181 unsigned int a_q = ac->
a - q;
207 for (i = 0; i < fsets->
elements; i++) {
210 for (j = 0; j < 16; j++) {
211 int total = av_clip(length - j * 8, 0, 8);
213 for (k = 0; k < 256; k++) {
216 for (l = 0; l < total; l++)
217 v += (((k >> l) & 1) * 2 - 1) * fsets->
coeff[i][j * 8 + l];
225 int *got_frame_ptr,
AVPacket *avpkt)
230 unsigned i,
ch, same_map, dst_x_bit;
241 if (avpkt->
size <= 1)
247 dsd = frame->
data[0];
248 pcm = (
float *)frame->
data[0];
287 memcpy(map_ch_to_pelem, map_ch_to_felem,
sizeof(map_ch_to_felem));
296 for (ch = 0; ch < avctx->
channels; ch++)
320 for (i = 0; i < samples_per_frame; i++) {
322 const unsigned felem = map_ch_to_felem[
ch];
327 #define F(x) filter[(x)][status[(x)]]
328 const int16_t
predict =
F( 0) +
F( 1) +
F( 2) +
F( 3) +
329 F( 4) +
F( 5) +
F( 6) +
F( 7) +
330 F( 8) +
F( 9) +
F(10) +
F(11) +
331 F(12) +
F(13) +
F(14) +
F(15);
334 if (!half_prob[ch] || i >= s->
fsets.
length[felem]) {
335 unsigned pelem = map_ch_to_pelem[
ch];
342 ac_get(ac, gb, prob, &residual);
343 v = ((predict >> 15) ^ residual) & 1;
344 dsd[((i >> 3) * channels + ch) << 2] |= v << (7 - (i & 0x7 ));
352 for (i = 0; i < avctx->
channels; i++) {
354 frame->
data[0] + i * 4,
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static av_always_inline int get_sr_golomb_dst(GetBitContext *gb, unsigned int k)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static av_cold int init(AVCodecContext *avctx)
const uint8_t ff_reverse[256]
av_cold void ff_init_dsd_data(void)
static int read_map(GetBitContext *gb, Table *t, unsigned int map[DST_MAX_CHANNELS], int channels)
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
static int get_sbits(GetBitContext *s, int n)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
enum AVSampleFormat sample_fmt
audio sample format
static const int8_t fsets_code_pred_coeff[3][3]
static void ac_init(ArithCoder *ac, GetBitContext *gb)
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
bitstream reader API header.
static int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len)
read unsigned golomb rice code (ffv1).
static const uint16_t table[]
#define prob(name, subs,...)
static int get_bits_left(GetBitContext *gb)
static void read_uncoded_coeff(GetBitContext *gb, int *dst, unsigned int elements, int coeff_bits, int is_signed, int offset)
int16_t filter[DST_MAX_ELEMENTS][16][256]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
static av_cold int decode_init(AVCodecContext *avctx)
static const int8_t probs_code_pred_coeff[3][3]
static const ElemCat * elements[ELEMENT_COUNT]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
void ff_dsd2pcm_translate(DSDContext *s, size_t samples, int lsbf, const unsigned char *src, ptrdiff_t src_stride, float *dst, ptrdiff_t dst_stride)
unsigned int length[DST_MAX_ELEMENTS]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
int sample_rate
samples per second
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static uint8_t prob_dst_x_bit(int c)
int coeff[DST_MAX_ELEMENTS][128]
static av_always_inline void ac_get(ArithCoder *ac, GetBitContext *gb, int p, int *e)
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
Describe the class of an AVClass context structure.
const VDPAUPixFmtMap * map
unsigned char buf[FIFOSIZE]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
static void build_filter(int16_t table[DST_MAX_ELEMENTS][16][256], const Table *fsets)
uint8_t status[DST_MAX_CHANNELS][16]
#define DST_SAMPLES_PER_FRAME(sample_rate)
DSDContext dsdctx[DST_MAX_CHANNELS]
static int read_table(GetBitContext *gb, Table *t, const int8_t code_pred_coeff[3][3], int length_bits, int coeff_bits, int is_signed, int offset)
int channels
number of audio channels
static enum AVSampleFormat sample_fmts[]
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_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MPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch