diff --git a/src/resample.cpp b/src/resample.cpp index 7d2f651a..950506a9 100755 --- a/src/resample.cpp +++ b/src/resample.cpp @@ -204,6 +204,12 @@ void CAudioResample::Init ( const int iNewInputBlockSize, iI = DECIM_D_2; break; + case ( SND_CRD_SAMPLE_RATE * 7 / 12 ): // 48 kHz to 28 kHz + pFiltTaps = fResTaps12_7; + iNumTaps = INTERP_I_12_7 * NUM_TAPS_PER_PHASE12_7; + iI = DECIM_D_12_7; + break; + case ( SND_CRD_SAMPLE_RATE * 2 / 3 ): // 48 kHz to 32 kHz pFiltTaps = fResTaps3_2; iNumTaps = INTERP_I_3_2 * NUM_TAPS_PER_PHASE3_2; @@ -212,6 +218,9 @@ void CAudioResample::Init ( const int iNewInputBlockSize, case SND_CRD_SAMPLE_RATE: // 48 kHz to 48 kHz // no resampling needed + pFiltTaps = NULL; + iNumTaps = 0; + iI = 1; break; default: @@ -230,6 +239,12 @@ void CAudioResample::Init ( const int iNewInputBlockSize, iI = INTERP_I_2; break; + case ( SND_CRD_SAMPLE_RATE * 7 / 12 ): // 28 kHz to 48 kHz + pFiltTaps = fResTaps12_7; + iNumTaps = DECIM_D_12_7 * NUM_TAPS_PER_PHASE12_7; + iI = INTERP_I_12_7; + break; + case ( SND_CRD_SAMPLE_RATE * 2 / 3 ): // 32 kHz to 48 kHz pFiltTaps = fResTaps3_2; iNumTaps = DECIM_D_3_2 * NUM_TAPS_PER_PHASE3_2; diff --git a/src/resamplefilter.h b/src/resamplefilter.h index 8dd573ee..82f49929 100644 --- a/src/resamplefilter.h +++ b/src/resamplefilter.h @@ -1,213 +1,365 @@ -/* Automatically generated file with MATLAB */ -/* File name: "ResampleFilter.m" */ -/* Filter taps in time-domain */ - -#ifndef _RESAMPLEFILTER_H_ -#define _RESAMPLEFILTER_H_ - -#define NUM_TAPS_PER_PHASE2 12 -#define NUM_TAPS_PER_PHASE3_2 12 -#define NUM_TAPS_PER_PHASE1 12 -#define INTERP_I_2 2 -#define DECIM_D_2 1 -#define INTERP_I_3_2 3 -#define DECIM_D_3_2 2 -#define INTERP_DECIM_I_D1 10 - - - -// Filter for ratio 2 -static float fResTaps2[INTERP_I_2 * DECIM_D_2 * NUM_TAPS_PER_PHASE2] = { - -0.00197231219263642580f, - -0.00149441363437698710f, - 0.00978643021021321540f, - 0.00681767720964485820f, - -0.02671025414462463400f, - -0.02086828471078093500f, - 0.05837045639157300400f, - 0.05384957575491138700f, - -0.11980958828278984000f, - -0.14170168497101379000f, - 0.30855591451377506000f, - 0.87515091657445054000f, - 0.87515091657445054000f, - 0.30855591451377506000f, - -0.14170168497101379000f, - -0.11980958828278984000f, - 0.05384957575491138700f, - 0.05837045639157300400f, - -0.02086828471078093500f, - -0.02671025414462463400f, - 0.00681767720964485820f, - 0.00978643021021321540f, - -0.00149441363437698710f, - -0.00197231219263642580f -}; - - -// Filter for ratio 3 / 2 -static float fResTaps3_2[INTERP_I_3_2 * DECIM_D_3_2 * NUM_TAPS_PER_PHASE3_2] = { - -0.00176046250093099540f, - -0.00336610762581997370f, - -0.00023822280323501131f, - 0.00833859487742245890f, - 0.01339722511380138700f, - 0.00269922033961634070f, - -0.02185973842102897900f, - -0.03569929574814127000f, - -0.01106578529670297800f, - 0.04574010538564617100f, - 0.08068909318354972000f, - 0.03356421112732931000f, - -0.08888051700234801700f, - -0.18084907976234993000f, - -0.10021438259584969000f, - 0.20666894693494509000f, - 0.62554698344706861000f, - 0.92713992460312022000f, - 0.92713992460312022000f, - 0.62554698344706861000f, - 0.20666894693494509000f, - -0.10021438259584969000f, - -0.18084907976234993000f, - -0.08888051700234801700f, - 0.03356421112732931000f, - 0.08068909318354972000f, - 0.04574010538564617100f, - -0.01106578529670297800f, - -0.03569929574814127000f, - -0.02185973842102897900f, - 0.00269922033961634070f, - 0.01339722511380138700f, - 0.00833859487742245890f, - -0.00023822280323501131f, - -0.00336610762581997370f, - -0.00176046250093099540f -}; - -// Filter for ratios close to 1 -static float fResTaps1[INTERP_DECIM_I_D1 * NUM_TAPS_PER_PHASE1] = { - -0.00129181992672801360f, - -0.00207886551285772290f, - -0.00287519800425638110f, - -0.00354120720771153910f, - -0.00391755659664638590f, - -0.00384568128202934270f, - -0.00319259334815649940f, - -0.00187713739944610450f, - 0.00010586149691723067f, - 0.00266742068076876060f, - 0.00561586829442904840f, - 0.00866090598717600930f, - 0.01143197533872717000f, - 0.01351098086300389300f, - 0.01447751287549226700f, - 0.01396276906259418800f, - 0.01170664402374247200f, - 0.00761119378345958850f, - 0.00178311012364952820f, - -0.00544188094946287510f, - -0.01349857823816511800f, - -0.02161960909069559500f, - -0.02889142869399521600f, - -0.03433664370844288100f, - -0.03701682481313090000f, - -0.03614676421513295800f, - -0.03120859084480779800f, - -0.02205265100214613000f, - -0.00897188476756275060f, - 0.00726225824406205160f, - 0.02541150940858524100f, - 0.04383507935997314800f, - 0.06060641890050100900f, - 0.07367662235517660800f, - 0.08107302414568577600f, - 0.08111657494320076400f, - 0.07263788052016696700f, - 0.05516985095031713000f, - 0.02909509423931267600f, - -0.00427135103965109450f, - -0.04267869501534898200f, - -0.08302470868585065700f, - -0.12152802242786863000f, - -0.15398027155782226000f, - -0.17606165300033697000f, - -0.18369620562420094000f, - -0.17341770937821352000f, - -0.14271415809850990000f, - -0.09031872116141286000f, - -0.01641812005088002400f, - 0.07724474282951483700f, - 0.18738870090358245000f, - 0.30933747340895279000f, - 0.43728178746780866000f, - 0.56464344237183917000f, - 0.68451472884717957000f, - 0.79013921003423337000f, - 0.87539536840978205000f, - 0.93524350914423104000f, - 0.96609875058711103000f, - 0.96609875058711103000f, - 0.93524350914423104000f, - 0.87539536840978205000f, - 0.79013921003423337000f, - 0.68451472884717957000f, - 0.56464344237183917000f, - 0.43728178746780866000f, - 0.30933747340895279000f, - 0.18738870090358245000f, - 0.07724474282951483700f, - -0.01641812005088002400f, - -0.09031872116141286000f, - -0.14271415809850990000f, - -0.17341770937821352000f, - -0.18369620562420094000f, - -0.17606165300033697000f, - -0.15398027155782226000f, - -0.12152802242786863000f, - -0.08302470868585065700f, - -0.04267869501534898200f, - -0.00427135103965109450f, - 0.02909509423931267600f, - 0.05516985095031713000f, - 0.07263788052016696700f, - 0.08111657494320076400f, - 0.08107302414568577600f, - 0.07367662235517660800f, - 0.06060641890050100900f, - 0.04383507935997314800f, - 0.02541150940858524100f, - 0.00726225824406205160f, - -0.00897188476756275060f, - -0.02205265100214613000f, - -0.03120859084480779800f, - -0.03614676421513295800f, - -0.03701682481313090000f, - -0.03433664370844288100f, - -0.02889142869399521600f, - -0.02161960909069559500f, - -0.01349857823816511800f, - -0.00544188094946287510f, - 0.00178311012364952820f, - 0.00761119378345958850f, - 0.01170664402374247200f, - 0.01396276906259418800f, - 0.01447751287549226700f, - 0.01351098086300389300f, - 0.01143197533872717000f, - 0.00866090598717600930f, - 0.00561586829442904840f, - 0.00266742068076876060f, - 0.00010586149691723067f, - -0.00187713739944610450f, - -0.00319259334815649940f, - -0.00384568128202934270f, - -0.00391755659664638590f, - -0.00354120720771153910f, - -0.00287519800425638110f, - -0.00207886551285772290f, - -0.00129181992672801360f -}; - - -#endif /* _RESAMPLEFILTER_H_ */ +/* Automatically generated file with MATLAB */ +/* File name: "ResampleFilter.m" */ +/* Filter taps in time-domain */ + +#ifndef _RESAMPLEFILTER_H_ +#define _RESAMPLEFILTER_H_ + +#define NUM_TAPS_PER_PHASE2 12 +#define NUM_TAPS_PER_PHASE3_2 12 +#define NUM_TAPS_PER_PHASE12_7 12 +#define NUM_TAPS_PER_PHASE1 12 +#define INTERP_I_2 2 +#define DECIM_D_2 1 +#define INTERP_I_3_2 3 +#define DECIM_D_3_2 2 +#define INTERP_I_12_7 12 +#define DECIM_D_12_7 7 +#define INTERP_DECIM_I_D1 10 + + + +// Filter for ratio 2 +static float fResTaps2[INTERP_I_2 * DECIM_D_2 * NUM_TAPS_PER_PHASE2] = { + -0.00197231219263642580f, + -0.00149441363437698710f, + 0.00978643021021321540f, + 0.00681767720964485820f, + -0.02671025414462463400f, + -0.02086828471078093500f, + 0.05837045639157300400f, + 0.05384957575491138700f, + -0.11980958828278984000f, + -0.14170168497101379000f, + 0.30855591451377506000f, + 0.87515091657445054000f, + 0.87515091657445054000f, + 0.30855591451377506000f, + -0.14170168497101379000f, + -0.11980958828278984000f, + 0.05384957575491138700f, + 0.05837045639157300400f, + -0.02086828471078093500f, + -0.02671025414462463400f, + 0.00681767720964485820f, + 0.00978643021021321540f, + -0.00149441363437698710f, + -0.00197231219263642580f +}; + + +// Filter for ratio 3 / 2 +static float fResTaps3_2[INTERP_I_3_2 * DECIM_D_3_2 * NUM_TAPS_PER_PHASE3_2] = { + -0.00176046250093099540f, + -0.00336610762581997370f, + -0.00023822280323501131f, + 0.00833859487742245890f, + 0.01339722511380138700f, + 0.00269922033961634070f, + -0.02185973842102897900f, + -0.03569929574814127000f, + -0.01106578529670297800f, + 0.04574010538564617100f, + 0.08068909318354972000f, + 0.03356421112732931000f, + -0.08888051700234801700f, + -0.18084907976234993000f, + -0.10021438259584969000f, + 0.20666894693494509000f, + 0.62554698344706861000f, + 0.92713992460312022000f, + 0.92713992460312022000f, + 0.62554698344706861000f, + 0.20666894693494509000f, + -0.10021438259584969000f, + -0.18084907976234993000f, + -0.08888051700234801700f, + 0.03356421112732931000f, + 0.08068909318354972000f, + 0.04574010538564617100f, + -0.01106578529670297800f, + -0.03569929574814127000f, + -0.02185973842102897900f, + 0.00269922033961634070f, + 0.01339722511380138700f, + 0.00833859487742245890f, + -0.00023822280323501131f, + -0.00336610762581997370f, + -0.00176046250093099540f +}; + + +// Filter for ratio 12 / 7 +static float fResTaps12_7[INTERP_I_12_7 * DECIM_D_12_7 * NUM_TAPS_PER_PHASE12_7] = { + -0.00125208827289417920f, + -0.00190626448556412160f, + -0.00258725330105407910f, + -0.00321911699468315850f, + -0.00371304124871946240f, + -0.00397449433584967650f, + -0.00391226244728601170f, + -0.00344872729447937270f, + -0.00253053775303447700f, + -0.00113866891904707700f, + 0.00070321859502462086f, + 0.00292319218332290870f, + 0.00539918825312160800f, + 0.00796161187294208010f, + 0.01040080648737300700f, + 0.01247940789020031800f, + 0.01394914970162503700f, + 0.01457122611642731000f, + 0.01413888175955135800f, + 0.01250052994177179200f, + 0.00958143947199255330f, + 0.00540191094345563410f, + 0.00008991148771200068f, + -0.00611363430350713410f, + -0.01285829127084545300f, + -0.01969712096259990500f, + -0.02610936928229550000f, + -0.03153216669657662300f, + -0.03539975740910365800f, + -0.03718799481084937600f, + -0.03646116541074920900f, + -0.03291769690105803700f, + -0.02643102432092192500f, + -0.01708187424006729600f, + -0.00517850526744063640f, + 0.00873798258468762820f, + 0.02390530685294215600f, + 0.03936958373129542700f, + 0.05403253332659402300f, + 0.06671467306160311400f, + 0.07623153406248735200f, + 0.08147871600785833200f, + 0.08152058589868019200f, + 0.07567671586657001600f, + 0.06359981811742342100f, + 0.04533902176348663500f, + 0.02138286854317816500f, + -0.00732262749824698880f, + -0.03938414980169741000f, + -0.07300109067071840200f, + -0.10603511604421303000f, + -0.13610699820077277000f, + -0.16071647179549162000f, + -0.17737908657056814000f, + -0.18377255785167662000f, + -0.17788407020636693000f, + -0.15814946187689599000f, + -0.12357526654261679000f, + -0.07383523520087217900f, + -0.00933418413014485730f, + 0.06876624614792664600f, + 0.15856318013703752000f, + 0.25747026200729783000f, + 0.36231581851199790000f, + 0.46947713391879947000f, + 0.57504420553142555000f, + 0.67500437604388086000f, + 0.76543776689193965000f, + 0.84271257101448604000f, + 0.90366907084389148000f, + 0.94578175032061074000f, + 0.96729004417063957000f, + 0.96729004417063957000f, + 0.94578175032061074000f, + 0.90366907084389148000f, + 0.84271257101448604000f, + 0.76543776689193965000f, + 0.67500437604388086000f, + 0.57504420553142555000f, + 0.46947713391879947000f, + 0.36231581851199790000f, + 0.25747026200729783000f, + 0.15856318013703752000f, + 0.06876624614792664600f, + -0.00933418413014485730f, + -0.07383523520087217900f, + -0.12357526654261679000f, + -0.15814946187689599000f, + -0.17788407020636693000f, + -0.18377255785167662000f, + -0.17737908657056814000f, + -0.16071647179549162000f, + -0.13610699820077277000f, + -0.10603511604421303000f, + -0.07300109067071840200f, + -0.03938414980169741000f, + -0.00732262749824698880f, + 0.02138286854317816500f, + 0.04533902176348663500f, + 0.06359981811742342100f, + 0.07567671586657001600f, + 0.08152058589868019200f, + 0.08147871600785833200f, + 0.07623153406248735200f, + 0.06671467306160311400f, + 0.05403253332659402300f, + 0.03936958373129542700f, + 0.02390530685294215600f, + 0.00873798258468762820f, + -0.00517850526744063640f, + -0.01708187424006729600f, + -0.02643102432092192500f, + -0.03291769690105803700f, + -0.03646116541074920900f, + -0.03718799481084937600f, + -0.03539975740910365800f, + -0.03153216669657662300f, + -0.02610936928229550000f, + -0.01969712096259990500f, + -0.01285829127084545300f, + -0.00611363430350713410f, + 0.00008991148771200068f, + 0.00540191094345563410f, + 0.00958143947199255330f, + 0.01250052994177179200f, + 0.01413888175955135800f, + 0.01457122611642731000f, + 0.01394914970162503700f, + 0.01247940789020031800f, + 0.01040080648737300700f, + 0.00796161187294208010f, + 0.00539918825312160800f, + 0.00292319218332290870f, + 0.00070321859502462086f, + -0.00113866891904707700f, + -0.00253053775303447700f, + -0.00344872729447937270f, + -0.00391226244728601170f, + -0.00397449433584967650f, + -0.00371304124871946240f, + -0.00321911699468315850f, + -0.00258725330105407910f, + -0.00190626448556412160f, + -0.00125208827289417920f +}; + +// Filter for ratios close to 1 +static float fResTaps1[INTERP_DECIM_I_D1 * NUM_TAPS_PER_PHASE1] = { + -0.00129181992672801360f, + -0.00207886551285772290f, + -0.00287519800425638110f, + -0.00354120720771153910f, + -0.00391755659664638590f, + -0.00384568128202934270f, + -0.00319259334815649940f, + -0.00187713739944610450f, + 0.00010586149691723067f, + 0.00266742068076876060f, + 0.00561586829442904840f, + 0.00866090598717600930f, + 0.01143197533872717000f, + 0.01351098086300389300f, + 0.01447751287549226700f, + 0.01396276906259418800f, + 0.01170664402374247200f, + 0.00761119378345958850f, + 0.00178311012364952820f, + -0.00544188094946287510f, + -0.01349857823816511800f, + -0.02161960909069559500f, + -0.02889142869399521600f, + -0.03433664370844288100f, + -0.03701682481313090000f, + -0.03614676421513295800f, + -0.03120859084480779800f, + -0.02205265100214613000f, + -0.00897188476756275060f, + 0.00726225824406205160f, + 0.02541150940858524100f, + 0.04383507935997314800f, + 0.06060641890050100900f, + 0.07367662235517660800f, + 0.08107302414568577600f, + 0.08111657494320076400f, + 0.07263788052016696700f, + 0.05516985095031713000f, + 0.02909509423931267600f, + -0.00427135103965109450f, + -0.04267869501534898200f, + -0.08302470868585065700f, + -0.12152802242786863000f, + -0.15398027155782226000f, + -0.17606165300033697000f, + -0.18369620562420094000f, + -0.17341770937821352000f, + -0.14271415809850990000f, + -0.09031872116141286000f, + -0.01641812005088002400f, + 0.07724474282951483700f, + 0.18738870090358245000f, + 0.30933747340895279000f, + 0.43728178746780866000f, + 0.56464344237183917000f, + 0.68451472884717957000f, + 0.79013921003423337000f, + 0.87539536840978205000f, + 0.93524350914423104000f, + 0.96609875058711103000f, + 0.96609875058711103000f, + 0.93524350914423104000f, + 0.87539536840978205000f, + 0.79013921003423337000f, + 0.68451472884717957000f, + 0.56464344237183917000f, + 0.43728178746780866000f, + 0.30933747340895279000f, + 0.18738870090358245000f, + 0.07724474282951483700f, + -0.01641812005088002400f, + -0.09031872116141286000f, + -0.14271415809850990000f, + -0.17341770937821352000f, + -0.18369620562420094000f, + -0.17606165300033697000f, + -0.15398027155782226000f, + -0.12152802242786863000f, + -0.08302470868585065700f, + -0.04267869501534898200f, + -0.00427135103965109450f, + 0.02909509423931267600f, + 0.05516985095031713000f, + 0.07263788052016696700f, + 0.08111657494320076400f, + 0.08107302414568577600f, + 0.07367662235517660800f, + 0.06060641890050100900f, + 0.04383507935997314800f, + 0.02541150940858524100f, + 0.00726225824406205160f, + -0.00897188476756275060f, + -0.02205265100214613000f, + -0.03120859084480779800f, + -0.03614676421513295800f, + -0.03701682481313090000f, + -0.03433664370844288100f, + -0.02889142869399521600f, + -0.02161960909069559500f, + -0.01349857823816511800f, + -0.00544188094946287510f, + 0.00178311012364952820f, + 0.00761119378345958850f, + 0.01170664402374247200f, + 0.01396276906259418800f, + 0.01447751287549226700f, + 0.01351098086300389300f, + 0.01143197533872717000f, + 0.00866090598717600930f, + 0.00561586829442904840f, + 0.00266742068076876060f, + 0.00010586149691723067f, + -0.00187713739944610450f, + -0.00319259334815649940f, + -0.00384568128202934270f, + -0.00391755659664638590f, + -0.00354120720771153910f, + -0.00287519800425638110f, + -0.00207886551285772290f, + -0.00129181992672801360f +}; + + +#endif /* _RESAMPLEFILTER_H_ */ diff --git a/src/resamplefilter.m b/src/resamplefilter.m index 82c78162..df28060b 100755 --- a/src/resamplefilter.m +++ b/src/resamplefilter.m @@ -9,9 +9,10 @@ function resamplefilter() % Number of taps per poly phase for different resampling types -NoTapsP2 = 12; -NoTapsP3_2 = 12; -NoTapsP1 = 12; +NoTapsP2 = 12; % 24 kHz +NoTapsP3_2 = 12; % 32 kHz +NoTapsP12_7 = 12; % 28 kHz +NoTapsP1 = 12; % 48 kHz % Filter for ratio 2 ----------------------------------------------------------- @@ -32,6 +33,15 @@ D3_2 = 2; h3_2 = DesignFilter(NoTapsP3_2, I3_2); +% Filter for ratio 12 / 7 ------------------------------------------------------ +% I and D +I12_7 = 12; +D12_7 = 7; + +% filter design +h12_7 = DesignFilter(NoTapsP12_7, I12_7); + + % Filter for ratios close to 1 ------------------------------------------------- % Fixed for sample-rate conversiones of R ~ 1 I1 = 10; % D = I in this mode @@ -56,6 +66,9 @@ fprintf(fid, '\n'); fprintf(fid, '#define NUM_TAPS_PER_PHASE3_2 '); fprintf(fid, int2str(NoTapsP3_2)); fprintf(fid, '\n'); +fprintf(fid, '#define NUM_TAPS_PER_PHASE12_7 '); +fprintf(fid, int2str(NoTapsP12_7)); +fprintf(fid, '\n'); fprintf(fid, '#define NUM_TAPS_PER_PHASE1 '); fprintf(fid, int2str(NoTapsP1)); fprintf(fid, '\n'); @@ -71,6 +84,12 @@ fprintf(fid, '\n'); fprintf(fid, '#define DECIM_D_3_2 '); fprintf(fid, int2str(D3_2)); fprintf(fid, '\n'); +fprintf(fid, '#define INTERP_I_12_7 '); +fprintf(fid, int2str(I12_7)); +fprintf(fid, '\n'); +fprintf(fid, '#define DECIM_D_12_7 '); +fprintf(fid, int2str(D12_7)); +fprintf(fid, '\n'); fprintf(fid, '#define INTERP_DECIM_I_D1 '); fprintf(fid, int2str(I1)); fprintf(fid, '\n'); @@ -83,6 +102,9 @@ ExportFilterTaps(fid, 'fResTaps2[INTERP_I_2 * DECIM_D_2 * NUM_TAPS_PER_PHASE2]', fprintf(fid, '\n// Filter for ratio 3 / 2\n'); ExportFilterTaps(fid, 'fResTaps3_2[INTERP_I_3_2 * DECIM_D_3_2 * NUM_TAPS_PER_PHASE3_2]', h3_2); +fprintf(fid, '\n// Filter for ratio 12 / 7\n'); +ExportFilterTaps(fid, 'fResTaps12_7[INTERP_I_12_7 * DECIM_D_12_7 * NUM_TAPS_PER_PHASE12_7]', h12_7); + fprintf(fid, '// Filter for ratios close to 1\n'); ExportFilterTaps(fid, 'fResTaps1[INTERP_DECIM_I_D1 * NUM_TAPS_PER_PHASE1]', h1);