From 560235c57b4ebdb636ddfa515effa65e4aa9fc48 Mon Sep 17 00:00:00 2001 From: Spoike Date: Wed, 28 Aug 2019 02:47:00 +0000 Subject: [PATCH] Fix a stupid bug with ffmpeg audio playback that was resulting in (practically) no sound. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5526 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- plugins/avplug/avaudio.c | 1 + plugins/avplug/avdecode.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/plugins/avplug/avaudio.c b/plugins/avplug/avaudio.c index 78fe83892..0cbff74b8 100644 --- a/plugins/avplug/avaudio.c +++ b/plugins/avplug/avaudio.c @@ -127,6 +127,7 @@ static void S_AV_ReadFrame(struct avaudioctx *ctx) auddatasize/=2; width = 2; } + break; case AV_SAMPLE_FMT_DBLP: auddatasize /= channels; diff --git a/plugins/avplug/avdecode.c b/plugins/avplug/avdecode.c index 1b4536b64..1a67e5823 100644 --- a/plugins/avplug/avdecode.c +++ b/plugins/avplug/avdecode.c @@ -374,8 +374,31 @@ static qboolean VARGS AVDec_DisplayFrame(void *vctx, qboolean nosound, qboolean break; case AV_SAMPLE_FMT_FLTP: - auddatasize /= channels; - channels = 1; + //FIXME: support float audio internally. + { + float *in[2] = {(float*)ctx->pAFrame->data[0],(float*)ctx->pAFrame->data[1]}; + signed short *out = (void*)auddata; + int v; + unsigned int i, c; + unsigned int frames = ctx->pAFrame->nb_samples; + if (channels > 2) + channels = 2; + for (i = 0; i < frames; i++) + { + for (c = 0; c < channels; c++) + { + v = (short)(in[c][i]*32767); + if (v < -32767) + v = -32767; + else if (v > 32767) + v = 32767; + *out++ = v; + } + } + width = sizeof(*out); + auddatasize = frames*width*channels; + } + break; case AV_SAMPLE_FMT_FLT: //FIXME: support float audio internally. { @@ -395,6 +418,7 @@ static qboolean VARGS AVDec_DisplayFrame(void *vctx, qboolean nosound, qboolean auddatasize/=2; width = 2; } + break; case AV_SAMPLE_FMT_DBLP: auddatasize /= channels;