[FFmpeg-devel] [DISCUSSION] Atrac3+ stream inside PSMF

2014-11-25 Thread Max Pole
>From b3013e56b0251d7e1a04191dfaa60ded3431bb23 Mon Sep 17 00:00:00 2001
From: Maxim Poliakovski 
Date: Mon, 24 Nov 2014 01:20:21 +0100
Subject: [PATCH 2/2] mpeg: add experimental support for PSMF audio.

---
 libavformat/mpeg.c | 61 ++
 1 file changed, 57 insertions(+), 4 deletions(-)

diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 827a3c2..fbd5a25 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -22,6 +22,7 @@
 #include "avformat.h"
 #include "internal.h"
 #include "mpeg.h"
+#include "oma.h"
 
 #if CONFIG_VOBSUB_DEMUXER
 # include "subtitles.h"
@@ -434,10 +435,10 @@ redo:
 goto redo;
 }
 
-if (startcode == PRIVATE_STREAM_1) {
-startcode = avio_r8(s->pb);
-len--;
-}
+//if (startcode == PRIVATE_STREAM_1) {
+//startcode = avio_r8(s->pb);
+//len--;
+//}
 if (len < 0)
 goto error_redo;
 if (dts != AV_NOPTS_VALUE && ppos) {
@@ -534,6 +535,58 @@ redo:
 else
 request_probe= 1;
 type = AVMEDIA_TYPE_VIDEO;
+} else if (startcode == PRIVATE_STREAM_1) {
+if (len < 4)
+goto skip;
+uint8_t stream_id = avio_r8(s->pb);
+avio_r8(s->pb); // skip padding
+size_t bytes_remain = avio_rb16(s->pb);
+len -= 4;
+if (!(stream_id & 0xF0)) { // seems like we got an ATRAC stream
+/* check if an appropriate stream already exists */
+for (i = 0; i < s->nb_streams; i++) {
+st = s->streams[i];
+if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->codec->codec_id == AV_CODEC_ID_ATRAC3P && st->id - 0x1BD0 == (stream_id & 0xF))
+goto found;
+}
+
+if (len < (bytes_remain + 8))
+goto skip;
+
+if (bytes_remain)
+avio_skip(s->pb, bytes_remain);
+
+uint16_t hdr_id = avio_rb16(s->pb);
+uint16_t atrac_config = avio_rb16(s->pb);
+avio_skip(s->pb, 4); // skip padding bytes
+len -= 8;
+
+if (hdr_id == 0x0FD0) {
+int sample_rate = ff_oma_srate_tab[(atrac_config >> 13) & 7] * 100;
+int channel_id  = (atrac_config >> 10) & 7;
+int frame_size  = ((atrac_config & 0x3FF) * 8) + 8;
+
+if (!channel_id || !sample_rate || !frame_size) {
+av_log(s, AV_LOG_ERROR, "Invalid ATRAC packet!\n");
+return AVERROR_INVALIDDATA;
+}
+
+/* add a new ATRAC audio stream */
+st = avformat_new_stream(s, NULL);
+if (!st)
+goto skip;
+st->id= 0x1BD0 + (stream_id & 0xF);
+st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+st->codec->codec_id   = AV_CODEC_ID_ATRAC3P;
+st->codec->sample_rate= sample_rate;
+st->codec->block_align= frame_size;
+st->codec->bit_rate   = sample_rate * frame_size * 8 / 2048;
+st->codec->channels   = ff_oma_chid_to_num_channels[channel_id - 1];
+st->codec->channel_layout = ff_oma_chid_to_native_layout[channel_id - 1];
+goto found;
+}
+goto skip;
+}
 } else if (startcode == PRIVATE_STREAM_2) {
 type = AVMEDIA_TYPE_DATA;
 codec_id = AV_CODEC_ID_DVD_NAV;
-- 
1.9.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] Reenable GHA phase inversion in Atrac3+

2015-06-07 Thread Max Pole
Hello crews,

I attached two simple patches reenabling a decoder feature been initially
disabled due to lack of real-world samples.

I've recently got a couple of appropriate samples from the PPSSPP emulator
project so I coud test this feature extensively.

The 2nd patch is a cosmetical one that renames the "phase_shift" variable
to "inverse_phase". This seems to give a better description of what's
actually going on (180° phase shift).

Do we need to update FATE tests to include a test for this feature?

Best regards
Maxim
From 9f4931faba250755c7d546596636ad7bdf150566 Mon Sep 17 00:00:00 2001
From: Max Poliakovski 
Date: Sat, 6 Jun 2015 23:28:47 +0200
Subject: [PATCH 1/2] atrac3plus: add support for GHA phase inversion.

---
 libavcodec/atrac3plus.c|  6 +-
 libavcodec/atrac3plusdsp.c | 10 --
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c
index f998a7f..3d75749 100644
--- a/libavcodec/atrac3plus.c
+++ b/libavcodec/atrac3plus.c
@@ -1724,11 +1724,7 @@ static int decode_tones_info(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
 if (num_channels == 2) {
 get_subband_flags(gb, ctx->waves_info->tone_sharing, ctx->waves_info->num_tone_bands);
 get_subband_flags(gb, ctx->waves_info->tone_master,  ctx->waves_info->num_tone_bands);
-if (get_subband_flags(gb, ctx->waves_info->phase_shift,
-  ctx->waves_info->num_tone_bands)) {
-avpriv_report_missing_feature(avctx, "GHA Phase shifting");
-return AVERROR_PATCHWELCOME;
-}
+get_subband_flags(gb, ctx->waves_info->phase_shift, ctx->waves_info->num_tone_bands);
 }
 
 ctx->waves_info->tones_index = 0;
diff --git a/libavcodec/atrac3plusdsp.c b/libavcodec/atrac3plusdsp.c
index 3c68f74..50ac134 100644
--- a/libavcodec/atrac3plusdsp.c
+++ b/libavcodec/atrac3plusdsp.c
@@ -116,6 +116,7 @@ av_cold void ff_atrac3p_init_wave_synth(void)
  *  @param[in]synth_param   ptr to common synthesis parameters
  *  @param[in]waves_infoparameters for each sine wave
  *  @param[in]envelope  envelope data for all waves in a group
+ *  @param[in]fdsp  ptr to floating-point DSP context
  *  @param[in]phase_shift   flag indicates 180° phase shift
  *  @param[in]reg_offsetregion offset for trimming envelope data
  *  @param[out]   out   receives sythesized data
@@ -123,6 +124,7 @@ av_cold void ff_atrac3p_init_wave_synth(void)
 static void waves_synth(Atrac3pWaveSynthParams *synth_param,
 Atrac3pWavesData *waves_info,
 Atrac3pWaveEnvelope *envelope,
+AVFloatDSPContext *fdsp,
 int phase_shift, int reg_offset, float *out)
 {
 int i, wn, inc, pos;
@@ -146,6 +148,10 @@ static void waves_synth(Atrac3pWaveSynthParams *synth_param,
 }
 }
 
+/* 180° phase shift if requested */
+if (phase_shift)
+fdsp->vector_fmul_scalar(out, out, -1.0f, 128);
+
 /* fade in with steep Hann window if requested */
 if (envelope->has_start_point) {
 pos = (envelope->start_pos << 2) - reg_offset;
@@ -216,11 +222,11 @@ void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *f
 /* synthesize waves for both overlapping regions */
 if (tones_now->num_wavs && reg1_env_nonzero)
 waves_synth(ch_unit->waves_info_prev, tones_now, &tones_now->curr_env,
-ch_unit->waves_info_prev->phase_shift[sb] & ch_num,
+fdsp, ch_unit->waves_info_prev->phase_shift[sb] & ch_num,
 128, wavreg1);
 
 if (tones_next->num_wavs && reg2_env_nonzero)
-waves_synth(ch_unit->waves_info, tones_next, &tones_next->curr_env,
+waves_synth(ch_unit->waves_info, tones_next, &tones_next->curr_env, fdsp,
 ch_unit->waves_info->phase_shift[sb] & ch_num, 0, wavreg2);
 
 /* Hann windowing for non-faded wave signals */
-- 
1.9.1

From 3e0a8c23c5752db78950b0c868fce9f955e789ae Mon Sep 17 00:00:00 2001
From: Max Poliakovski 
Date: Sun, 7 Jun 2015 12:52:06 +0200
Subject: [PATCH 2/2] atrac3plus: give the phase_shift flag a better name.

---
 libavcodec/atrac3plus.c|  2 +-
 libavcodec/atrac3plus.h|  2 +-
 libavcodec/atrac3plusdsp.c | 12 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c
index 3d75749..b16a139 100644
--- a/libavcodec/atrac3plus.c
+++ b/libavcodec/atrac3plus.c
@@ -1724,7 +1724,7 @@ static int decode_tones_info(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
 if (num_channels == 2) {
 get_subband_flags(gb, ctx->waves_info->tone_sharing, ctx->waves_info->num_tone_bands);
 get_subband_flags(gb, ctx->waves_info->tone_master,  ctx->waves_info->num_tone_bands);
-get_subband_flags(gb, ctx->waves_info->phase_shift, ctx->waves_info->num_tone_bands);
+get_sub

Re: [FFmpeg-devel] [PATCH] Reenable GHA phase inversion in Atrac3+

2015-06-07 Thread Max Pole
>
>
> > I've recently got a couple of appropriate samples from the PPSSPP
> emulator
> > project so I coud test this feature extensively.
>
> where can i find these samples ?
> are they online somewhere? can you upload them ?
>

I've just uploaded a folder named "atrac3p GHA phase inversion" to
upload.ffmpeg.org/incoming. Hopefully, it does contain everything you need.


>
> > Do we need to update FATE tests to include a test for this feature?
>
> a fate test  might be interresting if its possible/reliable and
> not too hard to implement
>

Unfortunately, I don't have no idea how to make FATE tests myself so any
help would be very appreciated!

Best regards
Maxim
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel