5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.sun.media.sound;
26
27 /**
28 * Fast Fourier Transformer.
29 *
30 * @author Karl Helgason
31 */
32 public final class FFT {
33
34 private final double[] w;
35 private final int fftFrameSize;
36 private final int sign;
37 private final int[] bitm_array;
38 private final int fftFrameSize2;
39
40 // Sign = -1 is FFT, 1 is IFFT (inverse FFT)
41 // Data = Interlaced double array to be transformed.
42 // The order is: real (sin), complex (cos)
43 // Framesize must be power of 2
44 public FFT(int fftFrameSize, int sign) {
571 datan1_r = datan1_r + tempr;
572 datan1_i = datan1_i + tempi;
573
574 data[m] = datam2_r;
575 data[m + 1] = datam2_i;
576 data[n] = datan2_r;
577 data[n + 1] = datan2_i;
578
579 n -= nnstep;
580 m -= nnstep;
581 data[m] = datam1_r;
582 data[m + 1] = datam1_i;
583 data[n] = datan1_r;
584 data[n + 1] = datan1_i;
585
586 }
587
588 i += jmax << 1;
589
590 }
591
592 }
593
594 // Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
595 // complex operators
596 private static void calcF4IE(int fftFrameSize, double[] data, int i,
597 int nstep, double[] w) {
598 final int fftFrameSize2 = fftFrameSize << 1; // 2*fftFrameSize;
599 // Factor-4 Decomposition
600
601 int w_len = w.length >> 1;
602 while (nstep < fftFrameSize2) {
603
604 int jmax = nstep;
605 int nnstep = nstep << 1;
606 if (nnstep == fftFrameSize2) {
607 // Factor-4 Decomposition not possible
608 calcF2E(fftFrameSize, data, i, nstep, w);
609 return;
610 }
611 nstep <<= 2;
665 datan1_r = datan1_r + tempr;
666 datan1_i = datan1_i + tempi;
667
668 data[m] = datam2_r;
669 data[m + 1] = datam2_i;
670 data[n] = datan2_r;
671 data[n + 1] = datan2_i;
672
673 n -= nnstep;
674 m -= nnstep;
675 data[m] = datam1_r;
676 data[m + 1] = datam1_i;
677 data[n] = datan1_r;
678 data[n + 1] = datan1_i;
679
680 }
681
682 i += jmax << 1;
683
684 }
685
686 }
687
688 private void bitreversal(double[] data) {
689 if (fftFrameSize < 4)
690 return;
691
692 int inverse = fftFrameSize2 - 2;
693 for (int i = 0; i < fftFrameSize; i += 4) {
694 int j = bitm_array[i];
695
696 // Performing Bit-Reversal, even v.s. even, O(2N)
697 if (i < j) {
698
699 int n = i;
700 int m = j;
701
702 // COMPLEX: SWAP(data[n], data[m])
703 // Real Part
704 double tempr = data[n];
705 data[n] = data[m];
726 data[n] = data[m];
727 data[m] = tempi;
728 }
729
730 // Performing Bit-Reversal, odd v.s. even, O(N)
731
732 int m = j + fftFrameSize; // bitm_array[i+2];
733 // COMPLEX: SWAP(data[n], data[m])
734 // Real Part
735 int n = i + 2;
736 double tempr = data[n];
737 data[n] = data[m];
738 data[m] = tempr;
739 // Imagery Part
740 n++;
741 m++;
742 double tempi = data[n];
743 data[n] = data[m];
744 data[m] = tempi;
745 }
746
747 }
748 }
|
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.media.sound;
27
28 /**
29 * Fast Fourier Transformer.
30 *
31 * @author Karl Helgason
32 */
33 public final class FFT {
34
35 private final double[] w;
36 private final int fftFrameSize;
37 private final int sign;
38 private final int[] bitm_array;
39 private final int fftFrameSize2;
40
41 // Sign = -1 is FFT, 1 is IFFT (inverse FFT)
42 // Data = Interlaced double array to be transformed.
43 // The order is: real (sin), complex (cos)
44 // Framesize must be power of 2
45 public FFT(int fftFrameSize, int sign) {
572 datan1_r = datan1_r + tempr;
573 datan1_i = datan1_i + tempi;
574
575 data[m] = datam2_r;
576 data[m + 1] = datam2_i;
577 data[n] = datan2_r;
578 data[n + 1] = datan2_i;
579
580 n -= nnstep;
581 m -= nnstep;
582 data[m] = datam1_r;
583 data[m + 1] = datam1_i;
584 data[n] = datan1_r;
585 data[n + 1] = datan1_i;
586
587 }
588
589 i += jmax << 1;
590
591 }
592 }
593
594 // Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
595 // complex operators
596 private static void calcF4IE(int fftFrameSize, double[] data, int i,
597 int nstep, double[] w) {
598 final int fftFrameSize2 = fftFrameSize << 1; // 2*fftFrameSize;
599 // Factor-4 Decomposition
600
601 int w_len = w.length >> 1;
602 while (nstep < fftFrameSize2) {
603
604 int jmax = nstep;
605 int nnstep = nstep << 1;
606 if (nnstep == fftFrameSize2) {
607 // Factor-4 Decomposition not possible
608 calcF2E(fftFrameSize, data, i, nstep, w);
609 return;
610 }
611 nstep <<= 2;
665 datan1_r = datan1_r + tempr;
666 datan1_i = datan1_i + tempi;
667
668 data[m] = datam2_r;
669 data[m + 1] = datam2_i;
670 data[n] = datan2_r;
671 data[n + 1] = datan2_i;
672
673 n -= nnstep;
674 m -= nnstep;
675 data[m] = datam1_r;
676 data[m + 1] = datam1_i;
677 data[n] = datan1_r;
678 data[n + 1] = datan1_i;
679
680 }
681
682 i += jmax << 1;
683
684 }
685 }
686
687 private void bitreversal(double[] data) {
688 if (fftFrameSize < 4)
689 return;
690
691 int inverse = fftFrameSize2 - 2;
692 for (int i = 0; i < fftFrameSize; i += 4) {
693 int j = bitm_array[i];
694
695 // Performing Bit-Reversal, even v.s. even, O(2N)
696 if (i < j) {
697
698 int n = i;
699 int m = j;
700
701 // COMPLEX: SWAP(data[n], data[m])
702 // Real Part
703 double tempr = data[n];
704 data[n] = data[m];
725 data[n] = data[m];
726 data[m] = tempi;
727 }
728
729 // Performing Bit-Reversal, odd v.s. even, O(N)
730
731 int m = j + fftFrameSize; // bitm_array[i+2];
732 // COMPLEX: SWAP(data[n], data[m])
733 // Real Part
734 int n = i + 2;
735 double tempr = data[n];
736 data[n] = data[m];
737 data[m] = tempr;
738 // Imagery Part
739 n++;
740 m++;
741 double tempi = data[n];
742 data[n] = data[m];
743 data[m] = tempi;
744 }
745 }
746 }
|