const float * pcm_dsd_to_float(struct pcm_dsd *dsd, unsigned channels, bool lsbfirst, const uint8_t *src, size_t src_size, size_t *dest_size_r) { assert(dsd != NULL); assert(src != NULL); assert(src_size > 0); assert(src_size % channels == 0); assert(channels <= G_N_ELEMENTS(dsd->dsd2pcm)); const unsigned num_samples = src_size; const unsigned num_frames = src_size / channels; float *dest; const size_t dest_size = num_samples * sizeof(*dest); *dest_size_r = dest_size; dest = pcm_buffer_get(&dsd->buffer, dest_size); for (unsigned c = 0; c < channels; ++c) { if (dsd->dsd2pcm[c] == NULL) { dsd->dsd2pcm[c] = dsd2pcm_init(); if (dsd->dsd2pcm[c] == NULL) return NULL; } dsd2pcm_translate(dsd->dsd2pcm[c], num_frames, src + c, channels, lsbfirst, dest + c, channels); } return dest; }
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { DSDContext * s = avctx->priv_data; AVFrame *frame = data; int ret, i; int lsbf = avctx->codec_id == AV_CODEC_ID_DSD_LSBF || avctx->codec_id == AV_CODEC_ID_DSD_LSBF_PLANAR; int src_next; int src_stride; frame->nb_samples = avpkt->size / avctx->channels; if (avctx->codec_id == AV_CODEC_ID_DSD_LSBF_PLANAR || avctx->codec_id == AV_CODEC_ID_DSD_MSBF_PLANAR) { src_next = frame->nb_samples; src_stride = 1; } else { src_next = 1; src_stride = avctx->channels; } if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; for (i = 0; i < avctx->channels; i++) { float * dst = ((float **)frame->extended_data)[i]; dsd2pcm_translate(&s[i], frame->nb_samples, lsbf, avpkt->data + i * src_next, src_stride, dst, 1); } *got_frame_ptr = 1; return frame->nb_samples * avctx->channels; }
void translate(size_t samples, const unsigned char *src, ptrdiff_t src_stride, bool lsbitfirst, float *dst, ptrdiff_t dst_stride) { dsd2pcm_translate(handle,samples,src,src_stride, lsbitfirst,dst,dst_stride); }