Makes bandwidth detection less aggressive.
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Tue, 12 Mar 2013 15:24:53 +0000 (11:24 -0400)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Tue, 12 Mar 2013 15:24:53 +0000 (11:24 -0400)
The original code was causing parts of a sine sweep to be completely dropped
due to the 300 Hz margin and the hysteresis. Also, fixes scaling for the
analysis downmix when the input is 16-bit PCM.

src/analysis.c
src/opus_encoder.c

index ddd2812..734364b 100644 (file)
@@ -376,8 +376,8 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info_out, con
        float E=0;
        int band_start, band_end;
        /* Keep a margin of 300 Hz for aliasing */
-       band_start = extra_bands[b]+3;
-       band_end = extra_bands[b+1]+3;
+       band_start = extra_bands[b];
+       band_end = extra_bands[b+1];
        for (i=band_start;i<band_end;i++)
        {
           float binE = out[i].r*out[i].r + out[N-i].r*out[N-i].r
@@ -569,11 +569,11 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info_out, con
        printf("%f ", features[i]);
     printf("\n");*/
 
-    if (bandwidth<=12 || (bandwidth==13 && tonal->opus_bandwidth == OPUS_BANDWIDTH_NARROWBAND))
+    if (bandwidth<=12)
        tonal->opus_bandwidth = OPUS_BANDWIDTH_NARROWBAND;
-    else if (bandwidth<=14 || (bandwidth==15 && tonal->opus_bandwidth == OPUS_BANDWIDTH_MEDIUMBAND))
+    else if (bandwidth<=14)
        tonal->opus_bandwidth = OPUS_BANDWIDTH_MEDIUMBAND;
-    else if (bandwidth<=16 || (bandwidth==17 && tonal->opus_bandwidth == OPUS_BANDWIDTH_WIDEBAND))
+    else if (bandwidth<=16)
        tonal->opus_bandwidth = OPUS_BANDWIDTH_WIDEBAND;
     else if (bandwidth<=18)
        tonal->opus_bandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND;
index 36fa897..b036861 100644 (file)
@@ -695,6 +695,8 @@ void downmix_int(const void *_x, float *sub, int subframe, int offset, int C)
    for (c=1;c<C;c++)
       for (j=0;j<subframe;j++)
          sub[j] += x[(j+offset)*C+c];
+   for (j=0;j<subframe;j++)
+      sub[j] *= (1.f/32768);
 }
 
 int optimize_framesize(const opus_val16 *x, int len, int C, opus_int32 Fs,