├── .gitignore ├── LICENSE.txt ├── README ├── pom.xml └── src ├── main ├── java │ ├── com │ │ └── jssrc │ │ │ └── resample │ │ │ ├── JSSRCResampler.java │ │ │ └── JSSRCSampleRateConversionProvider.java │ └── vavi │ │ ├── sound │ │ └── pcm │ │ │ └── resampling │ │ │ └── ssrc │ │ │ └── SSRC.java │ │ └── util │ │ ├── I0Bessel.java │ │ └── SplitRadixFft.java └── resources │ └── META-INF │ └── services │ └── javax.sound.sampled.spi.FormatConversionProvider ├── site ├── apt │ ├── downloads.apt │ ├── help.apt │ ├── index.apt │ ├── release-notes.apt │ └── source-repository.apt ├── changes │ └── changes.xml ├── resources │ ├── CNAME │ └── images │ │ └── logo.png └── site.xml └── test ├── java └── com │ └── jssrc │ └── resample │ └── JSSRCResamplerTest.java └── resources ├── mono_short_test.wav ├── stereo_long_test.wav └── testng.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | *.iml 3 | *.ipr 4 | 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | JAMAL software is developed and distributed under the 2 | terms of the GNU General Public License 3 | 4 | 5 | GNU GENERAL PUBLIC LICENSE 6 | Version 2, June 1991 7 | 8 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 9 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 10 | Everyone is permitted to copy and distribute verbatim copies 11 | of this license document, but changing it is not allowed. 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | License is intended to guarantee your freedom to share and change free 18 | software--to make sure the software is free for all its users. This 19 | General Public License applies to most of the Free Software 20 | Foundation's software and to any other program whose authors commit to 21 | using it. (Some other Free Software Foundation software is covered by 22 | the GNU Lesser General Public License instead.) You can apply it to 23 | your programs, too. 24 | 25 | When we speak of free software, we are referring to freedom, not 26 | price. Our General Public Licenses are designed to make sure that you 27 | have the freedom to distribute copies of free software (and charge for 28 | this service if you wish), that you receive source code or can get it 29 | if you want it, that you can change the software or use pieces of it 30 | in new free programs; and that you know you can do these things. 31 | 32 | To protect your rights, we need to make restrictions that forbid 33 | anyone to deny you these rights or to ask you to surrender the rights. 34 | These restrictions translate to certain responsibilities for you if you 35 | distribute copies of the software, or if you modify it. 36 | 37 | For example, if you distribute copies of such a program, whether 38 | gratis or for a fee, you must give the recipients all the rights that 39 | you have. You must make sure that they, too, receive or can get the 40 | source code. And you must show them these terms so they know their 41 | rights. 42 | 43 | We protect your rights with two steps: (1) copyright the software, and 44 | (2) offer you this license which gives you legal permission to copy, 45 | distribute and/or modify the software. 46 | 47 | Also, for each author's protection and ours, we want to make certain 48 | that everyone understands that there is no warranty for this free 49 | software. If the software is modified by someone else and passed on, we 50 | want its recipients to know that what they have is not the original, so 51 | that any problems introduced by others will not reflect on the original 52 | authors' reputations. 53 | 54 | Finally, any free program is threatened constantly by software 55 | patents. We wish to avoid the danger that redistributors of a free 56 | program will individually obtain patent licenses, in effect making the 57 | program proprietary. To prevent this, we have made it clear that any 58 | patent must be licensed for everyone's free use or not licensed at all. 59 | 60 | The precise terms and conditions for copying, distribution and 61 | modification follow. 62 | 63 | GNU GENERAL PUBLIC LICENSE 64 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 65 | 66 | 0. This License applies to any program or other work which contains 67 | a notice placed by the copyright holder saying it may be distributed 68 | under the terms of this General Public License. The "Program", below, 69 | refers to any such program or work, and a "work based on the Program" 70 | means either the Program or any derivative work under copyright law: 71 | that is to say, a work containing the Program or a portion of it, 72 | either verbatim or with modifications and/or translated into another 73 | language. (Hereinafter, translation is included without limitation in 74 | the term "modification".) Each licensee is addressed as "you". 75 | 76 | Activities other than copying, distribution and modification are not 77 | covered by this License; they are outside its scope. The act of 78 | running the Program is not restricted, and the output from the Program 79 | is covered only if its contents constitute a work based on the 80 | Program (independent of having been made by running the Program). 81 | Whether that is true depends on what the Program does. 82 | 83 | 1. You may copy and distribute verbatim copies of the Program's 84 | source code as you receive it, in any medium, provided that you 85 | conspicuously and appropriately publish on each copy an appropriate 86 | copyright notice and disclaimer of warranty; keep intact all the 87 | notices that refer to this License and to the absence of any warranty; 88 | and give any other recipients of the Program a copy of this License 89 | along with the Program. 90 | 91 | You may charge a fee for the physical act of transferring a copy, and 92 | you may at your option offer warranty protection in exchange for a fee. 93 | 94 | 2. You may modify your copy or copies of the Program or any portion 95 | of it, thus forming a work based on the Program, and copy and 96 | distribute such modifications or work under the terms of Section 1 97 | above, provided that you also meet all of these conditions: 98 | 99 | a) You must cause the modified files to carry prominent notices 100 | stating that you changed the files and the date of any change. 101 | 102 | b) You must cause any work that you distribute or publish, that in 103 | whole or in part contains or is derived from the Program or any 104 | part thereof, to be licensed as a whole at no charge to all third 105 | parties under the terms of this License. 106 | 107 | c) If the modified program normally reads commands interactively 108 | when run, you must cause it, when started running for such 109 | interactive use in the most ordinary way, to print or display an 110 | announcement including an appropriate copyright notice and a 111 | notice that there is no warranty (or else, saying that you provide 112 | a warranty) and that users may redistribute the program under 113 | these conditions, and telling the user how to view a copy of this 114 | License. (Exception: if the Program itself is interactive but 115 | does not normally print such an announcement, your work based on 116 | the Program is not required to print an announcement.) 117 | 118 | These requirements apply to the modified work as a whole. If 119 | identifiable sections of that work are not derived from the Program, 120 | and can be reasonably considered independent and separate works in 121 | themselves, then this License, and its terms, do not apply to those 122 | sections when you distribute them as separate works. But when you 123 | distribute the same sections as part of a whole which is a work based 124 | on the Program, the distribution of the whole must be on the terms of 125 | this License, whose permissions for other licensees extend to the 126 | entire whole, and thus to each and every part regardless of who wrote it. 127 | 128 | Thus, it is not the intent of this section to claim rights or contest 129 | your rights to work written entirely by you; rather, the intent is to 130 | exercise the right to control the distribution of derivative or 131 | collective works based on the Program. 132 | 133 | In addition, mere aggregation of another work not based on the Program 134 | with the Program (or with a work based on the Program) on a volume of 135 | a storage or distribution medium does not bring the other work under 136 | the scope of this License. 137 | 138 | 3. You may copy and distribute the Program (or a work based on it, 139 | under Section 2) in object code or executable form under the terms of 140 | Sections 1 and 2 above provided that you also do one of the following: 141 | 142 | a) Accompany it with the complete corresponding machine-readable 143 | source code, which must be distributed under the terms of Sections 144 | 1 and 2 above on a medium customarily used for software interchange; or, 145 | 146 | b) Accompany it with a written offer, valid for at least three 147 | years, to give any third party, for a charge no more than your 148 | cost of physically performing source distribution, a complete 149 | machine-readable copy of the corresponding source code, to be 150 | distributed under the terms of Sections 1 and 2 above on a medium 151 | customarily used for software interchange; or, 152 | 153 | c) Accompany it with the information you received as to the offer 154 | to distribute corresponding source code. (This alternative is 155 | allowed only for noncommercial distribution and only if you 156 | received the program in object code or executable form with such 157 | an offer, in accord with Subsection b above.) 158 | 159 | The source code for a work means the preferred form of the work for 160 | making modifications to it. For an executable work, complete source 161 | code means all the source code for all modules it contains, plus any 162 | associated interface definition files, plus the scripts used to 163 | control compilation and installation of the executable. However, as a 164 | special exception, the source code distributed need not include 165 | anything that is normally distributed (in either source or binary 166 | form) with the major components (compiler, kernel, and so on) of the 167 | operating system on which the executable runs, unless that component 168 | itself accompanies the executable. 169 | 170 | If distribution of executable or object code is made by offering 171 | access to copy from a designated place, then offering equivalent 172 | access to copy the source code from the same place counts as 173 | distribution of the source code, even though third parties are not 174 | compelled to copy the source along with the object code. 175 | 176 | 4. You may not copy, modify, sublicense, or distribute the Program 177 | except as expressly provided under this License. Any attempt 178 | otherwise to copy, modify, sublicense or distribute the Program is 179 | void, and will automatically terminate your rights under this License. 180 | However, parties who have received copies, or rights, from you under 181 | this License will not have their licenses terminated so long as such 182 | parties remain in full compliance. 183 | 184 | 5. You are not required to accept this License, since you have not 185 | signed it. However, nothing else grants you permission to modify or 186 | distribute the Program or its derivative works. These actions are 187 | prohibited by law if you do not accept this License. Therefore, by 188 | modifying or distributing the Program (or any work based on the 189 | Program), you indicate your acceptance of this License to do so, and 190 | all its terms and conditions for copying, distributing or modifying 191 | the Program or works based on it. 192 | 193 | 6. Each time you redistribute the Program (or any work based on the 194 | Program), the recipient automatically receives a license from the 195 | original licensor to copy, distribute or modify the Program subject to 196 | these terms and conditions. You may not impose any further 197 | restrictions on the recipients' exercise of the rights granted herein. 198 | You are not responsible for enforcing compliance by third parties to 199 | this License. 200 | 201 | 7. If, as a consequence of a court judgment or allegation of patent 202 | infringement or for any other reason (not limited to patent issues), 203 | conditions are imposed on you (whether by court order, agreement or 204 | otherwise) that contradict the conditions of this License, they do not 205 | excuse you from the conditions of this License. If you cannot 206 | distribute so as to satisfy simultaneously your obligations under this 207 | License and any other pertinent obligations, then as a consequence you 208 | may not distribute the Program at all. For example, if a patent 209 | license would not permit royalty-free redistribution of the Program by 210 | all those who receive copies directly or indirectly through you, then 211 | the only way you could satisfy both it and this License would be to 212 | refrain entirely from distribution of the Program. 213 | 214 | If any portion of this section is held invalid or unenforceable under 215 | any particular circumstance, the balance of the section is intended to 216 | apply and the section as a whole is intended to apply in other 217 | circumstances. 218 | 219 | It is not the purpose of this section to induce you to infringe any 220 | patents or other property right claims or to contest validity of any 221 | such claims; this section has the sole purpose of protecting the 222 | integrity of the free software distribution system, which is 223 | implemented by public license practices. Many people have made 224 | generous contributions to the wide range of software distributed 225 | through that system in reliance on consistent application of that 226 | system; it is up to the author/donor to decide if he or she is willing 227 | to distribute software through any other system and a licensee cannot 228 | impose that choice. 229 | 230 | This section is intended to make thoroughly clear what is believed to 231 | be a consequence of the rest of this License. 232 | 233 | 8. If the distribution and/or use of the Program is restricted in 234 | certain countries either by patents or by copyrighted interfaces, the 235 | original copyright holder who places the Program under this License 236 | may add an explicit geographical distribution limitation excluding 237 | those countries, so that distribution is permitted only in or among 238 | countries not thus excluded. In such case, this License incorporates 239 | the limitation as if written in the body of this License. 240 | 241 | 9. The Free Software Foundation may publish revised and/or new versions 242 | of the General Public License from time to time. Such new versions will 243 | be similar in spirit to the present version, but may differ in detail to 244 | address new problems or concerns. 245 | 246 | Each version is given a distinguishing version number. If the Program 247 | specifies a version number of this License which applies to it and "any 248 | later version", you have the option of following the terms and conditions 249 | either of that version or of any later version published by the Free 250 | Software Foundation. If the Program does not specify a version number of 251 | this License, you may choose any version ever published by the Free Software 252 | Foundation. 253 | 254 | 10. If you wish to incorporate parts of the Program into other free 255 | programs whose distribution conditions are different, write to the author 256 | to ask for permission. For software which is copyrighted by the Free 257 | Software Foundation, write to the Free Software Foundation; we sometimes 258 | make exceptions for this. Our decision will be guided by the two goals 259 | of preserving the free status of all derivatives of our free software and 260 | of promoting the sharing and reuse of software generally. 261 | 262 | NO WARRANTY 263 | 264 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 265 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 266 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 267 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 268 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 269 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 270 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 271 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 272 | REPAIR OR CORRECTION. 273 | 274 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 275 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 276 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 277 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 278 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 279 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 280 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 281 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 282 | POSSIBILITY OF SUCH DAMAGES. 283 | 284 | END OF TERMS AND CONDITIONS 285 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | JSSRC project is aimed at creating high quality audio resampler written in pure java. 2 | 3 | It is based on the SSRC High Quality Audio Sampling Rate Converter (http://shibatch.sourceforge.net/) by Naoki Shibata written in C. 4 | Naohide Sano ported the C code into java. 5 | Finally, a number of small modification were performed in order to have a java resampling service that is easy to use. 6 | 7 | You can find some examples of upsampling/downsampling in the test directory -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 4.0.0 6 | com.jssrc 7 | jssrc 8 | jar 9 | 1.0.2-SNAPSHOT 10 | JSSRC -- High Quality Java SSRC Resampler 11 | 12 | JSSRC -- High Quality Java SSRC Resampler project 13 | 14 | http://jssrc.khadkevich.org 15 | 16 | 17 | 18 | repo-snapshot 19 | Snapshots repository 20 | ${env.MAVEN_ARTIFACTORY_SNAPSHOTS} 21 | 22 | 23 | repo-release 24 | Release repository 25 | ${env.MAVEN_ARTIFACTORY} 26 | 27 | 28 | 29 | 30 | scm:git:git://github.com/hutm/JSSRC.git 31 | scm:git:git@github.com:hutm/JSSRC.git 32 | http://github.com/hutm/JSSRC.git 33 | 34 | 35 | 36 | github 37 | 38 | 39 | 40 | GPL 2 41 | http://www.gnu.org/licenses/gpl-2.0.txt 42 | 43 | 44 | 45 | 46 | 47 | JSSRC mailing list 48 | jssrc@googlegroups.com 49 | http://groups.google.com/group/jssrc 50 | 51 | 52 | 53 | 54 | Maksim Khadkevich 55 | http://www.khadkevich.org 56 | 57 | 58 | 59 | 60 | maksim.khadkevich 61 | Maksim Khadkevich 62 | hutmdev@gmail.com 63 | http://www.khadkevich.org 64 | 65 | developer 66 | 67 | 68 | 69 | 70 | 71 | 72 | Naoki Shibata 73 | shibatch@users.sourceforge.net 74 | 75 | developer 76 | 77 | 78 | 79 | Naohide Sano 80 | vavivavi@yahoo.co.jp 81 | 82 | developer 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | org.apache.maven.plugins 93 | maven-project-info-reports-plugin 94 | 2.0.1 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | org.testng 103 | testng 104 | 6.8 105 | test 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | org.apache.maven.plugins 115 | maven-compiler-plugin 116 | 117 | 1.6 118 | 1.6 119 | 120 | 121 | 122 | 123 | org.apache.maven.plugins 124 | maven-compiler-plugin 125 | 2.3.2 126 | 127 | 1.6 128 | 1.6 129 | 130 | 131 | 132 | 133 | maven-surefire-plugin 134 | 2.12.4 135 | 136 | 137 | src/test/resources/testng.xml 138 | 139 | true 140 | 141 | 142 | 143 | com.github.github 144 | site-maven-plugin 145 | 0.6 146 | 147 | Creating site for ${project.version} 148 | JSSRC 149 | hutm 150 | 151 | 152 | 153 | 154 | site 155 | 156 | site 157 | 158 | 159 | 160 | 161 | 162 | org.apache.maven.plugins 163 | maven-release-plugin 164 | 2.2.2 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /src/main/java/com/jssrc/resample/JSSRCResampler.java: -------------------------------------------------------------------------------- 1 | package com.jssrc.resample; 2 | 3 | 4 | import vavi.sound.pcm.resampling.ssrc.SSRC; 5 | import vavi.util.I0Bessel; 6 | import vavi.util.SplitRadixFft; 7 | 8 | import javax.sound.sampled.AudioFormat; 9 | import java.io.*; 10 | 11 | /** 12 | * @version 1.0 3/25/11 2:38 PM 13 | * @author: Maksim Khadkevich 14 | */ 15 | public class JSSRCResampler extends InputStream { 16 | 17 | 18 | protected AudioFormat inAudioFormat; 19 | protected AudioFormat outAudioFormat; 20 | 21 | 22 | protected InputStream ssrcInputStream; 23 | 24 | 25 | protected DataOutputStream dataOutputStream; 26 | protected DataInputStream dataInputStream; 27 | 28 | protected PipedInputStream pipedInputStream; 29 | protected PipedOutputStream pipedOutputStream; 30 | 31 | 32 | protected Runnable resamplingRunnable; 33 | protected Thread resamplingThread; 34 | 35 | 36 | protected ByteArrayInputStream byteArrayInputStream; 37 | 38 | 39 | public JSSRCResampler(AudioFormat inAudioFormat, AudioFormat outAudioFormat, InputStream inputStream) { 40 | this.inAudioFormat = inAudioFormat; 41 | this.outAudioFormat = outAudioFormat; 42 | this.ssrcInputStream = inputStream; 43 | initialize(); 44 | } 45 | 46 | 47 | protected void initialize() { 48 | 49 | if (outAudioFormat.getSampleRate() == inAudioFormat.getSampleRate()) { 50 | System.out.println("No sample rate conversion is needed"); 51 | return; 52 | } 53 | initializeClasses(); 54 | try { 55 | pipedInputStream = new PipedInputStream(); 56 | dataInputStream = new DataInputStream(new BufferedInputStream(pipedInputStream)); 57 | 58 | pipedOutputStream = new PipedOutputStream(pipedInputStream); 59 | dataOutputStream = new DataOutputStream(pipedOutputStream); 60 | 61 | ssrcInputStream = new BufferedInputStream(ssrcInputStream); 62 | 63 | resamplingRunnable = new Runnable() { 64 | public void run() { 65 | try { 66 | new SSRC(ssrcInputStream, dataOutputStream, (int) inAudioFormat.getSampleRate(), (int) outAudioFormat.getSampleRate(), 67 | inAudioFormat.getFrameSize() / inAudioFormat.getChannels(), 68 | inAudioFormat.getFrameSize() / inAudioFormat.getChannels(), 69 | inAudioFormat.getChannels(), Integer.MAX_VALUE, 0, 0, true); 70 | } catch (IOException e) { 71 | e.printStackTrace(); 72 | } 73 | } 74 | }; 75 | resamplingThread = new Thread(resamplingRunnable); 76 | resamplingThread.start(); 77 | this.byteArrayInputStream = new ByteArrayInputStream(new byte[0]); 78 | } catch (IOException e) { 79 | e.printStackTrace(); 80 | } 81 | } 82 | 83 | 84 | private void initializeClasses(){ 85 | try { 86 | Class.forName(SSRC.class.getName()); 87 | Class.forName(I0Bessel.class.getName()); 88 | Class.forName(SplitRadixFft.class.getName()); 89 | } catch (ClassNotFoundException e) { 90 | e.printStackTrace(); 91 | } 92 | } 93 | 94 | 95 | @Override 96 | public int read() throws IOException { 97 | if (byteArrayInputStream.available() <= 0) { 98 | fillByteArrayInputStream(); 99 | } 100 | return byteArrayInputStream.read(); 101 | } 102 | 103 | 104 | protected int fillByteArrayInputStream() throws IOException { 105 | int bytesRead; 106 | byte[] newData = new byte[65536]; 107 | if (resamplingThread.isAlive()) { 108 | bytesRead = dataInputStream.read(newData); 109 | } else { 110 | return -1; 111 | } 112 | if (bytesRead <= 0) { 113 | return -1; 114 | } else { 115 | byteArrayInputStream = new ByteArrayInputStream(newData, 0, bytesRead); 116 | return bytesRead; 117 | } 118 | } 119 | 120 | public void close() throws IOException { 121 | if (resamplingThread.isAlive()) { 122 | resamplingThread.stop(); 123 | } 124 | pipedInputStream.close(); 125 | pipedOutputStream.close(); 126 | } 127 | 128 | @Override 129 | public int available() throws IOException { 130 | if (byteArrayInputStream.available() > 0) { 131 | return byteArrayInputStream.available(); 132 | } 133 | int filledBytes = fillByteArrayInputStream(); 134 | if (filledBytes > 0) { 135 | return filledBytes; 136 | } else { 137 | return -1; 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/com/jssrc/resample/JSSRCSampleRateConversionProvider.java: -------------------------------------------------------------------------------- 1 | package com.jssrc.resample; 2 | 3 | 4 | import javax.sound.sampled.AudioFormat; 5 | import javax.sound.sampled.AudioInputStream; 6 | import javax.sound.sampled.AudioSystem; 7 | import javax.sound.sampled.spi.FormatConversionProvider; 8 | 9 | /** 10 | * @author Maksim Khadkevich 11 | */ 12 | 13 | public class JSSRCSampleRateConversionProvider extends FormatConversionProvider { 14 | private static final AudioFormat.Encoding[] inputEncodings = { 15 | AudioFormat.Encoding.PCM_SIGNED, 16 | }; 17 | 18 | private static final AudioFormat.Encoding[] outputEncodings = { 19 | AudioFormat.Encoding.PCM_SIGNED, 20 | }; 21 | 22 | 23 | public AudioFormat.Encoding[] getSourceEncodings() { 24 | AudioFormat.Encoding[] encodings = new AudioFormat.Encoding[inputEncodings.length]; 25 | System.arraycopy(inputEncodings, 0, encodings, 0, inputEncodings.length); 26 | return encodings; 27 | } 28 | 29 | public AudioFormat.Encoding[] getTargetEncodings() { 30 | AudioFormat.Encoding[] encodings = new AudioFormat.Encoding[outputEncodings.length]; 31 | System.arraycopy(outputEncodings, 0, encodings, 0, outputEncodings.length); 32 | return encodings; 33 | } 34 | 35 | 36 | public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat) { 37 | if (sourceFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) { 38 | 39 | AudioFormat.Encoding encs[] = new AudioFormat.Encoding[1]; 40 | encs[0] = AudioFormat.Encoding.PCM_SIGNED; 41 | return encs; 42 | } else { 43 | return new AudioFormat.Encoding[0]; 44 | } 45 | } 46 | 47 | 48 | public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) { 49 | return new AudioFormat[0]; 50 | } 51 | 52 | 53 | /** 54 | */ 55 | public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream) { 56 | 57 | if (isConversionSupported(targetEncoding, sourceStream.getFormat())) { 58 | 59 | AudioFormat sourceFormat = sourceStream.getFormat(); 60 | AudioFormat targetFormat = new AudioFormat(targetEncoding, 61 | sourceFormat.getSampleRate(), 62 | sourceFormat.getSampleSizeInBits(), 63 | sourceFormat.getChannels(), 64 | sourceFormat.getFrameSize(), 65 | sourceFormat.getFrameRate(), 66 | sourceFormat.isBigEndian()); 67 | 68 | return getAudioInputStream(targetFormat, sourceStream); 69 | 70 | } else { 71 | throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString()); 72 | } 73 | 74 | } 75 | 76 | 77 | public AudioInputStream getAudioInputStream(AudioFormat targetFormat, AudioInputStream sourceStream) { 78 | 79 | AudioFormat inputFormat = sourceStream.getFormat(); 80 | AudioFormat outputFormat = targetFormat; 81 | 82 | if (isConversionSupported(inputFormat, outputFormat)) { 83 | JSSRCResampler resampler = new JSSRCResampler(inputFormat, outputFormat, sourceStream); 84 | // set sample size from source stream if possible 85 | long length = AudioSystem.NOT_SPECIFIED; 86 | if (AudioSystem.NOT_SPECIFIED != sourceStream.getFrameLength()) { 87 | length = (long) (sourceStream.getFrameLength() * targetFormat.getSampleRate() / inputFormat.getSampleRate()); 88 | } 89 | return new AudioInputStream(resampler, outputFormat, length); 90 | } 91 | throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetFormat.toString()); 92 | } 93 | 94 | 95 | /** 96 | * Determines whether the codec supports conversion from one 97 | * particular format to another. 98 | * 99 | * @param inputFormat format of the incoming data 100 | * @return true if the conversion is supported, otherwise false 101 | */ 102 | public boolean isConversionSupported(AudioFormat inputFormat, AudioFormat outputFormat) { 103 | 104 | AudioFormat.Encoding inputEncoding = inputFormat.getEncoding(); 105 | AudioFormat.Encoding outputEncoding = outputFormat.getEncoding(); 106 | int inputSampleSize = inputFormat.getSampleSizeInBits(); 107 | int outputSampleSize = outputFormat.getSampleSizeInBits(); 108 | boolean inputIsBigEndian = inputFormat.isBigEndian(); 109 | boolean outputIsBigEndian = outputFormat.isBigEndian(); 110 | 111 | if (inputFormat.getSampleRate() == outputFormat.getSampleRate()) { 112 | return false; 113 | } 114 | 115 | if (inputIsBigEndian || outputIsBigEndian) { 116 | return false; 117 | } 118 | 119 | 120 | if (((inputSampleSize == 8) && (outputSampleSize == 8)) || 121 | ((inputSampleSize == 16) && (outputSampleSize == 16))) { 122 | 123 | if ((inputEncoding == AudioFormat.Encoding.PCM_SIGNED)) { 124 | if ((outputEncoding == AudioFormat.Encoding.PCM_SIGNED)) { 125 | return true; 126 | } else { 127 | return false; 128 | } 129 | } else { 130 | return false; 131 | } 132 | } else { 133 | return false; 134 | } 135 | } 136 | 137 | 138 | } 139 | 140 | -------------------------------------------------------------------------------- /src/main/java/vavi/util/I0Bessel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(C) 1996 Takuya OOURA (email: ooura@mmm.t.u-tokyo.ac.jp). 3 | * You may use, copy, modify this code for any purpose and 4 | * without fee. You may distribute this ORIGINAL package. 5 | */ 6 | package vavi.util; 7 | 8 | 9 | /** 10 | * Bessel I_0(). 11 | * 12 | * @author Takuya OOURA 13 | * @author Naohide Sano (nsano) 14 | * @version 0.00 060127 nsano port to java version
15 | */ 16 | public class I0Bessel { 17 | /** */ 18 | private static final double[] a = { 19 | 8.5246820682016865877e-11, 2.5966600546497407288e-9, 20 | 7.9689994568640180274e-8, 1.9906710409667748239e-6, 21 | 4.0312469446528002532e-5, 6.4499871606224265421e-4, 22 | 0.0079012345761930579108, 0.071111111109207045212, 23 | 0.444444444444724909, 1.7777777777777532045, 24 | 4.0000000000000011182, 3.99999999999999998, 25 | 1.0000000000000000001, 26 | 1.1520919130377195927e-10, 2.2287613013610985225e-9, 27 | 8.1903951930694585113e-8, 1.9821560631611544984e-6, 28 | 4.0335461940910133184e-5, 6.4495330974432203401e-4, 29 | 0.0079013012611467520626, 0.071111038160875566622, 30 | 0.44444450319062699316, 1.7777777439146450067, 31 | 4.0000000132337935071, 3.9999999968569015366, 32 | 1.0000000003426703174, 33 | 1.5476870780515238488e-10, 1.2685004214732975355e-9, 34 | 9.2776861851114223267e-8, 1.9063070109379044378e-6, 35 | 4.0698004389917945832e-5, 6.4370447244298070713e-4, 36 | 0.0079044749458444976958, 0.071105052411749363882, 37 | 0.44445280640924755082, 1.7777694934432109713, 38 | 4.0000055808824003386, 3.9999977081165740932, 39 | 1.0000004333949319118, 40 | 2.0675200625006793075e-10, -6.1689554705125681442e-10, 41 | 1.2436765915401571654e-7, 1.5830429403520613423e-6, 42 | 4.2947227560776583326e-5, 6.3249861665073441312e-4, 43 | 0.0079454472840953930811, 0.070994327785661860575, 44 | 0.44467219586283000332, 1.7774588182255374745, 45 | 4.0003038986252717972, 3.9998233869142057195, 46 | 1.0000472932961288324, 47 | 2.7475684794982708655e-10, -3.8991472076521332023e-9, 48 | 1.9730170483976049388e-7, 5.9651531561967674521e-7, 49 | 5.1992971474748995357e-5, 5.7327338675433770752e-4, 50 | 0.0082293143836530412024, 0.069990934858728039037, 51 | 0.44726764292723985087, 1.7726685170014087784, 52 | 4.0062907863712704432, 3.9952750700487845355, 53 | 1.0016354346654179322 54 | }; 55 | /** */ 56 | private static final double[] b = { 57 | 6.7852367144945531383e-8, 4.6266061382821826854e-7, 58 | 6.9703135812354071774e-6, 7.6637663462953234134e-5, 59 | 7.9113515222612691636e-4, 0.0073401204731103808981, 60 | 0.060677114958668837046, 0.43994941411651569622, 61 | 2.7420017097661750609, 14.289661921740860534, 62 | 59.820609640320710779, 188.78998681199150629, 63 | 399.8731367825601118, 427.56411572180478514, 64 | 1.8042097874891098754e-7, 1.2277164312044637357e-6, 65 | 1.8484393221474274861e-5, 2.0293995900091309208e-4, 66 | 0.0020918539850246207459, 0.019375315654033949297, 67 | 0.15985869016767185908, 1.1565260527420641724, 68 | 7.1896341224206072113, 37.354773811947484532, 69 | 155.80993164266268457, 489.5211371158540918, 70 | 1030.9147225169564806, 1093.5883545113746958, 71 | 4.8017305613187493564e-7, 3.261317843912380074e-6, 72 | 4.9073137508166159639e-5, 5.3806506676487583755e-4, 73 | 0.0055387918291051866561, 0.051223717488786549025, 74 | 0.42190298621367914765, 3.0463625987357355872, 75 | 18.895299447327733204, 97.915189029455461554, 76 | 407.13940115493494659, 1274.3088990480582632, 77 | 2670.9883037012547506, 2815.7166284662544712, 78 | 1.2789926338424623394e-6, 8.6718263067604918916e-6, 79 | 1.3041508821299929489e-4, 0.001428224737372747892, 80 | 0.014684070635768789378, 0.13561403190404185755, 81 | 1.1152592585977393953, 8.0387088559465389038, 82 | 49.761318895895479206, 257.2684232313529138, 83 | 1066.8543146269566231, 3328.3874581009636362, 84 | 6948.8586598121634874, 7288.4893398212481055, 85 | 3.409350368197032893e-6, 2.3079025203103376076e-5, 86 | 3.4691373283901830239e-4, 0.003794994977222908545, 87 | 0.038974209677945602145, 0.3594948380414878371, 88 | 2.9522878893539528226, 21.246564609514287056, 89 | 131.28727387146173141, 677.38107093296675421, 90 | 2802.3724744545046518, 8718.5731420798254081, 91 | 18141.348781638832286, 18948.925349296308859 92 | }; 93 | /** */ 94 | private static final double[] c = { 95 | 2.5568678676452702768e-15, 3.0393953792305924324e-14, 96 | 6.3343751991094840009e-13, 1.5041298011833009649e-11, 97 | 4.4569436918556541414e-10, 1.746393051427167951e-8, 98 | 1.0059224011079852317e-6, 1.0729838945088577089e-4, 99 | 0.05150322693642527738, 100 | 5.2527963991711562216e-15, 7.202118481421005641e-15, 101 | 7.2561421229904797156e-13, 1.482312146673104251e-11, 102 | 4.4602670450376245434e-10, 1.7463600061788679671e-8, 103 | 1.005922609132234756e-6, 1.0729838937545111487e-4, 104 | 0.051503226936437300716, 105 | 1.3365917359358069908e-14, -1.2932643065888544835e-13, 106 | 1.7450199447905602915e-12, 1.0419051209056979788e-11, 107 | 4.58047881980598326e-10, 1.7442405450073548966e-8, 108 | 1.0059461453281292278e-6, 1.0729837434500161228e-4, 109 | 0.051503226940658446941, 110 | 5.3771611477352308649e-14, -1.1396193006413731702e-12, 111 | 1.2858641335221653409e-11, -5.9802086004570057703e-11, 112 | 7.3666894305929510222e-10, 1.6731837150730356448e-8, 113 | 1.0070831435812128922e-6, 1.0729733111203704813e-4, 114 | 0.051503227360726294675, 115 | 3.7819492084858931093e-14, -4.8600496888588034879e-13, 116 | 1.6898350504817224909e-12, 4.5884624327524255865e-11, 117 | 1.2521615963377513729e-10, 1.8959658437754727957e-8, 118 | 1.0020716710561353622e-6, 1.073037119856927559e-4, 119 | 0.05150322383300230775 120 | }; 121 | 122 | /** 123 | * 124 | * @param x 125 | * @return 126 | */ 127 | public static double value(double x) { 128 | int k; 129 | double w, t, y; 130 | w = Math.abs(x); 131 | if (w < 8.5) { 132 | t = w * w * 0.0625; 133 | k = 13 * ((int) t); 134 | y = (((((((((((a[k] * t + a[k + 1]) * t + 135 | a[k + 2]) * t + a[k + 3]) * t + a[k + 4]) * t + 136 | a[k + 5]) * t + a[k + 6]) * t + a[k + 7]) * t + 137 | a[k + 8]) * t + a[k + 9]) * t + a[k + 10]) * t + 138 | a[k + 11]) * t + a[k + 12]; 139 | } else if (w < 12.5) { 140 | k = (int) w; 141 | t = w - k; 142 | k = 14 * (k - 8); 143 | y = ((((((((((((b[k] * t + b[k + 1]) * t + 144 | b[k + 2]) * t + b[k + 3]) * t + b[k + 4]) * t + 145 | b[k + 5]) * t + b[k + 6]) * t + b[k + 7]) * t + 146 | b[k + 8]) * t + b[k + 9]) * t + b[k + 10]) * t + 147 | b[k + 11]) * t + b[k + 12]) * t + b[k + 13]; 148 | } else { 149 | t = 60 / w; 150 | k = 9 * ((int) t); 151 | y = ((((((((c[k] * t + c[k + 1]) * t + 152 | c[k + 2]) * t + c[k + 3]) * t + c[k + 4]) * t + 153 | c[k + 5]) * t + c[k + 6]) * t + c[k + 7]) * t + 154 | c[k + 8]) * Math.sqrt(t) * Math.exp(w); 155 | } 156 | return y; 157 | } 158 | } 159 | 160 | /* */ 161 | -------------------------------------------------------------------------------- /src/main/java/vavi/util/SplitRadixFft.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Takuya OOURA, 1996-2001 3 | * 4 | * You may use, copy, modify and distribute this code 5 | * for any purpose (include commercial use) and without fee. 6 | * Please refer to this package when you modify this code. 7 | */ 8 | package vavi.util; 9 | 10 | 11 | 12 | 13 | /** 14 | * Fast Fourier/Cosine/Sine Transform. 15 | *
  16 |  *  dimension   :one
  17 |  *  data length :power of 2
  18 |  *  decimation  :frequency
  19 |  *  radix       :split-radix
  20 |  *  data        :inplace
  21 |  *  table       :use
  22 |  * 
23 | *

Appendix:

24 | *

25 | * The cos/sin table is recalculated when the larger table required. 26 | * w[] and ip[] are compatible with all routines. 27 | *

28 | * @author Takuya OOURA 29 | * @author Naohide Sano (nsano) 30 | * @version 0.00 060127 nsano port to java version
31 | */ 32 | public class SplitRadixFft { 33 | 34 | /** */ 35 | private static final int CDFT_RECURSIVE_N = 512; 36 | 37 | /** 38 | * Complex Discrete Fourier Transform. 39 | *
  40 |      *  [definition]
  41 |      *      <case1>
  42 |      *          X[k] = sum_j=0&circ;n-1 x[j]*exp(2*pi*i*j*k/n), 0<=k<n
  43 |      *      <case2>
  44 |      *          X[k] = sum_j=0&circ;n-1 x[j]*exp(-2*pi*i*j*k/n), 0<=k<n
  45 |      *      (notes: sum_j=0&circ;n-1 is a summation from j=0 to n-1)
  46 |      *  [usage]
  47 |      *      <case1>
  48 |      *          ip[0] = 0; // first time only
  49 |      *          cdft(2*n, 1, a, ip, w);
  50 |      *      <case2>
  51 |      *          ip[0] = 0; // first time only
  52 |      *          cdft(2*n, -1, a, ip, w);
  53 |      *  [remark]
  54 |      *      Inverse of
  55 |      *          cdft(2*n, -1, a, ip, w);
  56 |      *      is
  57 |      *          cdft(2*n, 1, a, ip, w);
  58 |      *          for (j = 0; j <= 2 * n - 1; j++) {
  59 |      *              a[j] *= 1.0 / n;
  60 |      *          }
  61 |      *      .
  62 |      * 
63 | * @param n 2*n data length (int) 64 | * n >= 1, n = power of 2 65 | * @param isgn 66 | * @param a a[0...2*n-1] input/output data (REAL *) 67 | * input data 68 | * a[2*j] = Re(x[j]), 69 | * a[2*j+1] = Im(x[j]), 0<=j<n 70 | * output data 71 | * a[2*k] = Re(X[k]), 72 | * a[2*k+1] = Im(X[k]), 0<=k<n 73 | * @param ip ip[0...*] work area for bit reversal (int *) 74 | * length of ip >= 2+sqrt(n) 75 | * strictly, 76 | * length of ip >= 77 | * 2+(1<<(int)(log(n+0.5)/log(2))/2). 78 | * ip[0],ip[1] are pointers of the cos/sin table. 79 | * @param w w[0...n/2-1] cos/sin table (REAL *) 80 | * w[],ip[] are initialized if ip[0] == 0. 81 | */ 82 | public void cdft(int n, int isgn, double[] a, int[] ip, double[] w) { 83 | int nw; 84 | 85 | nw = ip[0]; 86 | if (n > (nw << 2)) { 87 | nw = n >> 2; 88 | makewt(nw, ip, w); 89 | } 90 | if (isgn >= 0) { 91 | cftfsub(n, a, ip, 2, nw, w); 92 | } else { 93 | cftbsub(n, a, ip, 2, nw, w); 94 | } 95 | } 96 | 97 | /** 98 | * Real Discrete Fourier Transform. 99 | *
 100 |      *  [definition]
 101 |      *      <case1> RDFT
 102 |      *          R[k] = sum_j = 0 & ˆ (n - 1) a[j] * cos(2 * pi * j * k / n), 0 <= k <= n / 2
 103 |      *          I[k] = sum_j = 0 & ˆ (n - 1) a[j] * sin(2 * pi * j * k / n), 0 < k < n / 2
 104 |      *      <case2> IRDFT (excluding scale)
 105 |      *          a[k] = (R[0] + R[n / 2] * cos(pi * k)) / 2 +
 106 |      *              sum_j = 1 & ˆ (n / 2 - 1) R[j] * cos(2 * pi * j * k / n) +
 107 |      *              sum_j = 1 & ˆ (n / 2 - 1) I[j] * sin(2 * pi * j * k / n), 0 <= k < n
 108 |      *  [usage]
 109 |      *      <case1>
 110 |      *          ip[0] = 0; // first time only
 111 |      *          rdft(n, 1, a, ip, w);
 112 |      *      <case2>
 113 |      *          ip[0] = 0; // first time only
 114 |      *          rdft(n, -1, a, ip, w);
 115 |      *  [remark]
 116 |      *      Inverse of
 117 |      *          rdft(n, 1, a, ip, w);
 118 |      *      is
 119 |      *          rdft(n, -1, a, ip, w);
 120 |      *          for (j = 0; j <= n - 1; j++) {
 121 |      *              a[j] *= 2.0 / n;
 122 |      *          }
 123 |      *      .
 124 |      * 
125 | * @param n data length
126 | * n >= 2, n = power of 2 127 | * @param isgn 128 | * @param a [0...n-1] input/output data 129 | *
 130 |      *  <case1>
 131 |      *      output data
 132 |      *          a[2 * k] = R[k], 0 <= k < n / 2
 133 |      *          a[2 * k + 1] = I[k], 0 < k < n / 2
 134 |      *          a[1] = R[n/2]
 135 |      *  <case2>
 136 |      *      input data
 137 |      *          a[2 * j] = R[j], 0 <= j < n / 2
 138 |      *          a[2 * j + 1] = I[j], 0 < j < n / 2
 139 |      *          a[1] = R[n / 2]
 140 |      * 
141 | * @param ip [0...*] work area for bit reversal 142 | *
 143 |      *  length of ip >= 2 + sqrt(n / 2)
 144 |      *  strictly,
 145 |      *  length of ip >=
 146 |      *      2 + (1 << (int) (log(n / 2 + 0.5) / log(2)) / 2).
 147 |      * 
148 | * ip[0],ip[1] are pointers of the cos/sin table. 149 | * @param w [0...n/2-1] cos/sin table
150 | * w[],ip[] are initialized if ip[0] == 0. 151 | */ 152 | public void rdft(int n, int isgn, double[] a, int[] ip, double[] w) { 153 | int nw, nc; 154 | double xi; 155 | 156 | nw = ip[0]; 157 | if (n > (nw << 2)) { 158 | nw = n >> 2; 159 | makewt(nw, ip, w); 160 | } 161 | nc = ip[1]; 162 | if (n > (nc << 2)) { 163 | nc = n >> 2; 164 | makect(nc, ip, w, nw); 165 | } 166 | if (isgn >= 0) { 167 | if (n > 4) { 168 | cftfsub(n, a, ip, 2, nw, w); 169 | rftfsub(n, a, nc, w, nw); 170 | } else if (n == 4) { 171 | cftfsub(n, a, ip, 2, nw, w); 172 | } 173 | xi = a[0] - a[1]; 174 | a[0] += a[1]; 175 | a[1] = xi; 176 | } else { 177 | a[1] = 0.5 * (a[0] - a[1]); 178 | a[0] -= a[1]; 179 | if (n > 4) { 180 | rftbsub(n, a, nc, w, nw); 181 | cftbsub(n, a, ip, 2, nw, w); 182 | } else if (n == 4) { 183 | cftbsub(n, a, ip, 2, nw, w); 184 | } 185 | } 186 | } 187 | 188 | /** 189 | * Discrete Cosine Transform. 190 | *
 191 |      *  [definition]
 192 |      *      <case1> IDCT (excluding scale)
 193 |      *          C[k] = sum_j=0&circ;n-1 a[j]*cos(pi*j*(k+1/2)/n), 0<=k<n
 194 |      *      <case2> DCT
 195 |      *          C[k] = sum_j=0&circ;n-1 a[j]*cos(pi*(j+1/2)*k/n), 0<=k<n
 196 |      *  [usage]
 197 |      *      <case1>
 198 |      *          ip[0] = 0; // first time only
 199 |      *          ddct(n, 1, a, ip, w);
 200 |      *      <case2>
 201 |      *          ip[0] = 0; // first time only
 202 |      *          ddct(n, -1, a, ip, w);
 203 |      *  [remark]
 204 |      *      Inverse of
 205 |      *          ddct(n, -1, a, ip, w);
 206 |      *      is
 207 |      *          a[0] *= 0.5;
 208 |      *          ddct(n, 1, a, ip, w);
 209 |      *          for (j = 0; j <= n - 1; j++) {
 210 |      *              a[j] *= 2.0 / n;
 211 |      *          }
 212 |      *      .
 213 |      * 
214 | * @param n data length (int) 215 | *
 216 |      *  n >= 2, n = power of 2
 217 |      * 
218 | * @param isgn 219 | * @param a [0...n-1] input/output data (REAL *) 220 | *
 221 |      *  output data
 222 |      *      a[k] = C[k], 0<=k<n
 223 |      * 
224 | * @param ip [0...*] work area for bit reversal (int *) 225 | *
 226 |      *  length of ip >= 2+sqrt(n/2)
 227 |      *  strictly,
 228 |      *  length of ip >=
 229 |      *      2+(1<<(int)(log(n/2+0.5)/log(2))/2).
 230 |      *  ip[0],ip[1] are pointers of the cos/sin table.
 231 |      * 
232 | * @param w [0...n*5/4-1] cos/sin table (REAL *) 233 | *
 234 |      *  w[],ip[] are initialized if ip[0] == 0.
 235 |      * 
236 | */ 237 | public void ddct(int n, int isgn, double[] a, int[] ip, double[] w) { 238 | int j, nw, nc; 239 | double xr; 240 | 241 | nw = ip[0]; 242 | if (n > (nw << 2)) { 243 | nw = n >> 2; 244 | makewt(nw, ip, w); 245 | } 246 | nc = ip[1]; 247 | if (n > nc) { 248 | nc = n; 249 | makect(nc, ip, w, nw); 250 | } 251 | if (isgn < 0) { 252 | xr = a[n - 1]; 253 | for (j = n - 2; j >= 2; j -= 2) { 254 | a[j + 1] = a[j] - a[j - 1]; 255 | a[j] += a[j - 1]; 256 | } 257 | a[1] = a[0] - xr; 258 | a[0] += xr; 259 | if (n > 4) { 260 | rftbsub(n, a, nc, w, nw); 261 | cftbsub(n, a, ip, 2, nw, w); 262 | } else if (n == 4) { 263 | cftbsub(n, a, ip, 2, nw, w); 264 | } 265 | } 266 | dctsub(n, a, nc, w, nw); 267 | if (isgn >= 0) { 268 | if (n > 4) { 269 | cftfsub(n, a, ip, 2, nw, w); 270 | rftfsub(n, a, nc, w, nw); 271 | } else if (n == 4) { 272 | cftfsub(n, a, ip, 2, nw, w); 273 | } 274 | xr = a[0] - a[1]; 275 | a[0] += a[1]; 276 | for (j = 2; j < n; j += 2) { 277 | a[j - 1] = a[j] - a[j + 1]; 278 | a[j] += a[j + 1]; 279 | } 280 | a[n - 1] = xr; 281 | } 282 | } 283 | 284 | /** 285 | * Discrete Sine Transform. 286 | *
 287 |      *  [definition]
 288 |      *      <case1> IDST (excluding scale)
 289 |      *          S[k] = sum_j=1ˆn A[j]*sin(pi*j*(k+1/2)/n), 0<=k<n
 290 |      *      <case2> DST
 291 |      *          S[k] = sum_j=0ˆn-1 a[j]*sin(pi*(j+1/2)*k/n), 0<k<=n
 292 |      *  [usage]
 293 |      *      <case1>
 294 |      *          ip[0] = 0; // first time only
 295 |      *          ddst(n, 1, a, ip, w);
 296 |      *      <case2>
 297 |      *          ip[0] = 0; // first time only
 298 |      *          ddst(n, -1, a, ip, w);
 299 |      *  [remark]
 300 |      *      Inverse of
 301 |      *          ddst(n, -1, a, ip, w);
 302 |      *      is
 303 |      *          a[0] *= 0.5;
 304 |      *          ddst(n, 1, a, ip, w);
 305 |      *          for (j = 0; j <= n - 1; j++) {
 306 |      *              a[j] *= 2.0 / n;
 307 |      *          }
 308 |      *      .
 309 |      * 
310 | * @param n data length (int) 311 | * n >= 2, n = power of 2 312 | * @param isgn 313 | * @param a [0...n-1] input/output data (REAL *) 314 | * <case1> 315 | * input data 316 | * a[j] = A[j], 0<j<n 317 | * a[0] = A[n] 318 | * output data 319 | * a[k] = S[k], 0<=k<n 320 | * <case2> 321 | * output data 322 | * a[k] = S[k], 0<k<n 323 | * a[0] = S[n] 324 | * @param ip [0...*] work area for bit reversal (int *) 325 | * length of ip >= 2+sqrt(n/2) 326 | * strictly, 327 | * length of ip >= 328 | * 2+(1<<(int)(log(n/2+0.5)/log(2))/2). 329 | * ip[0],ip[1] are pointers of the cos/sin table. 330 | * @param w [0...n*5/4-1] cos/sin table (REAL *) 331 | * w[],ip[] are initialized if ip[0] == 0. 332 | */ 333 | public void ddst(int n, int isgn, double[] a, int[] ip, double[] w) { 334 | int j, nw, nc; 335 | double xr; 336 | 337 | nw = ip[0]; 338 | if (n > (nw << 2)) { 339 | nw = n >> 2; 340 | makewt(nw, ip, w); 341 | } 342 | nc = ip[1]; 343 | if (n > nc) { 344 | nc = n; 345 | makect(nc, ip, w, nw); 346 | } 347 | if (isgn < 0) { 348 | xr = a[n - 1]; 349 | for (j = n - 2; j >= 2; j -= 2) { 350 | a[j + 1] = -a[j] - a[j - 1]; 351 | a[j] -= a[j - 1]; 352 | } 353 | a[1] = a[0] + xr; 354 | a[0] -= xr; 355 | if (n > 4) { 356 | rftbsub(n, a, nc, w, nw); 357 | cftbsub(n, a, ip, 2, nw, w); 358 | } else if (n == 4) { 359 | cftbsub(n, a, ip, 2, nw, w); 360 | } 361 | } 362 | dstsub(n, a, nc, w, nw); 363 | if (isgn >= 0) { 364 | if (n > 4) { 365 | cftfsub(n, a, ip, 2, nw, w); 366 | rftfsub(n, a, nc, w, nw); 367 | } else if (n == 4) { 368 | cftfsub(n, a, ip, 2, nw, w); 369 | } 370 | xr = a[0] - a[1]; 371 | a[0] += a[1]; 372 | for (j = 2; j < n; j += 2) { 373 | a[j - 1] = -a[j] - a[j + 1]; 374 | a[j] -= a[j + 1]; 375 | } 376 | a[n - 1] = -xr; 377 | } 378 | } 379 | 380 | /** 381 | * Cosine Transform of RDFT (Real Symmetric DFT). 382 | *
 383 |      *  [definition]
 384 |      *      C[k] = sum_j=0ˆn a[j]*cos(pi*j*k/n), 0<=k<=n
 385 |      *  [usage]
 386 |      *      ip[0] = 0; // first time only
 387 |      *      dfct(n, a, t, ip, w);
 388 |      *  [parameters]
 389 |      *  [remark]
 390 |      *      Inverse of
 391 |      *          a[0] *= 0.5;
 392 |      *          a[n] *= 0.5;
 393 |      *          dfct(n, a, t, ip, w);
 394 |      *      is
 395 |      *          a[0] *= 0.5;
 396 |      *          a[n] *= 0.5;
 397 |      *          dfct(n, a, t, ip, w);
 398 |      *          for (j = 0; j <= n; j++) {
 399 |      *              a[j] *= 2.0 / n;
 400 |      *          }
 401 |      *      .
 402 |      * 
403 | * @param n data length - 1 (int) 404 | *
 405 |      *  n >= 2, n = power of 2
 406 |      * 
407 | * @param a [0...n] input/output data (REAL *) 408 | *
 409 |      *  output data
 410 |      *      a[k] = C[k], 0<=k<=n
 411 |      * 
412 | * @param t [0...n/2] work area (REAL *) 413 | * @param ip [0...*] work area for bit reversal (int *) 414 | *
 415 |      *  length of ip >= 2+sqrt(n/4)
 416 |      *  strictly,
 417 |      *  length of ip >=
 418 |      *      2+(1<<(int)(log(n/4+0.5)/log(2))/2).
 419 |      *  ip[0],ip[1] are pointers of the cos/sin table.
 420 |      * 
421 | * @param w [0...n*5/8-1] cos/sin table (REAL *) 422 | *
 423 |      *  w[],ip[] are initialized if ip[0] == 0.
 424 |      * 
425 | */ 426 | public void dfct(int n, double[] a, double[] t, int[] ip, double[] w) { 427 | int j, k, l, m, mh, nw, nc; 428 | double xr, xi, yr, yi; 429 | 430 | nw = ip[0]; 431 | if (n > (nw << 3)) { 432 | nw = n >> 3; 433 | makewt(nw, ip, w); 434 | } 435 | nc = ip[1]; 436 | if (n > (nc << 1)) { 437 | nc = n >> 1; 438 | makect(nc, ip, w, nw); 439 | } 440 | m = n >> 1; 441 | yi = a[m]; 442 | xi = a[0] + a[n]; 443 | a[0] -= a[n]; 444 | t[0] = xi - yi; 445 | t[m] = xi + yi; 446 | if (n > 2) { 447 | mh = m >> 1; 448 | for (j = 1; j < mh; j++) { 449 | k = m - j; 450 | xr = a[j] - a[n - j]; 451 | xi = a[j] + a[n - j]; 452 | yr = a[k] - a[n - k]; 453 | yi = a[k] + a[n - k]; 454 | a[j] = xr; 455 | a[k] = yr; 456 | t[j] = xi - yi; 457 | t[k] = xi + yi; 458 | } 459 | t[mh] = a[mh] + a[n - mh]; 460 | a[mh] -= a[n - mh]; 461 | dctsub(m, a, nc, w, nw); 462 | if (m > 4) { 463 | cftfsub(m, a, ip, 2, nw, w); 464 | rftfsub(m, a, nc, w, nw); 465 | } else if (m == 4) { 466 | cftfsub(m, a, ip, 2, nw, w); 467 | } 468 | a[n - 1] = a[0] - a[1]; 469 | a[1] = a[0] + a[1]; 470 | for (j = m - 2; j >= 2; j -= 2) { 471 | a[2 * j + 1] = a[j] + a[j + 1]; 472 | a[2 * j - 1] = a[j] - a[j + 1]; 473 | } 474 | l = 2; 475 | m = mh; 476 | while (m >= 2) { 477 | dctsub(m, t, nc, w, nw); 478 | if (m > 4) { 479 | cftfsub(m, t, ip, 2, nw, w); 480 | rftfsub(m, t, nc, w, nw); 481 | } else if (m == 4) { 482 | cftfsub(m, t, ip, 2, nw, w); 483 | } 484 | a[n - l] = t[0] - t[1]; 485 | a[l] = t[0] + t[1]; 486 | k = 0; 487 | for (j = 2; j < m; j += 2) { 488 | k += l << 2; 489 | a[k - l] = t[j] - t[j + 1]; 490 | a[k + l] = t[j] + t[j + 1]; 491 | } 492 | l <<= 1; 493 | mh = m >> 1; 494 | for (j = 0; j < mh; j++) { 495 | k = m - j; 496 | t[j] = t[m + k] - t[m + j]; 497 | t[k] = t[m + k] + t[m + j]; 498 | } 499 | t[mh] = t[m + mh]; 500 | m = mh; 501 | } 502 | a[l] = t[0]; 503 | a[n] = t[2] - t[1]; 504 | a[0] = t[2] + t[1]; 505 | } else { 506 | a[1] = a[0]; 507 | a[2] = t[0]; 508 | a[0] = t[1]; 509 | } 510 | } 511 | 512 | /** 513 | * Sine Transform of RDFT (Real Anti-symmetric DFT). 514 | *
 515 |      *  [definition]
 516 |      *      S[k] = sum_j=1&circ;n-1 a[j]*sin(pi*j*k/n), 0<k<n
 517 |      *  [usage]
 518 |      *      ip[0] = 0; // first time only
 519 |      *      dfst(n, a, t, ip, w);
 520 |      *  [remark]
 521 |      *      Inverse of
 522 |      *          dfst(n, a, t, ip, w);
 523 |      *      is
 524 |      *          dfst(n, a, t, ip, w);
 525 |      *          for (j = 1; j <= n - 1; j++) {
 526 |      *              a[j] *= 2.0 / n;
 527 |      *          }
 528 |      *      .
 529 |      * 
530 | * @param n data length + 1 (int) 531 | *
 532 |      *  n >= 2, n = power of 2
 533 |      * 
534 | * @param a [0...n-1] input/output data (REAL *) 535 | *
 536 |      *  output data
 537 |      *      a[k] = S[k], 0<k<n
 538 |      *      (a[0] is used for work area)
 539 |      * 
540 | * @param t [0...n/2-1] work area (REAL *) 541 | * @param ip [0...*] work area for bit reversal (int *) 542 | *
 543 |      *  length of ip >= 2+sqrt(n/4)
 544 |      *  strictly,
 545 |      *  length of ip >=
 546 |      *      2+(1<<(int)(log(n/4+0.5)/log(2))/2).
 547 |      *  ip[0],ip[1] are pointers of the cos/sin table.
 548 |      * 
549 | * @param w [0...n*5/8-1] cos/sin table (REAL *) 550 | *
 551 |      *  w[],ip[] are initialized if ip[0] == 0.
 552 |      * 
553 | */ 554 | public void dfst(int n, double[] a, double[] t, int[] ip, double[] w) { 555 | int j, k, l, m, mh, nw, nc; 556 | double xr, xi, yr, yi; 557 | 558 | nw = ip[0]; 559 | if (n > (nw << 3)) { 560 | nw = n >> 3; 561 | makewt(nw, ip, w); 562 | } 563 | nc = ip[1]; 564 | if (n > (nc << 1)) { 565 | nc = n >> 1; 566 | makect(nc, ip, w, nw); 567 | } 568 | if (n > 2) { 569 | m = n >> 1; 570 | mh = m >> 1; 571 | for (j = 1; j < mh; j++) { 572 | k = m - j; 573 | xr = a[j] + a[n - j]; 574 | xi = a[j] - a[n - j]; 575 | yr = a[k] + a[n - k]; 576 | yi = a[k] - a[n - k]; 577 | a[j] = xr; 578 | a[k] = yr; 579 | t[j] = xi + yi; 580 | t[k] = xi - yi; 581 | } 582 | t[0] = a[mh] - a[n - mh]; 583 | a[mh] += a[n - mh]; 584 | a[0] = a[m]; 585 | dstsub(m, a, nc, w, nw); 586 | if (m > 4) { 587 | cftfsub(m, a, ip, 2, nw, w); 588 | rftfsub(m, a, nc, w, nw); 589 | } else if (m == 4) { 590 | cftfsub(m, a, ip, 2, nw, w); 591 | } 592 | a[n - 1] = a[1] - a[0]; 593 | a[1] = a[0] + a[1]; 594 | for (j = m - 2; j >= 2; j -= 2) { 595 | a[2 * j + 1] = a[j] - a[j + 1]; 596 | a[2 * j - 1] = -a[j] - a[j + 1]; 597 | } 598 | l = 2; 599 | m = mh; 600 | while (m >= 2) { 601 | dstsub(m, t, nc, w, nw); 602 | if (m > 4) { 603 | cftfsub(m, t, ip, 2, nw, w); 604 | rftfsub(m, t, nc, w, nw); 605 | } else if (m == 4) { 606 | cftfsub(m, t, ip, 2, nw, w); 607 | } 608 | a[n - l] = t[1] - t[0]; 609 | a[l] = t[0] + t[1]; 610 | k = 0; 611 | for (j = 2; j < m; j += 2) { 612 | k += l << 2; 613 | a[k - l] = -t[j] - t[j + 1]; 614 | a[k + l] = t[j] - t[j + 1]; 615 | } 616 | l <<= 1; 617 | mh = m >> 1; 618 | for (j = 1; j < mh; j++) { 619 | k = m - j; 620 | t[j] = t[m + k] + t[m + j]; 621 | t[k] = t[m + k] - t[m + j]; 622 | } 623 | t[0] = t[m + mh]; 624 | m = mh; 625 | } 626 | a[l] = t[0]; 627 | } 628 | a[0] = 0; 629 | } 630 | 631 | // -------- initializing routines -------- 632 | 633 | /** */ 634 | private void makewt(int nw, int[] ip, double[] w) { 635 | int j, nwh, nw0, nw1; 636 | double delta, wn4r, wk1r, wk1i, wk3r, wk3i; 637 | 638 | ip[0] = nw; 639 | ip[1] = 1; 640 | if (nw > 2) { 641 | nwh = nw >> 1; 642 | // delta = Math.atan(1.0) / nwh; 643 | delta = Math.PI / 4 / nwh; 644 | wn4r = Math.cos(delta * nwh); 645 | w[0] = 1; 646 | w[1] = wn4r; 647 | if (nwh >= 4) { 648 | w[2] = 0.5 / Math.cos(delta * 2); 649 | w[3] = 0.5 / Math.cos(delta * 6); 650 | } 651 | for (j = 4; j < nwh; j += 4) { 652 | w[j] = Math.cos(delta * j); 653 | w[j + 1] = Math.sin(delta * j); 654 | w[j + 2] = Math.cos(3 * delta * j); 655 | w[j + 3] = Math.sin(3 * delta * j); 656 | } 657 | nw0 = 0; 658 | while (nwh > 2) { 659 | nw1 = nw0 + nwh; 660 | nwh >>= 1; 661 | w[nw1] = 1; 662 | w[nw1 + 1] = wn4r; 663 | if (nwh >= 4) { 664 | wk1r = w[nw0 + 4]; 665 | wk3r = w[nw0 + 6]; 666 | w[nw1 + 2] = 0.5 / wk1r; 667 | w[nw1 + 3] = 0.5 / wk3r; 668 | } 669 | for (j = 4; j < nwh; j += 4) { 670 | wk1r = w[nw0 + 2 * j]; 671 | wk1i = w[nw0 + 2 * j + 1]; 672 | wk3r = w[nw0 + 2 * j + 2]; 673 | wk3i = w[nw0 + 2 * j + 3]; 674 | w[nw1 + j] = wk1r; 675 | w[nw1 + j + 1] = wk1i; 676 | w[nw1 + j + 2] = wk3r; 677 | w[nw1 + j + 3] = wk3i; 678 | } 679 | nw0 = nw1; 680 | } 681 | } 682 | } 683 | 684 | /** */ 685 | private void makect(int nc, int[] ip, double[] c, int cP) { 686 | int j, nch; 687 | double delta; 688 | 689 | ip[1] = nc; 690 | if (nc > 1) { 691 | nch = nc >> 1; 692 | // delta = Math.atan(1.0) / nch; 693 | delta = Math.PI / 4 / nch; 694 | c[cP + 0] = Math.cos(delta * nch); 695 | c[cP + nch] = 0.5 * c[cP + 0]; 696 | for (j = 1; j < nch; j++) { 697 | c[cP + j] = 0.5 * Math.cos(delta * j); 698 | c[cP + nc - j] = 0.5 * Math.sin(delta * j); 699 | } 700 | } 701 | } 702 | 703 | // -------- child routines -------- 704 | 705 | /** 706 | * 2nd 707 | * @see #rdft(int, int, double[], int[], double[]) 708 | * @see #ddct(int, int, double[], int[], double[]) 709 | * @see #cdft(int, int, double[], int[], double[]) 710 | * @see #ddst(int, int, double[], int[], double[]) 711 | * @see #dfst(int, double[], double[], int[], double[]) 712 | * @see #dfct(int, double[], double[], int[], double[]) 713 | */ 714 | private void cftfsub(int n, double[] a, int[] ip, int ipP, int nw, double[] w) { 715 | int m; 716 | 717 | if (n > 32) { 718 | m = n >> 2; 719 | cftf1st(n, a, w, nw - m); 720 | if (n > CDFT_RECURSIVE_N) { 721 | cftrec1(m, a, 0, nw, w); 722 | cftrec2(m, a, m, nw, w); 723 | cftrec1(m, a, 2 * m, nw, w); 724 | cftrec1(m, a, 3 * m, nw, w); 725 | } else if (m > 32) { 726 | cftexp1(n, a, 0, nw, w); 727 | } else { 728 | cftfx41(n, a, 0, nw, w); 729 | } 730 | bitrv2(n, ip, ipP, a); 731 | } else if (n > 8) { 732 | if (n == 32) { 733 | cftf161(a, 0, w, nw - 8); 734 | bitrv216(a); 735 | } else { 736 | cftf081(a, 0, w, 0); 737 | bitrv208(a); 738 | } 739 | } else if (n == 8) { 740 | cftf040(a); 741 | } else if (n == 4) { 742 | cftx020(a); 743 | } 744 | } 745 | 746 | /** 747 | * 2nd 748 | * @see #rdft(int, int, double[], int[], double[]) 749 | * @see #ddct(int, int, double[], int[], double[]) 750 | * @see #cdft(int, int, double[], int[], double[]) 751 | * @see #ddst(int, int, double[], int[], double[]) 752 | */ 753 | private void cftbsub(int n, double[] a, int[] ip, int ipP, int nw, double[] w) { 754 | int m; 755 | 756 | if (n > 32) { 757 | m = n >> 2; 758 | cftb1st(n, a, w, nw - m); 759 | if (n > CDFT_RECURSIVE_N) { 760 | cftrec1(m, a, 0, nw, w); 761 | cftrec2(m, a, m, nw, w); 762 | cftrec1(m, a, 2 * m, nw, w); 763 | cftrec1(m, a, 3 * m, nw, w); 764 | } else if (m > 32) { 765 | cftexp1(n, a, 0, nw, w); 766 | } else { 767 | cftfx41(n, a, 0, nw, w); 768 | } 769 | bitrv2conj(n, ip, ipP, a); 770 | } else if (n > 8) { 771 | if (n == 32) { 772 | cftf161(a, 0, w, nw - 8); 773 | bitrv216neg(a); 774 | } else { 775 | cftf081(a, 0, w, 0); 776 | bitrv208neg(a); 777 | } 778 | } else if (n == 8) { 779 | cftb040(a); 780 | } else if (n == 4) { 781 | cftx020(a); 782 | } 783 | } 784 | 785 | /** 786 | * 3rd 787 | * @see #cftfsub(int, double[], int[], int, int, double[]) 788 | */ 789 | private final void bitrv2(int n, int[] ip, int ipP, double[] a) { 790 | int j, j1, k, k1, l, m, m2; 791 | double xr, xi, yr, yi; 792 | 793 | ip[ipP + 0] = 0; 794 | l = n; 795 | m = 1; 796 | while ((m << 3) < l) { 797 | l >>= 1; 798 | for (j = 0; j < m; j++) { 799 | ip[ipP + m + j] = ip[ipP + j] + l; 800 | } 801 | m <<= 1; 802 | } 803 | m2 = 2 * m; 804 | if ((m << 3) == l) { 805 | for (k = 0; k < m; k++) { 806 | for (j = 0; j < k; j++) { 807 | j1 = 2 * j + ip[ipP + k]; 808 | k1 = 2 * k + ip[ipP + j]; 809 | xr = a[j1]; 810 | xi = a[j1 + 1]; 811 | yr = a[k1]; 812 | yi = a[k1 + 1]; 813 | a[j1] = yr; 814 | a[j1 + 1] = yi; 815 | a[k1] = xr; 816 | a[k1 + 1] = xi; 817 | j1 += m2; 818 | k1 += 2 * m2; 819 | xr = a[j1]; 820 | xi = a[j1 + 1]; 821 | yr = a[k1]; 822 | yi = a[k1 + 1]; 823 | a[j1] = yr; 824 | a[j1 + 1] = yi; 825 | a[k1] = xr; 826 | a[k1 + 1] = xi; 827 | j1 += m2; 828 | k1 -= m2; 829 | xr = a[j1]; 830 | xi = a[j1 + 1]; 831 | yr = a[k1]; 832 | yi = a[k1 + 1]; 833 | a[j1] = yr; 834 | a[j1 + 1] = yi; 835 | a[k1] = xr; 836 | a[k1 + 1] = xi; 837 | j1 += m2; 838 | k1 += 2 * m2; 839 | xr = a[j1]; 840 | xi = a[j1 + 1]; 841 | yr = a[k1]; 842 | yi = a[k1 + 1]; 843 | a[j1] = yr; 844 | a[j1 + 1] = yi; 845 | a[k1] = xr; 846 | a[k1 + 1] = xi; 847 | } 848 | j1 = 2 * k + m2 + ip[ipP + k]; 849 | k1 = j1 + m2; 850 | xr = a[j1]; 851 | xi = a[j1 + 1]; 852 | yr = a[k1]; 853 | yi = a[k1 + 1]; 854 | a[j1] = yr; 855 | a[j1 + 1] = yi; 856 | a[k1] = xr; 857 | a[k1 + 1] = xi; 858 | } 859 | } else { 860 | for (k = 1; k < m; k++) { 861 | for (j = 0; j < k; j++) { 862 | j1 = 2 * j + ip[ipP + k]; 863 | k1 = 2 * k + ip[ipP + j]; 864 | xr = a[j1]; 865 | xi = a[j1 + 1]; 866 | yr = a[k1]; 867 | yi = a[k1 + 1]; 868 | a[j1] = yr; 869 | a[j1 + 1] = yi; 870 | a[k1] = xr; 871 | a[k1 + 1] = xi; 872 | j1 += m2; 873 | k1 += m2; 874 | xr = a[j1]; 875 | xi = a[j1 + 1]; 876 | yr = a[k1]; 877 | yi = a[k1 + 1]; 878 | a[j1] = yr; 879 | a[j1 + 1] = yi; 880 | a[k1] = xr; 881 | a[k1 + 1] = xi; 882 | } 883 | } 884 | } 885 | } 886 | 887 | /** 888 | * 3rd 889 | * @see #cftbsub(int, double[], int[], int, int, double[]) 890 | */ 891 | private final void bitrv2conj(int n, int[] ip, int ipP, double[] a) { 892 | int j, j1, k, k1, l, m, m2; 893 | double xr, xi, yr, yi; 894 | 895 | ip[ipP + 0] = 0; 896 | l = n; 897 | m = 1; 898 | while ((m << 3) < l) { 899 | l >>= 1; 900 | for (j = 0; j < m; j++) { 901 | ip[ipP + m + j] = ip[ipP + j] + l; 902 | } 903 | m <<= 1; 904 | } 905 | m2 = 2 * m; 906 | if ((m << 3) == l) { 907 | for (k = 0; k < m; k++) { 908 | for (j = 0; j < k; j++) { 909 | j1 = 2 * j + ip[ipP + k]; 910 | k1 = 2 * k + ip[ipP + j]; 911 | xr = a[j1]; 912 | xi = -a[j1 + 1]; 913 | yr = a[k1]; 914 | yi = -a[k1 + 1]; 915 | a[j1] = yr; 916 | a[j1 + 1] = yi; 917 | a[k1] = xr; 918 | a[k1 + 1] = xi; 919 | j1 += m2; 920 | k1 += 2 * m2; 921 | xr = a[j1]; 922 | xi = -a[j1 + 1]; 923 | yr = a[k1]; 924 | yi = -a[k1 + 1]; 925 | a[j1] = yr; 926 | a[j1 + 1] = yi; 927 | a[k1] = xr; 928 | a[k1 + 1] = xi; 929 | j1 += m2; 930 | k1 -= m2; 931 | xr = a[j1]; 932 | xi = -a[j1 + 1]; 933 | yr = a[k1]; 934 | yi = -a[k1 + 1]; 935 | a[j1] = yr; 936 | a[j1 + 1] = yi; 937 | a[k1] = xr; 938 | a[k1 + 1] = xi; 939 | j1 += m2; 940 | k1 += 2 * m2; 941 | xr = a[j1]; 942 | xi = -a[j1 + 1]; 943 | yr = a[k1]; 944 | yi = -a[k1 + 1]; 945 | a[j1] = yr; 946 | a[j1 + 1] = yi; 947 | a[k1] = xr; 948 | a[k1 + 1] = xi; 949 | } 950 | k1 = 2 * k + ip[ipP + k]; 951 | a[k1 + 1] = -a[k1 + 1]; 952 | j1 = k1 + m2; 953 | k1 = j1 + m2; 954 | xr = a[j1]; 955 | xi = -a[j1 + 1]; 956 | yr = a[k1]; 957 | yi = -a[k1 + 1]; 958 | a[j1] = yr; 959 | a[j1 + 1] = yi; 960 | a[k1] = xr; 961 | a[k1 + 1] = xi; 962 | k1 += m2; 963 | a[k1 + 1] = -a[k1 + 1]; 964 | } 965 | } else { 966 | a[1] = -a[1]; 967 | a[m2 + 1] = -a[m2 + 1]; 968 | for (k = 1; k < m; k++) { 969 | for (j = 0; j < k; j++) { 970 | j1 = 2 * j + ip[ipP + k]; 971 | k1 = 2 * k + ip[ipP + j]; 972 | xr = a[j1]; 973 | xi = -a[j1 + 1]; 974 | yr = a[k1]; 975 | yi = -a[k1 + 1]; 976 | a[j1] = yr; 977 | a[j1 + 1] = yi; 978 | a[k1] = xr; 979 | a[k1 + 1] = xi; 980 | j1 += m2; 981 | k1 += m2; 982 | xr = a[j1]; 983 | xi = -a[j1 + 1]; 984 | yr = a[k1]; 985 | yi = -a[k1 + 1]; 986 | a[j1] = yr; 987 | a[j1 + 1] = yi; 988 | a[k1] = xr; 989 | a[k1 + 1] = xi; 990 | } 991 | k1 = 2 * k + ip[ipP + k]; 992 | a[k1 + 1] = -a[k1 + 1]; 993 | a[k1 + m2 + 1] = -a[k1 + m2 + 1]; 994 | } 995 | } 996 | } 997 | 998 | /** 999 | * 3rd 1000 | * @see #cftfsub(int, double[], int[], int, int, double[]) 1001 | */ 1002 | private void bitrv216(double[] a) { 1003 | double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i, x5r, x5i, x7r, x7i, x8r, x8i, x10r, x10i, x11r, x11i, x12r, x12i, x13r, x13i, x14r, x14i; 1004 | 1005 | x1r = a[2]; 1006 | x1i = a[3]; 1007 | x2r = a[4]; 1008 | x2i = a[5]; 1009 | x3r = a[6]; 1010 | x3i = a[7]; 1011 | x4r = a[8]; 1012 | x4i = a[9]; 1013 | x5r = a[10]; 1014 | x5i = a[11]; 1015 | x7r = a[14]; 1016 | x7i = a[15]; 1017 | x8r = a[16]; 1018 | x8i = a[17]; 1019 | x10r = a[20]; 1020 | x10i = a[21]; 1021 | x11r = a[22]; 1022 | x11i = a[23]; 1023 | x12r = a[24]; 1024 | x12i = a[25]; 1025 | x13r = a[26]; 1026 | x13i = a[27]; 1027 | x14r = a[28]; 1028 | x14i = a[29]; 1029 | a[2] = x8r; 1030 | a[3] = x8i; 1031 | a[4] = x4r; 1032 | a[5] = x4i; 1033 | a[6] = x12r; 1034 | a[7] = x12i; 1035 | a[8] = x2r; 1036 | a[9] = x2i; 1037 | a[10] = x10r; 1038 | a[11] = x10i; 1039 | a[14] = x14r; 1040 | a[15] = x14i; 1041 | a[16] = x1r; 1042 | a[17] = x1i; 1043 | a[20] = x5r; 1044 | a[21] = x5i; 1045 | a[22] = x13r; 1046 | a[23] = x13i; 1047 | a[24] = x3r; 1048 | a[25] = x3i; 1049 | a[26] = x11r; 1050 | a[27] = x11i; 1051 | a[28] = x7r; 1052 | a[29] = x7i; 1053 | } 1054 | 1055 | /** 1056 | * 3rd 1057 | * @see #cftbsub(int, double[], int[], int, int, double[]) 1058 | */ 1059 | private void bitrv216neg(double[] a) { 1060 | double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i, x5r, x5i, x6r, x6i, x7r, x7i, x8r, x8i, x9r, x9i, x10r, x10i, x11r, x11i, x12r, x12i, x13r, x13i, x14r, x14i, x15r, x15i; 1061 | 1062 | x1r = a[2]; 1063 | x1i = a[3]; 1064 | x2r = a[4]; 1065 | x2i = a[5]; 1066 | x3r = a[6]; 1067 | x3i = a[7]; 1068 | x4r = a[8]; 1069 | x4i = a[9]; 1070 | x5r = a[10]; 1071 | x5i = a[11]; 1072 | x6r = a[12]; 1073 | x6i = a[13]; 1074 | x7r = a[14]; 1075 | x7i = a[15]; 1076 | x8r = a[16]; 1077 | x8i = a[17]; 1078 | x9r = a[18]; 1079 | x9i = a[19]; 1080 | x10r = a[20]; 1081 | x10i = a[21]; 1082 | x11r = a[22]; 1083 | x11i = a[23]; 1084 | x12r = a[24]; 1085 | x12i = a[25]; 1086 | x13r = a[26]; 1087 | x13i = a[27]; 1088 | x14r = a[28]; 1089 | x14i = a[29]; 1090 | x15r = a[30]; 1091 | x15i = a[31]; 1092 | a[2] = x15r; 1093 | a[3] = x15i; 1094 | a[4] = x7r; 1095 | a[5] = x7i; 1096 | a[6] = x11r; 1097 | a[7] = x11i; 1098 | a[8] = x3r; 1099 | a[9] = x3i; 1100 | a[10] = x13r; 1101 | a[11] = x13i; 1102 | a[12] = x5r; 1103 | a[13] = x5i; 1104 | a[14] = x9r; 1105 | a[15] = x9i; 1106 | a[16] = x1r; 1107 | a[17] = x1i; 1108 | a[18] = x14r; 1109 | a[19] = x14i; 1110 | a[20] = x6r; 1111 | a[21] = x6i; 1112 | a[22] = x10r; 1113 | a[23] = x10i; 1114 | a[24] = x2r; 1115 | a[25] = x2i; 1116 | a[26] = x12r; 1117 | a[27] = x12i; 1118 | a[28] = x4r; 1119 | a[29] = x4i; 1120 | a[30] = x8r; 1121 | a[31] = x8i; 1122 | } 1123 | 1124 | /** 1125 | * 3rd 1126 | * @see #cftfsub(int, double[], int[], int, int, double[]) 1127 | */ 1128 | private void bitrv208(double[] a) { 1129 | double x1r, x1i, x3r, x3i, x4r, x4i, x6r, x6i; 1130 | 1131 | x1r = a[2]; 1132 | x1i = a[3]; 1133 | x3r = a[6]; 1134 | x3i = a[7]; 1135 | x4r = a[8]; 1136 | x4i = a[9]; 1137 | x6r = a[12]; 1138 | x6i = a[13]; 1139 | a[2] = x4r; 1140 | a[3] = x4i; 1141 | a[6] = x6r; 1142 | a[7] = x6i; 1143 | a[8] = x1r; 1144 | a[9] = x1i; 1145 | a[12] = x3r; 1146 | a[13] = x3i; 1147 | } 1148 | 1149 | /** 1150 | * 3rd 1151 | * @see #cftbsub(int, double[], int[], int, int, double[]) 1152 | */ 1153 | private void bitrv208neg(double[] a) { 1154 | double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i, x5r, x5i, x6r, x6i, x7r, x7i; 1155 | 1156 | x1r = a[2]; 1157 | x1i = a[3]; 1158 | x2r = a[4]; 1159 | x2i = a[5]; 1160 | x3r = a[6]; 1161 | x3i = a[7]; 1162 | x4r = a[8]; 1163 | x4i = a[9]; 1164 | x5r = a[10]; 1165 | x5i = a[11]; 1166 | x6r = a[12]; 1167 | x6i = a[13]; 1168 | x7r = a[14]; 1169 | x7i = a[15]; 1170 | a[2] = x7r; 1171 | a[3] = x7i; 1172 | a[4] = x3r; 1173 | a[5] = x3i; 1174 | a[6] = x5r; 1175 | a[7] = x5i; 1176 | a[8] = x1r; 1177 | a[9] = x1i; 1178 | a[10] = x6r; 1179 | a[11] = x6i; 1180 | a[12] = x2r; 1181 | a[13] = x2i; 1182 | a[14] = x4r; 1183 | a[15] = x4i; 1184 | } 1185 | 1186 | /** 1187 | * 3rd 1188 | * @see #cftfsub(int, double[], int[], int, int, double[]) 1189 | */ 1190 | private void cftf1st(int n, double[] a, double[] w, int wP) { 1191 | int j, j0, j1, j2, j3, k, m, mh; 1192 | double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i, wd1r, wd1i, wd3r, wd3i; 1193 | double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i; 1194 | 1195 | mh = n >> 3; 1196 | m = 2 * mh; 1197 | j1 = m; 1198 | j2 = j1 + m; 1199 | j3 = j2 + m; 1200 | x0r = a[0] + a[j2]; 1201 | x0i = a[1] + a[j2 + 1]; 1202 | x1r = a[0] - a[j2]; 1203 | x1i = a[1] - a[j2 + 1]; 1204 | x2r = a[j1] + a[j3]; 1205 | x2i = a[j1 + 1] + a[j3 + 1]; 1206 | x3r = a[j1] - a[j3]; 1207 | x3i = a[j1 + 1] - a[j3 + 1]; 1208 | a[0] = x0r + x2r; 1209 | a[1] = x0i + x2i; 1210 | a[j1] = x0r - x2r; 1211 | a[j1 + 1] = x0i - x2i; 1212 | a[j2] = x1r - x3i; 1213 | a[j2 + 1] = x1i + x3r; 1214 | a[j3] = x1r + x3i; 1215 | a[j3 + 1] = x1i - x3r; 1216 | wn4r = w[wP + 1]; 1217 | csc1 = w[wP + 2]; 1218 | csc3 = w[wP + 3]; 1219 | wd1r = 1; 1220 | wd1i = 0; 1221 | wd3r = 1; 1222 | wd3i = 0; 1223 | k = 0; 1224 | for (j = 2; j < mh - 2; j += 4) { 1225 | k += 4; 1226 | wk1r = csc1 * (wd1r + w[wP + k]); 1227 | wk1i = csc1 * (wd1i + w[wP + k + 1]); 1228 | wk3r = csc3 * (wd3r + w[wP + k + 2]); 1229 | wk3i = csc3 * (wd3i - w[wP + k + 3]); 1230 | wd1r = w[wP + k]; 1231 | wd1i = w[wP + k + 1]; 1232 | wd3r = w[wP + k + 2]; 1233 | wd3i = -w[wP + k + 3]; 1234 | j1 = j + m; 1235 | j2 = j1 + m; 1236 | j3 = j2 + m; 1237 | x0r = a[j] + a[j2]; 1238 | x0i = a[j + 1] + a[j2 + 1]; 1239 | x1r = a[j] - a[j2]; 1240 | x1i = a[j + 1] - a[j2 + 1]; 1241 | y0r = a[j + 2] + a[j2 + 2]; 1242 | y0i = a[j + 3] + a[j2 + 3]; 1243 | y1r = a[j + 2] - a[j2 + 2]; 1244 | y1i = a[j + 3] - a[j2 + 3]; 1245 | x2r = a[j1] + a[j3]; 1246 | x2i = a[j1 + 1] + a[j3 + 1]; 1247 | x3r = a[j1] - a[j3]; 1248 | x3i = a[j1 + 1] - a[j3 + 1]; 1249 | y2r = a[j1 + 2] + a[j3 + 2]; 1250 | y2i = a[j1 + 3] + a[j3 + 3]; 1251 | y3r = a[j1 + 2] - a[j3 + 2]; 1252 | y3i = a[j1 + 3] - a[j3 + 3]; 1253 | a[j] = x0r + x2r; 1254 | a[j + 1] = x0i + x2i; 1255 | a[j + 2] = y0r + y2r; 1256 | a[j + 3] = y0i + y2i; 1257 | a[j1] = x0r - x2r; 1258 | a[j1 + 1] = x0i - x2i; 1259 | a[j1 + 2] = y0r - y2r; 1260 | a[j1 + 3] = y0i - y2i; 1261 | x0r = x1r - x3i; 1262 | x0i = x1i + x3r; 1263 | a[j2] = wk1r * x0r - wk1i * x0i; 1264 | a[j2 + 1] = wk1r * x0i + wk1i * x0r; 1265 | x0r = y1r - y3i; 1266 | x0i = y1i + y3r; 1267 | a[j2 + 2] = wd1r * x0r - wd1i * x0i; 1268 | a[j2 + 3] = wd1r * x0i + wd1i * x0r; 1269 | x0r = x1r + x3i; 1270 | x0i = x1i - x3r; 1271 | a[j3] = wk3r * x0r + wk3i * x0i; 1272 | a[j3 + 1] = wk3r * x0i - wk3i * x0r; 1273 | x0r = y1r + y3i; 1274 | x0i = y1i - y3r; 1275 | a[j3 + 2] = wd3r * x0r + wd3i * x0i; 1276 | a[j3 + 3] = wd3r * x0i - wd3i * x0r; 1277 | j0 = m - j; 1278 | j1 = j0 + m; 1279 | j2 = j1 + m; 1280 | j3 = j2 + m; 1281 | x0r = a[j0] + a[j2]; 1282 | x0i = a[j0 + 1] + a[j2 + 1]; 1283 | x1r = a[j0] - a[j2]; 1284 | x1i = a[j0 + 1] - a[j2 + 1]; 1285 | y0r = a[j0 - 2] + a[j2 - 2]; 1286 | y0i = a[j0 - 1] + a[j2 - 1]; 1287 | y1r = a[j0 - 2] - a[j2 - 2]; 1288 | y1i = a[j0 - 1] - a[j2 - 1]; 1289 | x2r = a[j1] + a[j3]; 1290 | x2i = a[j1 + 1] + a[j3 + 1]; 1291 | x3r = a[j1] - a[j3]; 1292 | x3i = a[j1 + 1] - a[j3 + 1]; 1293 | y2r = a[j1 - 2] + a[j3 - 2]; 1294 | y2i = a[j1 - 1] + a[j3 - 1]; 1295 | y3r = a[j1 - 2] - a[j3 - 2]; 1296 | y3i = a[j1 - 1] - a[j3 - 1]; 1297 | a[j0] = x0r + x2r; 1298 | a[j0 + 1] = x0i + x2i; 1299 | a[j0 - 2] = y0r + y2r; 1300 | a[j0 - 1] = y0i + y2i; 1301 | a[j1] = x0r - x2r; 1302 | a[j1 + 1] = x0i - x2i; 1303 | a[j1 - 2] = y0r - y2r; 1304 | a[j1 - 1] = y0i - y2i; 1305 | x0r = x1r - x3i; 1306 | x0i = x1i + x3r; 1307 | a[j2] = wk1i * x0r - wk1r * x0i; 1308 | a[j2 + 1] = wk1i * x0i + wk1r * x0r; 1309 | x0r = y1r - y3i; 1310 | x0i = y1i + y3r; 1311 | a[j2 - 2] = wd1i * x0r - wd1r * x0i; 1312 | a[j2 - 1] = wd1i * x0i + wd1r * x0r; 1313 | x0r = x1r + x3i; 1314 | x0i = x1i - x3r; 1315 | a[j3] = wk3i * x0r + wk3r * x0i; 1316 | a[j3 + 1] = wk3i * x0i - wk3r * x0r; 1317 | x0r = y1r + y3i; 1318 | x0i = y1i - y3r; 1319 | a[j3 - 2] = wd3i * x0r + wd3r * x0i; 1320 | a[j3 - 1] = wd3i * x0i - wd3r * x0r; 1321 | } 1322 | wk1r = csc1 * (wd1r + wn4r); 1323 | wk1i = csc1 * (wd1i + wn4r); 1324 | wk3r = csc3 * (wd3r - wn4r); 1325 | wk3i = csc3 * (wd3i - wn4r); 1326 | j0 = mh; 1327 | j1 = j0 + m; 1328 | j2 = j1 + m; 1329 | j3 = j2 + m; 1330 | x0r = a[j0 - 2] + a[j2 - 2]; 1331 | x0i = a[j0 - 1] + a[j2 - 1]; 1332 | x1r = a[j0 - 2] - a[j2 - 2]; 1333 | x1i = a[j0 - 1] - a[j2 - 1]; 1334 | x2r = a[j1 - 2] + a[j3 - 2]; 1335 | x2i = a[j1 - 1] + a[j3 - 1]; 1336 | x3r = a[j1 - 2] - a[j3 - 2]; 1337 | x3i = a[j1 - 1] - a[j3 - 1]; 1338 | a[j0 - 2] = x0r + x2r; 1339 | a[j0 - 1] = x0i + x2i; 1340 | a[j1 - 2] = x0r - x2r; 1341 | a[j1 - 1] = x0i - x2i; 1342 | x0r = x1r - x3i; 1343 | x0i = x1i + x3r; 1344 | a[j2 - 2] = wk1r * x0r - wk1i * x0i; 1345 | a[j2 - 1] = wk1r * x0i + wk1i * x0r; 1346 | x0r = x1r + x3i; 1347 | x0i = x1i - x3r; 1348 | a[j3 - 2] = wk3r * x0r + wk3i * x0i; 1349 | a[j3 - 1] = wk3r * x0i - wk3i * x0r; 1350 | x0r = a[j0] + a[j2]; 1351 | x0i = a[j0 + 1] + a[j2 + 1]; 1352 | x1r = a[j0] - a[j2]; 1353 | x1i = a[j0 + 1] - a[j2 + 1]; 1354 | x2r = a[j1] + a[j3]; 1355 | x2i = a[j1 + 1] + a[j3 + 1]; 1356 | x3r = a[j1] - a[j3]; 1357 | x3i = a[j1 + 1] - a[j3 + 1]; 1358 | a[j0] = x0r + x2r; 1359 | a[j0 + 1] = x0i + x2i; 1360 | a[j1] = x0r - x2r; 1361 | a[j1 + 1] = x0i - x2i; 1362 | x0r = x1r - x3i; 1363 | x0i = x1i + x3r; 1364 | a[j2] = wn4r * (x0r - x0i); 1365 | a[j2 + 1] = wn4r * (x0i + x0r); 1366 | x0r = x1r + x3i; 1367 | x0i = x1i - x3r; 1368 | a[j3] = -wn4r * (x0r + x0i); 1369 | a[j3 + 1] = -wn4r * (x0i - x0r); 1370 | x0r = a[j0 + 2] + a[j2 + 2]; 1371 | x0i = a[j0 + 3] + a[j2 + 3]; 1372 | x1r = a[j0 + 2] - a[j2 + 2]; 1373 | x1i = a[j0 + 3] - a[j2 + 3]; 1374 | x2r = a[j1 + 2] + a[j3 + 2]; 1375 | x2i = a[j1 + 3] + a[j3 + 3]; 1376 | x3r = a[j1 + 2] - a[j3 + 2]; 1377 | x3i = a[j1 + 3] - a[j3 + 3]; 1378 | a[j0 + 2] = x0r + x2r; 1379 | a[j0 + 3] = x0i + x2i; 1380 | a[j1 + 2] = x0r - x2r; 1381 | a[j1 + 3] = x0i - x2i; 1382 | x0r = x1r - x3i; 1383 | x0i = x1i + x3r; 1384 | a[j2 + 2] = wk1i * x0r - wk1r * x0i; 1385 | a[j2 + 3] = wk1i * x0i + wk1r * x0r; 1386 | x0r = x1r + x3i; 1387 | x0i = x1i - x3r; 1388 | a[j3 + 2] = wk3i * x0r + wk3r * x0i; 1389 | a[j3 + 3] = wk3i * x0i - wk3r * x0r; 1390 | } 1391 | 1392 | /** 1393 | * 3rd 1394 | * @see #cftbsub(int, double[], int[], int, int, double[]) 1395 | */ 1396 | private final void cftb1st(int n, double[] a, double[] w, int wP) { 1397 | int j, j0, j1, j2, j3, k, m, mh; 1398 | double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i, wd1r, wd1i, wd3r, wd3i; 1399 | double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i; 1400 | 1401 | mh = n >> 3; 1402 | m = 2 * mh; 1403 | j1 = m; 1404 | j2 = j1 + m; 1405 | j3 = j2 + m; 1406 | x0r = a[0] + a[j2]; 1407 | x0i = -a[1] - a[j2 + 1]; 1408 | x1r = a[0] - a[j2]; 1409 | x1i = -a[1] + a[j2 + 1]; 1410 | x2r = a[j1] + a[j3]; 1411 | x2i = a[j1 + 1] + a[j3 + 1]; 1412 | x3r = a[j1] - a[j3]; 1413 | x3i = a[j1 + 1] - a[j3 + 1]; 1414 | a[0] = x0r + x2r; 1415 | a[1] = x0i - x2i; 1416 | a[j1] = x0r - x2r; 1417 | a[j1 + 1] = x0i + x2i; 1418 | a[j2] = x1r + x3i; 1419 | a[j2 + 1] = x1i + x3r; 1420 | a[j3] = x1r - x3i; 1421 | a[j3 + 1] = x1i - x3r; 1422 | wn4r = w[wP + 1]; 1423 | csc1 = w[wP + 2]; 1424 | csc3 = w[wP + 3]; 1425 | wd1r = 1; 1426 | wd1i = 0; 1427 | wd3r = 1; 1428 | wd3i = 0; 1429 | k = 0; 1430 | for (j = 2; j < mh - 2; j += 4) { 1431 | k += 4; 1432 | wk1r = csc1 * (wd1r + w[wP + k]); 1433 | wk1i = csc1 * (wd1i + w[wP + k + 1]); 1434 | wk3r = csc3 * (wd3r + w[wP + k + 2]); 1435 | wk3i = csc3 * (wd3i - w[wP + k + 3]); 1436 | wd1r = w[wP + k]; 1437 | wd1i = w[wP + k + 1]; 1438 | wd3r = w[wP + k + 2]; 1439 | wd3i = -w[wP + k + 3]; 1440 | j1 = j + m; 1441 | j2 = j1 + m; 1442 | j3 = j2 + m; 1443 | x0r = a[j] + a[j2]; 1444 | x0i = -a[j + 1] - a[j2 + 1]; 1445 | x1r = a[j] - a[j2]; 1446 | x1i = -a[j + 1] + a[j2 + 1]; 1447 | y0r = a[j + 2] + a[j2 + 2]; 1448 | y0i = -a[j + 3] - a[j2 + 3]; 1449 | y1r = a[j + 2] - a[j2 + 2]; 1450 | y1i = -a[j + 3] + a[j2 + 3]; 1451 | x2r = a[j1] + a[j3]; 1452 | x2i = a[j1 + 1] + a[j3 + 1]; 1453 | x3r = a[j1] - a[j3]; 1454 | x3i = a[j1 + 1] - a[j3 + 1]; 1455 | y2r = a[j1 + 2] + a[j3 + 2]; 1456 | y2i = a[j1 + 3] + a[j3 + 3]; 1457 | y3r = a[j1 + 2] - a[j3 + 2]; 1458 | y3i = a[j1 + 3] - a[j3 + 3]; 1459 | a[j] = x0r + x2r; 1460 | a[j + 1] = x0i - x2i; 1461 | a[j + 2] = y0r + y2r; 1462 | a[j + 3] = y0i - y2i; 1463 | a[j1] = x0r - x2r; 1464 | a[j1 + 1] = x0i + x2i; 1465 | a[j1 + 2] = y0r - y2r; 1466 | a[j1 + 3] = y0i + y2i; 1467 | x0r = x1r + x3i; 1468 | x0i = x1i + x3r; 1469 | a[j2] = wk1r * x0r - wk1i * x0i; 1470 | a[j2 + 1] = wk1r * x0i + wk1i * x0r; 1471 | x0r = y1r + y3i; 1472 | x0i = y1i + y3r; 1473 | a[j2 + 2] = wd1r * x0r - wd1i * x0i; 1474 | a[j2 + 3] = wd1r * x0i + wd1i * x0r; 1475 | x0r = x1r - x3i; 1476 | x0i = x1i - x3r; 1477 | a[j3] = wk3r * x0r + wk3i * x0i; 1478 | a[j3 + 1] = wk3r * x0i - wk3i * x0r; 1479 | x0r = y1r - y3i; 1480 | x0i = y1i - y3r; 1481 | a[j3 + 2] = wd3r * x0r + wd3i * x0i; 1482 | a[j3 + 3] = wd3r * x0i - wd3i * x0r; 1483 | j0 = m - j; 1484 | j1 = j0 + m; 1485 | j2 = j1 + m; 1486 | j3 = j2 + m; 1487 | x0r = a[j0] + a[j2]; 1488 | x0i = -a[j0 + 1] - a[j2 + 1]; 1489 | x1r = a[j0] - a[j2]; 1490 | x1i = -a[j0 + 1] + a[j2 + 1]; 1491 | y0r = a[j0 - 2] + a[j2 - 2]; 1492 | y0i = -a[j0 - 1] - a[j2 - 1]; 1493 | y1r = a[j0 - 2] - a[j2 - 2]; 1494 | y1i = -a[j0 - 1] + a[j2 - 1]; 1495 | x2r = a[j1] + a[j3]; 1496 | x2i = a[j1 + 1] + a[j3 + 1]; 1497 | x3r = a[j1] - a[j3]; 1498 | x3i = a[j1 + 1] - a[j3 + 1]; 1499 | y2r = a[j1 - 2] + a[j3 - 2]; 1500 | y2i = a[j1 - 1] + a[j3 - 1]; 1501 | y3r = a[j1 - 2] - a[j3 - 2]; 1502 | y3i = a[j1 - 1] - a[j3 - 1]; 1503 | a[j0] = x0r + x2r; 1504 | a[j0 + 1] = x0i - x2i; 1505 | a[j0 - 2] = y0r + y2r; 1506 | a[j0 - 1] = y0i - y2i; 1507 | a[j1] = x0r - x2r; 1508 | a[j1 + 1] = x0i + x2i; 1509 | a[j1 - 2] = y0r - y2r; 1510 | a[j1 - 1] = y0i + y2i; 1511 | x0r = x1r + x3i; 1512 | x0i = x1i + x3r; 1513 | a[j2] = wk1i * x0r - wk1r * x0i; 1514 | a[j2 + 1] = wk1i * x0i + wk1r * x0r; 1515 | x0r = y1r + y3i; 1516 | x0i = y1i + y3r; 1517 | a[j2 - 2] = wd1i * x0r - wd1r * x0i; 1518 | a[j2 - 1] = wd1i * x0i + wd1r * x0r; 1519 | x0r = x1r - x3i; 1520 | x0i = x1i - x3r; 1521 | a[j3] = wk3i * x0r + wk3r * x0i; 1522 | a[j3 + 1] = wk3i * x0i - wk3r * x0r; 1523 | x0r = y1r - y3i; 1524 | x0i = y1i - y3r; 1525 | a[j3 - 2] = wd3i * x0r + wd3r * x0i; 1526 | a[j3 - 1] = wd3i * x0i - wd3r * x0r; 1527 | } 1528 | wk1r = csc1 * (wd1r + wn4r); 1529 | wk1i = csc1 * (wd1i + wn4r); 1530 | wk3r = csc3 * (wd3r - wn4r); 1531 | wk3i = csc3 * (wd3i - wn4r); 1532 | j0 = mh; 1533 | j1 = j0 + m; 1534 | j2 = j1 + m; 1535 | j3 = j2 + m; 1536 | x0r = a[j0 - 2] + a[j2 - 2]; 1537 | x0i = -a[j0 - 1] - a[j2 - 1]; 1538 | x1r = a[j0 - 2] - a[j2 - 2]; 1539 | x1i = -a[j0 - 1] + a[j2 - 1]; 1540 | x2r = a[j1 - 2] + a[j3 - 2]; 1541 | x2i = a[j1 - 1] + a[j3 - 1]; 1542 | x3r = a[j1 - 2] - a[j3 - 2]; 1543 | x3i = a[j1 - 1] - a[j3 - 1]; 1544 | a[j0 - 2] = x0r + x2r; 1545 | a[j0 - 1] = x0i - x2i; 1546 | a[j1 - 2] = x0r - x2r; 1547 | a[j1 - 1] = x0i + x2i; 1548 | x0r = x1r + x3i; 1549 | x0i = x1i + x3r; 1550 | a[j2 - 2] = wk1r * x0r - wk1i * x0i; 1551 | a[j2 - 1] = wk1r * x0i + wk1i * x0r; 1552 | x0r = x1r - x3i; 1553 | x0i = x1i - x3r; 1554 | a[j3 - 2] = wk3r * x0r + wk3i * x0i; 1555 | a[j3 - 1] = wk3r * x0i - wk3i * x0r; 1556 | x0r = a[j0] + a[j2]; 1557 | x0i = -a[j0 + 1] - a[j2 + 1]; 1558 | x1r = a[j0] - a[j2]; 1559 | x1i = -a[j0 + 1] + a[j2 + 1]; 1560 | x2r = a[j1] + a[j3]; 1561 | x2i = a[j1 + 1] + a[j3 + 1]; 1562 | x3r = a[j1] - a[j3]; 1563 | x3i = a[j1 + 1] - a[j3 + 1]; 1564 | a[j0] = x0r + x2r; 1565 | a[j0 + 1] = x0i - x2i; 1566 | a[j1] = x0r - x2r; 1567 | a[j1 + 1] = x0i + x2i; 1568 | x0r = x1r + x3i; 1569 | x0i = x1i + x3r; 1570 | a[j2] = wn4r * (x0r - x0i); 1571 | a[j2 + 1] = wn4r * (x0i + x0r); 1572 | x0r = x1r - x3i; 1573 | x0i = x1i - x3r; 1574 | a[j3] = -wn4r * (x0r + x0i); 1575 | a[j3 + 1] = -wn4r * (x0i - x0r); 1576 | x0r = a[j0 + 2] + a[j2 + 2]; 1577 | x0i = -a[j0 + 3] - a[j2 + 3]; 1578 | x1r = a[j0 + 2] - a[j2 + 2]; 1579 | x1i = -a[j0 + 3] + a[j2 + 3]; 1580 | x2r = a[j1 + 2] + a[j3 + 2]; 1581 | x2i = a[j1 + 3] + a[j3 + 3]; 1582 | x3r = a[j1 + 2] - a[j3 + 2]; 1583 | x3i = a[j1 + 3] - a[j3 + 3]; 1584 | a[j0 + 2] = x0r + x2r; 1585 | a[j0 + 3] = x0i - x2i; 1586 | a[j1 + 2] = x0r - x2r; 1587 | a[j1 + 3] = x0i + x2i; 1588 | x0r = x1r + x3i; 1589 | x0i = x1i + x3r; 1590 | a[j2 + 2] = wk1i * x0r - wk1r * x0i; 1591 | a[j2 + 3] = wk1i * x0i + wk1r * x0r; 1592 | x0r = x1r - x3i; 1593 | x0i = x1i - x3r; 1594 | a[j3 + 2] = wk3i * x0r + wk3r * x0i; 1595 | a[j3 + 3] = wk3i * x0i - wk3r * x0r; 1596 | } 1597 | 1598 | /** */ 1599 | private void cftrec1(int n, double[] a, int aP, int nw, double[] w) { 1600 | int m; 1601 | 1602 | m = n >> 2; 1603 | cftmdl1(n, a, aP, w, nw - 2 * m); 1604 | if (n > CDFT_RECURSIVE_N) { 1605 | cftrec1(m, a, aP, nw, w); 1606 | cftrec2(m, a, aP + m, nw, w); 1607 | cftrec1(m, a, aP + 2 * m, nw, w); 1608 | cftrec1(m, a, aP + 3 * m, nw, w); 1609 | } else { 1610 | cftexp1(n, a, aP, nw, w); 1611 | } 1612 | } 1613 | 1614 | /** */ 1615 | private void cftrec2(int n, double[] a, int aP, int nw, double[] w) { 1616 | int m; 1617 | 1618 | m = n >> 2; 1619 | cftmdl2(n, a, aP, w, nw - n); 1620 | if (n > CDFT_RECURSIVE_N) { 1621 | cftrec1(m, a, aP, nw, w); 1622 | cftrec2(m, a, aP + m, nw, w); 1623 | cftrec1(m, a, aP + 2 * m, nw, w); 1624 | cftrec2(m, a, aP + 3 * m, nw, w); 1625 | } else { 1626 | cftexp2(n, a, aP, nw, w); 1627 | } 1628 | } 1629 | 1630 | /** */ 1631 | private void cftexp1(int n, double[] a, int aP, int nw, double[] w) { 1632 | int j, k, l; 1633 | 1634 | l = n >> 2; 1635 | while (l > 128) { 1636 | for (k = l; k < n; k <<= 2) { 1637 | for (j = k - l; j < n; j += 4 * k) { 1638 | cftmdl1(l, a, aP + j, w, nw - (l >> 1)); 1639 | cftmdl2(l, a, aP + k + j, w, nw - l); 1640 | cftmdl1(l, a, aP + 2 * k + j, w, nw - (l >> 1)); 1641 | } 1642 | } 1643 | cftmdl1(l, a, aP + n - l, w, nw - (l >> 1)); 1644 | l >>= 2; 1645 | } 1646 | for (k = l; k < n; k <<= 2) { 1647 | for (j = k - l; j < n; j += 4 * k) { 1648 | cftmdl1(l, a, aP + j, w, nw - (l >> 1)); 1649 | cftfx41(l, a, aP + j, nw, w); 1650 | cftmdl2(l, a, aP + k + j, w, nw - l); 1651 | cftfx42(l, a, aP + k + j, nw, w); 1652 | cftmdl1(l, a, aP + 2 * k + j, w, nw - (l >> 1)); 1653 | cftfx41(l, a, aP + 2 * k + j, nw, w); 1654 | } 1655 | } 1656 | cftmdl1(l, a, aP + n - l, w, nw - (l >> 1)); 1657 | cftfx41(l, a, aP + n - l, nw, w); 1658 | } 1659 | 1660 | /** */ 1661 | private void cftexp2(int n, double[] a, int aP, int nw, double[] w) { 1662 | int j, k, l, m; 1663 | 1664 | m = n >> 1; 1665 | l = n >> 2; 1666 | while (l > 128) { 1667 | for (k = l; k < m; k <<= 2) { 1668 | for (j = k - l; j < m; j += 2 * k) { 1669 | cftmdl1(l, a, aP + j, w, nw - (l >> 1)); 1670 | cftmdl1(l, a, aP + m + j, w, nw - (l >> 1)); 1671 | } 1672 | for (j = 2 * k - l; j < m; j += 4 * k) { 1673 | cftmdl2(l, a, aP + j, w, nw - l); 1674 | cftmdl2(l, a, aP + m + j, w, nw - l); 1675 | } 1676 | } 1677 | l >>= 2; 1678 | } 1679 | for (k = l; k < m; k <<= 2) { 1680 | for (j = k - l; j < m; j += 2 * k) { 1681 | cftmdl1(l, a, aP + j, w, nw - (l >> 1)); 1682 | cftfx41(l, a, aP + j, nw, w); 1683 | cftmdl1(l, a, aP + m + j, w, nw - (l >> 1)); 1684 | cftfx41(l, a, aP + m + j, nw, w); 1685 | } 1686 | for (j = 2 * k - l; j < m; j += 4 * k) { 1687 | cftmdl2(l, a, aP + j, w, nw - l); 1688 | cftfx42(l, a, aP + j, nw, w); 1689 | cftmdl2(l, a, aP + m + j, w, nw - l); 1690 | cftfx42(l, a, aP + m + j, nw, w); 1691 | } 1692 | } 1693 | } 1694 | 1695 | /** */ 1696 | private final void cftmdl1(int n, double[] a, int aP, double[] w, int wP) { 1697 | int j, j0, j1, j2, j3, k, m, mh; 1698 | double wn4r, wk1r, wk1i, wk3r, wk3i; 1699 | double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; 1700 | 1701 | mh = n >> 3; 1702 | m = 2 * mh; 1703 | j1 = m; 1704 | j2 = j1 + m; 1705 | j3 = j2 + m; 1706 | x0r = a[aP + 0] + a[aP + j2]; 1707 | x0i = a[aP + 1] + a[aP + j2 + 1]; 1708 | x1r = a[aP + 0] - a[aP + j2]; 1709 | x1i = a[aP + 1] - a[aP + j2 + 1]; 1710 | x2r = a[aP + j1] + a[aP + j3]; 1711 | x2i = a[aP + j1 + 1] + a[aP + j3 + 1]; 1712 | x3r = a[aP + j1] - a[aP + j3]; 1713 | x3i = a[aP + j1 + 1] - a[aP + j3 + 1]; 1714 | a[aP + 0] = x0r + x2r; 1715 | a[aP + 1] = x0i + x2i; 1716 | a[aP + j1] = x0r - x2r; 1717 | a[aP + j1 + 1] = x0i - x2i; 1718 | a[aP + j2] = x1r - x3i; 1719 | a[aP + j2 + 1] = x1i + x3r; 1720 | a[aP + j3] = x1r + x3i; 1721 | a[aP + j3 + 1] = x1i - x3r; 1722 | wn4r = w[wP + 1]; 1723 | k = 0; 1724 | for (j = 2; j < mh; j += 2) { 1725 | k += 4; 1726 | wk1r = w[wP + k]; 1727 | wk1i = w[wP + k + 1]; 1728 | wk3r = w[wP + k + 2]; 1729 | wk3i = -w[wP + k + 3]; 1730 | j1 = j + m; 1731 | j2 = j1 + m; 1732 | j3 = j2 + m; 1733 | x0r = a[aP + j] + a[aP + j2]; 1734 | x0i = a[aP + j + 1] + a[aP + j2 + 1]; 1735 | x1r = a[aP + j] - a[aP + j2]; 1736 | x1i = a[aP + j + 1] - a[aP + j2 + 1]; 1737 | x2r = a[aP + j1] + a[aP + j3]; 1738 | x2i = a[aP + j1 + 1] + a[aP + j3 + 1]; 1739 | x3r = a[aP + j1] - a[aP + j3]; 1740 | x3i = a[aP + j1 + 1] - a[aP + j3 + 1]; 1741 | a[aP + j] = x0r + x2r; 1742 | a[aP + j + 1] = x0i + x2i; 1743 | a[aP + j1] = x0r - x2r; 1744 | a[aP + j1 + 1] = x0i - x2i; 1745 | x0r = x1r - x3i; 1746 | x0i = x1i + x3r; 1747 | a[aP + j2] = wk1r * x0r - wk1i * x0i; 1748 | a[aP + j2 + 1] = wk1r * x0i + wk1i * x0r; 1749 | x0r = x1r + x3i; 1750 | x0i = x1i - x3r; 1751 | a[aP + j3] = wk3r * x0r + wk3i * x0i; 1752 | a[aP + j3 + 1] = wk3r * x0i - wk3i * x0r; 1753 | j0 = m - j; 1754 | j1 = j0 + m; 1755 | j2 = j1 + m; 1756 | j3 = j2 + m; 1757 | x0r = a[aP + j0] + a[aP + j2]; 1758 | x0i = a[aP + j0 + 1] + a[aP + j2 + 1]; 1759 | x1r = a[aP + j0] - a[aP + j2]; 1760 | x1i = a[aP + j0 + 1] - a[aP + j2 + 1]; 1761 | x2r = a[aP + j1] + a[aP + j3]; 1762 | x2i = a[aP + j1 + 1] + a[aP + j3 + 1]; 1763 | x3r = a[aP + j1] - a[aP + j3]; 1764 | x3i = a[aP + j1 + 1] - a[aP + j3 + 1]; 1765 | a[aP + j0] = x0r + x2r; 1766 | a[aP + j0 + 1] = x0i + x2i; 1767 | a[aP + j1] = x0r - x2r; 1768 | a[aP + j1 + 1] = x0i - x2i; 1769 | x0r = x1r - x3i; 1770 | x0i = x1i + x3r; 1771 | a[aP + j2] = wk1i * x0r - wk1r * x0i; 1772 | a[aP + j2 + 1] = wk1i * x0i + wk1r * x0r; 1773 | x0r = x1r + x3i; 1774 | x0i = x1i - x3r; 1775 | a[aP + j3] = wk3i * x0r + wk3r * x0i; 1776 | a[aP + j3 + 1] = wk3i * x0i - wk3r * x0r; 1777 | } 1778 | j0 = mh; 1779 | j1 = j0 + m; 1780 | j2 = j1 + m; 1781 | j3 = j2 + m; 1782 | x0r = a[aP + j0] + a[aP + j2]; 1783 | x0i = a[aP + j0 + 1] + a[aP + j2 + 1]; 1784 | x1r = a[aP + j0] - a[aP + j2]; 1785 | x1i = a[aP + j0 + 1] - a[aP + j2 + 1]; 1786 | x2r = a[aP + j1] + a[aP + j3]; 1787 | x2i = a[aP + j1 + 1] + a[aP + j3 + 1]; 1788 | x3r = a[aP + j1] - a[aP + j3]; 1789 | x3i = a[aP + j1 + 1] - a[aP + j3 + 1]; 1790 | a[aP + j0] = x0r + x2r; 1791 | a[aP + j0 + 1] = x0i + x2i; 1792 | a[aP + j1] = x0r - x2r; 1793 | a[aP + j1 + 1] = x0i - x2i; 1794 | x0r = x1r - x3i; 1795 | x0i = x1i + x3r; 1796 | a[aP + j2] = wn4r * (x0r - x0i); 1797 | a[aP + j2 + 1] = wn4r * (x0i + x0r); 1798 | x0r = x1r + x3i; 1799 | x0i = x1i - x3r; 1800 | a[aP + j3] = -wn4r * (x0r + x0i); 1801 | a[aP + j3 + 1] = -wn4r * (x0i - x0r); 1802 | } 1803 | 1804 | /** */ 1805 | private final void cftmdl2(int n, double[] a, int aP, double[] w, int wP) { 1806 | int j, j0, j1, j2, j3, k, kr, m, mh; 1807 | double wn4r, wk1r, wk1i, wk3r, wk3i, wd1r, wd1i, wd3r, wd3i; 1808 | double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, y0r, y0i, y2r, y2i; 1809 | 1810 | mh = n >> 3; 1811 | m = 2 * mh; 1812 | wn4r = w[wP + 1]; 1813 | j1 = m; 1814 | j2 = j1 + m; 1815 | j3 = j2 + m; 1816 | x0r = a[aP + 0] - a[aP + j2 + 1]; 1817 | x0i = a[aP + 1] + a[aP + j2]; 1818 | x1r = a[aP + 0] + a[aP + j2 + 1]; 1819 | x1i = a[aP + 1] - a[aP + j2]; 1820 | x2r = a[aP + j1] - a[aP + j3 + 1]; 1821 | x2i = a[aP + j1 + 1] + a[aP + j3]; 1822 | x3r = a[aP + j1] + a[aP + j3 + 1]; 1823 | x3i = a[aP + j1 + 1] - a[aP + j3]; 1824 | y0r = wn4r * (x2r - x2i); 1825 | y0i = wn4r * (x2i + x2r); 1826 | a[aP + 0] = x0r + y0r; 1827 | a[aP + 1] = x0i + y0i; 1828 | a[aP + j1] = x0r - y0r; 1829 | a[aP + j1 + 1] = x0i - y0i; 1830 | y0r = wn4r * (x3r - x3i); 1831 | y0i = wn4r * (x3i + x3r); 1832 | a[aP + j2] = x1r - y0i; 1833 | a[aP + j2 + 1] = x1i + y0r; 1834 | a[aP + j3] = x1r + y0i; 1835 | a[aP + j3 + 1] = x1i - y0r; 1836 | k = 0; 1837 | kr = 2 * m; 1838 | for (j = 2; j < mh; j += 2) { 1839 | k += 4; 1840 | wk1r = w[wP + k]; 1841 | wk1i = w[wP + k + 1]; 1842 | wk3r = w[wP + k + 2]; 1843 | wk3i = -w[wP + k + 3]; 1844 | kr -= 4; 1845 | wd1i = w[wP + kr]; 1846 | wd1r = w[wP + kr + 1]; 1847 | wd3i = w[wP + kr + 2]; 1848 | wd3r = -w[wP + kr + 3]; 1849 | j1 = j + m; 1850 | j2 = j1 + m; 1851 | j3 = j2 + m; 1852 | x0r = a[aP + j] - a[aP + j2 + 1]; 1853 | x0i = a[aP + j + 1] + a[aP + j2]; 1854 | x1r = a[aP + j] + a[aP + j2 + 1]; 1855 | x1i = a[aP + j + 1] - a[aP + j2]; 1856 | x2r = a[aP + j1] - a[aP + j3 + 1]; 1857 | x2i = a[aP + j1 + 1] + a[aP + j3]; 1858 | x3r = a[aP + j1] + a[aP + j3 + 1]; 1859 | x3i = a[aP + j1 + 1] - a[aP + j3]; 1860 | y0r = wk1r * x0r - wk1i * x0i; 1861 | y0i = wk1r * x0i + wk1i * x0r; 1862 | y2r = wd1r * x2r - wd1i * x2i; 1863 | y2i = wd1r * x2i + wd1i * x2r; 1864 | a[aP + j] = y0r + y2r; 1865 | a[aP + j + 1] = y0i + y2i; 1866 | a[aP + j1] = y0r - y2r; 1867 | a[aP + j1 + 1] = y0i - y2i; 1868 | y0r = wk3r * x1r + wk3i * x1i; 1869 | y0i = wk3r * x1i - wk3i * x1r; 1870 | y2r = wd3r * x3r + wd3i * x3i; 1871 | y2i = wd3r * x3i - wd3i * x3r; 1872 | a[aP + j2] = y0r + y2r; 1873 | a[aP + j2 + 1] = y0i + y2i; 1874 | a[aP + j3] = y0r - y2r; 1875 | a[aP + j3 + 1] = y0i - y2i; 1876 | j0 = m - j; 1877 | j1 = j0 + m; 1878 | j2 = j1 + m; 1879 | j3 = j2 + m; 1880 | x0r = a[aP + j0] - a[aP + j2 + 1]; 1881 | x0i = a[aP + j0 + 1] + a[aP + j2]; 1882 | x1r = a[aP + j0] + a[aP + j2 + 1]; 1883 | x1i = a[aP + j0 + 1] - a[aP + j2]; 1884 | x2r = a[aP + j1] - a[aP + j3 + 1]; 1885 | x2i = a[aP + j1 + 1] + a[aP + j3]; 1886 | x3r = a[aP + j1] + a[aP + j3 + 1]; 1887 | x3i = a[aP + j1 + 1] - a[aP + j3]; 1888 | y0r = wd1i * x0r - wd1r * x0i; 1889 | y0i = wd1i * x0i + wd1r * x0r; 1890 | y2r = wk1i * x2r - wk1r * x2i; 1891 | y2i = wk1i * x2i + wk1r * x2r; 1892 | a[aP + j0] = y0r + y2r; 1893 | a[aP + j0 + 1] = y0i + y2i; 1894 | a[aP + j1] = y0r - y2r; 1895 | a[aP + j1 + 1] = y0i - y2i; 1896 | y0r = wd3i * x1r + wd3r * x1i; 1897 | y0i = wd3i * x1i - wd3r * x1r; 1898 | y2r = wk3i * x3r + wk3r * x3i; 1899 | y2i = wk3i * x3i - wk3r * x3r; 1900 | a[aP + j2] = y0r + y2r; 1901 | a[aP + j2 + 1] = y0i + y2i; 1902 | a[aP + j3] = y0r - y2r; 1903 | a[aP + j3 + 1] = y0i - y2i; 1904 | } 1905 | wk1r = w[wP + m]; 1906 | wk1i = w[wP + m + 1]; 1907 | j0 = mh; 1908 | j1 = j0 + m; 1909 | j2 = j1 + m; 1910 | j3 = j2 + m; 1911 | x0r = a[aP + j0] - a[aP + j2 + 1]; 1912 | x0i = a[aP + j0 + 1] + a[aP + j2]; 1913 | x1r = a[aP + j0] + a[aP + j2 + 1]; 1914 | x1i = a[aP + j0 + 1] - a[aP + j2]; 1915 | x2r = a[aP + j1] - a[aP + j3 + 1]; 1916 | x2i = a[aP + j1 + 1] + a[aP + j3]; 1917 | x3r = a[aP + j1] + a[aP + j3 + 1]; 1918 | x3i = a[aP + j1 + 1] - a[aP + j3]; 1919 | y0r = wk1r * x0r - wk1i * x0i; 1920 | y0i = wk1r * x0i + wk1i * x0r; 1921 | y2r = wk1i * x2r - wk1r * x2i; 1922 | y2i = wk1i * x2i + wk1r * x2r; 1923 | a[aP + j0] = y0r + y2r; 1924 | a[aP + j0 + 1] = y0i + y2i; 1925 | a[aP + j1] = y0r - y2r; 1926 | a[aP + j1 + 1] = y0i - y2i; 1927 | y0r = wk1i * x1r - wk1r * x1i; 1928 | y0i = wk1i * x1i + wk1r * x1r; 1929 | y2r = wk1r * x3r - wk1i * x3i; 1930 | y2i = wk1r * x3i + wk1i * x3r; 1931 | a[aP + j2] = y0r - y2r; 1932 | a[aP + j2 + 1] = y0i - y2i; 1933 | a[aP + j3] = y0r + y2r; 1934 | a[aP + j3 + 1] = y0i + y2i; 1935 | } 1936 | 1937 | /** */ 1938 | private void cftfx41(int n, double[] a, int aP, int nw, double[] w) { 1939 | if (n == 128) { 1940 | cftf161(a, aP, w, nw - 8); 1941 | cftf162(a, aP + 32, w, nw - 32); 1942 | cftf161(a, aP + 64, w, nw - 8); 1943 | cftf161(a, aP + 96, w, nw - 8); 1944 | } else { 1945 | cftf081(a, aP, w, nw - 16); 1946 | cftf082(a, aP + 16, w, nw - 16); 1947 | cftf081(a, aP + 32, w, nw - 16); 1948 | cftf081(a, aP + 48, w, nw - 16); 1949 | } 1950 | } 1951 | 1952 | /** */ 1953 | private void cftfx42(int n, double[] a, int aP, int nw, double[] w) { 1954 | if (n == 128) { 1955 | cftf161(a, aP, w, nw - 8); 1956 | cftf162(a, aP + 32, w, nw - 32); 1957 | cftf161(a, aP + 64, w, nw - 8); 1958 | cftf162(a, aP + 96, w, nw - 32); 1959 | } else { 1960 | cftf081(a, aP, w, nw - 16); 1961 | cftf082(a, aP + 16, w, nw - 16); 1962 | cftf081(a, aP + 32, w, nw - 16); 1963 | cftf082(a, aP + 48, w, nw - 16); 1964 | } 1965 | } 1966 | 1967 | /** */ 1968 | private void cftf161(double[] a, int aP, double[] w, int wP) { 1969 | double wn4r, wk1r, wk1i, x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i, y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i, y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i; 1970 | 1971 | wn4r = w[wP + 1]; 1972 | wk1i = wn4r * w[wP + 2]; 1973 | wk1r = wk1i + w[wP + 2]; 1974 | x0r = a[aP + 0] + a[aP + 16]; 1975 | x0i = a[aP + 1] + a[aP + 17]; 1976 | x1r = a[aP + 0] - a[aP + 16]; 1977 | x1i = a[aP + 1] - a[aP + 17]; 1978 | x2r = a[aP + 8] + a[aP + 24]; 1979 | x2i = a[aP + 9] + a[aP + 25]; 1980 | x3r = a[aP + 8] - a[aP + 24]; 1981 | x3i = a[aP + 9] - a[aP + 25]; 1982 | y0r = x0r + x2r; 1983 | y0i = x0i + x2i; 1984 | y4r = x0r - x2r; 1985 | y4i = x0i - x2i; 1986 | y8r = x1r - x3i; 1987 | y8i = x1i + x3r; 1988 | y12r = x1r + x3i; 1989 | y12i = x1i - x3r; 1990 | x0r = a[aP + 2] + a[aP + 18]; 1991 | x0i = a[aP + 3] + a[aP + 19]; 1992 | x1r = a[aP + 2] - a[aP + 18]; 1993 | x1i = a[aP + 3] - a[aP + 19]; 1994 | x2r = a[aP + 10] + a[aP + 26]; 1995 | x2i = a[aP + 11] + a[aP + 27]; 1996 | x3r = a[aP + 10] - a[aP + 26]; 1997 | x3i = a[aP + 11] - a[aP + 27]; 1998 | y1r = x0r + x2r; 1999 | y1i = x0i + x2i; 2000 | y5r = x0r - x2r; 2001 | y5i = x0i - x2i; 2002 | x0r = x1r - x3i; 2003 | x0i = x1i + x3r; 2004 | y9r = wk1r * x0r - wk1i * x0i; 2005 | y9i = wk1r * x0i + wk1i * x0r; 2006 | x0r = x1r + x3i; 2007 | x0i = x1i - x3r; 2008 | y13r = wk1i * x0r - wk1r * x0i; 2009 | y13i = wk1i * x0i + wk1r * x0r; 2010 | x0r = a[aP + 4] + a[aP + 20]; 2011 | x0i = a[aP + 5] + a[aP + 21]; 2012 | x1r = a[aP + 4] - a[aP + 20]; 2013 | x1i = a[aP + 5] - a[aP + 21]; 2014 | x2r = a[aP + 12] + a[aP + 28]; 2015 | x2i = a[aP + 13] + a[aP + 29]; 2016 | x3r = a[aP + 12] - a[aP + 28]; 2017 | x3i = a[aP + 13] - a[aP + 29]; 2018 | y2r = x0r + x2r; 2019 | y2i = x0i + x2i; 2020 | y6r = x0r - x2r; 2021 | y6i = x0i - x2i; 2022 | x0r = x1r - x3i; 2023 | x0i = x1i + x3r; 2024 | y10r = wn4r * (x0r - x0i); 2025 | y10i = wn4r * (x0i + x0r); 2026 | x0r = x1r + x3i; 2027 | x0i = x1i - x3r; 2028 | y14r = wn4r * (x0r + x0i); 2029 | y14i = wn4r * (x0i - x0r); 2030 | x0r = a[aP + 6] + a[aP + 22]; 2031 | x0i = a[aP + 7] + a[aP + 23]; 2032 | x1r = a[aP + 6] - a[aP + 22]; 2033 | x1i = a[aP + 7] - a[aP + 23]; 2034 | x2r = a[aP + 14] + a[aP + 30]; 2035 | x2i = a[aP + 15] + a[aP + 31]; 2036 | x3r = a[aP + 14] - a[aP + 30]; 2037 | x3i = a[aP + 15] - a[aP + 31]; 2038 | y3r = x0r + x2r; 2039 | y3i = x0i + x2i; 2040 | y7r = x0r - x2r; 2041 | y7i = x0i - x2i; 2042 | x0r = x1r - x3i; 2043 | x0i = x1i + x3r; 2044 | y11r = wk1i * x0r - wk1r * x0i; 2045 | y11i = wk1i * x0i + wk1r * x0r; 2046 | x0r = x1r + x3i; 2047 | x0i = x1i - x3r; 2048 | y15r = wk1r * x0r - wk1i * x0i; 2049 | y15i = wk1r * x0i + wk1i * x0r; 2050 | x0r = y12r - y14r; 2051 | x0i = y12i - y14i; 2052 | x1r = y12r + y14r; 2053 | x1i = y12i + y14i; 2054 | x2r = y13r - y15r; 2055 | x2i = y13i - y15i; 2056 | x3r = y13r + y15r; 2057 | x3i = y13i + y15i; 2058 | a[aP + 24] = x0r + x2r; 2059 | a[aP + 25] = x0i + x2i; 2060 | a[aP + 26] = x0r - x2r; 2061 | a[aP + 27] = x0i - x2i; 2062 | a[aP + 28] = x1r - x3i; 2063 | a[aP + 29] = x1i + x3r; 2064 | a[aP + 30] = x1r + x3i; 2065 | a[aP + 31] = x1i - x3r; 2066 | x0r = y8r + y10r; 2067 | x0i = y8i + y10i; 2068 | x1r = y8r - y10r; 2069 | x1i = y8i - y10i; 2070 | x2r = y9r + y11r; 2071 | x2i = y9i + y11i; 2072 | x3r = y9r - y11r; 2073 | x3i = y9i - y11i; 2074 | a[aP + 16] = x0r + x2r; 2075 | a[aP + 17] = x0i + x2i; 2076 | a[aP + 18] = x0r - x2r; 2077 | a[aP + 19] = x0i - x2i; 2078 | a[aP + 20] = x1r - x3i; 2079 | a[aP + 21] = x1i + x3r; 2080 | a[aP + 22] = x1r + x3i; 2081 | a[aP + 23] = x1i - x3r; 2082 | x0r = y5r - y7i; 2083 | x0i = y5i + y7r; 2084 | x2r = wn4r * (x0r - x0i); 2085 | x2i = wn4r * (x0i + x0r); 2086 | x0r = y5r + y7i; 2087 | x0i = y5i - y7r; 2088 | x3r = wn4r * (x0r - x0i); 2089 | x3i = wn4r * (x0i + x0r); 2090 | x0r = y4r - y6i; 2091 | x0i = y4i + y6r; 2092 | x1r = y4r + y6i; 2093 | x1i = y4i - y6r; 2094 | a[aP + 8] = x0r + x2r; 2095 | a[aP + 9] = x0i + x2i; 2096 | a[aP + 10] = x0r - x2r; 2097 | a[aP + 11] = x0i - x2i; 2098 | a[aP + 12] = x1r - x3i; 2099 | a[aP + 13] = x1i + x3r; 2100 | a[aP + 14] = x1r + x3i; 2101 | a[aP + 15] = x1i - x3r; 2102 | x0r = y0r + y2r; 2103 | x0i = y0i + y2i; 2104 | x1r = y0r - y2r; 2105 | x1i = y0i - y2i; 2106 | x2r = y1r + y3r; 2107 | x2i = y1i + y3i; 2108 | x3r = y1r - y3r; 2109 | x3i = y1i - y3i; 2110 | a[aP + 0] = x0r + x2r; 2111 | a[aP + 1] = x0i + x2i; 2112 | a[aP + 2] = x0r - x2r; 2113 | a[aP + 3] = x0i - x2i; 2114 | a[aP + 4] = x1r - x3i; 2115 | a[aP + 5] = x1i + x3r; 2116 | a[aP + 6] = x1r + x3i; 2117 | a[aP + 7] = x1i - x3r; 2118 | } 2119 | 2120 | /** */ 2121 | private void cftf162(double[] a, int aP, double[] w, int wP) { 2122 | double wn4r, wk1r, wk1i, wk2r, wk2i, wk3r, wk3i, x0r, x0i, x1r, x1i, x2r, x2i, y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i, y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i, y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i; 2123 | 2124 | wn4r = w[wP + 1]; 2125 | wk1r = w[wP + 4]; 2126 | wk1i = w[wP + 5]; 2127 | wk3r = w[wP + 6]; 2128 | wk3i = w[wP + 7]; 2129 | wk2r = w[wP + 8]; 2130 | wk2i = w[wP + 9]; 2131 | x1r = a[aP + 0] - a[aP + 17]; 2132 | x1i = a[aP + 1] + a[aP + 16]; 2133 | x0r = a[aP + 8] - a[aP + 25]; 2134 | x0i = a[aP + 9] + a[aP + 24]; 2135 | x2r = wn4r * (x0r - x0i); 2136 | x2i = wn4r * (x0i + x0r); 2137 | y0r = x1r + x2r; 2138 | y0i = x1i + x2i; 2139 | y4r = x1r - x2r; 2140 | y4i = x1i - x2i; 2141 | x1r = a[aP + 0] + a[aP + 17]; 2142 | x1i = a[aP + 1] - a[aP + 16]; 2143 | x0r = a[aP + 8] + a[aP + 25]; 2144 | x0i = a[aP + 9] - a[aP + 24]; 2145 | x2r = wn4r * (x0r - x0i); 2146 | x2i = wn4r * (x0i + x0r); 2147 | y8r = x1r - x2i; 2148 | y8i = x1i + x2r; 2149 | y12r = x1r + x2i; 2150 | y12i = x1i - x2r; 2151 | x0r = a[aP + 2] - a[aP + 19]; 2152 | x0i = a[aP + 3] + a[aP + 18]; 2153 | x1r = wk1r * x0r - wk1i * x0i; 2154 | x1i = wk1r * x0i + wk1i * x0r; 2155 | x0r = a[aP + 10] - a[aP + 27]; 2156 | x0i = a[aP + 11] + a[aP + 26]; 2157 | x2r = wk3i * x0r - wk3r * x0i; 2158 | x2i = wk3i * x0i + wk3r * x0r; 2159 | y1r = x1r + x2r; 2160 | y1i = x1i + x2i; 2161 | y5r = x1r - x2r; 2162 | y5i = x1i - x2i; 2163 | x0r = a[aP + 2] + a[aP + 19]; 2164 | x0i = a[aP + 3] - a[aP + 18]; 2165 | x1r = wk3r * x0r - wk3i * x0i; 2166 | x1i = wk3r * x0i + wk3i * x0r; 2167 | x0r = a[aP + 10] + a[aP + 27]; 2168 | x0i = a[aP + 11] - a[aP + 26]; 2169 | x2r = wk1r * x0r + wk1i * x0i; 2170 | x2i = wk1r * x0i - wk1i * x0r; 2171 | y9r = x1r - x2r; 2172 | y9i = x1i - x2i; 2173 | y13r = x1r + x2r; 2174 | y13i = x1i + x2i; 2175 | x0r = a[aP + 4] - a[aP + 21]; 2176 | x0i = a[aP + 5] + a[aP + 20]; 2177 | x1r = wk2r * x0r - wk2i * x0i; 2178 | x1i = wk2r * x0i + wk2i * x0r; 2179 | x0r = a[aP + 12] - a[aP + 29]; 2180 | x0i = a[aP + 13] + a[aP + 28]; 2181 | x2r = wk2i * x0r - wk2r * x0i; 2182 | x2i = wk2i * x0i + wk2r * x0r; 2183 | y2r = x1r + x2r; 2184 | y2i = x1i + x2i; 2185 | y6r = x1r - x2r; 2186 | y6i = x1i - x2i; 2187 | x0r = a[aP + 4] + a[aP + 21]; 2188 | x0i = a[aP + 5] - a[aP + 20]; 2189 | x1r = wk2i * x0r - wk2r * x0i; 2190 | x1i = wk2i * x0i + wk2r * x0r; 2191 | x0r = a[aP + 12] + a[aP + 29]; 2192 | x0i = a[aP + 13] - a[aP + 28]; 2193 | x2r = wk2r * x0r - wk2i * x0i; 2194 | x2i = wk2r * x0i + wk2i * x0r; 2195 | y10r = x1r - x2r; 2196 | y10i = x1i - x2i; 2197 | y14r = x1r + x2r; 2198 | y14i = x1i + x2i; 2199 | x0r = a[aP + 6] - a[aP + 23]; 2200 | x0i = a[aP + 7] + a[aP + 22]; 2201 | x1r = wk3r * x0r - wk3i * x0i; 2202 | x1i = wk3r * x0i + wk3i * x0r; 2203 | x0r = a[aP + 14] - a[aP + 31]; 2204 | x0i = a[aP + 15] + a[aP + 30]; 2205 | x2r = wk1i * x0r - wk1r * x0i; 2206 | x2i = wk1i * x0i + wk1r * x0r; 2207 | y3r = x1r + x2r; 2208 | y3i = x1i + x2i; 2209 | y7r = x1r - x2r; 2210 | y7i = x1i - x2i; 2211 | x0r = a[aP + 6] + a[aP + 23]; 2212 | x0i = a[aP + 7] - a[aP + 22]; 2213 | x1r = wk1i * x0r + wk1r * x0i; 2214 | x1i = wk1i * x0i - wk1r * x0r; 2215 | x0r = a[aP + 14] + a[aP + 31]; 2216 | x0i = a[aP + 15] - a[aP + 30]; 2217 | x2r = wk3i * x0r - wk3r * x0i; 2218 | x2i = wk3i * x0i + wk3r * x0r; 2219 | y11r = x1r + x2r; 2220 | y11i = x1i + x2i; 2221 | y15r = x1r - x2r; 2222 | y15i = x1i - x2i; 2223 | x1r = y0r + y2r; 2224 | x1i = y0i + y2i; 2225 | x2r = y1r + y3r; 2226 | x2i = y1i + y3i; 2227 | a[aP + 0] = x1r + x2r; 2228 | a[aP + 1] = x1i + x2i; 2229 | a[aP + 2] = x1r - x2r; 2230 | a[aP + 3] = x1i - x2i; 2231 | x1r = y0r - y2r; 2232 | x1i = y0i - y2i; 2233 | x2r = y1r - y3r; 2234 | x2i = y1i - y3i; 2235 | a[aP + 4] = x1r - x2i; 2236 | a[aP + 5] = x1i + x2r; 2237 | a[aP + 6] = x1r + x2i; 2238 | a[aP + 7] = x1i - x2r; 2239 | x1r = y4r - y6i; 2240 | x1i = y4i + y6r; 2241 | x0r = y5r - y7i; 2242 | x0i = y5i + y7r; 2243 | x2r = wn4r * (x0r - x0i); 2244 | x2i = wn4r * (x0i + x0r); 2245 | a[aP + 8] = x1r + x2r; 2246 | a[aP + 9] = x1i + x2i; 2247 | a[aP + 10] = x1r - x2r; 2248 | a[aP + 11] = x1i - x2i; 2249 | x1r = y4r + y6i; 2250 | x1i = y4i - y6r; 2251 | x0r = y5r + y7i; 2252 | x0i = y5i - y7r; 2253 | x2r = wn4r * (x0r - x0i); 2254 | x2i = wn4r * (x0i + x0r); 2255 | a[aP + 12] = x1r - x2i; 2256 | a[aP + 13] = x1i + x2r; 2257 | a[aP + 14] = x1r + x2i; 2258 | a[aP + 15] = x1i - x2r; 2259 | x1r = y8r + y10r; 2260 | x1i = y8i + y10i; 2261 | x2r = y9r - y11r; 2262 | x2i = y9i - y11i; 2263 | a[aP + 16] = x1r + x2r; 2264 | a[aP + 17] = x1i + x2i; 2265 | a[aP + 18] = x1r - x2r; 2266 | a[aP + 19] = x1i - x2i; 2267 | x1r = y8r - y10r; 2268 | x1i = y8i - y10i; 2269 | x2r = y9r + y11r; 2270 | x2i = y9i + y11i; 2271 | a[aP + 20] = x1r - x2i; 2272 | a[aP + 21] = x1i + x2r; 2273 | a[aP + 22] = x1r + x2i; 2274 | a[aP + 23] = x1i - x2r; 2275 | x1r = y12r - y14i; 2276 | x1i = y12i + y14r; 2277 | x0r = y13r + y15i; 2278 | x0i = y13i - y15r; 2279 | x2r = wn4r * (x0r - x0i); 2280 | x2i = wn4r * (x0i + x0r); 2281 | a[aP + 24] = x1r + x2r; 2282 | a[aP + 25] = x1i + x2i; 2283 | a[aP + 26] = x1r - x2r; 2284 | a[aP + 27] = x1i - x2i; 2285 | x1r = y12r + y14i; 2286 | x1i = y12i - y14r; 2287 | x0r = y13r - y15i; 2288 | x0i = y13i + y15r; 2289 | x2r = wn4r * (x0r - x0i); 2290 | x2i = wn4r * (x0i + x0r); 2291 | a[aP + 28] = x1r - x2i; 2292 | a[aP + 29] = x1i + x2r; 2293 | a[aP + 30] = x1r + x2i; 2294 | a[aP + 31] = x1i - x2r; 2295 | } 2296 | 2297 | /** */ 2298 | private void cftf081(double[] a, int aP, double[] w, int wP) { 2299 | double wn4r, x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i; 2300 | 2301 | wn4r = w[wP + 1]; 2302 | x0r = a[aP + 0] + a[aP + 8]; 2303 | x0i = a[aP + 1] + a[aP + 9]; 2304 | x1r = a[aP + 0] - a[aP + 8]; 2305 | x1i = a[aP + 1] - a[aP + 9]; 2306 | x2r = a[aP + 4] + a[aP + 12]; 2307 | x2i = a[aP + 5] + a[aP + 13]; 2308 | x3r = a[aP + 4] - a[aP + 12]; 2309 | x3i = a[aP + 5] - a[aP + 13]; 2310 | y0r = x0r + x2r; 2311 | y0i = x0i + x2i; 2312 | y2r = x0r - x2r; 2313 | y2i = x0i - x2i; 2314 | y1r = x1r - x3i; 2315 | y1i = x1i + x3r; 2316 | y3r = x1r + x3i; 2317 | y3i = x1i - x3r; 2318 | x0r = a[aP + 2] + a[aP + 10]; 2319 | x0i = a[aP + 3] + a[aP + 11]; 2320 | x1r = a[aP + 2] - a[aP + 10]; 2321 | x1i = a[aP + 3] - a[aP + 11]; 2322 | x2r = a[aP + 6] + a[aP + 14]; 2323 | x2i = a[aP + 7] + a[aP + 15]; 2324 | x3r = a[aP + 6] - a[aP + 14]; 2325 | x3i = a[aP + 7] - a[aP + 15]; 2326 | y4r = x0r + x2r; 2327 | y4i = x0i + x2i; 2328 | y6r = x0r - x2r; 2329 | y6i = x0i - x2i; 2330 | x0r = x1r - x3i; 2331 | x0i = x1i + x3r; 2332 | x2r = x1r + x3i; 2333 | x2i = x1i - x3r; 2334 | y5r = wn4r * (x0r - x0i); 2335 | y5i = wn4r * (x0r + x0i); 2336 | y7r = wn4r * (x2r - x2i); 2337 | y7i = wn4r * (x2r + x2i); 2338 | a[aP + 8] = y1r + y5r; 2339 | a[aP + 9] = y1i + y5i; 2340 | a[aP + 10] = y1r - y5r; 2341 | a[aP + 11] = y1i - y5i; 2342 | a[aP + 12] = y3r - y7i; 2343 | a[aP + 13] = y3i + y7r; 2344 | a[aP + 14] = y3r + y7i; 2345 | a[aP + 15] = y3i - y7r; 2346 | a[aP + 0] = y0r + y4r; 2347 | a[aP + 1] = y0i + y4i; 2348 | a[aP + 2] = y0r - y4r; 2349 | a[aP + 3] = y0i - y4i; 2350 | a[aP + 4] = y2r - y6i; 2351 | a[aP + 5] = y2i + y6r; 2352 | a[aP + 6] = y2r + y6i; 2353 | a[aP + 7] = y2i - y6r; 2354 | } 2355 | 2356 | /** */ 2357 | private void cftf082(double[] a, int aP, double[] w, int wP) { 2358 | double wn4r, wk1r, wk1i, x0r, x0i, x1r, x1i, y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i; 2359 | 2360 | wn4r = w[wP + 1]; 2361 | wk1r = w[wP + 4]; 2362 | wk1i = w[wP + 5]; 2363 | y0r = a[aP + 0] - a[aP + 9]; 2364 | y0i = a[aP + 1] + a[aP + 8]; 2365 | y1r = a[aP + 0] + a[aP + 9]; 2366 | y1i = a[aP + 1] - a[aP + 8]; 2367 | x0r = a[aP + 4] - a[aP + 13]; 2368 | x0i = a[aP + 5] + a[aP + 12]; 2369 | y2r = wn4r * (x0r - x0i); 2370 | y2i = wn4r * (x0i + x0r); 2371 | x0r = a[aP + 4] + a[aP + 13]; 2372 | x0i = a[aP + 5] - a[aP + 12]; 2373 | y3r = wn4r * (x0r - x0i); 2374 | y3i = wn4r * (x0i + x0r); 2375 | x0r = a[aP + 2] - a[aP + 11]; 2376 | x0i = a[aP + 3] + a[aP + 10]; 2377 | y4r = wk1r * x0r - wk1i * x0i; 2378 | y4i = wk1r * x0i + wk1i * x0r; 2379 | x0r = a[aP + 2] + a[aP + 11]; 2380 | x0i = a[aP + 3] - a[aP + 10]; 2381 | y5r = wk1i * x0r - wk1r * x0i; 2382 | y5i = wk1i * x0i + wk1r * x0r; 2383 | x0r = a[aP + 6] - a[aP + 15]; 2384 | x0i = a[aP + 7] + a[aP + 14]; 2385 | y6r = wk1i * x0r - wk1r * x0i; 2386 | y6i = wk1i * x0i + wk1r * x0r; 2387 | x0r = a[aP + 6] + a[aP + 15]; 2388 | x0i = a[aP + 7] - a[aP + 14]; 2389 | y7r = wk1r * x0r - wk1i * x0i; 2390 | y7i = wk1r * x0i + wk1i * x0r; 2391 | x0r = y0r + y2r; 2392 | x0i = y0i + y2i; 2393 | x1r = y4r + y6r; 2394 | x1i = y4i + y6i; 2395 | a[aP + 0] = x0r + x1r; 2396 | a[aP + 1] = x0i + x1i; 2397 | a[aP + 2] = x0r - x1r; 2398 | a[aP + 3] = x0i - x1i; 2399 | x0r = y0r - y2r; 2400 | x0i = y0i - y2i; 2401 | x1r = y4r - y6r; 2402 | x1i = y4i - y6i; 2403 | a[aP + 4] = x0r - x1i; 2404 | a[aP + 5] = x0i + x1r; 2405 | a[aP + 6] = x0r + x1i; 2406 | a[aP + 7] = x0i - x1r; 2407 | x0r = y1r - y3i; 2408 | x0i = y1i + y3r; 2409 | x1r = y5r - y7r; 2410 | x1i = y5i - y7i; 2411 | a[aP + 8] = x0r + x1r; 2412 | a[aP + 9] = x0i + x1i; 2413 | a[aP + 10] = x0r - x1r; 2414 | a[aP + 11] = x0i - x1i; 2415 | x0r = y1r + y3i; 2416 | x0i = y1i - y3r; 2417 | x1r = y5r + y7r; 2418 | x1i = y5i + y7i; 2419 | a[aP + 12] = x0r - x1i; 2420 | a[aP + 13] = x0i + x1r; 2421 | a[aP + 14] = x0r + x1i; 2422 | a[aP + 15] = x0i - x1r; 2423 | } 2424 | 2425 | /** 2426 | * 3rd 2427 | * when n = 8. 2428 | * @see #cftfsub(int, double[], int[], int, int, double[]) 2429 | */ 2430 | private void cftf040(double[] a) { 2431 | double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; 2432 | 2433 | x0r = a[0] + a[4]; 2434 | x0i = a[1] + a[5]; 2435 | x1r = a[0] - a[4]; 2436 | x1i = a[1] - a[5]; 2437 | x2r = a[2] + a[6]; 2438 | x2i = a[3] + a[7]; 2439 | x3r = a[2] - a[6]; 2440 | x3i = a[3] - a[7]; 2441 | a[0] = x0r + x2r; 2442 | a[1] = x0i + x2i; 2443 | a[4] = x0r - x2r; 2444 | a[5] = x0i - x2i; 2445 | a[2] = x1r - x3i; 2446 | a[3] = x1i + x3r; 2447 | a[6] = x1r + x3i; 2448 | a[7] = x1i - x3r; 2449 | } 2450 | 2451 | /** 2452 | * 3rd 2453 | * when n = 8. 2454 | * @see #cftbsub(int, double[], int[], int, int, double[]) 2455 | */ 2456 | private void cftb040(double[] a) { 2457 | double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; 2458 | 2459 | x0r = a[0] + a[4]; 2460 | x0i = a[1] + a[5]; 2461 | x1r = a[0] - a[4]; 2462 | x1i = a[1] - a[5]; 2463 | x2r = a[2] + a[6]; 2464 | x2i = a[3] + a[7]; 2465 | x3r = a[2] - a[6]; 2466 | x3i = a[3] - a[7]; 2467 | a[0] = x0r + x2r; 2468 | a[1] = x0i + x2i; 2469 | a[4] = x0r - x2r; 2470 | a[5] = x0i - x2i; 2471 | a[2] = x1r + x3i; 2472 | a[3] = x1i - x3r; 2473 | a[6] = x1r - x3i; 2474 | a[7] = x1i + x3r; 2475 | } 2476 | 2477 | /** 2478 | * 3rd 2479 | * when n = 4. 2480 | * @see #cftbsub(int, double[], int[], int, int, double[]) 2481 | * @see #cftfsub(int, double[], int[], int, int, double[]) 2482 | */ 2483 | private void cftx020(double[] a) { 2484 | double x0r, x0i; 2485 | 2486 | x0r = a[0] - a[2]; 2487 | x0i = a[1] - a[3]; 2488 | a[0] += a[2]; 2489 | a[1] += a[3]; 2490 | a[2] = x0r; 2491 | a[3] = x0i; 2492 | } 2493 | 2494 | /** 2495 | * 2nd 2496 | * @see #rdft(int, int, double[], int[], double[]) 2497 | * @see #ddct(int, int, double[], int[], double[]) 2498 | * @see #ddst(int, int, double[], int[], double[]) 2499 | * @see #dfst(int, double[], double[], int[], double[]) 2500 | * @see #dfct(int, double[], double[], int[], double[]) 2501 | */ 2502 | private void rftfsub(int n, double[] a, int nc, double[] c, int cP) { 2503 | int j, k, kk, ks, m; 2504 | double wkr, wki, xr, xi, yr, yi; 2505 | 2506 | m = n >> 1; 2507 | ks = 2 * nc / m; 2508 | kk = 0; 2509 | for (j = 2; j < m; j += 2) { 2510 | k = n - j; 2511 | kk += ks; 2512 | wkr = 0.5 - c[cP + nc - kk]; 2513 | wki = c[cP + kk]; 2514 | xr = a[j] - a[k]; 2515 | xi = a[j + 1] + a[k + 1]; 2516 | yr = wkr * xr - wki * xi; 2517 | yi = wkr * xi + wki * xr; 2518 | a[j] -= yr; 2519 | a[j + 1] -= yi; 2520 | a[k] += yr; 2521 | a[k + 1] -= yi; 2522 | } 2523 | } 2524 | 2525 | /** 2526 | * 2nd 2527 | * @see #rdft(int, int, double[], int[], double[]) 2528 | * @see #ddct(int, int, double[], int[], double[]) 2529 | * @see #ddst(int, int, double[], int[], double[]) 2530 | */ 2531 | private void rftbsub(int n, double[] a, int nc, double[] c, int cP) { 2532 | int j, k, kk, ks, m; 2533 | double wkr, wki, xr, xi, yr, yi; 2534 | 2535 | m = n >> 1; 2536 | ks = 2 * nc / m; 2537 | kk = 0; 2538 | for (j = 2; j < m; j += 2) { 2539 | k = n - j; 2540 | kk += ks; 2541 | wkr = 0.5 - c[cP + nc - kk]; 2542 | wki = c[cP + kk]; 2543 | xr = a[j] - a[k]; 2544 | xi = a[j + 1] + a[k + 1]; 2545 | yr = wkr * xr + wki * xi; 2546 | yi = wkr * xi - wki * xr; 2547 | a[j] -= yr; 2548 | a[j + 1] -= yi; 2549 | a[k] += yr; 2550 | a[k + 1] -= yi; 2551 | } 2552 | } 2553 | 2554 | /** 2555 | * 2nd 2556 | * @see #ddct(int, int, double[], int[], double[]) 2557 | * @see #dfct(int, double[], double[], int[], double[]) 2558 | */ 2559 | private void dctsub(int n, double[] a, int nc, double[] c, int cP) { 2560 | int j, k, kk, ks, m; 2561 | double wkr, wki, xr; 2562 | 2563 | m = n >> 1; 2564 | ks = nc / n; 2565 | kk = 0; 2566 | for (j = 1; j < m; j++) { 2567 | k = n - j; 2568 | kk += ks; 2569 | wkr = c[cP + kk] - c[cP + nc - kk]; 2570 | wki = c[cP + kk] + c[cP + nc - kk]; 2571 | xr = wki * a[j] - wkr * a[k]; 2572 | a[j] = wkr * a[j] + wki * a[k]; 2573 | a[k] = xr; 2574 | } 2575 | a[m] *= c[cP + 0]; 2576 | } 2577 | 2578 | /** 2579 | * 2nd 2580 | * @see #ddst(int, int, double[], int[], double[]) 2581 | * @see #dfst(int, double[], double[], int[], double[]) 2582 | */ 2583 | private void dstsub(int n, double[] a, int nc, double[] c, int cP) { 2584 | int j, k, kk, ks, m; 2585 | double wkr, wki, xr; 2586 | 2587 | m = n >> 1; 2588 | ks = nc / n; 2589 | kk = 0; 2590 | for (j = 1; j < m; j++) { 2591 | k = n - j; 2592 | kk += ks; 2593 | wkr = c[cP + kk] - c[cP + nc - kk]; 2594 | wki = c[cP + kk] + c[cP + nc - kk]; 2595 | xr = wki * a[k] - wkr * a[j]; 2596 | a[k] = wkr * a[k] + wki * a[j]; 2597 | a[j] = xr; 2598 | } 2599 | a[m] *= c[cP + 0]; 2600 | } 2601 | } 2602 | 2603 | /* */ 2604 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/javax.sound.sampled.spi.FormatConversionProvider: -------------------------------------------------------------------------------- 1 | com.jssrc.resample.JSSRCSampleRateConversionProvider 2 | 3 | -------------------------------------------------------------------------------- /src/site/apt/downloads.apt: -------------------------------------------------------------------------------- 1 | ---------- 2 | Downloads 3 | ---------- 4 | Maksim Khadkevich 5 | ---------- 6 | 2013-02-28 7 | ----------- 8 | 9 | Downloads 10 | 11 | The main master branch can be downloaded either as {{{http://github.com/hutm/JSSRC/zipball/master}zip}} archive or as {{{http://github.com/hutm/JSSRC/tarball/master}tar}} tarball. 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/site/apt/help.apt: -------------------------------------------------------------------------------- 1 | ---------- 2 | Help 3 | ---------- 4 | Maksim Khadkevich 5 | ---------- 6 | 2013-02-28 7 | ----------- 8 | 9 | Help 10 | 11 | Visit {{{http://groups.google.com/group/jssrc}JSSRC Google group}} to get help or discuss {{{http://jssrc.khadkevich.org/}JSSRC}}. 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/site/apt/index.apt: -------------------------------------------------------------------------------- 1 | ---------- 2 | Overview 3 | ---------- 4 | Maksim Khadkevich 5 | ---------- 6 | 2013-02-28 7 | ----------- 8 | 9 | 10 | JSSRC Resampling Library 11 | 12 | JSSRC project is aimed at creating high quality audio resampler written in pure java. 13 | 14 | It is based on the {{{http://shibatch.sourceforge.net/}SSRC}} High Quality Audio Sampling Rate Converter by Naoki Shibata written in C. 15 | 16 | Evaluation of the SSRC resampler can be found {{{http://www.mainly.me.uk/resampling/index.html} here}}. 17 | 18 | Naohide Sano ported the C code into java. 19 | 20 | Finally, a number of small modification was performed in order to have a java resampling service that is easy to use. 21 | 22 | -------------------------------------------------------------------------------- /src/site/apt/release-notes.apt: -------------------------------------------------------------------------------- 1 | ------------------------------ 2 | Release Notes 3 | ------------------------------ 4 | Maksim Khadkevich 5 | ------------------------------ 6 | 2013-02-28 7 | ------------------------------ 8 | 9 | Release Notes for 1.0.1 10 | 11 | Minor Bug fixes. 12 | 13 | Release Notes for 1.0 14 | 15 | Initial release. 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/site/apt/source-repository.apt: -------------------------------------------------------------------------------- 1 | ------------------------------ 2 | Source repository 3 | ------------------------------ 4 | Maksim Khadkevich 5 | ------------------------------ 6 | 2013-02-28 7 | ------------------------------ 8 | 9 | Repository 10 | 11 | This project uses GitHub for source code management. 12 | Instructions on Git use can be found at {{http://git-scm.com/}}. 13 | 14 | 15 | * Web Access 16 | 17 | The following is a {{{https://github.com/hutm/JSSRC}link}} to the online source repository. 18 | 19 | +----------------------------------------------------------------------------+ 20 | https://github.com/hutm/JSSRC 21 | +----------------------------------------------------------------------------+ 22 | 23 | * Anonymous access 24 | 25 | The source can be checked out from GitHub with this command: 26 | 27 | 28 | +----------------------------------------------------------------------------+ 29 | $ git clone git://github.com/hutm/JSSRC.git 30 | +----------------------------------------------------------------------------+ 31 | 32 | -------------------------------------------------------------------------------- /src/site/changes/changes.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | JSSRC Library 6 | Maksim Khadkevich 7 | 8 | 9 | 10 | 11 | Bug fixes 12 | 13 | 14 | 15 | 16 | Initial Release 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/site/resources/CNAME: -------------------------------------------------------------------------------- 1 | jssrc.khadkevich.org -------------------------------------------------------------------------------- /src/site/resources/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hutm/JSSRC/4a9c1c36c4339989165a16deedd7ede180016115/src/site/resources/images/logo.png -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | org.apache.maven.skins 7 | maven-stylus-skin 8 | 1.2 9 | 10 | 11 | 12 | JSSRC_LOGO 13 | images/logo.png 14 | http://github.com/hutm/JSSRC 15 | 16 | 17 | 18 | 19 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/test/java/com/jssrc/resample/JSSRCResamplerTest.java: -------------------------------------------------------------------------------- 1 | package com.jssrc.resample; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import javax.sound.sampled.AudioFileFormat; 6 | import javax.sound.sampled.AudioFormat; 7 | import javax.sound.sampled.AudioInputStream; 8 | import javax.sound.sampled.AudioSystem; 9 | import java.io.File; 10 | 11 | /** 12 | * JSSRCResampler Tester. 13 | * 14 | * @author Maksim Khadkevich 15 | * @since
03/25/2011
16 | * @version 1.0 17 | */ 18 | public class JSSRCResamplerTest { 19 | 20 | /** 21 | * 22 | * This simple test downsamples and upsamples two test files 23 | * 24 | */ 25 | @Test 26 | public void testReadSamples() throws Exception { 27 | 28 | String[] fileNames = new String[]{"/mono_short_test.wav", "/stereo_long_test.wav"}; 29 | 30 | float[] outSamplingRates = new float[]{11025f, 96000f}; 31 | 32 | for (String inFileName:fileNames) { 33 | for (float outSamplingRate:outSamplingRates) { 34 | String inFilePath = this.getClass().getResource(inFileName).getPath(); 35 | AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(inFilePath)); 36 | AudioFormat sourceFormat = audioInputStream.getFormat(); 37 | 38 | 39 | AudioFormat targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 40 | outSamplingRate, 41 | sourceFormat.getSampleSizeInBits(), 42 | sourceFormat.getChannels(), 43 | sourceFormat.getFrameSize(), 44 | sourceFormat.getFrameRate(), 45 | sourceFormat.isBigEndian()); 46 | 47 | AudioInputStream inputStream = AudioSystem.getAudioInputStream(targetFormat, audioInputStream); 48 | 49 | AudioSystem.write(inputStream, AudioFileFormat.Type.WAVE, new File(String.format("%s_resampled_%d.wav", inFilePath, (int) outSamplingRate))); 50 | } 51 | } 52 | 53 | } 54 | 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/resources/mono_short_test.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hutm/JSSRC/4a9c1c36c4339989165a16deedd7ede180016115/src/test/resources/mono_short_test.wav -------------------------------------------------------------------------------- /src/test/resources/stereo_long_test.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hutm/JSSRC/4a9c1c36c4339989165a16deedd7ede180016115/src/test/resources/stereo_long_test.wav -------------------------------------------------------------------------------- /src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | --------------------------------------------------------------------------------