29 #define WS_MAX_CHANNELS 32
30 #define INF_TS 0x7FFFFFFFFFFFFFFF
106 #define LCG_A 1284865837
107 #define LCG_C 4150755663
108 #define LCG_AI 849225893
118 uint32_t
a,
c, t = *
s;
146 for (j = 0; j < 7; j++) {
166 if (
b < (uint64_t)1 << 32) {
168 return ((
a /
b) << 32) | ((
a %
b) << 32) /
b;
170 if (
b < (uint64_t)1 << 48) {
171 for (
i = 0;
i < 4;
i++) {
173 r = (
r << 16) | (
a /
b);
178 for (
i = 63;
i >= 0;
i--) {
179 if (
a >= (uint64_t)1 << 63 || a << 1 >=
b) {
180 r |= (uint64_t)1 <<
i;
191 uint64_t dt = ts - (uint64_t)
in->ts_start;
192 uint64_t dt2 = dt & 1 ?
193 dt * ((dt - 1) >> 1) : (dt >> 1) * (dt - 1);
194 return in->phi0 + dt *
in->dphi0 + dt2 *
in->ddphi;
207 if (ts >=
in->ts_end)
212 in->dphi =
in->dphi0 + (ts -
in->ts_start) *
in->ddphi;
213 in->amp =
in->amp0 + (ts -
in->ts_start) *
in->damp;
221 uint64_t pink_ts_next = ts & ~(
PINK_UNIT - 1);
241 int64_t dphi1, dphi2, dt, cur_ts = -0x8000000000000000;
257 if (edata_end - edata < 24)
264 if (
in->ts_start < cur_ts ||
265 in->ts_end <=
in->ts_start ||
266 (uint64_t)
in->ts_end -
in->ts_start > INT64_MAX
269 cur_ts =
in->ts_start;
270 dt =
in->ts_end -
in->ts_start;
273 if (edata_end - edata < 20 || avc->
sample_rate <= 0)
284 in->ddphi = (int64_t)(dphi2 - (uint64_t)dphi1) / dt;
285 if (
phi & 0x80000000) {
291 in->phi0 = (uint64_t)
phi << 33;
295 if (edata_end - edata < 8)
304 in->amp0 = (uint64_t)
a1 << 32;
305 in->damp = (int64_t)(((uint64_t)
a2 << 32) - ((uint64_t)
a1 << 32)) / dt;
307 if (edata != edata_end)
319 "This implementation is limited to %d channels.\n",
350 uint32_t
c, all_ch = 0;
360 if (ts >=
in->ts_end) {
371 in->dphi +=
in->ddphi;
374 val =
amp * (unsigned)pink;
382 *cv += (unsigned)
val;
402 if (ts >=
in->ts_end)
407 in->dphi =
in->dphi0;
427 if (packet->
size != 12)
static double val(void *priv, double ch)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
#define MKTAG(a, b, c, d)
static __device__ float floor(float a)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
AVCodec ff_ffwavesynth_decoder
static void wavesynth_enter_intervals(struct wavesynth_context *ws, int64_t ts)
static int wavesynth_parse_extradata(AVCodecContext *avc)
static uint64_t phi_at(struct ws_interval *in, int64_t ts)
static av_cold int wavesynth_close(AVCodecContext *avc)
static av_cold int wavesynth_init(AVCodecContext *avc)
static uint64_t frac64(uint64_t a, uint64_t b)
static void lcg_seek(uint32_t *s, uint32_t dt)
static uint32_t lcg_next(uint32_t *s)
static int wavesynth_decode(AVCodecContext *avc, void *rframe, int *rgot_frame, AVPacket *packet)
static void wavesynth_synth_sample(struct wavesynth_context *ws, int64_t ts, int32_t *channels)
static void wavesynth_seek(struct wavesynth_context *ws, int64_t ts)
static void pink_fill(struct wavesynth_context *ws)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
@ AV_CODEC_ID_FFWAVESYNTH
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int sample_rate
samples per second
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
struct ws_interval * inter
int32_t pink_pool[PINK_UNIT]
enum ws_interval_type type