diff mbox

[FFmpeg-devel,2/2] tests/audiomatch: Refine the code.

Message ID 98e2fbdd-76a8-0d0d-778b-7193152e2197@gmail.com
State New
Headers show

Commit Message

Jun Zhao Dec. 18, 2017, 1:41 a.m. UTC
From d2e3ba49180883dc71eb0eb0f5fa228368b4c9d5 Mon Sep 17 00:00:00 2001
From: Jun Zhao <jun.zhao@intel.com>
Date: Mon, 18 Dec 2017 09:16:52 +0800
Subject: [PATCH 2/2] tests/audiomatch: Refine the code.

Refine the coding style and change to use sizeof date type.

Signed-off-by: Jun Zhao <jun.zhao@intel.com>
---
 tests/audiomatch.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

Comments

Carl Eugen Hoyos Dec. 18, 2017, 2:25 a.m. UTC | #1
2017-12-18 2:41 GMT+01:00 Jun Zhao <mypopydev@gmail.com>:

> tests/audiomatch: Refine the code.

Shouldn't this be: "tests/audiomatch: Cosmetics, fix whitespace"?

Carl Eugen
Jun Zhao Dec. 18, 2017, 2:47 a.m. UTC | #2
On 2017/12/18 10:25, Carl Eugen Hoyos wrote:
> 2017-12-18 2:41 GMT+01:00 Jun Zhao <mypopydev@gmail.com>:
>
>> tests/audiomatch: Refine the code.
> Shouldn't this be: "tests/audiomatch: Cosmetics, fix whitespace"?
except fix whitespace, the other change is use date type in sizeof.
>
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Michael Niedermayer Dec. 19, 2017, 8:08 p.m. UTC | #3
On Mon, Dec 18, 2017 at 09:41:08AM +0800, Jun Zhao wrote:
> 

>  audiomatch.c |   34 +++++++++++++++++-----------------
>  1 file changed, 17 insertions(+), 17 deletions(-)
> 731bb5fb6d343903e65d5f1336b6393527bfa780  0002-tests-audiomatch-Refine-the-code.patch
> From d2e3ba49180883dc71eb0eb0f5fa228368b4c9d5 Mon Sep 17 00:00:00 2001
> From: Jun Zhao <jun.zhao@intel.com>
> Date: Mon, 18 Dec 2017 09:16:52 +0800
> Subject: [PATCH 2/2] tests/audiomatch: Refine the code.
> 
> Refine the coding style and change to use sizeof date type.
> 
> Signed-off-by: Jun Zhao <jun.zhao@intel.com>
> ---
>  tests/audiomatch.c | 34 +++++++++++++++++-----------------
>  1 file changed, 17 insertions(+), 17 deletions(-)

will apply without the data type change, as it would duplicate the type


thanks

[...]
diff mbox

Patch

diff --git a/tests/audiomatch.c b/tests/audiomatch.c
index e63e494add..b432b66ec5 100644
--- a/tests/audiomatch.c
+++ b/tests/audiomatch.c
@@ -25,23 +25,23 @@ 
 #define FFMIN(a,b) ((a) > (b) ? (b) : (a))
 #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
 
-static int64_t fsize(FILE *f){
-    int64_t end, pos= ftell(f);
+static int64_t fsize(FILE *f) {
+    int64_t end, pos = ftell(f);
     fseek(f, 0, SEEK_END);
     end = ftell(f);
     fseek(f, pos, SEEK_SET);
     return end;
 }
 
-int main(int argc, char **argv){
+int main(int argc, char **argv) {
     FILE *f[2];
     int i, pos;
     int siglen, datlen;
     int bestpos = 0;
-    double bestc=0;
-    double sigamp= 0;
+    double bestc = 0;
+    double sigamp = 0;
     int16_t *signal, *data;
-    int maxshift= 16384;
+    int maxshift = 16384;
 
     if (argc < 3) {
         printf("audiomatch <testfile> <reffile>\n");
@@ -77,8 +77,8 @@  int main(int argc, char **argv){
 
     datlen = fsize(f[0]) - ftell(f[0]);
     siglen = fsize(f[1]) - ftell(f[1]);
-    data   = malloc(datlen * sizeof(*data));
-    signal = malloc(siglen * sizeof(*signal));
+    data   = malloc(datlen * sizeof(int16_t));
+    signal = malloc(siglen * sizeof(int16_t));
 
     if (fread(data  , 1, datlen, f[0]) != datlen)
         return 1;
@@ -87,24 +87,24 @@  int main(int argc, char **argv){
     datlen /= 2;
     siglen /= 2;
 
-    for(i=0; i<siglen; i++){
+    for (i = 0; i < siglen; i++) {
         signal[i] = ((uint8_t*)(signal + i))[0] + 256*((uint8_t*)(signal + i))[1];
         sigamp += signal[i] * signal[i];
     }
-    for(i=0; i<datlen; i++)
+    for (i = 0; i < datlen; i++)
         data[i] = ((uint8_t*)(data + i))[0] + 256*((uint8_t*)(data + i))[1];
 
-    for(pos = 0; pos<maxshift; pos = pos < 0 ? -pos: -pos-1){
-        int64_t c= 0;
+    for (pos = 0; pos < maxshift; pos = pos < 0 ? -pos: -pos-1) {
+        int64_t c = 0;
         int testlen = FFMIN(siglen, datlen-pos);
-        for(i=FFMAX(0, -pos); i<testlen; i++){
-            int j= pos+i;
+        for (i = FFMAX(0, -pos); i < testlen; i++) {
+            int j = pos + i;
             c += signal[i] * data[j];
         }
-        if(fabs(c) > sigamp * 0.94)
+        if (fabs(c) > sigamp * 0.94)
             maxshift = FFMIN(maxshift, fabs(pos)+32);
-        if(fabs(c)>fabs(bestc)){
-            bestc= c;
+        if (fabs(c) > fabs(bestc)) {
+            bestc = c;
             bestpos = pos;
         }
     }