diff mbox

[FFmpeg-devel,5/5] af_hdcd: tweak hdcd_analyze_prepare() a bit

Message ID 1473074325-20959-6-git-send-email-pburt0@gmail.com
State Accepted
Commit eb0086588f1823841108ab1dee08683ab67cf507
Headers show

Commit Message

Burt P Sept. 5, 2016, 11:18 a.m. UTC
* use the actual sample rate
* use a more sensible frequency for the tone
* update fate test result

Signed-off-by: Burt P <pburt0@gmail.com>
---
 libavfilter/af_hdcd.c       | 9 ++++++---
 tests/fate/filter-audio.mak | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

Comments

Carl Eugen Hoyos Sept. 6, 2016, 10:22 a.m. UTC | #1
2016-09-05 13:18 GMT+02:00 Burt P <pburt0@gmail.com>:
> * use the actual sample rate

Is hdcd supposed to work for sample_rates
different from 44100?

> * use a more sensible frequency for the tone
> * update fate test result

Can't this be split?

Carl Eugen
Burt P Sept. 6, 2016, 11:02 a.m. UTC | #2
On Tue, Sep 6, 2016 at 5:22 AM, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
> 2016-09-05 13:18 GMT+02:00 Burt P <pburt0@gmail.com>:
>> * use the actual sample rate
>
> Is hdcd supposed to work for sample_rates
> different from 44100?

As I understand it, yes. The PM Model 2 supported code insertion at
all CD and DVD-Audio sample rates, so:
44.1, 48, 88.2, 96, 176.4, and 192 kHz.
If any DVD-Audio was ever actually released with HDCD encoding, I do not know.

>> * use a more sensible frequency for the tone
>> * update fate test result
>
> Can't this be split?

It could, if you would like it to be.
Carl Eugen Hoyos Sept. 6, 2016, 11:12 a.m. UTC | #3
2016-09-06 13:02 GMT+02:00 Burt P. <pburt0@gmail.com>:
> On Tue, Sep 6, 2016 at 5:22 AM, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
>> 2016-09-05 13:18 GMT+02:00 Burt P <pburt0@gmail.com>:
>>> * use the actual sample rate
>>
>> Is hdcd supposed to work for sample_rates
>> different from 44100?
>
> As I understand it, yes. The PM Model 2 supported code
> insertion at all CD and DVD-Audio sample rates, so:
> 44.1, 48, 88.2, 96, 176.4, and 192 kHz.
> If any DVD-Audio was ever actually released with HDCD
> encoding, I do not know.

Is there a test if the sample_rate is any of the above?

>>> * use a more sensible frequency for the tone
>>> * update fate test result
>>
>> Can't this be split?
>
> It could, if you would like it to be.

You are the maintainer;-)

Carl Eugen
Burt P Sept. 6, 2016, 12:01 p.m. UTC | #4
On Tue, Sep 6, 2016 at 6:12 AM, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
> 2016-09-06 13:02 GMT+02:00 Burt P. <pburt0@gmail.com>:
>> On Tue, Sep 6, 2016 at 5:22 AM, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
>>> 2016-09-05 13:18 GMT+02:00 Burt P <pburt0@gmail.com>:
>>>> * use the actual sample rate
>>>
>>> Is hdcd supposed to work for sample_rates
>>> different from 44100?
>>
>> As I understand it, yes. The PM Model 2 supported code
>> insertion at all CD and DVD-Audio sample rates, so:
>> 44.1, 48, 88.2, 96, 176.4, and 192 kHz.
>> If any DVD-Audio was ever actually released with HDCD
>> encoding, I do not know.
>
> Is there a test if the sample_rate is any of the above?
>

Right now, query_formats only accepts 44100. I don't have any higher
rate samples to test, I don't know if it is a good idea to just add
the other rates to the accepted list if I can't test the results.
In this patch, I took the opportunity to remove a hard-coded rate and
use one from the framework. I did the same in patch 4/5 in this set.
hdcd_reset() already uses a variable rate to set the cdt period. All
that is left is to make whatever changes to hdcd_envelope(), if any.
So, perhaps in the future it will be possible to support the higher
rates.

I don't have any HDCD-encoded DVD-Audio (or any DVD-Audio), and I also
don't have a PM Model Two to generate some. For now anyway, I can't
test it.
Carl Eugen Hoyos Sept. 6, 2016, 12:03 p.m. UTC | #5
2016-09-06 14:01 GMT+02:00 Burt P. <pburt0@gmail.com>:

> In this patch, I took the opportunity to remove a hard-coded rate and
> use one from the framework.

Thanks for explaining!

Carl Eugen
Burt P Sept. 7, 2016, 4:01 p.m. UTC | #6
applied

On Mon, Sep 5, 2016 at 6:18 AM, Burt P <pburt0@gmail.com> wrote:
> * use the actual sample rate
> * use a more sensible frequency for the tone
> * update fate test result
>
> Signed-off-by: Burt P <pburt0@gmail.com>
> ---
>  libavfilter/af_hdcd.c       | 9 ++++++---
>  tests/fate/filter-audio.mak | 2 +-
>  2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/libavfilter/af_hdcd.c b/libavfilter/af_hdcd.c
> index 1487a0b..fde6b7b 100644
> --- a/libavfilter/af_hdcd.c
> +++ b/libavfilter/af_hdcd.c
> @@ -871,6 +871,7 @@ typedef struct {
>       *  a code. -1 for timer never set. */
>      int count_sustain_expired;
>
> +    int rate;                   /**< sampling rate */
>      int _ana_snb;               /**< used in the analyze mode tone generator */
>  } hdcd_state;
>
> @@ -1026,6 +1027,7 @@ static void hdcd_reset(hdcd_state *state, unsigned rate, unsigned cdt_ms)
>      state->max_gain = 0;
>      state->count_sustain_expired = -1;
>
> +    state->rate = rate;
>      state->_ana_snb = 0;
>  }
>
> @@ -1297,7 +1299,8 @@ static int hdcd_scan_stereo(HDCDContext *ctx, const int32_t *samples, int max)
>
>  /** replace audio with solid tone, but save LSBs */
>  static void hdcd_analyze_prepare(hdcd_state *state, int32_t *samples, int count, int stride) {
> -    int n;
> +    int n, f = 300;
> +    int so = state->rate / f;
>      for (n = 0; n < count * stride; n += stride) {
>          /* in analyze mode, the audio is replaced by a solid tone, and
>           * amplitude is changed to signal when the specified feature is
> @@ -1306,9 +1309,9 @@ static void hdcd_analyze_prepare(hdcd_state *state, int32_t *samples, int count,
>           * bit 1: Original sample was above PE level */
>          int32_t save = (abs(samples[n]) - PEAK_EXT_LEVEL >= 0) ? 2 : 0; /* above PE level */
>          save |= samples[n] & 1;                      /* save LSB for HDCD packets */
> -        samples[n] = TONEGEN16(state->_ana_snb, 277.18, 44100, 0.1);
> +        samples[n] = TONEGEN16(state->_ana_snb, f, state->rate, 0.1);
>          samples[n] = (samples[n] | 3) ^ ((~save) & 3);
> -        if (++state->_ana_snb > 0x3fffffff) state->_ana_snb = 0;
> +        if (++state->_ana_snb > so) state->_ana_snb = 0;
>      }
>  }
>
> diff --git a/tests/fate/filter-audio.mak b/tests/fate/filter-audio.mak
> index 2066fa9..cf92ef6 100644
> --- a/tests/fate/filter-audio.mak
> +++ b/tests/fate/filter-audio.mak
> @@ -242,7 +242,7 @@ FATE_AFILTER_SAMPLES-$(call FILTERDEMDECENCMUX, HDCD, FLAC, FLAC, PCM_S24LE, PCM
>  fate-filter-hdcd-analyze: SRC = $(TARGET_SAMPLES)/filter/hdcd.flac
>  fate-filter-hdcd-analyze: CMD = md5 -i $(SRC) -af hdcd=analyze_mode=pe -f s24le
>  fate-filter-hdcd-analyze: CMP = oneline
> -fate-filter-hdcd-analyze: REF = 81a4f00f85a585bc0198e9a0670a8cde
> +fate-filter-hdcd-analyze: REF = 6e39dc4629c1e84321c0d8bc069b42f6
>
>  FATE_AFILTER_SAMPLES-$(call FILTERDEMDECENCMUX, HDCD, FLAC, FLAC, PCM_S24LE, PCM_S24LE) += fate-filter-hdcd-false-positive
>  fate-filter-hdcd-false-positive: SRC = $(TARGET_SAMPLES)/filter/hdcd-false-positive.flac
> --
> 2.7.4
>
diff mbox

Patch

diff --git a/libavfilter/af_hdcd.c b/libavfilter/af_hdcd.c
index 1487a0b..fde6b7b 100644
--- a/libavfilter/af_hdcd.c
+++ b/libavfilter/af_hdcd.c
@@ -871,6 +871,7 @@  typedef struct {
      *  a code. -1 for timer never set. */
     int count_sustain_expired;
 
+    int rate;                   /**< sampling rate */
     int _ana_snb;               /**< used in the analyze mode tone generator */
 } hdcd_state;
 
@@ -1026,6 +1027,7 @@  static void hdcd_reset(hdcd_state *state, unsigned rate, unsigned cdt_ms)
     state->max_gain = 0;
     state->count_sustain_expired = -1;
 
+    state->rate = rate;
     state->_ana_snb = 0;
 }
 
@@ -1297,7 +1299,8 @@  static int hdcd_scan_stereo(HDCDContext *ctx, const int32_t *samples, int max)
 
 /** replace audio with solid tone, but save LSBs */
 static void hdcd_analyze_prepare(hdcd_state *state, int32_t *samples, int count, int stride) {
-    int n;
+    int n, f = 300;
+    int so = state->rate / f;
     for (n = 0; n < count * stride; n += stride) {
         /* in analyze mode, the audio is replaced by a solid tone, and
          * amplitude is changed to signal when the specified feature is
@@ -1306,9 +1309,9 @@  static void hdcd_analyze_prepare(hdcd_state *state, int32_t *samples, int count,
          * bit 1: Original sample was above PE level */
         int32_t save = (abs(samples[n]) - PEAK_EXT_LEVEL >= 0) ? 2 : 0; /* above PE level */
         save |= samples[n] & 1;                      /* save LSB for HDCD packets */
-        samples[n] = TONEGEN16(state->_ana_snb, 277.18, 44100, 0.1);
+        samples[n] = TONEGEN16(state->_ana_snb, f, state->rate, 0.1);
         samples[n] = (samples[n] | 3) ^ ((~save) & 3);
-        if (++state->_ana_snb > 0x3fffffff) state->_ana_snb = 0;
+        if (++state->_ana_snb > so) state->_ana_snb = 0;
     }
 }
 
diff --git a/tests/fate/filter-audio.mak b/tests/fate/filter-audio.mak
index 2066fa9..cf92ef6 100644
--- a/tests/fate/filter-audio.mak
+++ b/tests/fate/filter-audio.mak
@@ -242,7 +242,7 @@  FATE_AFILTER_SAMPLES-$(call FILTERDEMDECENCMUX, HDCD, FLAC, FLAC, PCM_S24LE, PCM
 fate-filter-hdcd-analyze: SRC = $(TARGET_SAMPLES)/filter/hdcd.flac
 fate-filter-hdcd-analyze: CMD = md5 -i $(SRC) -af hdcd=analyze_mode=pe -f s24le
 fate-filter-hdcd-analyze: CMP = oneline
-fate-filter-hdcd-analyze: REF = 81a4f00f85a585bc0198e9a0670a8cde
+fate-filter-hdcd-analyze: REF = 6e39dc4629c1e84321c0d8bc069b42f6
 
 FATE_AFILTER_SAMPLES-$(call FILTERDEMDECENCMUX, HDCD, FLAC, FLAC, PCM_S24LE, PCM_S24LE) += fate-filter-hdcd-false-positive
 fate-filter-hdcd-false-positive: SRC = $(TARGET_SAMPLES)/filter/hdcd-false-positive.flac