55#include <sox/sox-phi.h>
66#include <util/aformat.h>
77#include <ffsys/globals.h>
8+ #include <ffbase/args.h>
89
910static const phi_core * core ;
1011#define errlog (t , ...) phi_errlog(core, NULL, t, __VA_ARGS__)
@@ -39,24 +40,44 @@ static int request_input_conversion(phi_track *t)
3940 t -> aconv .out = t -> audio .format ;
4041 t -> aconv .out .format = PHI_PCM_32 ;
4142 t -> aconv .out .interleaved = 1 ;
42- if (!t -> conf .oaudio .format .format )
43- t -> conf .oaudio .format .format = PHI_PCM_FLOAT64 ;
4443 t -> oaudio .format = t -> aconv .out ;
4544 t -> data_out = t -> data_in ;
4645 return PHI_BACK ;
4746}
4847
49- static int argv_extract (ffstr * s , char * * argv , uint n )
48+ struct sox_eq_conf {
49+ const char * frequency , * width , * gain ;
50+ };
51+
52+ #define O (m ) (void*)(ffsize)FF_OFF(struct sox_eq_conf, m)
53+ static const struct ffarg sox_eq_args [] = {
54+ { "frequency" , 's' , O (frequency ) },
55+ { "gain" , 's' , O (gain ) },
56+ { "width" , 's' , O (width ) },
57+ {}
58+ };
59+ #undef O
60+
61+ static int sox_argv_extract (struct sox * c , phi_track * t , ffstr * s , char * * argv , uint n )
5062{
51- for (uint i = 0 ; i < n ; i ++ ) {
52- ffstr a ;
53- ffstr_splitby (s , ' ' , & a , s );
54- if (!a .len )
55- return -1 ;
56- a .ptr [a .len ] = '\0' ;
57- argv [i ] = a .ptr ;
58- }
63+ struct sox_eq_conf eqc = {};
64+ ffstr sc = {};
65+ ffstr_splitby (s , ',' , & sc , s );
5966 ffstr_skipchar (s , ' ' );
67+ sc .ptr [sc .len ] = '\0' ;
68+
69+ struct ffargs a = {};
70+ if (ffargs_process_line (& a , sox_eq_args , & eqc , FFARGS_O_PARTIAL | FFARGS_O_DUPLICATES , sc .ptr )) {
71+ errlog (t , "%s" , a .error );
72+ return -1 ;
73+ }
74+
75+ if (!eqc .frequency || !eqc .width || !eqc .gain )
76+ return -1 ;
77+
78+ argv [0 ] = (char * )eqc .frequency ;
79+ argv [1 ] = (char * )eqc .width ;
80+ argv [2 ] = (char * )eqc .gain ;
6081 return 0 ;
6182}
6283
@@ -94,7 +115,7 @@ static int sox_process(struct sox *c, phi_track *t)
94115 uint i = 1 ;
95116 while (s .len ) {
96117 char * argv [3 ];
97- if (argv_extract ( & s , argv , 3 )) {
118+ if (sox_argv_extract ( c , t , & s , argv , 3 )) {
98119 errlog (t , "Equalizer: incorrect parameters" );
99120 t -> error = PHI_E_FILTER_CONF ;
100121 return PHI_ERR ;
@@ -103,7 +124,7 @@ static int sox_process(struct sox *c, phi_track *t)
103124 errlog (t , "phi_sox_filter" );
104125 return PHI_ERR ;
105126 }
106- dbglog (t , "added filter #%u 'equalizer'" , i );
127+ dbglog (t , "added filter #%u 'equalizer': %s %s %s " , i , argv [ 0 ], argv [ 1 ], argv [ 2 ] );
107128 i ++ ;
108129 }
109130
0 commit comments