]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/af_sofalizer.c
Merge commit '5ece6911010b3464d2fdacfa8031c15b5bd83418'
[ffmpeg] / libavfilter / af_sofalizer.c
index 7558f57eb9294bd5f6d5351c472c2bfa49df7bfe..5f0ab31a2ad0824786bff96e0bc4240126e25ffc 100644 (file)
@@ -373,9 +373,8 @@ error:
     return ret;
 }
 
-static int parse_channel_name(char **arg, int *rchannel)
+static int parse_channel_name(char **arg, int *rchannel, char *buf)
 {
-    char buf[8];
     int len, i, channel_id = 0;
     int64_t layout, layout0;
 
@@ -409,12 +408,15 @@ static void parse_speaker_pos(AVFilterContext *ctx, int64_t in_channel_layout)
     p = args;
 
     while ((arg = av_strtok(p, "|", &tokenizer))) {
+        char buf[8];
         float azim, elev;
         int out_ch_id;
 
         p = NULL;
-        if (parse_channel_name(&arg, &out_ch_id))
+        if (parse_channel_name(&arg, &out_ch_id, buf)) {
+            av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf);
             continue;
+        }
         if (sscanf(arg, "%f %f", &azim, &elev) == 2) {
             s->vspkrpos[out_ch_id].set = 1;
             s->vspkrpos[out_ch_id].azim = azim;
@@ -701,6 +703,8 @@ static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr,
     FFTContext *fft = s->fft[jobnr];
     const int n_conv = s->n_conv;
     const int n_fft = s->n_fft;
+    const float fft_scale = 1.0f / s->n_fft;
+    FFTComplex *hrtf_offset;
     int wr = *write;
     int n_read;
     int i, j;
@@ -734,6 +738,7 @@ static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr,
 
         /* outer loop: go through all input channels to be convolved */
         offset = i * n_fft; /* no. samples already processed */
+        hrtf_offset = hrtf + offset;
 
         /* fill FFT input with 0 (we want to zero-pad) */
         memset(fft_in, 0, sizeof(FFTComplex) * n_fft);
@@ -748,14 +753,15 @@ static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr,
         av_fft_permute(fft, fft_in);
         av_fft_calc(fft, fft_in);
         for (j = 0; j < n_fft; j++) {
+            const FFTComplex *hcomplex = hrtf_offset + j;
             const float re = fft_in[j].re;
             const float im = fft_in[j].im;
 
             /* complex multiplication of input signal and HRTFs */
             /* output channel (real): */
-            fft_in[j].re = re * (hrtf + offset + j)->re - im * (hrtf + offset + j)->im;
+            fft_in[j].re = re * hcomplex->re - im * hcomplex->im;
             /* output channel (imag): */
-            fft_in[j].im = re * (hrtf + offset + j)->im + im * (hrtf + offset + j)->re;
+            fft_in[j].im = re * hcomplex->im + im * hcomplex->re;
         }
 
         /* transform output signal of current channel back to time domain */
@@ -764,14 +770,14 @@ static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr,
 
         for (j = 0; j < in->nb_samples; j++) {
             /* write output signal of current channel to output buffer */
-            dst[2 * j] += fft_in[j].re / (float)n_fft;
+            dst[2 * j] += fft_in[j].re * fft_scale;
         }
 
         for (j = 0; j < n_samples - 1; j++) { /* overflow length is IR length - 1 */
             /* write the rest of output signal to overflow buffer */
             int write_pos = (wr + j) & modulo;
 
-            *(ringbuffer + write_pos) += fft_in[in->nb_samples + j].re / (float)n_fft;
+            *(ringbuffer + write_pos) += fft_in[in->nb_samples + j].re * fft_scale;
         }
     }
 
@@ -779,7 +785,7 @@ static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr,
     for (i = 0; i < out->nb_samples; i++) {
         /* clippings counter */
         if (fabs(*dst) > 1) { /* if current output sample > 1 */
-            *n_clippings = *n_clippings + 1;
+            n_clippings[0]++;
         }
 
         /* move output buffer pointer by +2 to get to next sample of processed channel: */