diff options
author | Chris Robinson <[email protected]> | 2018-05-24 00:16:50 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-05-24 00:16:50 -0700 |
commit | 803d331711cf5c0ecd0796bf28e9c95cf3724198 (patch) | |
tree | 8874f59490749796c9b117d0ff8094930f2fd121 /common/alcomplex.c | |
parent | 422cf429e61c610f271a05c9b5ac44c60b7e58fe (diff) |
Improve formatting of the hilbert function
Diffstat (limited to 'common/alcomplex.c')
-rw-r--r-- | common/alcomplex.c | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/common/alcomplex.c b/common/alcomplex.c index 9cf9d9bd..d4045aeb 100644 --- a/common/alcomplex.c +++ b/common/alcomplex.c @@ -60,37 +60,33 @@ void complex_fft(ALcomplex *FFTBuffer, ALsizei FFTSize, ALdouble Sign) } } -/*Discrete Hilbert Transform (analytic signal form)*/ -void hilbert(ALsizei size, ALcomplex *InOutBuffer )
-{
- ALsizei k;
- const ALdouble inverse_size = 1.0/(ALdouble)size;
-
- for ( k = 0; k < size;k++ )
- InOutBuffer[k].Imag = 0.0;
-
- complex_fft( InOutBuffer, size, 1.0 );
-
- for( k = 0; k < size; k++ )
- {
- if( k == 0 || k == size/2 )
- {
- InOutBuffer[k].Real *= inverse_size;
- InOutBuffer[k].Imag *= inverse_size;
- }
-
- else if ( k >=1 && k < size/2 )
- {
- InOutBuffer[k].Real *= 2.0*inverse_size;
- InOutBuffer[k].Imag *= 2.0*inverse_size;
- }
-
- else
- {
- InOutBuffer[k].Real = 0.0;
- InOutBuffer[k].Imag = 0.0;
- }
- }
-
- complex_fft( InOutBuffer, size,-1.0 );
+void complex_hilbert(ALcomplex *Buffer, ALsizei size) +{ + const ALdouble inverse_size = 1.0/(ALdouble)size; + ALsizei todo, i; + + for(i = 0;i < size;i++) + Buffer[i].Imag = 0.0; + + complex_fft(Buffer, size, 1.0); + + todo = size >> 1; + Buffer[0].Real *= inverse_size; + Buffer[0].Imag *= inverse_size; + for(i = 1;i < todo;i++) + { + Buffer[i].Real *= 2.0*inverse_size; + Buffer[i].Imag *= 2.0*inverse_size; + } + Buffer[i].Real *= inverse_size; + Buffer[i].Imag *= inverse_size; + i++; + + for(;i < size;i++) + { + Buffer[i].Real = 0.0; + Buffer[i].Imag = 0.0; + } + + complex_fft(Buffer, size, -1.0); } |