合并分支 'develop' 到 'master'
第一次提交 查看合并请求 !1
正在显示
41 个修改的文件
包含
4838 行增加
和
0 行删除
.gitignore
0 → 100644
.idea/.name
0 → 100644
1 | +zhongqiyan |
.idea/codeStyles/Project.xml
0 → 100644
1 | +<component name="ProjectCodeStyleConfiguration"> | ||
2 | + <code_scheme name="Project" version="173"> | ||
3 | + <JetCodeStyleSettings> | ||
4 | + <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> | ||
5 | + </JetCodeStyleSettings> | ||
6 | + <MarkdownNavigatorCodeStyleSettings> | ||
7 | + <option name="RIGHT_MARGIN" value="72" /> | ||
8 | + </MarkdownNavigatorCodeStyleSettings> | ||
9 | + <codeStyleSettings language="XML"> | ||
10 | + <indentOptions> | ||
11 | + <option name="CONTINUATION_INDENT_SIZE" value="4" /> | ||
12 | + </indentOptions> | ||
13 | + <arrangement> | ||
14 | + <rules> | ||
15 | + <section> | ||
16 | + <rule> | ||
17 | + <match> | ||
18 | + <AND> | ||
19 | + <NAME>xmlns:android</NAME> | ||
20 | + <XML_ATTRIBUTE /> | ||
21 | + <XML_NAMESPACE>^$</XML_NAMESPACE> | ||
22 | + </AND> | ||
23 | + </match> | ||
24 | + </rule> | ||
25 | + </section> | ||
26 | + <section> | ||
27 | + <rule> | ||
28 | + <match> | ||
29 | + <AND> | ||
30 | + <NAME>xmlns:.*</NAME> | ||
31 | + <XML_ATTRIBUTE /> | ||
32 | + <XML_NAMESPACE>^$</XML_NAMESPACE> | ||
33 | + </AND> | ||
34 | + </match> | ||
35 | + <order>BY_NAME</order> | ||
36 | + </rule> | ||
37 | + </section> | ||
38 | + <section> | ||
39 | + <rule> | ||
40 | + <match> | ||
41 | + <AND> | ||
42 | + <NAME>.*:id</NAME> | ||
43 | + <XML_ATTRIBUTE /> | ||
44 | + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> | ||
45 | + </AND> | ||
46 | + </match> | ||
47 | + </rule> | ||
48 | + </section> | ||
49 | + <section> | ||
50 | + <rule> | ||
51 | + <match> | ||
52 | + <AND> | ||
53 | + <NAME>.*:name</NAME> | ||
54 | + <XML_ATTRIBUTE /> | ||
55 | + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> | ||
56 | + </AND> | ||
57 | + </match> | ||
58 | + </rule> | ||
59 | + </section> | ||
60 | + <section> | ||
61 | + <rule> | ||
62 | + <match> | ||
63 | + <AND> | ||
64 | + <NAME>name</NAME> | ||
65 | + <XML_ATTRIBUTE /> | ||
66 | + <XML_NAMESPACE>^$</XML_NAMESPACE> | ||
67 | + </AND> | ||
68 | + </match> | ||
69 | + </rule> | ||
70 | + </section> | ||
71 | + <section> | ||
72 | + <rule> | ||
73 | + <match> | ||
74 | + <AND> | ||
75 | + <NAME>style</NAME> | ||
76 | + <XML_ATTRIBUTE /> | ||
77 | + <XML_NAMESPACE>^$</XML_NAMESPACE> | ||
78 | + </AND> | ||
79 | + </match> | ||
80 | + </rule> | ||
81 | + </section> | ||
82 | + <section> | ||
83 | + <rule> | ||
84 | + <match> | ||
85 | + <AND> | ||
86 | + <NAME>.*</NAME> | ||
87 | + <XML_ATTRIBUTE /> | ||
88 | + <XML_NAMESPACE>^$</XML_NAMESPACE> | ||
89 | + </AND> | ||
90 | + </match> | ||
91 | + <order>BY_NAME</order> | ||
92 | + </rule> | ||
93 | + </section> | ||
94 | + <section> | ||
95 | + <rule> | ||
96 | + <match> | ||
97 | + <AND> | ||
98 | + <NAME>.*</NAME> | ||
99 | + <XML_ATTRIBUTE /> | ||
100 | + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> | ||
101 | + </AND> | ||
102 | + </match> | ||
103 | + <order>ANDROID_ATTRIBUTE_ORDER</order> | ||
104 | + </rule> | ||
105 | + </section> | ||
106 | + <section> | ||
107 | + <rule> | ||
108 | + <match> | ||
109 | + <AND> | ||
110 | + <NAME>.*</NAME> | ||
111 | + <XML_ATTRIBUTE /> | ||
112 | + <XML_NAMESPACE>.*</XML_NAMESPACE> | ||
113 | + </AND> | ||
114 | + </match> | ||
115 | + <order>BY_NAME</order> | ||
116 | + </rule> | ||
117 | + </section> | ||
118 | + </rules> | ||
119 | + </arrangement> | ||
120 | + </codeStyleSettings> | ||
121 | + <codeStyleSettings language="kotlin"> | ||
122 | + <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> | ||
123 | + </codeStyleSettings> | ||
124 | + </code_scheme> | ||
125 | +</component> |
.idea/codeStyles/codeStyleConfig.xml
0 → 100644
.idea/gradle.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project version="4"> | ||
3 | + <component name="GradleMigrationSettings" migrationVersion="1" /> | ||
4 | + <component name="GradleSettings"> | ||
5 | + <option name="linkedExternalProjectsSettings"> | ||
6 | + <GradleProjectSettings> | ||
7 | + <option name="delegatedBuild" value="true" /> | ||
8 | + <option name="testRunner" value="PLATFORM" /> | ||
9 | + <option name="distributionType" value="DEFAULT_WRAPPED" /> | ||
10 | + <option name="externalProjectPath" value="$PROJECT_DIR$" /> | ||
11 | + <option name="modules"> | ||
12 | + <set> | ||
13 | + <option value="$PROJECT_DIR$" /> | ||
14 | + <option value="$PROJECT_DIR$/app" /> | ||
15 | + </set> | ||
16 | + </option> | ||
17 | + <option name="resolveModulePerSourceSet" value="false" /> | ||
18 | + </GradleProjectSettings> | ||
19 | + </option> | ||
20 | + </component> | ||
21 | +</project> |
.idea/misc.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project version="4"> | ||
3 | + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | ||
4 | + <output url="file://$PROJECT_DIR$/build/classes" /> | ||
5 | + </component> | ||
6 | + <component name="ProjectType"> | ||
7 | + <option name="id" value="Android" /> | ||
8 | + </component> | ||
9 | +</project> |
.idea/runConfigurations.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project version="4"> | ||
3 | + <component name="RunConfigurationProducerService"> | ||
4 | + <option name="ignoredProducers"> | ||
5 | + <set> | ||
6 | + <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" /> | ||
7 | + <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" /> | ||
8 | + <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" /> | ||
9 | + </set> | ||
10 | + </option> | ||
11 | + </component> | ||
12 | +</project> |
app/.gitignore
0 → 100644
1 | +/build |
app/build.gradle
0 → 100644
1 | +apply plugin: 'com.android.application' | ||
2 | + | ||
3 | +apply plugin: 'kotlin-android' | ||
4 | + | ||
5 | +apply plugin: 'kotlin-android-extensions' | ||
6 | + | ||
7 | +android { | ||
8 | + compileSdkVersion 28 | ||
9 | + buildToolsVersion "28.0.3" | ||
10 | + defaultConfig { | ||
11 | + applicationId "com.example.zhongqiyan" | ||
12 | + minSdkVersion 15 | ||
13 | + targetSdkVersion 28 | ||
14 | + versionCode 1 | ||
15 | + versionName "1.0" | ||
16 | + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
17 | + } | ||
18 | + buildTypes { | ||
19 | + release { | ||
20 | + minifyEnabled false | ||
21 | + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
22 | + } | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +dependencies { | ||
27 | + implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
28 | + implementation 'com.android.support:support-v4:28.0.0' | ||
29 | + implementation 'com.android.support:appcompat-v7:28.0.0' | ||
30 | + implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
31 | + testImplementation 'junit:junit:4.12' | ||
32 | + androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
33 | + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
34 | + | ||
35 | + implementation 'org.greenrobot:eventbus:3.1.1' | ||
36 | + | ||
37 | + // retrofit | ||
38 | + implementation 'com.squareup.retrofit2:retrofit:2.3.0' | ||
39 | + implementation 'com.squareup.retrofit2:converter-gson:2.3.0' | ||
40 | + implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' | ||
41 | + //rxjava rxandroid | ||
42 | + implementation 'io.reactivex.rxjava2:rxjava:2.2.0' | ||
43 | + implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' | ||
44 | + implementation 'io.reactivex:rxandroid:1.2.1' | ||
45 | + //配合Rxjava 使用 | ||
46 | + implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1' | ||
47 | + implementation 'com.squareup.okhttp3:okhttp:3.2.0' | ||
48 | + implementation 'com.squareup.okio:okio:1.7.0' | ||
49 | + // // butterknife 注解框架 | ||
50 | + // butterknife 注解框架 | ||
51 | + implementation 'com.jakewharton:butterknife:8.1.0' | ||
52 | + annotationProcessor 'com.jakewharton:butterknife-compiler:8.1.0' | ||
53 | + implementation 'com.android.support:recyclerview-v7:28.0.0' | ||
54 | + // Gson | ||
55 | + implementation 'com.google.code.gson:gson:2.8.5' | ||
56 | + | ||
57 | + implementation 'com.jakewharton:butterknife:8.1.0' | ||
58 | + annotationProcessor 'com.jakewharton:butterknife-compiler:8.1.0' | ||
59 | + | ||
60 | + testImplementation 'junit:junit:4.12' | ||
61 | + androidTestImplementation 'androidx.test.ext:junit:1.1.0' | ||
62 | + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' | ||
63 | +} |
app/proguard-rules.pro
0 → 100644
1 | +# Add project specific ProGuard rules here. | ||
2 | +# You can control the set of applied configuration files using the | ||
3 | +# proguardFiles setting in build.gradle. | ||
4 | +# | ||
5 | +# For more details, see | ||
6 | +# http://developer.android.com/guide/developing/tools/proguard.html | ||
7 | + | ||
8 | +# If your project uses WebView with JS, uncomment the following | ||
9 | +# and specify the fully qualified class name to the JavaScript interface | ||
10 | +# class: | ||
11 | +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
12 | +# public *; | ||
13 | +#} | ||
14 | + | ||
15 | +# Uncomment this to preserve the line number information for | ||
16 | +# debugging stack traces. | ||
17 | +#-keepattributes SourceFile,LineNumberTable | ||
18 | + | ||
19 | +# If you keep the line number information, uncomment this to | ||
20 | +# hide the original source file name. | ||
21 | +#-renamesourcefileattribute SourceFile |
1 | +package com.example.zhongqiyan | ||
2 | + | ||
3 | +import androidx.test.platform.app.InstrumentationRegistry | ||
4 | +import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
5 | + | ||
6 | +import org.junit.Test | ||
7 | +import org.junit.runner.RunWith | ||
8 | + | ||
9 | +import org.junit.Assert.* | ||
10 | + | ||
11 | +/** | ||
12 | + * Instrumented test, which will execute on an Android device. | ||
13 | + * | ||
14 | + * See [testing documentation](http://d.android.com/tools/testing). | ||
15 | + */ | ||
16 | +@RunWith(AndroidJUnit4::class) | ||
17 | +class ExampleInstrumentedTest { | ||
18 | + @Test | ||
19 | + fun useAppContext() { | ||
20 | + // Context of the app under test. | ||
21 | + val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
22 | + assertEquals("com.example.zhongqiyan", appContext.packageName) | ||
23 | + } | ||
24 | +} |
app/src/main/AndroidManifest.xml
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
3 | + xmlns:tools="http://schemas.android.com/tools" | ||
4 | + package="com.example.zhongqiyan"> | ||
5 | + | ||
6 | + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
7 | + <uses-permission android:name="android.permission.VIBRATE" /> | ||
8 | + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
9 | + <uses-permission | ||
10 | + android:name="android.permission.WRITE_SETTINGS" | ||
11 | + tools:ignore="ProtectedPermissions" /> | ||
12 | + <uses-permission android:name="android.permission.CAMERA" /> | ||
13 | + <uses-permission android:name="android.permission.INTERNET" /> | ||
14 | + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
15 | + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
16 | + <uses-permission | ||
17 | + android:name="android.permission.INSTALL_PACKAGES" | ||
18 | + tools:ignore="ProtectedPermissions" /> | ||
19 | + <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> | ||
20 | + <uses-permission | ||
21 | + android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" | ||
22 | + tools:ignore="ProtectedPermissions" /> <!-- 录音 --> | ||
23 | + <uses-permission android:name="android.permission.RECORD_AUDIO" /> <!-- 播音 --> | ||
24 | + <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- 极光 --> | ||
25 | + <!-- 获取手机信息 --> | ||
26 | + <uses-permission android:name="android.permission.READ_PHONE_STATE" /> | ||
27 | + <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" /> <!-- 2017.5.27 极光推送权限 ym start --> | ||
28 | + <uses-permission android:name="android.permission.WAKE_LOCK" /> | ||
29 | + <uses-permission android:name="android.permission.VIBRATE" /> | ||
30 | + <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" /> | ||
31 | + | ||
32 | + <application | ||
33 | + android:allowBackup="true" | ||
34 | + android:icon="@mipmap/ic_launcher" | ||
35 | + android:label="@string/app_name" | ||
36 | + android:roundIcon="@mipmap/ic_launcher_round" | ||
37 | + android:supportsRtl="true" | ||
38 | + android:theme="@style/AppTheme"> | ||
39 | + <activity android:name=".login.LoginActivity"> | ||
40 | + <intent-filter> | ||
41 | + <action android:name="android.intent.action.MAIN" /> | ||
42 | + | ||
43 | + <category android:name="android.intent.category.LAUNCHER" /> | ||
44 | + </intent-filter> | ||
45 | + </activity> | ||
46 | + <activity | ||
47 | + android:name=".MainActivity" | ||
48 | + android:screenOrientation="portrait" | ||
49 | + android:windowSoftInputMode="adjustResize|stateHidden" /> | ||
50 | + <activity | ||
51 | + android:name=".login.ForgotPasswordActivity" | ||
52 | + android:screenOrientation="portrait" | ||
53 | + android:windowSoftInputMode="adjustResize|stateHidden" /> | ||
54 | + <activity | ||
55 | + android:name=".login.ResetPasswordActivity" | ||
56 | + android:screenOrientation="portrait" | ||
57 | + android:windowSoftInputMode="adjustResize|stateHidden" /> | ||
58 | + <activity | ||
59 | + android:name=".login.RegisterdActivity" | ||
60 | + android:screenOrientation="portrait" | ||
61 | + android:windowSoftInputMode="adjustResize|stateHidden" /> | ||
62 | + </application> | ||
63 | + | ||
64 | +</manifest> |
1 | +package com.example.zhongqiyan; | ||
2 | + | ||
3 | +import android.app.Activity; | ||
4 | +import android.graphics.Bitmap; | ||
5 | +import android.graphics.Canvas; | ||
6 | +import android.graphics.Color; | ||
7 | +import android.graphics.Paint; | ||
8 | +import android.media.AudioFormat; | ||
9 | +import android.media.AudioRecord; | ||
10 | +import android.media.MediaRecorder; | ||
11 | +import android.os.AsyncTask; | ||
12 | +import android.os.Bundle; | ||
13 | +import android.util.Log; | ||
14 | +import android.view.View; | ||
15 | +import android.widget.Button; | ||
16 | +import android.widget.ImageView; | ||
17 | + | ||
18 | +import com.example.zhongqiyan.javasource.ca.uol.aig.fftpack.RealDoubleFFT; | ||
19 | + | ||
20 | +public class AudioProcessing extends Activity implements View.OnClickListener { | ||
21 | + int frequency = 8000; | ||
22 | + int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_MONO; | ||
23 | + int audioEncoding = AudioFormat.ENCODING_PCM_16BIT; | ||
24 | + | ||
25 | + | ||
26 | + private RealDoubleFFT transformer; | ||
27 | + int blockSize = 256; | ||
28 | + Button startStopButton; | ||
29 | + boolean started = false; | ||
30 | + | ||
31 | + RecordAudio recordTask; | ||
32 | + | ||
33 | + ImageView imageView; | ||
34 | + Bitmap bitmap; | ||
35 | + Canvas canvas; | ||
36 | + Paint paint; | ||
37 | + /** Called when the activity is first created. */ | ||
38 | + @Override | ||
39 | + public void onCreate(Bundle savedInstanceState) { | ||
40 | + super.onCreate(savedInstanceState); | ||
41 | + setContentView(R.layout.main); | ||
42 | + startStopButton = (Button) this.findViewById(R.id.StartStopButton); | ||
43 | + startStopButton.setOnClickListener(this); | ||
44 | + | ||
45 | + transformer = new RealDoubleFFT(blockSize); | ||
46 | + | ||
47 | + imageView = (ImageView) this.findViewById(R.id.ImageView01); | ||
48 | + bitmap = Bitmap.createBitmap((int)256,(int)100,Bitmap.Config.ARGB_8888); | ||
49 | + canvas = new Canvas(bitmap); | ||
50 | + paint = new Paint(); | ||
51 | + paint.setColor(Color.GREEN); | ||
52 | + imageView.setImageBitmap(bitmap); | ||
53 | + } | ||
54 | + | ||
55 | + private class RecordAudio extends AsyncTask<Void, double[], Void> { | ||
56 | + @Override | ||
57 | + protected Void doInBackground(Void... params) { | ||
58 | + try { | ||
59 | + int bufferSize = AudioRecord.getMinBufferSize(frequency, | ||
60 | + channelConfiguration, audioEncoding); | ||
61 | + AudioRecord audioRecord = new AudioRecord( | ||
62 | + MediaRecorder.AudioSource.DEFAULT, frequency, | ||
63 | + channelConfiguration, audioEncoding, bufferSize); | ||
64 | + | ||
65 | + short[] buffer = new short[blockSize]; | ||
66 | + double[] toTransform = new double[blockSize]; | ||
67 | + audioRecord.startRecording(); | ||
68 | + while (started) { | ||
69 | + int bufferReadResult = audioRecord.read(buffer, 0, blockSize); | ||
70 | + | ||
71 | + for (int i = 0; i < blockSize && i < bufferReadResult; i++) { | ||
72 | + toTransform[i] = (double) buffer[i] / 32768.0; // signed 16 bit | ||
73 | + } | ||
74 | + | ||
75 | + transformer.ft(toTransform); | ||
76 | + publishProgress(toTransform); | ||
77 | + } | ||
78 | + audioRecord.stop(); | ||
79 | + } catch (Throwable t) { | ||
80 | + Log.e("AudioRecord", "Recording Failed"); | ||
81 | + } | ||
82 | + return null; | ||
83 | + } | ||
84 | + } | ||
85 | + | ||
86 | + protected void onProgressUpdate(double[]... toTransform) { | ||
87 | + canvas.drawColor(Color.BLACK); | ||
88 | + for (int i = 0; i < toTransform[0].length; i++) { | ||
89 | + int x = i; | ||
90 | + int downy = (int) (100 - (toTransform[0][i] * 10)); | ||
91 | + int upy = 100; | ||
92 | + canvas.drawLine(x, downy, x, upy, paint); | ||
93 | + } | ||
94 | + imageView.invalidate(); | ||
95 | + } | ||
96 | + | ||
97 | + public void onClick(View v) { | ||
98 | + if (started) { | ||
99 | + started = false; | ||
100 | + startStopButton.setText("Start"); | ||
101 | + recordTask.cancel(true); | ||
102 | + } else { | ||
103 | + started = true; | ||
104 | + startStopButton.setText("Stop"); | ||
105 | + recordTask = new RecordAudio(); | ||
106 | + recordTask.execute(); | ||
107 | + } | ||
108 | + } | ||
109 | +} |
1 | +package com.example.zhongqiyan; | ||
2 | + | ||
3 | +import android.app.Activity; | ||
4 | +import android.graphics.Bitmap; | ||
5 | +import android.graphics.Canvas; | ||
6 | +import android.graphics.Color; | ||
7 | +import android.graphics.Paint; | ||
8 | +import android.media.AudioFormat; | ||
9 | +import android.media.AudioRecord; | ||
10 | +import android.media.MediaRecorder; | ||
11 | +import android.os.AsyncTask; | ||
12 | +import android.os.Bundle; | ||
13 | +import android.util.Log; | ||
14 | +import android.view.View; | ||
15 | +import android.widget.Button; | ||
16 | +import android.widget.ImageView; | ||
17 | + | ||
18 | +import com.example.zhongqiyan.javasource.ca.uol.aig.fftpack.RealDoubleFFT; | ||
19 | + | ||
20 | +/** | ||
21 | + | ||
22 | + * 可视化频率 | ||
23 | + * | ||
24 | + * @time 下午12:00:21 | ||
25 | + * @author retacn yue | ||
26 | + * @Email zhenhuayue@sina.com | ||
27 | + */ | ||
28 | +public class AudioProcessingActivity extends Activity implements View.OnClickListener { | ||
29 | + private Button btn_start_stop; | ||
30 | + private ImageView img_frequency; | ||
31 | + | ||
32 | + | ||
33 | + private Bitmap bitmap; | ||
34 | + private Canvas canvas; | ||
35 | + private Paint paint; | ||
36 | + private AudioRecordTask recordTask; | ||
37 | + private RealDoubleFFT trasformer; | ||
38 | + | ||
39 | + | ||
40 | + int blockSize = 256; | ||
41 | + | ||
42 | + | ||
43 | + int frequency = 8000; | ||
44 | + int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_MONO; | ||
45 | + int audioEncoding = AudioFormat.ENCODING_PCM_16BIT; | ||
46 | + boolean started = false; | ||
47 | + | ||
48 | + | ||
49 | + @Override | ||
50 | + public void onCreate(Bundle savedInstanceState) { | ||
51 | + super.onCreate(savedInstanceState); | ||
52 | + setContentView(R.layout.audio_processing); | ||
53 | + findView(); | ||
54 | + | ||
55 | + | ||
56 | + trasformer = new RealDoubleFFT(blockSize); | ||
57 | + | ||
58 | + | ||
59 | + bitmap = Bitmap.createBitmap(256, 100, Bitmap.Config.ARGB_8888); | ||
60 | + canvas = new Canvas(bitmap); | ||
61 | + paint = new Paint(); | ||
62 | + paint.setColor(Color.RED); | ||
63 | + img_frequency.setImageBitmap(bitmap); | ||
64 | + } | ||
65 | + | ||
66 | + | ||
67 | + @Override | ||
68 | + public void onClick(View v) { | ||
69 | + if (started) { | ||
70 | + started = false; | ||
71 | + btn_start_stop.setText("Start"); | ||
72 | + | ||
73 | + | ||
74 | + } else { | ||
75 | + started = true; | ||
76 | + btn_start_stop.setText("Stop"); | ||
77 | + recordTask = new AudioRecordTask(); | ||
78 | + recordTask.execute(); | ||
79 | + } | ||
80 | + } | ||
81 | + | ||
82 | + | ||
83 | + /** | ||
84 | + * 实例化控件 | ||
85 | + */ | ||
86 | + private void findView() { | ||
87 | + btn_start_stop = (Button) this.findViewById(R.id.StartStopButton); | ||
88 | + btn_start_stop.setOnClickListener(this); | ||
89 | + | ||
90 | + | ||
91 | + img_frequency = (ImageView) this.findViewById(R.id.ImageView01); | ||
92 | + } | ||
93 | + | ||
94 | + | ||
95 | + /*****************************************************************/ | ||
96 | + private static int[] mSampleRates = new int[] { 8000, 11025, 22050, 44100 }; | ||
97 | + | ||
98 | + | ||
99 | + public AudioRecord findAudioRecord() { | ||
100 | + for (int rate : mSampleRates) { | ||
101 | + for (short audioFormat : new short[] { AudioFormat.ENCODING_PCM_8BIT, AudioFormat.ENCODING_PCM_16BIT }) { | ||
102 | + for (short channelConfig : new short[] { AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.CHANNEL_CONFIGURATION_STEREO }) { | ||
103 | + try { | ||
104 | + Log.d("tag", "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: " + channelConfig); | ||
105 | + int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat); | ||
106 | + | ||
107 | + | ||
108 | + if (bufferSize != AudioRecord.ERROR_BAD_VALUE) { | ||
109 | + Log.e("tag", "++++++++"); | ||
110 | + AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, rate, channelConfig, audioFormat, bufferSize); | ||
111 | + | ||
112 | + | ||
113 | + if (recorder.getState() == AudioRecord.STATE_INITIALIZED) | ||
114 | + Log.e("tag", "-----"); | ||
115 | + return recorder; | ||
116 | + } | ||
117 | + } catch (Exception e) { | ||
118 | + Log.e("tag", rate + "Exception, keep trying.", e); | ||
119 | + } | ||
120 | + } | ||
121 | + } | ||
122 | + } | ||
123 | + Log.e("tag", "==========="); | ||
124 | + return null; | ||
125 | + } | ||
126 | + | ||
127 | + | ||
128 | + /** | ||
129 | + * 音频合成任务 | ||
130 | + */ | ||
131 | + private class AudioRecordTask extends AsyncTask<Void, double[], Void> { | ||
132 | + | ||
133 | + | ||
134 | + @Override | ||
135 | + protected Void doInBackground(Void... params) { | ||
136 | + | ||
137 | + | ||
138 | + try { | ||
139 | + int bufferSize = AudioRecord.getMinBufferSize(frequency, // | ||
140 | + channelConfiguration, // | ||
141 | + audioEncoding); | ||
142 | + | ||
143 | + | ||
144 | + AudioRecord audioRecord = findAudioRecord(); | ||
145 | +/*****************************************************************/ | ||
146 | + /* | ||
147 | + * AudioRecord audioRecord = new | ||
148 | + * AudioRecord(MediaRecorder.AudioSource.MIC,// 输入源 frequency,// | ||
149 | + * channelConfiguration,// audioEncoding,// bufferSize); | ||
150 | + */ | ||
151 | + | ||
152 | + | ||
153 | + short[] buffer = new short[blockSize]; | ||
154 | + double[] toTransform = new double[blockSize]; | ||
155 | + audioRecord.startRecording(); | ||
156 | + while (started) { | ||
157 | + int bufferReadResult = audioRecord.read(buffer, 0, blockSize); | ||
158 | + for (int i = 0; i < blockSize && i < bufferReadResult; i++) { | ||
159 | + toTransform[i] = (double) buffer[i] / 32768.0; | ||
160 | + } | ||
161 | +// TODO | ||
162 | + DebugLog.e("toTransform==="+toTransform); | ||
163 | + trasformer.ft(toTransform); | ||
164 | + publishProgress(toTransform); | ||
165 | + } | ||
166 | + audioRecord.stop(); | ||
167 | + } catch (IllegalArgumentException e) { | ||
168 | + e.printStackTrace(); | ||
169 | + } catch (IllegalStateException e) { | ||
170 | + e.printStackTrace(); | ||
171 | + } | ||
172 | + | ||
173 | + | ||
174 | + return null; | ||
175 | + } | ||
176 | + | ||
177 | + | ||
178 | + protected void onProgressUpdate(double[]... toTransform) { | ||
179 | + canvas.drawColor(Color.BLACK); | ||
180 | + for (int i = 0; i < toTransform[0].length; i++) { | ||
181 | + int x = i; | ||
182 | + int downy = (int) (100 - (toTransform[0][i] * 10)); | ||
183 | + int upy = 100; | ||
184 | + canvas.drawLine(x, downy, x, upy, paint); | ||
185 | + } | ||
186 | + img_frequency.invalidate(); | ||
187 | + } | ||
188 | + } | ||
189 | + | ||
190 | +} |
1 | +package com.example.zhongqiyan; | ||
2 | + | ||
3 | +import android.os.Looper; | ||
4 | +import android.util.Log; | ||
5 | + | ||
6 | +import androidx.annotation.IntRange; | ||
7 | + | ||
8 | + | ||
9 | +/** | ||
10 | + * 日志打印工具 | ||
11 | + * | ||
12 | + * @author wr | ||
13 | + */ | ||
14 | + | ||
15 | +public class DebugLog { | ||
16 | + | ||
17 | + /** | ||
18 | + * 控制是否打印日志 | ||
19 | + **/ | ||
20 | + public static boolean isDebug = true; | ||
21 | + /** | ||
22 | + * 类名 | ||
23 | + **/ | ||
24 | + private static String className; | ||
25 | + /** | ||
26 | + * 方法名 | ||
27 | + **/ | ||
28 | + private static String methodName; | ||
29 | + | ||
30 | + private DebugLog() { | ||
31 | + /* Protect from instantiations */ | ||
32 | + } | ||
33 | + | ||
34 | + private static String createLog(String log) { | ||
35 | + | ||
36 | + StringBuffer buffer = new StringBuffer(); | ||
37 | + buffer.append("["); | ||
38 | + buffer.append(methodName); | ||
39 | + buffer.append("]"); | ||
40 | + buffer.append(log); | ||
41 | + | ||
42 | + return buffer.toString(); | ||
43 | + } | ||
44 | + | ||
45 | + private static void getMethodNames(StackTraceElement[] sElements) { | ||
46 | + className = sElements[1].getFileName(); | ||
47 | + methodName = sElements[1].getMethodName(); | ||
48 | + } | ||
49 | + | ||
50 | + public static void e(String message) { | ||
51 | + if (!isDebug) | ||
52 | + return; | ||
53 | + e(message, 3); | ||
54 | + } | ||
55 | + | ||
56 | + public static void e(String message, int stackLevel) { | ||
57 | + if (!isDebug) | ||
58 | + return; | ||
59 | + | ||
60 | + printCallStatck(4, stackLevel); | ||
61 | + getMethodNames(new Throwable().getStackTrace()); | ||
62 | + Log.e(className, createLog(message)); | ||
63 | + } | ||
64 | + | ||
65 | + public static void i(String message) { | ||
66 | + if (!isDebug) | ||
67 | + return; | ||
68 | + printCallStatck(2); | ||
69 | + getMethodNames(new Throwable().getStackTrace()); | ||
70 | + Log.i(className, createLog(message)); | ||
71 | + } | ||
72 | + | ||
73 | + public static void d(String message) { | ||
74 | + if (!isDebug) | ||
75 | + return; | ||
76 | + printCallStatck(1); | ||
77 | + getMethodNames(new Throwable().getStackTrace()); | ||
78 | + Log.d(className, createLog(message)); | ||
79 | + } | ||
80 | + | ||
81 | + public static void v(String message) { | ||
82 | + if (!isDebug) | ||
83 | + return; | ||
84 | + printCallStatck(0); | ||
85 | + getMethodNames(new Throwable().getStackTrace()); | ||
86 | + Log.v(className, createLog(message)); | ||
87 | + } | ||
88 | + | ||
89 | + public static void w(String message) { | ||
90 | + if (!isDebug) | ||
91 | + return; | ||
92 | + printCallStatck(3); | ||
93 | + getMethodNames(new Throwable().getStackTrace()); | ||
94 | + Log.w(className, createLog(message)); | ||
95 | + } | ||
96 | + | ||
97 | + public static void wtf(String message) { | ||
98 | + if (!isDebug) | ||
99 | + return; | ||
100 | + printCallStatck(5); | ||
101 | + getMethodNames(new Throwable().getStackTrace()); | ||
102 | + Log.wtf(className, createLog(message)); | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * 打印堆栈信息 | ||
107 | + */ | ||
108 | + public static void printCallStatck(@IntRange(from = 0, to = 6) int level) { | ||
109 | +// if (true) { | ||
110 | +// return; | ||
111 | +// } | ||
112 | + printCallStatck(level, 2); | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * 打印堆栈信息 | ||
117 | + */ | ||
118 | + public static void printCallStatck(@IntRange(from = 0, to = 6) int level, int stackLeve) { | ||
119 | +// if (true) { | ||
120 | +// return; | ||
121 | +// } | ||
122 | + printInfo("----", " ", level); | ||
123 | + printThreadInfo(level); | ||
124 | + Throwable ex = new Throwable(); | ||
125 | + StringBuffer sb = new StringBuffer(); | ||
126 | + StackTraceElement[] stackElements = ex.getStackTrace(); | ||
127 | + if (stackElements == null || stackElements.length <= stackLeve) { | ||
128 | + return; | ||
129 | + } | ||
130 | + sb.append("at " + stackElements[stackLeve].getClassName() + "."); | ||
131 | + sb.append(stackElements[stackLeve].getMethodName()); | ||
132 | + sb.append("(" + | ||
133 | + stackElements[stackLeve].getFileName() + | ||
134 | + ":" | ||
135 | + + stackElements[stackLeve].getLineNumber() + | ||
136 | + ")"); | ||
137 | + sb.append("\n"); | ||
138 | + printInfo("CallStatckInfo", sb.toString(), level); | ||
139 | + } | ||
140 | + | ||
141 | + /** | ||
142 | + * 打印线程信息 | ||
143 | + * | ||
144 | + * @param level | ||
145 | + */ | ||
146 | + private static void printThreadInfo(@IntRange(from = 0, to = 6) int level) { | ||
147 | + if (Looper.myLooper() == Looper.getMainLooper()) { | ||
148 | + printInfo("ThreadInfo ", "MainThread", level); | ||
149 | + } else { | ||
150 | + printInfo("ThreadInfo ", "ThreadGroup:" + Thread.currentThread().getThreadGroup() | ||
151 | + + "ThreadName:" + Thread.currentThread().getName() | ||
152 | + + "ThreadID:" + Thread.currentThread().getId(), level); | ||
153 | + } | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * 根据级别打印信息 | ||
158 | + * | ||
159 | + * @param tag | ||
160 | + * @param msg | ||
161 | + * @param level | ||
162 | + */ | ||
163 | + private static void printInfo(String tag, String msg, @IntRange(from = 0, to = 6) int level) { | ||
164 | + switch (level) { | ||
165 | + case 0: | ||
166 | + Log.v(tag, msg); | ||
167 | + break; | ||
168 | + case 1: | ||
169 | + Log.d(tag, msg); | ||
170 | + break; | ||
171 | + case 2: | ||
172 | + Log.i(tag, msg); | ||
173 | + break; | ||
174 | + case 3: | ||
175 | + Log.w(tag, msg); | ||
176 | + break; | ||
177 | + case 4: | ||
178 | + Log.e(tag, msg); | ||
179 | + break; | ||
180 | + case 5: | ||
181 | + Log.wtf(tag, msg); | ||
182 | + break; | ||
183 | + } | ||
184 | + } | ||
185 | + | ||
186 | +// public static void eLogHttpRequest(OkHttpRequest okHttpRequest, String response) { | ||
187 | +// StringBuilder sb = new StringBuilder(); | ||
188 | +// sb.append("url:" + okHttpRequest.getUrl() + "\n"); | ||
189 | +// if (okHttpRequest.getTag() != null) { | ||
190 | +// sb.append("tag:" + okHttpRequest.getTag().toString() + "\n"); | ||
191 | +// } | ||
192 | +// Map<String, String> params = okHttpRequest.getParams(); | ||
193 | +// if (params != null) { | ||
194 | +// sb.append("params:\n"); | ||
195 | +// for (String key : params.keySet()) { | ||
196 | +// sb.append(key + ":" + params.get(key) + "\n"); | ||
197 | +// } | ||
198 | +// } | ||
199 | +// sb.append("response:" + response); | ||
200 | +// e(sb.toString(), 3); | ||
201 | +// } | ||
202 | + | ||
203 | +} |
1 | +package com.example.zhongqiyan; | ||
2 | + | ||
3 | +import android.app.Activity; | ||
4 | +import android.graphics.Bitmap; | ||
5 | +import android.graphics.Canvas; | ||
6 | +import android.graphics.Color; | ||
7 | +import android.graphics.Paint; | ||
8 | +import android.media.AudioFormat; | ||
9 | +import android.media.AudioRecord; | ||
10 | +import android.media.MediaRecorder; | ||
11 | +import android.os.AsyncTask; | ||
12 | +import android.os.Bundle; | ||
13 | +import android.util.Log; | ||
14 | +import android.view.Menu; | ||
15 | +import android.view.View; | ||
16 | +import android.widget.Button; | ||
17 | +import android.widget.ImageView; | ||
18 | + | ||
19 | +import com.example.zhongqiyan.javasource.ca.uol.aig.fftpack.RealDoubleFFT; | ||
20 | + | ||
21 | +public class MainActivity extends Activity implements View.OnClickListener { | ||
22 | + //采样率:音频的采样频率,每秒钟能够采样的次数,采样率越高,音质越高。给出的实例是44100、22050、11025但不限于这几个参数。例如要采集低质量的音频就可以使用4000、8000等低采样率。 | ||
23 | + int frequency = 8000; | ||
24 | + //声道设置:android支持双声道立体声和单声道。MONO单声道,STEREO立体声 | ||
25 | + int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_MONO; | ||
26 | + int audioEncoding = AudioFormat.ENCODING_PCM_16BIT; | ||
27 | + private RealDoubleFFT transformer; | ||
28 | + int blockSize = 256; | ||
29 | + | ||
30 | + Button startStopButton; | ||
31 | + boolean started = false; | ||
32 | + | ||
33 | + RecordAudio recordTask; | ||
34 | + | ||
35 | + ImageView imageView; | ||
36 | + Bitmap bitmap; | ||
37 | + Canvas canvas; | ||
38 | + Paint paint; | ||
39 | + | ||
40 | + //AudioRecord audioRecord; | ||
41 | + | ||
42 | + @Override | ||
43 | + public void onCreate(Bundle savedInstanceState) { | ||
44 | + super.onCreate(savedInstanceState); | ||
45 | + setContentView(R.layout.activity_main); | ||
46 | + | ||
47 | + startStopButton = (Button) this.findViewById(R.id.StartStopButton); | ||
48 | + startStopButton.setOnClickListener(this); | ||
49 | + | ||
50 | + transformer = new RealDoubleFFT(blockSize); | ||
51 | + | ||
52 | + imageView = (ImageView) this.findViewById(R.id.ImageView01); | ||
53 | + bitmap = Bitmap.createBitmap((int) 256, (int) 100, | ||
54 | + Bitmap.Config.ARGB_8888); | ||
55 | + canvas = new Canvas(bitmap); | ||
56 | + paint = new Paint(); | ||
57 | + paint.setColor(Color.GREEN); | ||
58 | + imageView.setImageBitmap(bitmap); | ||
59 | + | ||
60 | + } | ||
61 | + | ||
62 | + public class RecordAudio extends AsyncTask<Void, double[], Void> { | ||
63 | + | ||
64 | + @Override | ||
65 | + protected Void doInBackground(Void... arg0) { | ||
66 | + | ||
67 | + try { | ||
68 | + // int bufferSize = AudioRecord.getMinBufferSize(frequency, | ||
69 | + // AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT); | ||
70 | + int bufferSize = AudioRecord.getMinBufferSize(frequency, | ||
71 | + channelConfiguration, audioEncoding); | ||
72 | + | ||
73 | + //audioSource: | ||
74 | + //音频源:指的是从哪里采集音频。这里我们当然是从麦克风采集音频,所以此参数的值为MIC | ||
75 | + //sampleRateInHz: | ||
76 | + //采样率:音频的采样频率,每秒钟能够采样的次数,采样率越高,音质越高。给出的实例是44100、22050、11025但不限于这几个参数。例如要采集低质量的音频就可以使用4000、8000等低采样率。 | ||
77 | + //channelConfig: | ||
78 | + //声道设置:android支持双声道立体声和单声道。MONO单声道,STEREO立体声 | ||
79 | + //audioFormat: | ||
80 | + //编码制式和采样大小:采集来的数据当然使用PCM编码(脉冲代码调制编码,即PCM编码。PCM通过抽样、量化、编码三个步骤将连续变化的模拟信号转换为数字编码。) | ||
81 | + //android支持的采样大小16bit 或者8bit。当然采样大小越大,那么信息量越多,音质也越高,现在主流的采样大小都是16bit,在低质量的语音传输的时候8bit足够了。 | ||
82 | + //bufferSizeInBytes: | ||
83 | + //采集数据需要的缓冲区的大小,如果不知道最小需要的大小可以在getMinBufferSize()查看。 | ||
84 | + AudioRecord audioRecord = new AudioRecord( | ||
85 | + MediaRecorder.AudioSource.MIC, frequency, | ||
86 | + channelConfiguration, audioEncoding, bufferSize); | ||
87 | + | ||
88 | + short[] buffer = new short[blockSize]; | ||
89 | + double[] toTransform = new double[blockSize]; | ||
90 | + DebugLog.e("buffer==="+buffer.toString()); | ||
91 | + audioRecord.startRecording(); | ||
92 | + | ||
93 | + // started = true; hopes this should true before calling | ||
94 | + // following while loop | ||
95 | + | ||
96 | + while (started) { | ||
97 | + int bufferReadResult = audioRecord.read(buffer, 0, | ||
98 | + blockSize); | ||
99 | + | ||
100 | + for (int i = 0; i < blockSize && i < bufferReadResult; i++) { | ||
101 | + toTransform[i] = (double) buffer[i] / 32768.0; // signed | ||
102 | + // 16 | ||
103 | + } | ||
104 | + DebugLog.e("2buffer==="+toTransform.toString());// bit | ||
105 | + transformer.ft(toTransform); | ||
106 | + publishProgress(toTransform); | ||
107 | + | ||
108 | + | ||
109 | + | ||
110 | + } | ||
111 | + | ||
112 | + audioRecord.stop(); | ||
113 | + | ||
114 | + } catch (Throwable t) { | ||
115 | + t.printStackTrace(); | ||
116 | + Log.e("AudioRecord", "Recording Failed"); | ||
117 | + } | ||
118 | + return null; | ||
119 | + } | ||
120 | + | ||
121 | + @Override | ||
122 | + protected void onProgressUpdate(double[]... toTransform) { | ||
123 | + | ||
124 | + canvas.drawColor(Color.BLACK); | ||
125 | + | ||
126 | + for (int i = 0; i < toTransform[0].length; i++) { | ||
127 | + int x = i; | ||
128 | + int downy = (int) (100 - (toTransform[0][i] * 10)); | ||
129 | + int upy = 100; | ||
130 | + | ||
131 | + canvas.drawLine(x, downy, x, upy, paint); | ||
132 | + } | ||
133 | + | ||
134 | + imageView.invalidate(); | ||
135 | + | ||
136 | + // TODO Auto-generated method stub | ||
137 | + // super.onProgressUpdate(values); | ||
138 | + } | ||
139 | + | ||
140 | + } | ||
141 | + | ||
142 | +// @Override | ||
143 | +// public boolean onCreateOptionsMenu(Menu menu) { | ||
144 | +// getMenuInflater().inflate(R.menu.activity_main, menu); | ||
145 | +// return true; | ||
146 | +// } | ||
147 | + | ||
148 | + public void onClick(View arg0) { | ||
149 | + // TODO Auto-generated method stub | ||
150 | + if (started) { | ||
151 | + started = false; | ||
152 | + startStopButton.setText("Start"); | ||
153 | + recordTask.cancel(true); | ||
154 | + } else { | ||
155 | + started = true; | ||
156 | + startStopButton.setText("Stop"); | ||
157 | + recordTask = new RecordAudio(); | ||
158 | + recordTask.execute(); | ||
159 | + } | ||
160 | + } | ||
161 | +} |
1 | +package com.example.zhongqiyan; | ||
2 | + | ||
3 | +import android.annotation.SuppressLint; | ||
4 | +import android.app.Activity; | ||
5 | +import android.graphics.Bitmap; | ||
6 | +import android.graphics.Canvas; | ||
7 | +import android.graphics.Color; | ||
8 | +import android.graphics.Paint; | ||
9 | +import android.media.AudioFormat; | ||
10 | +import android.media.AudioRecord; | ||
11 | +import android.media.MediaRecorder; | ||
12 | +import android.os.AsyncTask; | ||
13 | +import android.os.Bundle; | ||
14 | +import android.util.Log; | ||
15 | +import android.view.Menu; | ||
16 | +import android.view.View; | ||
17 | +import android.widget.Button; | ||
18 | +import android.widget.ImageView; | ||
19 | +import android.widget.TextView; | ||
20 | + | ||
21 | +import com.example.zhongqiyan.javasource.ca.uol.aig.fftpack.RealDoubleFFT; | ||
22 | + | ||
23 | +public class MainActivity2 extends Activity implements View.OnClickListener { | ||
24 | + | ||
25 | + int audioSource = MediaRecorder.AudioSource.MIC; // Audio source is the device MIC | ||
26 | + int channelConfig = AudioFormat.CHANNEL_IN_MONO; // Recording in mono | ||
27 | + int audioEncoding = AudioFormat.ENCODING_PCM_16BIT; // Records in 16bit | ||
28 | + | ||
29 | +// private DoubleFFT_1D fft; // The fft double array | ||
30 | + private RealDoubleFFT transformer; | ||
31 | + int blockSize = 256; // deal with this many samples at a time | ||
32 | + int sampleRate = 8000; // Sample rate in Hz | ||
33 | + public double frequency = 0.0; // the frequency given | ||
34 | + | ||
35 | + RecordAudio recordTask; // Creates a Record Audio command | ||
36 | + TextView tv; // Creates a text view for the frequency | ||
37 | + boolean started = false; | ||
38 | + Button startStopButton; | ||
39 | + @Override | ||
40 | + protected void onCreate(Bundle savedInstanceState) { | ||
41 | + super.onCreate(savedInstanceState); | ||
42 | + setContentView(R.layout.activity_main); | ||
43 | + tv = (TextView)findViewById(R.id.textView1); | ||
44 | + startStopButton= (Button)findViewById(R.id.StartStopButton); | ||
45 | + } | ||
46 | + | ||
47 | +// @Override | ||
48 | +// public boolean onCreateOptionsMenu(Menu menu) { | ||
49 | +// // Inflate the menu; this adds items to the action bar if it is present. | ||
50 | +// getMenuInflater().inflate(R.menu.main, menu); | ||
51 | +// return true; | ||
52 | +// } | ||
53 | + | ||
54 | + | ||
55 | + private class RecordAudio extends AsyncTask<Void, Double, Void>{ | ||
56 | + @SuppressLint("WrongThread") | ||
57 | + @Override | ||
58 | + protected Void doInBackground(Void... params){ | ||
59 | + | ||
60 | + /*Calculates the fft and frequency of the input*/ | ||
61 | + //try{ | ||
62 | + int bufferSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioEncoding); // Gets the minimum buffer needed | ||
63 | + AudioRecord audioRecord = new AudioRecord(audioSource, sampleRate, channelConfig, audioEncoding, bufferSize); // The RAW PCM sample recording | ||
64 | + | ||
65 | + | ||
66 | + | ||
67 | + short[] buffer = new short[blockSize]; // Save the raw PCM samples as short bytes | ||
68 | + | ||
69 | + // double[] audioDataDoubles = new double[(blockSize*2)]; // Same values as above, as doubles | ||
70 | + // ----------------------------------------------- | ||
71 | + double[] re = new double[blockSize]; | ||
72 | + double[] im = new double[blockSize]; | ||
73 | + double[] magnitude = new double[blockSize]; | ||
74 | + // ---------------------------------------------------- | ||
75 | + double[] toTransform = new double[blockSize]; | ||
76 | + | ||
77 | + tv.setText("Hello"); | ||
78 | + // fft = new DoubleFFT_1D(blockSize); | ||
79 | + | ||
80 | + | ||
81 | + try{ | ||
82 | + audioRecord.startRecording(); //Start | ||
83 | + }catch(Throwable t){ | ||
84 | + Log.e("AudioRecord", "Recording Failed"); | ||
85 | + } | ||
86 | + | ||
87 | + while(started){ | ||
88 | + /* Reads the data from the microphone. it takes in data | ||
89 | + * to the size of the window "blockSize". The data is then | ||
90 | + * given in to audioRecord. The int returned is the number | ||
91 | + * of bytes that were read*/ | ||
92 | + | ||
93 | + int bufferReadResult = audioRecord.read(buffer, 0, blockSize); | ||
94 | + | ||
95 | + // Read in the data from the mic to the array | ||
96 | + for(int i = 0; i < blockSize && i < bufferReadResult; i++) { | ||
97 | + | ||
98 | + /* dividing the short by 32768.0 gives us the | ||
99 | + * result in a range -1.0 to 1.0. | ||
100 | + * Data for the compextForward is given back | ||
101 | + * as two numbers in sequence. Therefore audioDataDoubles | ||
102 | + * needs to be twice as large*/ | ||
103 | + | ||
104 | + // audioDataDoubles[2*i] = (double) buffer[i]/32768.0; // signed 16 bit | ||
105 | + //audioDataDoubles[(2*i)+1] = 0.0; | ||
106 | + toTransform[i] = (double) buffer[i] / 32768.0; // signed 16 bit | ||
107 | + | ||
108 | + } | ||
109 | + | ||
110 | + //audiodataDoubles now holds data to work with | ||
111 | + // fft.complexForward(audioDataDoubles); | ||
112 | + transformer.ft(toTransform); | ||
113 | + //------------------------------------------------------------------------------------------ | ||
114 | + // Calculate the Real and imaginary and Magnitude. | ||
115 | + for(int i = 0; i < blockSize; i++){ | ||
116 | + // real is stored in first part of array | ||
117 | + re[i] = toTransform[i*2]; | ||
118 | + // imaginary is stored in the sequential part | ||
119 | + im[i] = toTransform[(i*2)+1]; | ||
120 | + // magnitude is calculated by the square root of (imaginary^2 + real^2) | ||
121 | + magnitude[i] = Math.sqrt((re[i] * re[i]) + (im[i]*im[i])); | ||
122 | + } | ||
123 | + | ||
124 | + double peak = -1.0; | ||
125 | + // Get the largest magnitude peak | ||
126 | + for(int i = 0; i < blockSize; i++){ | ||
127 | + if(peak < magnitude[i]) | ||
128 | + peak = magnitude[i]; | ||
129 | + } | ||
130 | + // calculated the frequency | ||
131 | + frequency = (sampleRate * peak)/blockSize; | ||
132 | +//---------------------------------------------------------------------------------------------- | ||
133 | + /* calls onProgressUpdate | ||
134 | + * publishes the frequency | ||
135 | + */ | ||
136 | + publishProgress(frequency); | ||
137 | + try{ | ||
138 | + audioRecord.stop(); | ||
139 | + } | ||
140 | + catch(IllegalStateException e){ | ||
141 | + Log.e("Stop failed", e.toString()); | ||
142 | + | ||
143 | + } | ||
144 | + } | ||
145 | + | ||
146 | + // } | ||
147 | + return null; | ||
148 | + } | ||
149 | + | ||
150 | + protected void onProgressUpdate(Double... frequencies){ | ||
151 | + //print the frequency | ||
152 | + String info = Double.toString(frequencies[0]); | ||
153 | + tv.setText(info); | ||
154 | + } | ||
155 | + | ||
156 | + } | ||
157 | + | ||
158 | + @Override | ||
159 | + public void onClick(View v) { | ||
160 | + // TODO Auto-generated method stub | ||
161 | + if(started){ | ||
162 | + started = false; | ||
163 | + startStopButton.setText("Start"); | ||
164 | + recordTask.cancel(true); | ||
165 | + } else { | ||
166 | + started = true; | ||
167 | + startStopButton.setText("Stop"); | ||
168 | + recordTask = new RecordAudio(); | ||
169 | + recordTask.execute(); | ||
170 | + } | ||
171 | + | ||
172 | + } | ||
173 | + | ||
174 | +} |
1 | +package com.example.zhongqiyan.base; | ||
2 | + | ||
3 | +/** | ||
4 | + * Activity管理类 | ||
5 | + * Created by 18514 on 2019/1/5. | ||
6 | + */ | ||
7 | + | ||
8 | +import android.app.Activity; | ||
9 | + | ||
10 | +import java.util.Stack; | ||
11 | + | ||
12 | +/** | ||
13 | + * Activity管理类 | ||
14 | + */ | ||
15 | +public class ActivityStackManager { | ||
16 | + private static Stack<Activity> activityStack; | ||
17 | + private static ActivityStackManager instance; | ||
18 | + | ||
19 | + private ActivityStackManager() { | ||
20 | + } | ||
21 | + | ||
22 | + public synchronized static ActivityStackManager getActivityStackManager() { | ||
23 | + if (instance == null) { | ||
24 | + instance = new ActivityStackManager(); | ||
25 | + } | ||
26 | + return instance; | ||
27 | + } | ||
28 | + | ||
29 | + /** | ||
30 | + * 关闭activity | ||
31 | + * finish the activity and remove it from stack. | ||
32 | + * | ||
33 | + * @param activity | ||
34 | + */ | ||
35 | + public void popActivity(Activity activity) { | ||
36 | + if (activityStack == null) { | ||
37 | + return; | ||
38 | + } | ||
39 | + if (activity != null) { | ||
40 | + activity.finish(); | ||
41 | + activity.overridePendingTransition(0, 0); | ||
42 | + activityStack.remove(activity); | ||
43 | + activity = null; | ||
44 | + } | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * 获取当前的Activity | ||
49 | + * get the current activity. | ||
50 | + * | ||
51 | + * @return | ||
52 | + */ | ||
53 | + public Activity currentActivity() { | ||
54 | + if (activityStack == null || activityStack.isEmpty()) { | ||
55 | + return null; | ||
56 | + } | ||
57 | + Activity activity = (Activity) activityStack.lastElement(); | ||
58 | + return activity; | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * 获取最后一个的Activity | ||
63 | + * get the first activity in the stack. | ||
64 | + * | ||
65 | + * @return | ||
66 | + */ | ||
67 | + public Activity firstActivity() { | ||
68 | + if (activityStack == null || activityStack.isEmpty()) { | ||
69 | + return null; | ||
70 | + } | ||
71 | + Activity activity = (Activity) activityStack.firstElement(); | ||
72 | + return activity; | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * 添加activity到Stack | ||
77 | + * add the activity to the stack. | ||
78 | + * | ||
79 | + * @param activity | ||
80 | + */ | ||
81 | + public void pushActivity(Activity activity) { | ||
82 | + if (activityStack == null) { | ||
83 | + activityStack = new Stack<Activity>(); | ||
84 | + } | ||
85 | + activityStack.add(activity); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * remove所有Activity | ||
90 | + * remove all activity. | ||
91 | + */ | ||
92 | + public void popAllActivity() { | ||
93 | + if (activityStack == null) { | ||
94 | + return; | ||
95 | + } | ||
96 | + while (true) { | ||
97 | + if (activityStack.empty()) { | ||
98 | + break; | ||
99 | + } | ||
100 | + Activity activity = currentActivity(); | ||
101 | + popActivity(activity); | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * remove所有Activity但保持目前的Activity | ||
107 | + * remove all activity but keep the current activity. | ||
108 | + */ | ||
109 | + public void popAllActivityWithOutCurrent() { | ||
110 | + Activity activity = currentActivity(); | ||
111 | + while (true) { | ||
112 | + if (activityStack.size() == 1) { | ||
113 | + break; | ||
114 | + } | ||
115 | + if (firstActivity() == activity) { | ||
116 | + break; | ||
117 | + } else { | ||
118 | + popActivity(firstActivity()); | ||
119 | + } | ||
120 | + } | ||
121 | + } | ||
122 | +} | ||
123 | + |
1 | +package com.example.zhongqiyan.base; | ||
2 | + | ||
3 | +import android.app.Activity; | ||
4 | + | ||
5 | +import java.util.Stack; | ||
6 | + | ||
7 | +/** | ||
8 | + * activity 堆栈工具 | ||
9 | + * | ||
10 | + * @packageName: cn.white.ymc.wanandroidmaster.util | ||
11 | + * @fileName: AppDavikActivityUtil | ||
12 | + * @date: 2018/7/19 15:47 | ||
13 | + * @author: ymc | ||
14 | + * @QQ:745612618 | ||
15 | + */ | ||
16 | + | ||
17 | +public class AppDavikActivityUtil { | ||
18 | + | ||
19 | + /** | ||
20 | + * 存储ActivityStack | ||
21 | + */ | ||
22 | + private static Stack<Activity> activityStack = new Stack<>(); | ||
23 | + | ||
24 | + /** | ||
25 | + * 单例模式 | ||
26 | + */ | ||
27 | + private static AppDavikActivityUtil instance; | ||
28 | + | ||
29 | + | ||
30 | + /** | ||
31 | + * 单列堆栈集合对象 | ||
32 | + * @return AppDavikActivityMgr 单利堆栈集合对象 | ||
33 | + */ | ||
34 | + public static AppDavikActivityUtil getScreenManager() { | ||
35 | + if (instance == null) { | ||
36 | + synchronized (AppDavikActivityUtil.class){ | ||
37 | + if (instance == null) { | ||
38 | + instance = new AppDavikActivityUtil(); | ||
39 | + } | ||
40 | + } | ||
41 | + } | ||
42 | + return instance; | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
46 | + * 堆栈中销毁并移除 | ||
47 | + * @param activity 指定Act对象 | ||
48 | + */ | ||
49 | + public void removeActivity(Activity activity) { | ||
50 | + if (null != activity) { | ||
51 | + activityStack.remove(activity); | ||
52 | + activity.finish(); | ||
53 | + activity = null; | ||
54 | + } | ||
55 | + } | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + /** | ||
60 | + * 栈中销毁并移除所有Act对象 | ||
61 | + */ | ||
62 | + public void removeAllActivity() { | ||
63 | + if (null != activityStack && activityStack.size() > 0) { | ||
64 | + //创建临时集合对象 | ||
65 | + Stack<Activity> activityTemp = new Stack<Activity>(); | ||
66 | + for (Activity activity : activityStack) { | ||
67 | + if (null != activity) { | ||
68 | + //添加到临时集合中 | ||
69 | + activityTemp.add(activity); | ||
70 | + //结束Activity | ||
71 | + activity.finish(); | ||
72 | + } | ||
73 | + } | ||
74 | + activityStack.removeAll(activityTemp); | ||
75 | + } | ||
76 | + System.gc(); | ||
77 | + System.exit(0); | ||
78 | + } | ||
79 | + | ||
80 | + | ||
81 | + /** | ||
82 | + * 获取当前Act对象 | ||
83 | + * @return Activity 当前act | ||
84 | + */ | ||
85 | + public Activity currentActivity() { | ||
86 | + Activity activity = null; | ||
87 | + if (!activityStack.empty()){ | ||
88 | + activity = activityStack.lastElement(); | ||
89 | + } | ||
90 | + return activity; | ||
91 | + } | ||
92 | + | ||
93 | + | ||
94 | + /** | ||
95 | + * 获得当前Act的类名 | ||
96 | + * @return String | ||
97 | + */ | ||
98 | + public String getCurrentActivityName() { | ||
99 | + String actSimpleName = ""; | ||
100 | + if (!activityStack.empty()) { | ||
101 | + actSimpleName = activityStack.lastElement().getClass().getSimpleName(); | ||
102 | + } | ||
103 | + return actSimpleName; | ||
104 | + } | ||
105 | + | ||
106 | + | ||
107 | + /** | ||
108 | + * 将Act纳入推栈集合中 | ||
109 | + * @param activity Act对象 | ||
110 | + */ | ||
111 | + public void addActivity(Activity activity) { | ||
112 | + if (null == activityStack) { | ||
113 | + activityStack = new Stack<>(); | ||
114 | + } | ||
115 | + activityStack.add(activity); | ||
116 | + } | ||
117 | + | ||
118 | + | ||
119 | + | ||
120 | + /** | ||
121 | + * 退出栈中所有Activity | ||
122 | + * @param cls | ||
123 | + * @return void | ||
124 | + */ | ||
125 | + public void exitApp(Class<?> cls) { | ||
126 | + while (true) { | ||
127 | + Activity activity = currentActivity(); | ||
128 | + if (null == activity) { | ||
129 | + break; | ||
130 | + } | ||
131 | + if (activity.getClass().equals(cls)) { | ||
132 | + break; | ||
133 | + } | ||
134 | + removeActivity(activity); | ||
135 | + } | ||
136 | + System.gc(); | ||
137 | + System.exit(0); | ||
138 | + } | ||
139 | + | ||
140 | +} |
1 | +package com.example.zhongqiyan.base; | ||
2 | + | ||
3 | +import android.annotation.SuppressLint; | ||
4 | +import android.app.Activity; | ||
5 | +import android.content.Context; | ||
6 | +import android.content.Intent; | ||
7 | +import android.os.Bundle; | ||
8 | +import android.util.Log; | ||
9 | +import android.view.Display; | ||
10 | +import android.view.MotionEvent; | ||
11 | +import android.view.View; | ||
12 | +import android.view.WindowManager; | ||
13 | +import android.widget.TextView; | ||
14 | + | ||
15 | +import androidx.annotation.Nullable; | ||
16 | +import androidx.appcompat.app.AppCompatActivity; | ||
17 | +import androidx.fragment.app.Fragment; | ||
18 | +import androidx.fragment.app.FragmentManager; | ||
19 | +import androidx.recyclerview.widget.GridLayoutManager; | ||
20 | +import androidx.recyclerview.widget.LinearLayoutManager; | ||
21 | +import androidx.recyclerview.widget.RecyclerView; | ||
22 | + | ||
23 | + | ||
24 | +import com.example.zhongqiyan.DebugLog; | ||
25 | +import com.example.zhongqiyan.R; | ||
26 | +import com.example.zhongqiyan.base.instant.ViewInject; | ||
27 | +import com.example.zhongqiyan.base.instant.slideslip.SlideLip; | ||
28 | +import com.example.zhongqiyan.network.ApiService; | ||
29 | +import com.example.zhongqiyan.network.ApiStore; | ||
30 | + | ||
31 | +import java.util.List; | ||
32 | + | ||
33 | +import butterknife.ButterKnife; | ||
34 | +import butterknife.Unbinder; | ||
35 | + | ||
36 | +public abstract class BaseActivity extends AppCompatActivity{ | ||
37 | + | ||
38 | + public AppDavikActivityUtil appDavikActivityUtil = AppDavikActivityUtil.getScreenManager(); | ||
39 | + final String TAG = this.getClass().getSimpleName(); //获取当前activity | ||
40 | + | ||
41 | + /** | ||
42 | + * context | ||
43 | + */ | ||
44 | + protected Context ctx; | ||
45 | + protected BaseActivity activity; | ||
46 | + boolean lip; | ||
47 | + | ||
48 | + private int width; | ||
49 | + private int height; | ||
50 | + | ||
51 | + private Unbinder bind; | ||
52 | + | ||
53 | + int yes, no; | ||
54 | + | ||
55 | + /** | ||
56 | + * 初始化数据 | ||
57 | + */ | ||
58 | + protected abstract void initData(); | ||
59 | + | ||
60 | + /** | ||
61 | + * 绑定事件 | ||
62 | + */ | ||
63 | + protected abstract void setEvent(); | ||
64 | + | ||
65 | + | ||
66 | + @SuppressLint("NewApi") | ||
67 | + @Override | ||
68 | + public void onCreate(@Nullable Bundle savedInstanceState) { | ||
69 | + | ||
70 | + no = getResources().getColor(R.color.color_232323); | ||
71 | + yes = getResources().getColor(R.color.color_ffab13); | ||
72 | + | ||
73 | + super.onCreate(savedInstanceState); | ||
74 | + DebugLog.e(TAG + "--->OnCreate"); | ||
75 | + activity = this; // 上下文 | ||
76 | + new ViewInject(activity).setView().injectViews().injectEvents().TopNavigationBar(); // 先初始化 - > 实例化 - > 点击事件 - > 导航栏颜色 , 样式 | ||
77 | + | ||
78 | + bind = ButterKnife.bind(this); | ||
79 | + | ||
80 | + initData();//数据 | ||
81 | + setEvent();//事件 | ||
82 | + ctx = this; | ||
83 | + ActivityStackManager.getActivityStackManager().pushActivity(this); // 将activity添加到堆栈中 | ||
84 | + | ||
85 | + initAttributes(); | ||
86 | + | ||
87 | + } | ||
88 | + | ||
89 | + // 注解 | ||
90 | + private void initAttributes() { | ||
91 | + WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); | ||
92 | + Display defaultDisplay = windowManager.getDefaultDisplay(); | ||
93 | + width = defaultDisplay.getWidth(); | ||
94 | + height = defaultDisplay.getHeight(); | ||
95 | + | ||
96 | + SlideLip slide = activity.getClass().getAnnotation(SlideLip.class); | ||
97 | + if (slide != null) { | ||
98 | + try { | ||
99 | + lip = slide.slidelip(); | ||
100 | + } catch (Exception e) { | ||
101 | + e.printStackTrace(); | ||
102 | + } | ||
103 | + } | ||
104 | + } | ||
105 | + | ||
106 | + // ---------------------------------------------------- 简用 ------------------------------------------------------------- | ||
107 | + | ||
108 | + /** | ||
109 | + * @param manager // - > manager 0 = GridLayoutManager | 1 = LinearLayoutManager | ||
110 | + * @param rv | ||
111 | + * @param orientation // - > orientation 0 = VERTICAL | else HORIZONTAL | ||
112 | + * @param count // - > count 设置 GridLayoutManager 的横向数量 | ||
113 | + */ | ||
114 | + @SuppressLint("WrongConstant") | ||
115 | + public void setRv(RecyclerView rv, int manager, int orientation, int count) { | ||
116 | + if (manager == 0) { | ||
117 | + GridLayoutManager gridManager = new GridLayoutManager(this, count); | ||
118 | + rv.setLayoutManager(gridManager); | ||
119 | + } else { | ||
120 | + LinearLayoutManager linearManager = new LinearLayoutManager(this); | ||
121 | + if (orientation == 0) { | ||
122 | + linearManager.setOrientation(LinearLayoutManager.VERTICAL); | ||
123 | + } else { | ||
124 | + linearManager.setOrientation(LinearLayoutManager.HORIZONTAL); | ||
125 | + } | ||
126 | + rv.setLayoutManager(linearManager); | ||
127 | + } | ||
128 | + } | ||
129 | + | ||
130 | + // -------------------------- api ------------------------------------------- | ||
131 | + public ApiService Api() { | ||
132 | + ApiService api = ApiStore.createApi(ApiService.class); | ||
133 | + return api; | ||
134 | + } | ||
135 | + | ||
136 | + | ||
137 | + // ----------------------- check 仿 tablayout .. --------------------------------- | ||
138 | + // - > 主要是因为懒 .. 所以手写一个 后面闲的蛋疼的时候 , 会自己去写控件 这个只是提供一个思路 | ||
139 | + List<View> list; | ||
140 | + | ||
141 | + public void checkData(List<View> line) { | ||
142 | + this.list = line; | ||
143 | + check(); | ||
144 | + } | ||
145 | + | ||
146 | + // 0 . 2 . 4 .. text 1 . 3 . 5 .. view | ||
147 | + public void check() { | ||
148 | + for (int i = 1; i < list.size() + 1; i++) { | ||
149 | + if (i == 1 || i % 2 == 1) { | ||
150 | + ((TextView) list.get(i - 1)).setTextColor(no); | ||
151 | + } else { | ||
152 | + list.get(i - 1).setBackgroundColor(no); | ||
153 | + list.get(i - 1).setVisibility(View.INVISIBLE); | ||
154 | + } | ||
155 | + } | ||
156 | + } | ||
157 | + | ||
158 | + // ----------------------------------- 生命周期 ---------------------------------- | ||
159 | + @Override | ||
160 | + protected void onStart() { | ||
161 | + super.onStart(); | ||
162 | + Log.i(TAG, "--->onStart()"); | ||
163 | + } | ||
164 | + | ||
165 | + @Override | ||
166 | + protected void onResume() { | ||
167 | + super.onResume(); | ||
168 | + Log.i(TAG, "--->onResume()"); | ||
169 | + } | ||
170 | + | ||
171 | + @Override | ||
172 | + protected void onRestart() { | ||
173 | + super.onRestart(); | ||
174 | + Log.i(TAG, "--->onRestart()"); | ||
175 | + } | ||
176 | + | ||
177 | + @Override | ||
178 | + protected void onPause() { | ||
179 | + super.onPause(); | ||
180 | + Log.i(TAG, "--->onPause()"); | ||
181 | + } | ||
182 | + | ||
183 | + @Override | ||
184 | + protected void onStop() { | ||
185 | + super.onStop(); | ||
186 | + Log.i(TAG, "--->onStop()"); | ||
187 | + } | ||
188 | + | ||
189 | + @Override | ||
190 | + protected void onDestroy() { | ||
191 | + appDavikActivityUtil.removeActivity(this); | ||
192 | + Log.i(TAG, "--->onDestroy()"); | ||
193 | + bind.unbind(); | ||
194 | + super.onDestroy(); | ||
195 | + } | ||
196 | + | ||
197 | + @Override | ||
198 | + public boolean onTouchEvent(MotionEvent event) { | ||
199 | + float dx = 0, dy = 0, ux = 0, uy = 0; | ||
200 | + if (lip == true) { | ||
201 | + switch (event.getAction()) { | ||
202 | + case MotionEvent.ACTION_DOWN: // down | ||
203 | + dx = event.getX(); | ||
204 | + dy = event.getY(); | ||
205 | + break; | ||
206 | + case MotionEvent.ACTION_UP: | ||
207 | + ux = event.getX(); | ||
208 | + uy = event.getY(); | ||
209 | + | ||
210 | + if ((ux - dx) > (width / 2)) { | ||
211 | + activity.finish(); | ||
212 | + } | ||
213 | + break; | ||
214 | + } | ||
215 | + } | ||
216 | + return super.onTouchEvent(event); | ||
217 | + } | ||
218 | + | ||
219 | + /** | ||
220 | + * 跳转Activity Flag == true --> finish | ||
221 | + * skip Another Activity | ||
222 | + * | ||
223 | + * @param activity | ||
224 | + * @param cls | ||
225 | + */ | ||
226 | + public static void skipAnotherActivity(Activity activity, Class<? extends Activity> cls, boolean flag) { | ||
227 | + activity.startActivity(new Intent(activity, cls)); | ||
228 | + if (flag == true) { | ||
229 | + activity.finish(); | ||
230 | + } | ||
231 | + } | ||
232 | + | ||
233 | + /** | ||
234 | + * 退出应用 | ||
235 | + * called while exit app | ||
236 | + */ | ||
237 | + public void exitLogic() { | ||
238 | + ActivityStackManager.getActivityStackManager().popAllActivity(); //清楚所有栈中的activity | ||
239 | + System.exit(0); | ||
240 | + } | ||
241 | + | ||
242 | + @Override | ||
243 | + protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
244 | + FragmentManager fm = getSupportFragmentManager(); | ||
245 | + int index = requestCode >> 16; | ||
246 | + if (index != 0) { | ||
247 | + index--; | ||
248 | + if (fm.getFragments() == null || index < 0 | ||
249 | + || index >= fm.getFragments().size()) { | ||
250 | + Log.w(TAG, "Activity result fragment index out of range: 0x" | ||
251 | + + Integer.toHexString(requestCode)); | ||
252 | + return; | ||
253 | + } | ||
254 | + Fragment frag = fm.getFragments().get(index); | ||
255 | + if (frag == null) { | ||
256 | + Log.w(TAG, "Activity result no fragment exists for index: 0x" | ||
257 | + + Integer.toHexString(requestCode)); | ||
258 | + } else { | ||
259 | + handleResult(frag, requestCode, resultCode, data); | ||
260 | + } | ||
261 | + return; | ||
262 | + } | ||
263 | + | ||
264 | + } | ||
265 | + | ||
266 | + /** | ||
267 | + * 递归调用,对所有子Fragement生效 | ||
268 | + * | ||
269 | + * @param frag | ||
270 | + * @param requestCode | ||
271 | + * @param resultCode | ||
272 | + * @param data | ||
273 | + */ | ||
274 | + private void handleResult(Fragment frag, int requestCode, int resultCode, | ||
275 | + Intent data) { | ||
276 | + frag.onActivityResult(requestCode & 0xffff, resultCode, data); | ||
277 | + List<Fragment> frags = frag.getChildFragmentManager().getFragments(); | ||
278 | + if (frags != null) { | ||
279 | + for (Fragment f : frags) { | ||
280 | + if (f != null) | ||
281 | + handleResult(f, requestCode, resultCode, data); | ||
282 | + } | ||
283 | + } | ||
284 | + } | ||
285 | +} |
1 | +package com.example.zhongqiyan.base; | ||
2 | + | ||
3 | +public class Config { | ||
4 | + public static int RUN_MODE = 1; // 0 测试 1 正式 | ||
5 | + public static final String BASE_IP = "http://ctest.ynsdfx.com";//测试服务器 | ||
6 | + public static final String LOGIN_IP = "http://api.ynsdfx.com";//登录的 | ||
7 | + public static String Token = ""; // 0 测试 1 正式 | ||
8 | +} |
1 | +package com.example.zhongqiyan.base.instant; | ||
2 | + | ||
3 | +import java.lang.annotation.ElementType; | ||
4 | +import java.lang.annotation.Retention; | ||
5 | +import java.lang.annotation.RetentionPolicy; | ||
6 | +import java.lang.annotation.Target; | ||
7 | + | ||
8 | +/** | ||
9 | + * @fileName: InstantViews | ||
10 | + * @date: 2019/12/7 | ||
11 | + * @author: lm | ||
12 | + * @QQ:820139338 - > 没事别加着玩 | ||
13 | + */ | ||
14 | + | ||
15 | +@Target({ElementType.FIELD}) | ||
16 | +@Retention(RetentionPolicy.RUNTIME) | ||
17 | +public @interface InstantViews { | ||
18 | + int value(); | ||
19 | + | ||
20 | + int[] inject() default 0; | ||
21 | +} |
1 | +package com.example.zhongqiyan.base.instant; | ||
2 | + | ||
3 | +import java.lang.annotation.ElementType; | ||
4 | +import java.lang.annotation.Retention; | ||
5 | +import java.lang.annotation.RetentionPolicy; | ||
6 | +import java.lang.annotation.Target; | ||
7 | + | ||
8 | +/** | ||
9 | + * @fileName: Layout | ||
10 | + * @date: 2019/12/7 | ||
11 | + * @author: lm | ||
12 | + * @QQ:820139338 - > 没事别加着玩 | ||
13 | + */ | ||
14 | + | ||
15 | +@Retention(RetentionPolicy.RUNTIME) | ||
16 | +@Target({ElementType.TYPE}) | ||
17 | +public @interface Layout { | ||
18 | + int value() default -1; | ||
19 | +} |
1 | +package com.example.zhongqiyan.base.instant; | ||
2 | + | ||
3 | +import android.graphics.Color; | ||
4 | + | ||
5 | +import java.lang.annotation.ElementType; | ||
6 | +import java.lang.annotation.Retention; | ||
7 | +import java.lang.annotation.RetentionPolicy; | ||
8 | +import java.lang.annotation.Target; | ||
9 | + | ||
10 | +/** | ||
11 | + * @fileName: TopNavigationBar | ||
12 | + * @date: 2019/12/7 | ||
13 | + * @author: lm | ||
14 | + * @QQ:820139338 - > 没事别加着玩 | ||
15 | + */ | ||
16 | + | ||
17 | +@Target({ElementType.TYPE}) | ||
18 | +@Retention(RetentionPolicy.RUNTIME) | ||
19 | +public @interface TopNavigationBar { | ||
20 | + int color() default Color.TRANSPARENT; // 0 - > 状态栏颜色 | ||
21 | + | ||
22 | + int setBarBiack() default 0; // - > 状态栏字体颜色 | ||
23 | +} |
1 | +package com.example.zhongqiyan.base.instant; | ||
2 | + | ||
3 | +import android.app.Activity; | ||
4 | +import android.content.Context; | ||
5 | +import android.os.Build; | ||
6 | +import android.view.View; | ||
7 | + | ||
8 | + | ||
9 | +import com.example.zhongqiyan.base.BaseActivity; | ||
10 | +import com.example.zhongqiyan.base.instant.click.ClickView; | ||
11 | +import com.example.zhongqiyan.base.instant.click.DynamicHandler; | ||
12 | +import com.example.zhongqiyan.base.instant.click.ListenerViews; | ||
13 | + | ||
14 | +import java.lang.reflect.Field; | ||
15 | +import java.lang.reflect.InvocationTargetException; | ||
16 | +import java.lang.reflect.Method; | ||
17 | +import java.lang.reflect.Proxy; | ||
18 | + | ||
19 | +/** | ||
20 | + * @fileName: ViewInject | ||
21 | + * @date: 2019/12/7 | ||
22 | + * @author: lm | ||
23 | + * @QQ:820139338 - > 没事别加着玩 | ||
24 | + */ | ||
25 | + | ||
26 | +public class ViewInject { | ||
27 | + | ||
28 | + Activity activity; | ||
29 | + | ||
30 | + public ViewInject(BaseActivity activity) { | ||
31 | + this.activity = activity; | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * 初始化 | ||
36 | + * | ||
37 | + */ | ||
38 | + public ViewInject setView() { | ||
39 | + for (Class c = activity.getClass(); c != Context.class; c = c.getSuperclass()) { | ||
40 | + Layout annotation = (Layout) c.getAnnotation(Layout.class); | ||
41 | + if (annotation != null) { | ||
42 | + try { | ||
43 | + activity.setContentView(annotation.value()); | ||
44 | + } catch (RuntimeException e) { | ||
45 | + e.printStackTrace(); | ||
46 | + } | ||
47 | +// return; | ||
48 | + } | ||
49 | + } | ||
50 | + return this; | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * 状态栏设置 | ||
55 | + * | ||
56 | + * @param activity | ||
57 | + */ | ||
58 | + public ViewInject TopNavigationBar() { | ||
59 | + TopNavigationBar annotation = activity.getClass().getAnnotation(TopNavigationBar.class); | ||
60 | + if (annotation != null) { | ||
61 | + try { | ||
62 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
63 | + int color = annotation.color(); // 状态栏颜色 | ||
64 | + activity.getWindow().setStatusBarColor(color); | ||
65 | + | ||
66 | + int status = annotation.setBarBiack(); // - > 状态栏模式 | ||
67 | + switch (status) { | ||
68 | + case 0: // SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 状态栏存在 , 布局下推 , 字体黑色 | ||
69 | + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | ||
70 | + break; | ||
71 | + case 1: // SYSTEM_UI_FLAG_FULLSCREEN 状态栏初始隐藏(模式全屏), 滑动后可唤醒 (布局下推) | ||
72 | + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN); | ||
73 | + break; | ||
74 | + case 2: // SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 字体白色 | ||
75 | + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); // 隐藏 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | ||
76 | + break; | ||
77 | + } | ||
78 | + | ||
79 | + } | ||
80 | + } catch (Exception e) { | ||
81 | + e.printStackTrace(); | ||
82 | + } | ||
83 | + } | ||
84 | + return this; | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * 实例化 | ||
89 | + * | ||
90 | + * @param activity | ||
91 | + */ | ||
92 | + public ViewInject injectViews() { | ||
93 | + Class<? extends Activity> a = activity.getClass(); | ||
94 | + Field[] fields = a.getDeclaredFields(); | ||
95 | + for (Field field : fields) { | ||
96 | + if (field.isAnnotationPresent(InstantViews.class)) { | ||
97 | + InstantViews annotation = field.getAnnotation(InstantViews.class); | ||
98 | + int value = annotation.value(); | ||
99 | + try { | ||
100 | + Method method = a.getMethod("findViewById", int.class); | ||
101 | + Object invoke = method.invoke(activity, value); | ||
102 | + field.setAccessible(true); //值为 true 则指示反射的对象在使用时应该取消 Java 语言访问检查 | ||
103 | + field.set(activity, invoke); | ||
104 | + } catch (Exception e) { | ||
105 | + e.printStackTrace(); | ||
106 | + } | ||
107 | + } | ||
108 | + } | ||
109 | + return this; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * 点击事件 | ||
114 | + * | ||
115 | + * @param activity | ||
116 | + */ | ||
117 | + public ViewInject injectEvents() { | ||
118 | + Class<? extends Activity> aClass = activity.getClass(); | ||
119 | + Method[] methods = aClass.getDeclaredMethods(); | ||
120 | + for (Method method : methods) { | ||
121 | + if (method.isAnnotationPresent(ClickView.class)) { | ||
122 | + ClickView onClick = method.getAnnotation(ClickView.class); | ||
123 | + int[] viewIds = onClick.value(); | ||
124 | + ListenerViews eventBase = onClick.annotationType().getAnnotation(ListenerViews.class); | ||
125 | + String listenerSetter = eventBase.listenerSetter(); | ||
126 | + Class listenerType = eventBase.listenerType(); | ||
127 | + String methodName = eventBase.methodName(); | ||
128 | + DynamicHandler handler = new DynamicHandler(activity); | ||
129 | + Object listener = Proxy.newProxyInstance(listenerType.getClassLoader(), new Class<?>[]{listenerType}, handler); | ||
130 | + handler.addMethod(methodName, method); | ||
131 | + for (int viewId : viewIds) { | ||
132 | + try { | ||
133 | + Method findViewByIdMethod = aClass.getMethod("findViewById", int.class); | ||
134 | + findViewByIdMethod.setAccessible(true); | ||
135 | + View view = (View) findViewByIdMethod.invoke(activity, viewId); | ||
136 | + Method setEventListenerMethod = view.getClass().getMethod(listenerSetter, listenerType); | ||
137 | + setEventListenerMethod.setAccessible(true); | ||
138 | + setEventListenerMethod.invoke(view, listener); | ||
139 | + } catch (NoSuchMethodException e) { | ||
140 | + e.printStackTrace(); | ||
141 | + } catch (InvocationTargetException e) { | ||
142 | + e.printStackTrace(); | ||
143 | + } catch (IllegalAccessException e) { | ||
144 | + e.printStackTrace(); | ||
145 | + } | ||
146 | + } | ||
147 | + } | ||
148 | + } | ||
149 | + return this; | ||
150 | + } | ||
151 | + | ||
152 | +} |
1 | +package com.example.zhongqiyan.base.instant.click; | ||
2 | + | ||
3 | +import android.view.View; | ||
4 | + | ||
5 | +import java.lang.annotation.ElementType; | ||
6 | +import java.lang.annotation.Retention; | ||
7 | +import java.lang.annotation.RetentionPolicy; | ||
8 | +import java.lang.annotation.Target; | ||
9 | + | ||
10 | +/** | ||
11 | + * @fileName: ClickView | ||
12 | + * @date: 2019/12/7 | ||
13 | + * @author: lm | ||
14 | + * @QQ:820139338 - > 没事别加着玩 | ||
15 | + */ | ||
16 | + | ||
17 | +@Target({ElementType.METHOD}) | ||
18 | +@Retention(RetentionPolicy.RUNTIME) | ||
19 | +@ListenerViews(listenerType = View.OnClickListener.class,listenerSetter = "setOnClickListener", methodName = "onClick") | ||
20 | +public @interface ClickView { | ||
21 | + int[] value() default 0; | ||
22 | +} |
1 | +package com.example.zhongqiyan.base.instant.click; | ||
2 | + | ||
3 | +import java.lang.ref.WeakReference; | ||
4 | +import java.lang.reflect.InvocationHandler; | ||
5 | +import java.lang.reflect.Method; | ||
6 | +import java.util.HashMap; | ||
7 | + | ||
8 | +/** | ||
9 | + * @fileName: DynamicHandler | ||
10 | + * @date: 2019/12/7 | ||
11 | + * @author: lm | ||
12 | + * @QQ:820139338 - > 没事别加着玩 | ||
13 | + */ | ||
14 | + | ||
15 | +public class DynamicHandler implements InvocationHandler { | ||
16 | + | ||
17 | + private final HashMap<String, Method> methodMap = new HashMap<>(1); | ||
18 | + // 因为传进来的为activity,使用弱引用主要是为了防止内存泄漏 | ||
19 | + private WeakReference<Object> handlerRef; | ||
20 | + | ||
21 | + public DynamicHandler(Object object) { | ||
22 | + this.handlerRef = new WeakReference<Object>(object); | ||
23 | + } | ||
24 | + | ||
25 | + public void addMethod(String name, Method method) { | ||
26 | + methodMap.put(name, method); | ||
27 | + } | ||
28 | + | ||
29 | + // 当回到OnClickListener的OnClick方法的时候,它会调用这里的invoke方法 | ||
30 | + @Override | ||
31 | + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
32 | + // 得到activity实例 | ||
33 | + Object handler = handlerRef.get(); | ||
34 | + if (handler != null) { | ||
35 | + // method对应的就是回调方法OnClick,得到方法名 | ||
36 | + String methodName = method.getName(); | ||
37 | + // 得到activtiy里面的clickBtnInvoked方法 | ||
38 | + method = methodMap.get(methodName); | ||
39 | + if (method != null) { | ||
40 | + // 回调clickBtnInvoked方法 | ||
41 | + return method.invoke(handler, args); | ||
42 | + } | ||
43 | + } | ||
44 | + return null; | ||
45 | + } | ||
46 | + | ||
47 | +} |
1 | +package com.example.zhongqiyan.base.instant.click; | ||
2 | + | ||
3 | +import java.lang.annotation.ElementType; | ||
4 | +import java.lang.annotation.Retention; | ||
5 | +import java.lang.annotation.RetentionPolicy; | ||
6 | +import java.lang.annotation.Target; | ||
7 | + | ||
8 | +/** | ||
9 | + * @fileName: ListenerViews | ||
10 | + * @date: 2019/12/7 | ||
11 | + * @author: lm | ||
12 | + * @QQ:820139338 - > 没事别加着玩 | ||
13 | + */ | ||
14 | + | ||
15 | +@Target({ElementType.TYPE}) | ||
16 | +@Retention(RetentionPolicy.RUNTIME) | ||
17 | +public @interface ListenerViews { | ||
18 | + Class listenerType(); | ||
19 | + String listenerSetter(); | ||
20 | + String methodName(); | ||
21 | +} |
1 | +package com.example.zhongqiyan.base.instant.fragment; | ||
2 | + | ||
3 | +import java.lang.annotation.ElementType; | ||
4 | +import java.lang.annotation.Retention; | ||
5 | +import java.lang.annotation.RetentionPolicy; | ||
6 | +import java.lang.annotation.Target; | ||
7 | + | ||
8 | +/** | ||
9 | + * @author: Kongzue | ||
10 | + * @github: https://github.com/kongzue/ | ||
11 | + * @homepage: http://kongzue.com/ | ||
12 | + * @mail: myzcxhh@live.cn | ||
13 | + * @createTime: 2019/11/21 15:17 | ||
14 | + */ | ||
15 | +@Target(ElementType.FIELD) | ||
16 | +@Retention(RetentionPolicy.RUNTIME) | ||
17 | +public @interface BindView { | ||
18 | + int value() default 0; | ||
19 | +} |
1 | +package com.example.zhongqiyan.base.instant.fragment; | ||
2 | + | ||
3 | + | ||
4 | +import java.lang.annotation.ElementType; | ||
5 | +import java.lang.annotation.Retention; | ||
6 | +import java.lang.annotation.RetentionPolicy; | ||
7 | +import java.lang.annotation.Target; | ||
8 | + | ||
9 | +/** | ||
10 | + * @author: Kongzue | ||
11 | + * @github: https://github.com/kongzue/ | ||
12 | + * @homepage: http://kongzue.com/ | ||
13 | + * @mail: myzcxhh@live.cn | ||
14 | + * @createTime: 2019/11/21 22:08 | ||
15 | + */ | ||
16 | +@Target(ElementType.FIELD) | ||
17 | +@Retention(RetentionPolicy.RUNTIME) | ||
18 | +public @interface BindViews { | ||
19 | + int[] value() default 0; | ||
20 | +} |
1 | +package com.example.zhongqiyan.base.instant.fragment; | ||
2 | + | ||
3 | +import java.lang.annotation.ElementType; | ||
4 | +import java.lang.annotation.Retention; | ||
5 | +import java.lang.annotation.RetentionPolicy; | ||
6 | +import java.lang.annotation.Target; | ||
7 | + | ||
8 | +/** | ||
9 | + * @author: Kongzue | ||
10 | + * @github: https://github.com/kongzue/ | ||
11 | + * @homepage: http://kongzue.com/ | ||
12 | + * @mail: myzcxhh@live.cn | ||
13 | + * @createTime: 2019/11/21 15:19 | ||
14 | + */ | ||
15 | +@Target(ElementType.METHOD) | ||
16 | +@Retention(RetentionPolicy.RUNTIME) | ||
17 | +public @interface OnClick { | ||
18 | + int value() default 0; | ||
19 | +} |
1 | +package com.example.zhongqiyan.base.instant.slideslip; | ||
2 | + | ||
3 | +import java.lang.annotation.ElementType; | ||
4 | +import java.lang.annotation.Retention; | ||
5 | +import java.lang.annotation.RetentionPolicy; | ||
6 | +import java.lang.annotation.Target; | ||
7 | + | ||
8 | +/** | ||
9 | + * @fileName: SlideLip | ||
10 | + * @date: 2019/12/7 | ||
11 | + * @author: lm | ||
12 | + * @QQ:820139338 - > 没事别加着玩 | ||
13 | + */ | ||
14 | + | ||
15 | +@Target({ElementType.TYPE}) | ||
16 | +@Retention(RetentionPolicy.RUNTIME) | ||
17 | +public @interface SlideLip { | ||
18 | + boolean slidelip() default false; | ||
19 | +} |
1 | +package com.example.zhongqiyan.javasource.ca.uol.aig.fftpack; | ||
2 | +/** | ||
3 | + * Construct a 1-D complex data sequence. | ||
4 | +*/ | ||
5 | +public class Complex1D | ||
6 | +{ | ||
7 | +/** | ||
8 | + * <em>x</em>[<em>i</em>] is the real part of <em>i</em>-th complex data. | ||
9 | +*/ | ||
10 | + public double x[]; | ||
11 | +/** | ||
12 | + * <em>y</em>[<em>i</em>] is the imaginary part of <em>i</em>-th complex data. | ||
13 | +*/ | ||
14 | + public double y[]; | ||
15 | +} |
app/src/main/java/com/example/zhongqiyan/javasource/ca/uol/aig/fftpack/ComplexDoubleFFT.java
0 → 100644
1 | +package com.example.zhongqiyan.javasource.ca.uol.aig.fftpack; | ||
2 | +/** | ||
3 | + * FFT transform of a complex periodic sequence. | ||
4 | + * @author Baoshe Zhang | ||
5 | + * @author Astronomical Instrument Group of University of Lethbridge. | ||
6 | +*/ | ||
7 | +public class ComplexDoubleFFT extends ComplexDoubleFFT_Mixed | ||
8 | +{ | ||
9 | +/** | ||
10 | + * <em>norm_factor</em> can be used to normalize this FFT transform. This is because | ||
11 | + * a call of forward transform (<em>ft</em>) followed by a call of backward transform | ||
12 | + * (<em>bt</em>) will multiply the input sequence by <em>norm_factor</em>. | ||
13 | +*/ | ||
14 | + public double norm_factor; | ||
15 | + private double wavetable[]; | ||
16 | + private int ndim; | ||
17 | + | ||
18 | +/** | ||
19 | + * Construct a wavenumber table with size <em>n</em> for Complex FFT. | ||
20 | + * The sequences with the same size can share a wavenumber table. The prime | ||
21 | + * factorization of <em>n</em> together with a tabulation of the trigonometric functions | ||
22 | + * are computed and stored. | ||
23 | + * | ||
24 | + * @param n the size of a complex data sequence. When <em>n</em> is a multiplication of small | ||
25 | + * numbers (4, 2, 3, 5), this FFT transform is very efficient. | ||
26 | +*/ | ||
27 | + public ComplexDoubleFFT(int n) | ||
28 | + { | ||
29 | + ndim = n; | ||
30 | + norm_factor = n; | ||
31 | + if(wavetable == null || wavetable.length !=(4*ndim+15)) | ||
32 | + { | ||
33 | + wavetable = new double[4*ndim + 15]; | ||
34 | + } | ||
35 | + cffti(ndim, wavetable); | ||
36 | + } | ||
37 | + | ||
38 | +/** | ||
39 | + * Forward complex FFT transform. | ||
40 | + * | ||
41 | + * @param x 2*<em>n</em> real double data representing <em>n</em> complex double data. | ||
42 | + * As an input parameter, <em>x</em> is an array of 2*<em>n</em> real | ||
43 | + * data representing <em>n</em> complex data. As an output parameter, <em>x</em> represents <em>n</em> | ||
44 | + * FFT'd complex data. Their relation as follows: | ||
45 | + * <br> | ||
46 | + * x[2*i] is the real part of <em>i</em>-th complex data; | ||
47 | + * <br> | ||
48 | + * x[2*i+1] is the imaginary part of <em>i</em>-the complex data. | ||
49 | + * | ||
50 | +*/ | ||
51 | + public void ft(double x[]) | ||
52 | + { | ||
53 | + if(x.length != 2*ndim) | ||
54 | + throw new IllegalArgumentException("The length of data can not match that of the wavetable"); | ||
55 | + cfftf(ndim, x, wavetable); | ||
56 | + } | ||
57 | + | ||
58 | +/** | ||
59 | + * Forward complex FFT transform. | ||
60 | + * | ||
61 | + * @param x an array of <em>n</em> Complex data | ||
62 | +*/ | ||
63 | + public void ft(Complex1D x) | ||
64 | + { | ||
65 | + if(x.x.length != ndim) | ||
66 | + throw new IllegalArgumentException("The length of data can not match that of the wavetable"); | ||
67 | + double[] y = new double[2*ndim]; | ||
68 | + for(int i=0; i<ndim; i++) | ||
69 | + { | ||
70 | + y[2*i] = x.x[i]; | ||
71 | + y[2*i+1] = x.y[i]; | ||
72 | + } | ||
73 | + cfftf(ndim, y, wavetable); | ||
74 | + for(int i=0; i<ndim; i++) | ||
75 | + { | ||
76 | + x.x[i]=y[2*i]; | ||
77 | + x.y[i]=y[2*i+1]; | ||
78 | + } | ||
79 | + } | ||
80 | + | ||
81 | +/** | ||
82 | + * Backward complex FFT transform. It is the unnormalized inverse transform of <em>ft</em>(double[]). | ||
83 | + * | ||
84 | + * @param x 2*<em>n</em> real double data representing <em>n</em> complex double data. | ||
85 | + * | ||
86 | + * As an input parameter, <em>x</em> is an array of 2*<em>n</em> | ||
87 | + * real data representing <em>n</em> complex data. As an output parameter, <em>x</em> represents | ||
88 | + * <em>n</em> FFT'd complex data. Their relation as follows: | ||
89 | + * <br> | ||
90 | + * x[2*<em>i</em>] is the real part of <em>i</em>-th complex data; | ||
91 | + * <br> | ||
92 | + * x[2*<em>i</em>+1] is the imaginary part of <em>i</em>-the complex data. | ||
93 | + * | ||
94 | +*/ | ||
95 | + public void bt(double x[]) | ||
96 | + { | ||
97 | + if(x.length != 2*ndim) | ||
98 | + throw new IllegalArgumentException("The length of data can not match that of the wavetable"); | ||
99 | + cfftb(ndim, x, wavetable); | ||
100 | + } | ||
101 | + | ||
102 | +/** | ||
103 | + * Backward complex FFT transform. It is the unnormalized inverse transform of <em>ft</em>(Complex1D[]). | ||
104 | + * | ||
105 | + * | ||
106 | + * @param x an array of <em>n</em> Complex data | ||
107 | +*/ | ||
108 | + public void bt(Complex1D x) | ||
109 | + { | ||
110 | + if(x.x.length != ndim) | ||
111 | + throw new IllegalArgumentException("The length of data can not match that of the wavetable"); | ||
112 | + double[] y = new double[2*ndim]; | ||
113 | + for(int i=0; i<ndim; i++) | ||
114 | + { | ||
115 | + y[2*i] = x.x[i]; | ||
116 | + y[2*i+1] = x.y[i]; | ||
117 | + } | ||
118 | + cfftb(ndim, y, wavetable); | ||
119 | + for(int i=0; i<ndim; i++) | ||
120 | + { | ||
121 | + x.x[i]=y[2*i]; | ||
122 | + x.y[i]=y[2*i+1]; | ||
123 | + } | ||
124 | + } | ||
125 | +} |
app/src/main/java/com/example/zhongqiyan/javasource/ca/uol/aig/fftpack/ComplexDoubleFFT_Mixed.java
0 → 100644
1 | +package com.example.zhongqiyan.javasource.ca.uol.aig.fftpack; | ||
2 | +/** | ||
3 | + * @author Baoshe Zhang | ||
4 | + * @author Astronomical Instrument Group of University of Lethbridge. | ||
5 | +*/ | ||
6 | +class ComplexDoubleFFT_Mixed | ||
7 | +{ | ||
8 | + | ||
9 | +/*---------------------------------------------------------------------- | ||
10 | + passf2: Complex FFT's forward/backward processing of factor 2; | ||
11 | + isign is +1 for backward and -1 for forward transforms | ||
12 | + ----------------------------------------------------------------------*/ | ||
13 | + | ||
14 | + void passf2(int ido, int l1, final double cc[], double ch[], final double wtable[], int offset, int isign) | ||
15 | + /*isign==+1 for backward transform*/ | ||
16 | + { | ||
17 | + int i, k, ah, ac; | ||
18 | + double ti2, tr2; | ||
19 | + int iw1; | ||
20 | + | ||
21 | + iw1 = offset; | ||
22 | + if(ido<=2) | ||
23 | + { | ||
24 | + for(k=0; k<l1; k++) | ||
25 | + { | ||
26 | + ah=k*ido; | ||
27 | + ac=2*k*ido; | ||
28 | + ch[ah]=cc[ac]+cc[ac+ido]; | ||
29 | + ch[ah+ido*l1]=cc[ac]-cc[ac+ido]; | ||
30 | + ch[ah+1]=cc[ac+1]+cc[ac+ido+1]; | ||
31 | + ch[ah+ido*l1+1]=cc[ac+1]-cc[ac+ido+1]; | ||
32 | + } | ||
33 | + } | ||
34 | + else | ||
35 | + { | ||
36 | + for(k=0; k<l1; k++) | ||
37 | + { | ||
38 | + for(i=0; i<ido-1; i+=2) | ||
39 | + { | ||
40 | + ah=i+k*ido; | ||
41 | + ac=i+2*k*ido; | ||
42 | + ch[ah]=cc[ac]+cc[ac+ido]; | ||
43 | + tr2=cc[ac]-cc[ac+ido]; | ||
44 | + ch[ah+1]=cc[ac+1]+cc[ac+1+ido]; | ||
45 | + ti2=cc[ac+1]-cc[ac+1+ido]; | ||
46 | + ch[ah+l1*ido+1]=wtable[i+iw1]*ti2+isign*wtable[i+1+iw1]*tr2; | ||
47 | + ch[ah+l1*ido]=wtable[i+iw1]*tr2-isign*wtable[i+1+iw1]*ti2; | ||
48 | + } | ||
49 | + } | ||
50 | + } | ||
51 | + } | ||
52 | + | ||
53 | +/*---------------------------------------------------------------------- | ||
54 | + passf3: Complex FFT's forward/backward processing of factor 3; | ||
55 | + isign is +1 for backward and -1 for forward transforms | ||
56 | + ----------------------------------------------------------------------*/ | ||
57 | + void passf3(int ido, int l1, final double cc[], double ch[], final double wtable[], int offset, int isign) | ||
58 | + { | ||
59 | + final double taur=-0.5; | ||
60 | + final double taui=0.866025403784439; | ||
61 | + int i, k, ac, ah; | ||
62 | + double ci2, ci3, di2, di3, cr2, cr3, dr2, dr3, ti2, tr2; | ||
63 | + int iw1, iw2; | ||
64 | + | ||
65 | + iw1 = offset; | ||
66 | + iw2 = iw1 + ido; | ||
67 | + | ||
68 | + if(ido==2) | ||
69 | + { | ||
70 | + for(k=1; k<=l1; k++) | ||
71 | + { | ||
72 | + ac=(3*k-2)*ido; | ||
73 | + tr2=cc[ac]+cc[ac+ido]; | ||
74 | + cr2=cc[ac-ido]+taur*tr2; | ||
75 | + ah=(k-1)*ido; | ||
76 | + ch[ah]=cc[ac-ido]+tr2; | ||
77 | + | ||
78 | + ti2=cc[ac+1]+cc[ac+ido+1]; | ||
79 | + ci2=cc[ac-ido+1]+taur*ti2; | ||
80 | + ch[ah+1]=cc[ac-ido+1]+ti2; | ||
81 | + | ||
82 | + cr3=isign*taui*(cc[ac]-cc[ac+ido]); | ||
83 | + ci3=isign*taui*(cc[ac+1]-cc[ac+ido+1]); | ||
84 | + ch[ah+l1*ido]=cr2-ci3; | ||
85 | + ch[ah+2*l1*ido]=cr2+ci3; | ||
86 | + ch[ah+l1*ido+1]=ci2+cr3; | ||
87 | + ch[ah+2*l1*ido+1]=ci2-cr3; | ||
88 | + } | ||
89 | + } | ||
90 | + else | ||
91 | + { | ||
92 | + for(k=1; k<=l1; k++) | ||
93 | + { | ||
94 | + for(i=0; i<ido-1; i+=2) | ||
95 | + { | ||
96 | + ac=i+(3*k-2)*ido; | ||
97 | + tr2=cc[ac]+cc[ac+ido]; | ||
98 | + cr2=cc[ac-ido]+taur*tr2; | ||
99 | + ah=i+(k-1)*ido; | ||
100 | + ch[ah]=cc[ac-ido]+tr2; | ||
101 | + ti2=cc[ac+1]+cc[ac+ido+1]; | ||
102 | + ci2=cc[ac-ido+1]+taur*ti2; | ||
103 | + ch[ah+1]=cc[ac-ido+1]+ti2; | ||
104 | + cr3=isign*taui*(cc[ac]-cc[ac+ido]); | ||
105 | + ci3=isign*taui*(cc[ac+1]-cc[ac+ido+1]); | ||
106 | + dr2=cr2-ci3; | ||
107 | + dr3=cr2+ci3; | ||
108 | + di2=ci2+cr3; | ||
109 | + di3=ci2-cr3; | ||
110 | + ch[ah+l1*ido+1]=wtable[i+iw1]*di2+isign*wtable[i+1+iw1]*dr2; | ||
111 | + ch[ah+l1*ido]=wtable[i+iw1]*dr2-isign*wtable[i+1+iw1]*di2; | ||
112 | + ch[ah+2*l1*ido+1]=wtable[i+iw2]*di3+isign*wtable[i+1+iw2]*dr3; | ||
113 | + ch[ah+2*l1*ido]=wtable[i+iw2]*dr3-isign*wtable[i+1+iw2]*di3; | ||
114 | + } | ||
115 | + } | ||
116 | + } | ||
117 | + } | ||
118 | + | ||
119 | +/*---------------------------------------------------------------------- | ||
120 | + passf4: Complex FFT's forward/backward processing of factor 4; | ||
121 | + isign is +1 for backward and -1 for forward transforms | ||
122 | + ----------------------------------------------------------------------*/ | ||
123 | + void passf4(int ido, int l1, final double cc[], double ch[], final double wtable[], int offset, int isign) | ||
124 | + { | ||
125 | + int i, k, ac, ah; | ||
126 | + double ci2, ci3, ci4, cr2, cr3, cr4, ti1, ti2, ti3, ti4, tr1, tr2, tr3, tr4; | ||
127 | + int iw1, iw2, iw3; | ||
128 | + iw1 = offset; | ||
129 | + iw2 = iw1 + ido; | ||
130 | + iw3 = iw2 + ido; | ||
131 | + | ||
132 | + if(ido==2) | ||
133 | + { | ||
134 | + for(k=0; k<l1; k++) | ||
135 | + { | ||
136 | + ac=4*k*ido+1; | ||
137 | + ti1=cc[ac]-cc[ac+2*ido]; | ||
138 | + ti2=cc[ac]+cc[ac+2*ido]; | ||
139 | + tr4=cc[ac+3*ido]-cc[ac+ido]; | ||
140 | + ti3=cc[ac+ido]+cc[ac+3*ido]; | ||
141 | + tr1=cc[ac-1]-cc[ac+2*ido-1]; | ||
142 | + tr2=cc[ac-1]+cc[ac+2*ido-1]; | ||
143 | + ti4=cc[ac+ido-1]-cc[ac+3*ido-1]; | ||
144 | + tr3=cc[ac+ido-1]+cc[ac+3*ido-1]; | ||
145 | + ah=k*ido; | ||
146 | + ch[ah]=tr2+tr3; | ||
147 | + ch[ah+2*l1*ido]=tr2-tr3; | ||
148 | + ch[ah+1]=ti2+ti3; | ||
149 | + ch[ah+2*l1*ido+1]=ti2-ti3; | ||
150 | + ch[ah+l1*ido]=tr1+isign*tr4; | ||
151 | + ch[ah+3*l1*ido]=tr1-isign*tr4; | ||
152 | + ch[ah+l1*ido+1]=ti1+isign*ti4; | ||
153 | + ch[ah+3*l1*ido+1]=ti1-isign*ti4; | ||
154 | + } | ||
155 | + } | ||
156 | + else | ||
157 | + { | ||
158 | + for(k=0; k<l1; k++) | ||
159 | + { | ||
160 | + for(i=0; i<ido-1; i+=2) | ||
161 | + { | ||
162 | + ac=i+1+4*k*ido; | ||
163 | + ti1=cc[ac]-cc[ac+2*ido]; | ||
164 | + ti2=cc[ac]+cc[ac+2*ido]; | ||
165 | + ti3=cc[ac+ido]+cc[ac+3*ido]; | ||
166 | + tr4=cc[ac+3*ido]-cc[ac+ido]; | ||
167 | + tr1=cc[ac-1]-cc[ac+2*ido-1]; | ||
168 | + tr2=cc[ac-1]+cc[ac+2*ido-1]; | ||
169 | + ti4=cc[ac+ido-1]-cc[ac+3*ido-1]; | ||
170 | + tr3=cc[ac+ido-1]+cc[ac+3*ido-1]; | ||
171 | + ah=i+k*ido; | ||
172 | + ch[ah]=tr2+tr3; | ||
173 | + cr3=tr2-tr3; | ||
174 | + ch[ah+1]=ti2+ti3; | ||
175 | + ci3=ti2-ti3; | ||
176 | + cr2=tr1+isign*tr4; | ||
177 | + cr4=tr1-isign*tr4; | ||
178 | + ci2=ti1+isign*ti4; | ||
179 | + ci4=ti1-isign*ti4; | ||
180 | + ch[ah+l1*ido]=wtable[i+iw1]*cr2-isign*wtable[i+1+iw1]*ci2; | ||
181 | + ch[ah+l1*ido+1]=wtable[i+iw1]*ci2+isign*wtable[i+1+iw1]*cr2; | ||
182 | + ch[ah+2*l1*ido]=wtable[i+iw2]*cr3-isign*wtable[i+1+iw2]*ci3; | ||
183 | + ch[ah+2*l1*ido+1]=wtable[i+iw2]*ci3+isign*wtable[i+1+iw2]*cr3; | ||
184 | + ch[ah+3*l1*ido]=wtable[i+iw3]*cr4-isign*wtable[i+1+iw3]*ci4; | ||
185 | + ch[ah+3*l1*ido+1]=wtable[i+iw3]*ci4+isign*wtable[i+1+iw3]*cr4; | ||
186 | + } | ||
187 | + } | ||
188 | + } | ||
189 | + } | ||
190 | + | ||
191 | +/*---------------------------------------------------------------------- | ||
192 | + passf5: Complex FFT's forward/backward processing of factor 5; | ||
193 | + isign is +1 for backward and -1 for forward transforms | ||
194 | + ----------------------------------------------------------------------*/ | ||
195 | + void passf5(int ido, int l1, final double cc[], double ch[], final double wtable[], int offset, int isign) | ||
196 | + /*isign==-1 for forward transform and+1 for backward transform*/ | ||
197 | + { | ||
198 | + final double tr11=0.309016994374947; | ||
199 | + final double ti11=0.951056516295154; | ||
200 | + final double tr12=-0.809016994374947; | ||
201 | + final double ti12=0.587785252292473; | ||
202 | + int i, k, ac, ah; | ||
203 | + double ci2, ci3, ci4, ci5, di3, di4, di5, di2, cr2, cr3, cr5, cr4, | ||
204 | + ti2, ti3, ti4, ti5, dr3, dr4, dr5, dr2, tr2, tr3, tr4, tr5; | ||
205 | + int iw1, iw2, iw3, iw4; | ||
206 | + | ||
207 | + iw1 = offset; | ||
208 | + iw2 = iw1 + ido; | ||
209 | + iw3 = iw2 + ido; | ||
210 | + iw4 = iw3 + ido; | ||
211 | + | ||
212 | + if(ido==2) | ||
213 | + { | ||
214 | + for(k=1; k<=l1;++k) | ||
215 | + { | ||
216 | + ac=(5*k-4)*ido+1; | ||
217 | + ti5=cc[ac]-cc[ac+3*ido]; | ||
218 | + ti2=cc[ac]+cc[ac+3*ido]; | ||
219 | + ti4=cc[ac+ido]-cc[ac+2*ido]; | ||
220 | + ti3=cc[ac+ido]+cc[ac+2*ido]; | ||
221 | + tr5=cc[ac-1]-cc[ac+3*ido-1]; | ||
222 | + tr2=cc[ac-1]+cc[ac+3*ido-1]; | ||
223 | + tr4=cc[ac+ido-1]-cc[ac+2*ido-1]; | ||
224 | + tr3=cc[ac+ido-1]+cc[ac+2*ido-1]; | ||
225 | + ah=(k-1)*ido; | ||
226 | + ch[ah]=cc[ac-ido-1]+tr2+tr3; | ||
227 | + ch[ah+1]=cc[ac-ido]+ti2+ti3; | ||
228 | + cr2=cc[ac-ido-1]+tr11*tr2+tr12*tr3; | ||
229 | + ci2=cc[ac-ido]+tr11*ti2+tr12*ti3; | ||
230 | + cr3=cc[ac-ido-1]+tr12*tr2+tr11*tr3; | ||
231 | + ci3=cc[ac-ido]+tr12*ti2+tr11*ti3; | ||
232 | + cr5=isign*(ti11*tr5+ti12*tr4); | ||
233 | + ci5=isign*(ti11*ti5+ti12*ti4); | ||
234 | + cr4=isign*(ti12*tr5-ti11*tr4); | ||
235 | + ci4=isign*(ti12*ti5-ti11*ti4); | ||
236 | + ch[ah+l1*ido]=cr2-ci5; | ||
237 | + ch[ah+4*l1*ido]=cr2+ci5; | ||
238 | + ch[ah+l1*ido+1]=ci2+cr5; | ||
239 | + ch[ah+2*l1*ido+1]=ci3+cr4; | ||
240 | + ch[ah+2*l1*ido]=cr3-ci4; | ||
241 | + ch[ah+3*l1*ido]=cr3+ci4; | ||
242 | + ch[ah+3*l1*ido+1]=ci3-cr4; | ||
243 | + ch[ah+4*l1*ido+1]=ci2-cr5; | ||
244 | + } | ||
245 | + } | ||
246 | + else | ||
247 | + { | ||
248 | + for(k=1; k<=l1; k++) | ||
249 | + { | ||
250 | + for(i=0; i<ido-1; i+=2) | ||
251 | + { | ||
252 | + ac=i+1+(k*5-4)*ido; | ||
253 | + ti5=cc[ac]-cc[ac+3*ido]; | ||
254 | + ti2=cc[ac]+cc[ac+3*ido]; | ||
255 | + ti4=cc[ac+ido]-cc[ac+2*ido]; | ||
256 | + ti3=cc[ac+ido]+cc[ac+2*ido]; | ||
257 | + tr5=cc[ac-1]-cc[ac+3*ido-1]; | ||
258 | + tr2=cc[ac-1]+cc[ac+3*ido-1]; | ||
259 | + tr4=cc[ac+ido-1]-cc[ac+2*ido-1]; | ||
260 | + tr3=cc[ac+ido-1]+cc[ac+2*ido-1]; | ||
261 | + ah=i+(k-1)*ido; | ||
262 | + ch[ah]=cc[ac-ido-1]+tr2+tr3; | ||
263 | + ch[ah+1]=cc[ac-ido]+ti2+ti3; | ||
264 | + cr2=cc[ac-ido-1]+tr11*tr2+tr12*tr3; | ||
265 | + | ||
266 | + ci2=cc[ac-ido]+tr11*ti2+tr12*ti3; | ||
267 | + cr3=cc[ac-ido-1]+tr12*tr2+tr11*tr3; | ||
268 | + | ||
269 | + ci3=cc[ac-ido]+tr12*ti2+tr11*ti3; | ||
270 | + cr5=isign*(ti11*tr5+ti12*tr4); | ||
271 | + ci5=isign*(ti11*ti5+ti12*ti4); | ||
272 | + cr4=isign*(ti12*tr5-ti11*tr4); | ||
273 | + ci4=isign*(ti12*ti5-ti11*ti4); | ||
274 | + dr3=cr3-ci4; | ||
275 | + dr4=cr3+ci4; | ||
276 | + di3=ci3+cr4; | ||
277 | + di4=ci3-cr4; | ||
278 | + dr5=cr2+ci5; | ||
279 | + dr2=cr2-ci5; | ||
280 | + di5=ci2-cr5; | ||
281 | + di2=ci2+cr5; | ||
282 | + ch[ah+l1*ido]=wtable[i+iw1]*dr2-isign*wtable[i+1+iw1]*di2; | ||
283 | + ch[ah+l1*ido+1]=wtable[i+iw1]*di2+isign*wtable[i+1+iw1]*dr2; | ||
284 | + ch[ah+2*l1*ido]=wtable[i+iw2]*dr3-isign*wtable[i+1+iw2]*di3; | ||
285 | + ch[ah+2*l1*ido+1]=wtable[i+iw2]*di3+isign*wtable[i+1+iw2]*dr3; | ||
286 | + ch[ah+3*l1*ido]=wtable[i+iw3]*dr4-isign*wtable[i+1+iw3]*di4; | ||
287 | + ch[ah+3*l1*ido+1]=wtable[i+iw3]*di4+isign*wtable[i+1+iw3]*dr4; | ||
288 | + ch[ah+4*l1*ido]=wtable[i+iw4]*dr5-isign*wtable[i+1+iw4]*di5; | ||
289 | + ch[ah+4*l1*ido+1]=wtable[i+iw4]*di5+isign*wtable[i+1+iw4]*dr5; | ||
290 | + } | ||
291 | + } | ||
292 | + } | ||
293 | + } | ||
294 | + | ||
295 | +/*---------------------------------------------------------------------- | ||
296 | + passfg: Complex FFT's forward/backward processing of general factor; | ||
297 | + isign is +1 for backward and -1 for forward transforms | ||
298 | + ----------------------------------------------------------------------*/ | ||
299 | + void passfg(int nac[], int ido, int ip, int l1, int idl1, | ||
300 | + final double cc[], double c1[], double c2[], double ch[], double ch2[], | ||
301 | + final double wtable[], int offset, int isign) | ||
302 | + { | ||
303 | + int idij, idlj, idot, ipph, i, j, k, l, jc, lc, ik, nt, idj, idl, inc, idp; | ||
304 | + double wai, war; | ||
305 | + int iw1; | ||
306 | + | ||
307 | + iw1 = offset; | ||
308 | + idot=ido / 2; | ||
309 | + nt=ip*idl1; | ||
310 | + ipph=(ip+1)/ 2; | ||
311 | + idp=ip*ido; | ||
312 | + if(ido>=l1) | ||
313 | + { | ||
314 | + for(j=1; j<ipph; j++) | ||
315 | + { | ||
316 | + jc=ip-j; | ||
317 | + for(k=0; k<l1; k++) | ||
318 | + { | ||
319 | + for(i=0; i<ido; i++) | ||
320 | + { | ||
321 | + ch[i+(k+j*l1)*ido]=cc[i+(j+k*ip)*ido]+cc[i+(jc+k*ip)*ido]; | ||
322 | + ch[i+(k+jc*l1)*ido]=cc[i+(j+k*ip)*ido]-cc[i+(jc+k*ip)*ido]; | ||
323 | + } | ||
324 | + } | ||
325 | + } | ||
326 | + for(k=0; k<l1; k++) | ||
327 | + for(i=0; i<ido; i++) | ||
328 | + ch[i+k*ido]=cc[i+k*ip*ido]; | ||
329 | + } | ||
330 | + else | ||
331 | + { | ||
332 | + for(j=1; j<ipph; j++) | ||
333 | + { | ||
334 | + jc=ip-j; | ||
335 | + for(i=0; i<ido; i++) | ||
336 | + { | ||
337 | + for(k=0; k<l1; k++) | ||
338 | + { | ||
339 | + ch[i+(k+j*l1)*ido]=cc[i+(j+k*ip)*ido]+cc[i+(jc+k*ip)*ido]; | ||
340 | + ch[i+(k+jc*l1)*ido]=cc[i+(j+k*ip)*ido]-cc[i+(jc+k*ip)*ido]; | ||
341 | + } | ||
342 | + } | ||
343 | + } | ||
344 | + for(i=0; i<ido; i++) | ||
345 | + for(k=0; k<l1; k++) | ||
346 | + ch[i+k*ido]=cc[i+k*ip*ido]; | ||
347 | + } | ||
348 | + | ||
349 | + idl=2-ido; | ||
350 | + inc=0; | ||
351 | + for(l=1; l<ipph; l++) | ||
352 | + { | ||
353 | + lc=ip-l; | ||
354 | + idl+=ido; | ||
355 | + for(ik=0; ik<idl1; ik++) | ||
356 | + { | ||
357 | + c2[ik+l*idl1]=ch2[ik]+wtable[idl-2+iw1]*ch2[ik+idl1]; | ||
358 | + c2[ik+lc*idl1]=isign*wtable[idl-1+iw1]*ch2[ik+(ip-1)*idl1]; | ||
359 | + } | ||
360 | + idlj=idl; | ||
361 | + inc+=ido; | ||
362 | + for(j=2; j<ipph; j++) | ||
363 | + { | ||
364 | + jc=ip-j; | ||
365 | + idlj+=inc; | ||
366 | + if(idlj>idp) idlj-=idp; | ||
367 | + war=wtable[idlj-2+iw1]; | ||
368 | + wai=wtable[idlj-1+iw1]; | ||
369 | + for(ik=0; ik<idl1; ik++) | ||
370 | + { | ||
371 | + c2[ik+l*idl1]+=war*ch2[ik+j*idl1]; | ||
372 | + c2[ik+lc*idl1]+=isign*wai*ch2[ik+jc*idl1]; | ||
373 | + } | ||
374 | + } | ||
375 | + } | ||
376 | + for(j=1; j<ipph; j++) | ||
377 | + for(ik=0; ik<idl1; ik++) | ||
378 | + ch2[ik]+=ch2[ik+j*idl1]; | ||
379 | + for(j=1; j<ipph; j++) | ||
380 | + { | ||
381 | + jc=ip-j; | ||
382 | + for(ik=1; ik<idl1; ik+=2) | ||
383 | + { | ||
384 | + ch2[ik-1+j*idl1]=c2[ik-1+j*idl1]-c2[ik+jc*idl1]; | ||
385 | + ch2[ik-1+jc*idl1]=c2[ik-1+j*idl1]+c2[ik+jc*idl1]; | ||
386 | + ch2[ik+j*idl1]=c2[ik+j*idl1]+c2[ik-1+jc*idl1]; | ||
387 | + ch2[ik+jc*idl1]=c2[ik+j*idl1]-c2[ik-1+jc*idl1]; | ||
388 | + } | ||
389 | + } | ||
390 | + nac[0]=1; | ||
391 | + if(ido==2) return; | ||
392 | + nac[0]=0; | ||
393 | + for(ik=0; ik<idl1; ik++) c2[ik]=ch2[ik]; | ||
394 | + for(j=1; j<ip; j++) | ||
395 | + { | ||
396 | + for(k=0; k<l1; k++) | ||
397 | + { | ||
398 | + c1[(k+j*l1)*ido+0]=ch[(k+j*l1)*ido+0]; | ||
399 | + c1[(k+j*l1)*ido+1]=ch[(k+j*l1)*ido+1]; | ||
400 | + } | ||
401 | + } | ||
402 | + if(idot<=l1) | ||
403 | + { | ||
404 | + idij=0; | ||
405 | + for(j=1; j<ip; j++) | ||
406 | + { | ||
407 | + idij+=2; | ||
408 | + for(i=3; i<ido; i+=2) | ||
409 | + { | ||
410 | + idij+=2; | ||
411 | + for(k=0; k<l1; k++) | ||
412 | + { | ||
413 | + c1[i-1+(k+j*l1)*ido]= | ||
414 | + wtable[idij-2+iw1]*ch[i-1+(k+j*l1)*ido]- | ||
415 | + isign*wtable[idij-1+iw1]*ch[i+(k+j*l1)*ido]; | ||
416 | + c1[i+(k+j*l1)*ido]= | ||
417 | + wtable[idij-2+iw1]*ch[i+(k+j*l1)*ido]+ | ||
418 | + isign*wtable[idij-1+iw1]*ch[i-1+(k+j*l1)*ido]; | ||
419 | + } | ||
420 | + } | ||
421 | + } | ||
422 | + } | ||
423 | + else | ||
424 | + { | ||
425 | + idj=2-ido; | ||
426 | + for(j=1; j<ip; j++) | ||
427 | + { | ||
428 | + idj+=ido; | ||
429 | + for(k=0; k<l1; k++) | ||
430 | + { | ||
431 | + idij=idj; | ||
432 | + for(i=3; i<ido; i+=2) | ||
433 | + { | ||
434 | + idij+=2; | ||
435 | + c1[i-1+(k+j*l1)*ido]= | ||
436 | + wtable[idij-2+iw1]*ch[i-1+(k+j*l1)*ido]- | ||
437 | + isign*wtable[idij-1+iw1]*ch[i+(k+j*l1)*ido]; | ||
438 | + c1[i+(k+j*l1)*ido]= | ||
439 | + wtable[idij-2+iw1]*ch[i+(k+j*l1)*ido]+ | ||
440 | + isign*wtable[idij-1+iw1]*ch[i-1+(k+j*l1)*ido]; | ||
441 | + } | ||
442 | + } | ||
443 | + } | ||
444 | + } | ||
445 | + } | ||
446 | + | ||
447 | +/*--------------------------------------------------------- | ||
448 | + cfftf1: further processing of Complex forward FFT | ||
449 | + --------------------------------------------------------*/ | ||
450 | + void cfftf1(int n, double c[], final double wtable[], int isign) | ||
451 | + { | ||
452 | + int idot, i; | ||
453 | + int k1, l1, l2; | ||
454 | + int na, nf, ip, iw, ido, idl1; | ||
455 | + int[] nac = new int[1]; | ||
456 | + | ||
457 | + int iw1, iw2; | ||
458 | + double[] ch = new double[2*n]; | ||
459 | + | ||
460 | + iw1=2*n; | ||
461 | + iw2=4*n; | ||
462 | + System.arraycopy(wtable, 0, ch, 0, 2*n); | ||
463 | + | ||
464 | + nac[0] = 0; | ||
465 | + | ||
466 | + nf=(int)wtable[1+iw2]; | ||
467 | + na=0; | ||
468 | + l1=1; | ||
469 | + iw=iw1; | ||
470 | + for(k1=2; k1<=nf+1; k1++) | ||
471 | + { | ||
472 | + ip=(int)wtable[k1+iw2]; | ||
473 | + l2=ip*l1; | ||
474 | + ido=n / l2; | ||
475 | + idot=ido+ido; | ||
476 | + idl1=idot*l1; | ||
477 | + if(ip==4) | ||
478 | + { | ||
479 | + if(na==0) | ||
480 | + { | ||
481 | + passf4(idot, l1, c, ch, wtable, iw, isign); | ||
482 | + } | ||
483 | + else | ||
484 | + { | ||
485 | + passf4(idot, l1, ch, c, wtable, iw, isign); | ||
486 | + } | ||
487 | + na=1-na; | ||
488 | + } | ||
489 | + else if(ip==2) | ||
490 | + { | ||
491 | + if(na==0) | ||
492 | + { | ||
493 | + passf2(idot, l1, c, ch, wtable, iw, isign); | ||
494 | + } | ||
495 | + else | ||
496 | + { | ||
497 | + passf2(idot, l1, ch, c, wtable, iw, isign); | ||
498 | + } | ||
499 | + na=1-na; | ||
500 | + } | ||
501 | + else if(ip==3) | ||
502 | + { | ||
503 | + if(na==0) | ||
504 | + { | ||
505 | + passf3(idot, l1, c, ch, wtable, iw, isign); | ||
506 | + } | ||
507 | + else | ||
508 | + { | ||
509 | + passf3(idot, l1, ch, c, wtable, iw, isign); | ||
510 | + } | ||
511 | + na=1-na; | ||
512 | + } | ||
513 | + else if(ip==5) | ||
514 | + { | ||
515 | + if(na==0) | ||
516 | + { | ||
517 | + passf5(idot, l1, c, ch, wtable, iw, isign); | ||
518 | + } | ||
519 | + else | ||
520 | + { | ||
521 | + passf5(idot, l1, ch, c, wtable, iw, isign); | ||
522 | + } | ||
523 | + na=1-na; | ||
524 | + } | ||
525 | + else | ||
526 | + { | ||
527 | + if(na==0) | ||
528 | + { | ||
529 | + passfg(nac, idot, ip, l1, idl1, c, c, c, ch, ch, wtable, iw, isign); | ||
530 | + } | ||
531 | + else | ||
532 | + { | ||
533 | + passfg(nac, idot, ip, l1, idl1, ch, ch, ch, c, c, wtable, iw, isign); | ||
534 | + } | ||
535 | + if(nac[0] !=0) na=1-na; | ||
536 | + } | ||
537 | + l1=l2; | ||
538 | + iw+=(ip-1)*idot; | ||
539 | + } | ||
540 | + if(na==0) return; | ||
541 | + for(i=0; i<2*n; i++) c[i]=ch[i]; | ||
542 | + } | ||
543 | + | ||
544 | +/*--------------------------------------------------------- | ||
545 | + cfftf: Complex forward FFT | ||
546 | + --------------------------------------------------------*/ | ||
547 | + void cfftf(int n, double c[], double wtable[]) | ||
548 | + { | ||
549 | + cfftf1(n, c, wtable, -1); | ||
550 | + } | ||
551 | + | ||
552 | +/*--------------------------------------------------------- | ||
553 | + cfftb: Complex borward FFT | ||
554 | + --------------------------------------------------------*/ | ||
555 | + void cfftb(int n, double c[], double wtable[]) | ||
556 | + { | ||
557 | + cfftf1(n, c, wtable, +1); | ||
558 | + } | ||
559 | + | ||
560 | +/*--------------------------------------------------------- | ||
561 | + cffti1: further initialization of Complex FFT | ||
562 | + --------------------------------------------------------*/ | ||
563 | + void cffti1(int n, double wtable[]) | ||
564 | + { | ||
565 | + | ||
566 | + final int[] ntryh = {3, 4, 2, 5}; | ||
567 | + final double twopi=2.0D*Math.PI; | ||
568 | + double argh; | ||
569 | + int idot, ntry=0, i, j; | ||
570 | + double argld; | ||
571 | + int i1, k1, l1, l2, ib; | ||
572 | + double fi; | ||
573 | + int ld, ii, nf, ip, nl, nq, nr; | ||
574 | + double arg; | ||
575 | + int ido, ipm; | ||
576 | + | ||
577 | + nl=n; | ||
578 | + nf=0; | ||
579 | + j=0; | ||
580 | + | ||
581 | + factorize_loop: | ||
582 | + while(true) | ||
583 | + { | ||
584 | + j++; | ||
585 | + if(j<=4) | ||
586 | + ntry=ntryh[j-1]; | ||
587 | + else | ||
588 | + ntry+=2; | ||
589 | + do | ||
590 | + { | ||
591 | + nq=nl / ntry; | ||
592 | + nr=nl-ntry*nq; | ||
593 | + if(nr !=0) continue factorize_loop; | ||
594 | + nf++; | ||
595 | + wtable[nf+1+4*n]=ntry; | ||
596 | + nl=nq; | ||
597 | + if(ntry==2 && nf !=1) | ||
598 | + { | ||
599 | + for(i=2; i<=nf; i++) | ||
600 | + { | ||
601 | + ib=nf-i+2; | ||
602 | + wtable[ib+1+4*n]=wtable[ib+4*n]; | ||
603 | + } | ||
604 | + wtable[2+4*n]=2; | ||
605 | + } | ||
606 | + } while(nl !=1); | ||
607 | + break factorize_loop; | ||
608 | + } | ||
609 | + wtable[0+4*n]=n; | ||
610 | + wtable[1+4*n]=nf; | ||
611 | + argh=twopi /(double)n; | ||
612 | + i=1; | ||
613 | + l1=1; | ||
614 | + for(k1=1; k1<=nf; k1++) | ||
615 | + { | ||
616 | + ip=(int)wtable[k1+1+4*n]; | ||
617 | + ld=0; | ||
618 | + l2=l1*ip; | ||
619 | + ido=n / l2; | ||
620 | + idot=ido+ido+2; | ||
621 | + ipm=ip-1; | ||
622 | + for(j=1; j<=ipm; j++) | ||
623 | + { | ||
624 | + i1=i; | ||
625 | + wtable[i-1+2*n]=1; | ||
626 | + wtable[i+2*n]=0; | ||
627 | + ld+=l1; | ||
628 | + fi=0; | ||
629 | + argld=ld*argh; | ||
630 | + for(ii=4; ii<=idot; ii+=2) | ||
631 | + { | ||
632 | + i+=2; | ||
633 | + fi+=1; | ||
634 | + arg=fi*argld; | ||
635 | + wtable[i-1+2*n]=Math.cos(arg); | ||
636 | + wtable[i+2*n]=Math.sin(arg); | ||
637 | + } | ||
638 | + if(ip>5) | ||
639 | + { | ||
640 | + wtable[i1-1+2*n]=wtable[i-1+2*n]; | ||
641 | + wtable[i1+2*n]=wtable[i+2*n]; | ||
642 | + } | ||
643 | + } | ||
644 | + l1=l2; | ||
645 | + } | ||
646 | + | ||
647 | + } | ||
648 | + | ||
649 | +/*--------------------------------------------------------- | ||
650 | + cffti: Initialization of Real forward FFT | ||
651 | + --------------------------------------------------------*/ | ||
652 | + void cffti(int n, double wtable[]) | ||
653 | + { | ||
654 | + if(n==1) return; | ||
655 | + cffti1(n, wtable); | ||
656 | + } /*cffti*/ | ||
657 | + | ||
658 | +} |
app/src/main/java/com/example/zhongqiyan/javasource/ca/uol/aig/fftpack/RealDoubleFFT.java
0 → 100644
1 | +package com.example.zhongqiyan.javasource.ca.uol.aig.fftpack; | ||
2 | +/** | ||
3 | + * FFT transform of a real periodic sequence. | ||
4 | + * @author Baoshe Zhang | ||
5 | + * @author Astronomical Instrument Group of University of Lethbridge. | ||
6 | +*/ | ||
7 | +public class RealDoubleFFT extends RealDoubleFFT_Mixed | ||
8 | +{ | ||
9 | +/** | ||
10 | + * <em>norm_factor</em> can be used to normalize this FFT transform. This is because | ||
11 | + * a call of forward transform (<em>ft</em>) followed by a call of backward transform | ||
12 | + * (<em>bt</em>) will multiply the input sequence by <em>norm_factor</em>. | ||
13 | +*/ | ||
14 | + public double norm_factor; | ||
15 | + private double wavetable[]; | ||
16 | + private int ndim; | ||
17 | + | ||
18 | +/** | ||
19 | + * Construct a wavenumber table with size <em>n</em>. | ||
20 | + * The sequences with the same size can share a wavenumber table. The prime | ||
21 | + * factorization of <em>n</em> together with a tabulation of the trigonometric functions | ||
22 | + * are computed and stored. | ||
23 | + * | ||
24 | + * @param n the size of a real data sequence. When <em>n</em> is a multiplication of small | ||
25 | + * numbers (4, 2, 3, 5), this FFT transform is very efficient. | ||
26 | +*/ | ||
27 | + public RealDoubleFFT(int n) | ||
28 | + { | ||
29 | + ndim = n; | ||
30 | + norm_factor = n; | ||
31 | + if(wavetable == null || wavetable.length !=(2*ndim+15)) | ||
32 | + { | ||
33 | + wavetable = new double[2*ndim + 15]; | ||
34 | + } | ||
35 | + rffti(ndim, wavetable); | ||
36 | + } | ||
37 | + | ||
38 | +/** | ||
39 | + * Forward real FFT transform. It computes the discrete transform of a real data sequence. | ||
40 | + * | ||
41 | + * @param x an array which contains the sequence to be transformed. After FFT, | ||
42 | + * <em>x</em> contains the transform coeffients used to construct <em>n</em> complex FFT coeffients. | ||
43 | + * <br> | ||
44 | + * The real part of the first complex FFT coeffients is <em>x</em>[0]; its imaginary part | ||
45 | + * is 0. If <em>n</em> is even set <em>m</em> = <em>n</em>/2, if <em>n</em> is odd set | ||
46 | + * <em>m</em> = <em>n</em>/2, then for | ||
47 | + * <br> | ||
48 | + * <em>k</em> = 1, ..., <em>m</em>-1 <br> | ||
49 | + * the real part of <em>k</em>-th complex FFT coeffients is <em>x</em>[2*<em>k</em>-1]; | ||
50 | + * <br> | ||
51 | + * the imaginary part of <em>k</em>-th complex FFT coeffients is <em>x</em>[2*<em>k</em>-2]. | ||
52 | + * <br> | ||
53 | + * If <em>n</em> is even, | ||
54 | + * the real of part of (<em>n</em>/2)-th complex FFT coeffients is <em>x</em>[<em>n</em>]; its imaginary part is 0. | ||
55 | + * The remaining complex FFT coeffients can be obtained by the symmetry relation: | ||
56 | + * the (<em>n</em>-<em>k</em>)-th complex FFT coeffient is the conjugate of <em>n</em>-th complex FFT coeffient. | ||
57 | + * | ||
58 | +*/ | ||
59 | + public void ft(double x[]) | ||
60 | + { | ||
61 | + if(x.length != ndim) | ||
62 | + throw new IllegalArgumentException("The length of data can not match that of the wavetable"); | ||
63 | + rfftf(ndim, x, wavetable); | ||
64 | + } | ||
65 | + | ||
66 | +/** | ||
67 | + * Forward real FFT transform. It computes the discrete transform of a real data sequence. | ||
68 | + * | ||
69 | + * @param x an array which contains the sequence to be transformed. After FFT, | ||
70 | + * <em>x</em> contains the transform coeffients used to construct <em>n</em> complex FFT coeffients. | ||
71 | + * <br> | ||
72 | + * @param y the first complex (<em>n</em>+1)/2 (when <em>n</em> is odd) or (<em>n</em>/2+1) (when | ||
73 | + * <em>n</em> is even) FFT coeffients. | ||
74 | + * The remaining complex FFT coeffients can be obtained by the symmetry relation: | ||
75 | + * the (<em>n</em>-<em>k</em>)-th complex FFT coeffient is the conjugate of <em>n</em>-th complex FFT coeffient. | ||
76 | + * | ||
77 | +*/ | ||
78 | + public void ft(double x[], Complex1D y) | ||
79 | + { | ||
80 | + if(x.length != ndim) | ||
81 | + throw new IllegalArgumentException("The length of data can not match that of the wavetable"); | ||
82 | + rfftf(ndim, x, wavetable); | ||
83 | + | ||
84 | + if(ndim%2 == 0) | ||
85 | + { | ||
86 | + y.x = new double[ndim/2 + 1]; | ||
87 | + y.y = new double[ndim/2 + 1]; | ||
88 | + } | ||
89 | + else | ||
90 | + { | ||
91 | + y.x = new double[(ndim+1)/2]; | ||
92 | + y.y = new double[(ndim+1)/2]; | ||
93 | + } | ||
94 | + | ||
95 | + | ||
96 | + y.x[0] = x[0]; | ||
97 | + y.y[0] = 0.0D; | ||
98 | + for(int i=1; i<(ndim+1)/2; i++) | ||
99 | + { | ||
100 | + y.x[i] = x[2*i-1]; | ||
101 | + y.y[i] = x[2*i]; | ||
102 | + } | ||
103 | + if(ndim%2 == 0) | ||
104 | + { | ||
105 | + y.x[ndim/2] = x[ndim-1]; | ||
106 | + y.y[ndim/2] = 0.0D; | ||
107 | + } | ||
108 | + | ||
109 | + } | ||
110 | + | ||
111 | +/** | ||
112 | + * Backward real FFT transform. It is the unnormalized inverse transform of <em>ft</em>(double[]). | ||
113 | + * | ||
114 | + * @param x an array which contains the sequence to be transformed. After FFT, | ||
115 | + * <em>x</em> contains the transform coeffients. Also see the comments of <em>ft</em>(double[]) | ||
116 | + * for the relation between <em>x</em> and complex FFT coeffients. | ||
117 | +*/ | ||
118 | + public void bt(double x[]) | ||
119 | + { | ||
120 | + if(x.length != ndim) | ||
121 | + throw new IllegalArgumentException("The length of data can not match that of the wavetable"); | ||
122 | + rfftb(ndim, x, wavetable); | ||
123 | + } | ||
124 | +/** | ||
125 | + * Backward real FFT transform. It is the unnormalized inverse transform of <em>ft</em>(Complex1D, double[]). | ||
126 | + * | ||
127 | + * @param x an array which contains the sequence to be transformed. When <em>n</em> is odd, it contains the first | ||
128 | + * (<em>n</em>+1)/2 complex data; when <em>n</em> is even, it contains (<em>n</em>/2+1) complex data. | ||
129 | + * @param y the real FFT coeffients. | ||
130 | + * <br> | ||
131 | + * Also see the comments of <em>ft</em>(double[]) for the relation | ||
132 | + * between <em>x</em> and complex FFT coeffients. | ||
133 | +*/ | ||
134 | + public void bt(Complex1D x, double y[]) | ||
135 | + { | ||
136 | + if(ndim%2 == 0) | ||
137 | + { | ||
138 | + if(x.x.length != ndim/2+1) | ||
139 | + throw new IllegalArgumentException("The length of data can not match that of the wavetable"); | ||
140 | + } | ||
141 | + else | ||
142 | + { | ||
143 | + if(x.x.length != (ndim+1)/2) | ||
144 | + throw new IllegalArgumentException("The length of data can not match that of the wavetable"); | ||
145 | + } | ||
146 | + | ||
147 | + y[0] = x.x[0]; | ||
148 | + for(int i=1; i<(ndim+1)/2; i++) | ||
149 | + { | ||
150 | + y[2*i-1]=x.x[i]; | ||
151 | + y[2*i]=x.y[i]; | ||
152 | + } | ||
153 | + if(ndim%2 == 0) | ||
154 | + { | ||
155 | + y[ndim-1]=x.x[ndim/2]; | ||
156 | + } | ||
157 | + rfftb(ndim, y, wavetable); | ||
158 | + } | ||
159 | +} |
app/src/main/java/com/example/zhongqiyan/javasource/ca/uol/aig/fftpack/RealDoubleFFT_Even.java
0 → 100644
1 | +package com.example.zhongqiyan.javasource.ca.uol.aig.fftpack; | ||
2 | +/** | ||
3 | + * cosine FFT transform of a real even sequence. | ||
4 | + * @author Baoshe Zhang | ||
5 | + * @author Astronomical Instrument Group of University of Lethbridge. | ||
6 | +*/ | ||
7 | +public class RealDoubleFFT_Even extends RealDoubleFFT_Mixed | ||
8 | +{ | ||
9 | +/** | ||
10 | + * <em>norm_factor</em> can be used to normalize this FFT transform. This is because | ||
11 | + * a call of forward transform (<em>ft</em>) followed by a call of backward transform | ||
12 | + * (<em>bt</em>) will multiply the input sequence by <em>norm_factor</em>. | ||
13 | +*/ | ||
14 | + public double norm_factor; | ||
15 | + private double wavetable[]; | ||
16 | + private int ndim; | ||
17 | + | ||
18 | +/** | ||
19 | + * Construct a wavenumber table with size <em>n</em>. | ||
20 | + * The sequences with the same size can share a wavenumber table. The prime | ||
21 | + * factorization of <em>n</em> together with a tabulation of the trigonometric functions | ||
22 | + * are computed and stored. | ||
23 | + * | ||
24 | + * @param n the size of a real data sequence. When (<em>n</em>-1) is a multiplication of small | ||
25 | + * numbers (4, 2, 3, 5), this FFT transform is very efficient. | ||
26 | +*/ | ||
27 | + public RealDoubleFFT_Even(int n) | ||
28 | + { | ||
29 | + ndim = n; | ||
30 | + norm_factor = 2*(n-1); | ||
31 | + if(wavetable == null || wavetable.length !=(3*ndim+15)) | ||
32 | + { | ||
33 | + wavetable = new double[3*ndim + 15]; | ||
34 | + } | ||
35 | + costi(ndim, wavetable); | ||
36 | + } | ||
37 | + | ||
38 | +/** | ||
39 | + * Forward cosine FFT transform. It computes the discrete sine transform of | ||
40 | + * an odd sequence. | ||
41 | + * | ||
42 | + * @param x an array which contains the sequence to be transformed. After FFT, | ||
43 | + * <em>x</em> contains the transform coeffients. | ||
44 | +*/ | ||
45 | + public void ft(double x[]) | ||
46 | + { | ||
47 | + cost(ndim, x, wavetable); | ||
48 | + } | ||
49 | + | ||
50 | +/** | ||
51 | + * Backward cosine FFT transform. It is the unnormalized inverse transform of <em>ft</em>. | ||
52 | + * | ||
53 | + * @param x an array which contains the sequence to be transformed. After FFT, | ||
54 | + * <em>x</em> contains the transform coeffients. | ||
55 | +*/ | ||
56 | + public void bt(double x[]) | ||
57 | + { | ||
58 | + cost(ndim, x, wavetable); | ||
59 | + } | ||
60 | + | ||
61 | + | ||
62 | +/*------------------------------------------------------------- | ||
63 | + cost: cosine FFT. Backward and forward cos-FFT are the same. | ||
64 | + ------------------------------------------------------------*/ | ||
65 | + void cost(int n, double x[], final double wtable[]) | ||
66 | + { | ||
67 | + int modn, i, k; | ||
68 | + double c1, t1, t2; | ||
69 | + int kc; | ||
70 | + double xi; | ||
71 | + int nm1; | ||
72 | + double x1h; | ||
73 | + int ns2; | ||
74 | + double tx2, x1p3, xim2; | ||
75 | + | ||
76 | + | ||
77 | + nm1=n-1; | ||
78 | + ns2=n / 2; | ||
79 | + if(n-2<0) return; | ||
80 | + else if(n==2) | ||
81 | + { | ||
82 | + x1h=x[0]+x[1]; | ||
83 | + x[1]=x[0]-x[1]; | ||
84 | + x[0]=x1h; | ||
85 | + } | ||
86 | + else if(n==3) | ||
87 | + { | ||
88 | + x1p3=x[0]+x[2]; | ||
89 | + tx2=x[1]+x[1]; | ||
90 | + x[1]=x[0]-x[2]; | ||
91 | + x[0]=x1p3+tx2; | ||
92 | + x[2]=x1p3-tx2; | ||
93 | + } | ||
94 | + else | ||
95 | + { | ||
96 | + c1=x[0]-x[n-1]; | ||
97 | + x[0]+=x[n-1]; | ||
98 | + for(k=1; k<ns2; k++) | ||
99 | + { | ||
100 | + kc=nm1-k; | ||
101 | + t1=x[k]+x[kc]; | ||
102 | + t2=x[k]-x[kc]; | ||
103 | + c1+=wtable[kc]*t2; | ||
104 | + t2=wtable[k]*t2; | ||
105 | + x[k]=t1-t2; | ||
106 | + x[kc]=t1+t2; | ||
107 | + } | ||
108 | + modn=n%2; | ||
109 | + if(modn !=0) x[ns2]+=x[ns2]; | ||
110 | + rfftf1(nm1, x, wtable, n); | ||
111 | + xim2=x[1]; | ||
112 | + x[1]=c1; | ||
113 | + for(i=3; i<n; i+=2) | ||
114 | + { | ||
115 | + xi=x[i]; | ||
116 | + x[i]=x[i-2]-x[i-1]; | ||
117 | + x[i-1]=xim2; | ||
118 | + xim2=xi; | ||
119 | + } | ||
120 | + if(modn !=0) x[n-1]=xim2; | ||
121 | + } | ||
122 | + } | ||
123 | + | ||
124 | +/*---------------------------------- | ||
125 | + costi: initialization of cos-FFT | ||
126 | + ---------------------------------*/ | ||
127 | + void costi(int n, double wtable[]) | ||
128 | + { | ||
129 | + final double pi=Math.PI; //3.14159265358979; | ||
130 | + int k, kc, ns2; | ||
131 | + double dt; | ||
132 | + | ||
133 | + if(n<=3) return; | ||
134 | + ns2=n / 2; | ||
135 | + dt=pi /(double)(n-1); | ||
136 | + for(k=1; k<ns2; k++) | ||
137 | + { | ||
138 | + kc=n-k-1; | ||
139 | + wtable[k]=2*Math.sin(k*dt); | ||
140 | + wtable[kc]=2*Math.cos(k*dt); | ||
141 | + } | ||
142 | + rffti1(n-1, wtable, n); | ||
143 | + } | ||
144 | +} |
app/src/main/java/com/example/zhongqiyan/javasource/ca/uol/aig/fftpack/RealDoubleFFT_Even_Odd.java
0 → 100644
1 | +package com.example.zhongqiyan.javasource.ca.uol.aig.fftpack; | ||
2 | +/** | ||
3 | + * cosine FFT transform with odd wave numbers. | ||
4 | + * @author Baoshe Zhang | ||
5 | + * @author Astronomical Instrument Group of University of Lethbridge. | ||
6 | +*/ | ||
7 | +public class RealDoubleFFT_Even_Odd extends RealDoubleFFT_Mixed | ||
8 | +{ | ||
9 | +/** | ||
10 | + * <em>norm_factor</em> can be used to normalize this FFT transform. This is because | ||
11 | + * a call of forward transform (<em>ft</em>) followed by a call of backward transform | ||
12 | + * (<em>bt</em>) will multiply the input sequence by <em>norm_factor</em>. | ||
13 | +*/ | ||
14 | + public double norm_factor; | ||
15 | + protected double wavetable[]; | ||
16 | + protected int ndim; | ||
17 | + | ||
18 | +/** | ||
19 | + * Construct a wavenumber table with size <em>n</em>. | ||
20 | + * The sequences with the same size can share a wavenumber table. The prime | ||
21 | + * factorization of <em>n</em> together with a tabulation of the trigonometric functions | ||
22 | + * are computed and stored. | ||
23 | + * | ||
24 | + * @param n the size of a real data sequence. When <em>n</em> is a multiplication of small | ||
25 | + * numbers(4, 2, 3, 5), this FFT transform is very efficient. | ||
26 | +*/ | ||
27 | + public RealDoubleFFT_Even_Odd(int n) | ||
28 | + { | ||
29 | + ndim = n; | ||
30 | + norm_factor = 4*n; | ||
31 | + if(wavetable == null || wavetable.length !=(3*ndim+15)) | ||
32 | + { | ||
33 | + wavetable = new double[3*ndim + 15]; | ||
34 | + } | ||
35 | + cosqi(ndim, wavetable); | ||
36 | + } | ||
37 | + | ||
38 | +/** | ||
39 | + * Forward FFT transform of quarter wave data. It computes the coeffients in | ||
40 | + * cosine series representation with only odd wave numbers. | ||
41 | + * | ||
42 | + * @param x an array which contains the sequence to be transformed. After FFT, | ||
43 | + * <em>x</em> contains the transform coeffients. | ||
44 | +*/ | ||
45 | + public void ft(double x[]) | ||
46 | + { | ||
47 | + cosqf(ndim, x, wavetable); | ||
48 | + } | ||
49 | + | ||
50 | +/** | ||
51 | + * Backward FFT transform of quarter wave data. It is the unnormalized inverse transform | ||
52 | + * of <em>ft</em>. | ||
53 | + * | ||
54 | + * @param x an array which contains the sequence to be tranformed. After FFT, <em>x</em> contains | ||
55 | + * the transform coeffients. | ||
56 | +*/ | ||
57 | + public void bt(double x[]) | ||
58 | + { | ||
59 | + cosqb(ndim, x, wavetable); | ||
60 | + } | ||
61 | + | ||
62 | +/*---------------------------------------------------------------------- | ||
63 | + cosqf1: further processing of forward cos-FFT with odd wave numbers. | ||
64 | + ----------------------------------------------------------------------*/ | ||
65 | + void cosqf1(int n, double x[], double wtable[]) | ||
66 | + { | ||
67 | + int modn, i, k; | ||
68 | + int kc, np2, ns2; | ||
69 | + double xim1; | ||
70 | + | ||
71 | + ns2=(n+1)/ 2; | ||
72 | + np2=n+2; | ||
73 | + for(k=1; k<ns2; k++) | ||
74 | + { | ||
75 | + kc=n-k; | ||
76 | + wtable[k+n]=x[k]+x[kc]; | ||
77 | + wtable[kc+n]=x[k]-x[kc]; | ||
78 | + } | ||
79 | + modn=n%2; | ||
80 | + if(modn==0) wtable[ns2+n]=x[ns2]+x[ns2]; | ||
81 | + for(k=1; k<ns2; k++) | ||
82 | + { | ||
83 | + kc=n-k; | ||
84 | + x[k]=wtable[k-1]*wtable[kc+n]+wtable[kc-1]*wtable[k+n]; | ||
85 | + x[kc]=wtable[k-1]*wtable[k+n]-wtable[kc-1]*wtable[kc+n]; | ||
86 | + } | ||
87 | + if(modn==0) x[ns2]=wtable[ns2-1]*wtable[ns2+n]; | ||
88 | + rfftf1(n, x, wtable, n); | ||
89 | + for(i=2; i<n; i+=2) | ||
90 | + { | ||
91 | + xim1=x[i-1]-x[i]; | ||
92 | + x[i]=x[i-1]+x[i]; | ||
93 | + x[i-1]=xim1; | ||
94 | + } | ||
95 | + } | ||
96 | + | ||
97 | +/*---------------------------------------------------------------------- | ||
98 | + cosqb1: further processing of backward cos-FFT with odd wave numbers. | ||
99 | + ----------------------------------------------------------------------*/ | ||
100 | + void cosqb1(int n, double x[], double wtable[]) | ||
101 | + { | ||
102 | + int modn, i, k; | ||
103 | + int kc, ns2; | ||
104 | + double xim1; | ||
105 | + | ||
106 | + ns2=(n+1)/ 2; | ||
107 | + for(i=2; i<n; i+=2) | ||
108 | + { | ||
109 | + xim1=x[i-1]+x[i]; | ||
110 | + x[i]-=x[i-1]; | ||
111 | + x[i-1]=xim1; | ||
112 | + } | ||
113 | + x[0]+=x[0]; | ||
114 | + modn=n%2; | ||
115 | + if(modn==0) x[n-1]+=x[n-1]; | ||
116 | + rfftb1(n, x, wtable, n); | ||
117 | + for(k=1; k<ns2; k++) | ||
118 | + { | ||
119 | + kc=n-k; | ||
120 | + wtable[k+n]=wtable[k-1]*x[kc]+wtable[kc-1]*x[k]; | ||
121 | + wtable[kc+n]=wtable[k-1]*x[k]-wtable[kc-1]*x[kc]; | ||
122 | + } | ||
123 | + if(modn==0) x[ns2]=wtable[ns2-1]*(x[ns2]+x[ns2]); | ||
124 | + for(k=1; k<ns2; k++) | ||
125 | + { | ||
126 | + kc=n-k; | ||
127 | + x[k]=wtable[k+n]+wtable[kc+n]; | ||
128 | + x[kc]=wtable[k+n]-wtable[kc+n]; | ||
129 | + } | ||
130 | + x[0]+=x[0]; | ||
131 | + } | ||
132 | + | ||
133 | +/*----------------------------------------------- | ||
134 | + cosqf: forward cosine FFT with odd wave numbers. | ||
135 | + ----------------------------------------------*/ | ||
136 | + void cosqf(int n, double x[], final double wtable[]) | ||
137 | + { | ||
138 | + final double sqrt2=1.4142135623731; | ||
139 | + double tsqx; | ||
140 | + | ||
141 | + if(n<2) | ||
142 | + { | ||
143 | + return; | ||
144 | + } | ||
145 | + else if(n==2) | ||
146 | + { | ||
147 | + tsqx=sqrt2*x[1]; | ||
148 | + x[1]=x[0]-tsqx; | ||
149 | + x[0]+=tsqx; | ||
150 | + } | ||
151 | + else | ||
152 | + { | ||
153 | + cosqf1(n, x, wtable); | ||
154 | + } | ||
155 | + } | ||
156 | + | ||
157 | +/*----------------------------------------------- | ||
158 | + cosqb: backward cosine FFT with odd wave numbers. | ||
159 | + ----------------------------------------------*/ | ||
160 | + void cosqb(int n, double x[], double wtable[]) | ||
161 | + { | ||
162 | + final double tsqrt2=2.82842712474619; | ||
163 | + double x1; | ||
164 | + | ||
165 | + if(n<2) | ||
166 | + { | ||
167 | + x[0]*=4; | ||
168 | + } | ||
169 | + else if(n==2) | ||
170 | + { | ||
171 | + x1=4*(x[0]+x[1]); | ||
172 | + x[1]=tsqrt2*(x[0]-x[1]); | ||
173 | + x[0]=x1; | ||
174 | + } | ||
175 | + else | ||
176 | + { | ||
177 | + cosqb1(n, x, wtable); | ||
178 | + } | ||
179 | + } | ||
180 | + | ||
181 | +/*----------------------------------------------------------- | ||
182 | + cosqi: initialization of cosine FFT with odd wave numbers. | ||
183 | + ----------------------------------------------------------*/ | ||
184 | + void cosqi(int n, double wtable[]) | ||
185 | + { | ||
186 | + final double pih=Math.PI/2.0D; //1.57079632679491; | ||
187 | + int k; | ||
188 | + double dt; | ||
189 | + dt=pih / (double)n; | ||
190 | + for(k=0; k<n; k++) wtable[k]=Math.cos((k+1)*dt); | ||
191 | + rffti1(n, wtable, n); | ||
192 | + } | ||
193 | + | ||
194 | +} |
app/src/main/java/com/example/zhongqiyan/javasource/ca/uol/aig/fftpack/RealDoubleFFT_Mixed.java
0 → 100644
1 | +package com.example.zhongqiyan.javasource.ca.uol.aig.fftpack; | ||
2 | +/** | ||
3 | + * @author Baoshe Zhang | ||
4 | + * @author Astronomical Instrument Group of University of Lethbridge. | ||
5 | +*/ | ||
6 | +class RealDoubleFFT_Mixed | ||
7 | +{ | ||
8 | + | ||
9 | +/*------------------------------------------------- | ||
10 | + radf2: Real FFT's forward processing of factor 2 | ||
11 | + -------------------------------------------------*/ | ||
12 | + void radf2(int ido, int l1, final double cc[], double ch[], | ||
13 | + final double wtable[], int offset) | ||
14 | + { | ||
15 | + int i, k, ic; | ||
16 | + double ti2, tr2; | ||
17 | + int iw1; | ||
18 | + iw1 = offset; | ||
19 | + | ||
20 | + for(k=0; k<l1; k++) | ||
21 | + { | ||
22 | + ch[2*k*ido]=cc[k*ido]+cc[(k+l1)*ido]; | ||
23 | + ch[(2*k+1)*ido+ido-1]=cc[k*ido]-cc[(k+l1)*ido]; | ||
24 | + } | ||
25 | + if(ido<2) return; | ||
26 | + if(ido !=2) | ||
27 | + { | ||
28 | + for(k=0; k<l1; k++) | ||
29 | + { | ||
30 | + for(i=2; i<ido; i+=2) | ||
31 | + { | ||
32 | + ic=ido-i; | ||
33 | + tr2 = wtable[i-2+iw1]*cc[i-1+(k+l1)*ido] | ||
34 | + +wtable[i-1+iw1]*cc[i+(k+l1)*ido]; | ||
35 | + ti2 = wtable[i-2+iw1]*cc[i+(k+l1)*ido] | ||
36 | + -wtable[i-1+iw1]*cc[i-1+(k+l1)*ido]; | ||
37 | + ch[i+2*k*ido]=cc[i+k*ido]+ti2; | ||
38 | + ch[ic+(2*k+1)*ido]=ti2-cc[i+k*ido]; | ||
39 | + ch[i-1+2*k*ido]=cc[i-1+k*ido]+tr2; | ||
40 | + ch[ic-1+(2*k+1)*ido]=cc[i-1+k*ido]-tr2; | ||
41 | + } | ||
42 | + } | ||
43 | + if(ido%2==1)return; | ||
44 | + } | ||
45 | + for(k=0; k<l1; k++) | ||
46 | + { | ||
47 | + ch[(2*k+1)*ido]=-cc[ido-1+(k+l1)*ido]; | ||
48 | + ch[ido-1+2*k*ido]=cc[ido-1+k*ido]; | ||
49 | + } | ||
50 | + } | ||
51 | + | ||
52 | +/*------------------------------------------------- | ||
53 | + radb2: Real FFT's backward processing of factor 2 | ||
54 | + -------------------------------------------------*/ | ||
55 | + void radb2(int ido, int l1, final double cc[], double ch[], | ||
56 | + final double wtable[], int offset) | ||
57 | + { | ||
58 | + int i, k, ic; | ||
59 | + double ti2, tr2; | ||
60 | + int iw1 = offset; | ||
61 | + | ||
62 | + for(k=0; k<l1; k++) | ||
63 | + { | ||
64 | + ch[k*ido]=cc[2*k*ido]+cc[ido-1+(2*k+1)*ido]; | ||
65 | + ch[(k+l1)*ido]=cc[2*k*ido]-cc[ido-1+(2*k+1)*ido]; | ||
66 | + } | ||
67 | + if(ido<2) return; | ||
68 | + if(ido !=2) | ||
69 | + { | ||
70 | + for(k=0; k<l1;++k) | ||
71 | + { | ||
72 | + for(i=2; i<ido; i+=2) | ||
73 | + { | ||
74 | + ic=ido-i; | ||
75 | + ch[i-1+k*ido]=cc[i-1+2*k*ido]+cc[ic-1+(2*k+1)*ido]; | ||
76 | + tr2=cc[i-1+2*k*ido]-cc[ic-1+(2*k+1)*ido]; | ||
77 | + ch[i+k*ido]=cc[i+2*k*ido]-cc[ic+(2*k+1)*ido]; | ||
78 | + ti2=cc[i+(2*k)*ido]+cc[ic+(2*k+1)*ido]; | ||
79 | + ch[i-1+(k+l1)*ido]=wtable[i-2+iw1]*tr2-wtable[i-1+iw1]*ti2; | ||
80 | + ch[i+(k+l1)*ido]=wtable[i-2+iw1]*ti2+wtable[i-1+iw1]*tr2; | ||
81 | + } | ||
82 | + } | ||
83 | + if(ido%2==1) return; | ||
84 | + } | ||
85 | + for(k=0; k<l1; k++) | ||
86 | + { | ||
87 | + ch[ido-1+k*ido]=2*cc[ido-1+2*k*ido]; | ||
88 | + ch[ido-1+(k+l1)*ido]=-2*cc[(2*k+1)*ido]; | ||
89 | + } | ||
90 | + } | ||
91 | + | ||
92 | +/*------------------------------------------------- | ||
93 | + radf3: Real FFT's forward processing of factor 3 | ||
94 | + -------------------------------------------------*/ | ||
95 | + void radf3(int ido, int l1, final double cc[], double ch[], | ||
96 | + final double wtable[], int offset) | ||
97 | + { | ||
98 | + final double taur=-0.5D; | ||
99 | + final double taui=0.866025403784439D; | ||
100 | + int i, k, ic; | ||
101 | + double ci2, di2, di3, cr2, dr2, dr3, ti2, ti3, tr2, tr3; | ||
102 | + int iw1, iw2; | ||
103 | + iw1 = offset; | ||
104 | + iw2 = iw1 + ido; | ||
105 | + | ||
106 | + for(k=0; k<l1; k++) | ||
107 | + { | ||
108 | + cr2=cc[(k+l1)*ido]+cc[(k+2*l1)*ido]; | ||
109 | + ch[3*k*ido]=cc[k*ido]+cr2; | ||
110 | + ch[(3*k+2)*ido]=taui*(cc[(k+l1*2)*ido]-cc[(k+l1)*ido]); | ||
111 | + ch[ido-1+(3*k+1)*ido]=cc[k*ido]+taur*cr2; | ||
112 | + } | ||
113 | + if(ido==1) return; | ||
114 | + for(k=0; k<l1; k++) | ||
115 | + { | ||
116 | + for(i=2; i<ido; i+=2) | ||
117 | + { | ||
118 | + ic=ido-i; | ||
119 | + dr2 = wtable[i-2+iw1]*cc[i-1+(k+l1)*ido] | ||
120 | + +wtable[i-1+iw1]*cc[i+(k+l1)*ido]; | ||
121 | + di2 = wtable[i-2+iw1]*cc[i+(k+l1)*ido] | ||
122 | + -wtable[i-1+iw1]*cc[i-1+(k+l1)*ido]; | ||
123 | + dr3 = wtable[i-2+iw2]*cc[i-1+(k+l1*2)*ido] | ||
124 | + +wtable[i-1+iw2]*cc[i+(k+l1*2)*ido]; | ||
125 | + di3 = wtable[i-2+iw2]*cc[i+(k+l1*2)*ido] | ||
126 | + -wtable[i-1+iw2]*cc[i-1+(k+l1*2)*ido]; | ||
127 | + cr2 = dr2+dr3; | ||
128 | + ci2 = di2+di3; | ||
129 | + ch[i-1+3*k*ido]=cc[i-1+k*ido]+cr2; | ||
130 | + ch[i+3*k*ido]=cc[i+k*ido]+ci2; | ||
131 | + tr2=cc[i-1+k*ido]+taur*cr2; | ||
132 | + ti2=cc[i+k*ido]+taur*ci2; | ||
133 | + tr3=taui*(di2-di3); | ||
134 | + ti3=taui*(dr3-dr2); | ||
135 | + ch[i-1+(3*k+2)*ido]=tr2+tr3; | ||
136 | + ch[ic-1+(3*k+1)*ido]=tr2-tr3; | ||
137 | + ch[i+(3*k+2)*ido]=ti2+ti3; | ||
138 | + ch[ic+(3*k+1)*ido]=ti3-ti2; | ||
139 | + } | ||
140 | + } | ||
141 | + } | ||
142 | + | ||
143 | +/*------------------------------------------------- | ||
144 | + radb3: Real FFT's backward processing of factor 3 | ||
145 | + -------------------------------------------------*/ | ||
146 | + void radb3(int ido, int l1, final double cc[], double ch[], | ||
147 | + final double wtable[], int offset) | ||
148 | + { | ||
149 | + final double taur=-0.5D; | ||
150 | + final double taui=0.866025403784439D; | ||
151 | + int i, k, ic; | ||
152 | + double ci2, ci3, di2, di3, cr2, cr3, dr2, dr3, ti2, tr2; | ||
153 | + int iw1, iw2; | ||
154 | + iw1 = offset; | ||
155 | + iw2 = iw1 + ido; | ||
156 | + | ||
157 | + for(k=0; k<l1; k++) | ||
158 | + { | ||
159 | + tr2=2*cc[ido-1+(3*k+1)*ido]; | ||
160 | + cr2=cc[3*k*ido]+taur*tr2; | ||
161 | + ch[k*ido]=cc[3*k*ido]+tr2; | ||
162 | + ci3=2*taui*cc[(3*k+2)*ido]; | ||
163 | + ch[(k+l1)*ido]=cr2-ci3; | ||
164 | + ch[(k+2*l1)*ido]=cr2+ci3; | ||
165 | + } | ||
166 | + if(ido==1) return; | ||
167 | + for(k=0; k<l1; k++) | ||
168 | + { | ||
169 | + for(i=2; i<ido; i+=2) | ||
170 | + { | ||
171 | + ic=ido-i; | ||
172 | + tr2=cc[i-1+(3*k+2)*ido]+cc[ic-1+(3*k+1)*ido]; | ||
173 | + cr2=cc[i-1+3*k*ido]+taur*tr2; | ||
174 | + ch[i-1+k*ido]=cc[i-1+3*k*ido]+tr2; | ||
175 | + ti2=cc[i+(3*k+2)*ido]-cc[ic+(3*k+1)*ido]; | ||
176 | + ci2=cc[i+3*k*ido]+taur*ti2; | ||
177 | + ch[i+k*ido]=cc[i+3*k*ido]+ti2; | ||
178 | + cr3=taui*(cc[i-1+(3*k+2)*ido]-cc[ic-1+(3*k+1)*ido]); | ||
179 | + ci3=taui*(cc[i+(3*k+2)*ido]+cc[ic+(3*k+1)*ido]); | ||
180 | + dr2=cr2-ci3; | ||
181 | + dr3=cr2+ci3; | ||
182 | + di2=ci2+cr3; | ||
183 | + di3=ci2-cr3; | ||
184 | + ch[i-1+(k+l1)*ido] = wtable[i-2+iw1]*dr2 | ||
185 | + -wtable[i-1+iw1]*di2; | ||
186 | + ch[i+(k+l1)*ido] = wtable[i-2+iw1]*di2 | ||
187 | + +wtable[i-1+iw1]*dr2; | ||
188 | + ch[i-1+(k+2*l1)*ido] = wtable[i-2+iw2]*dr3 | ||
189 | + -wtable[i-1+iw2]*di3; | ||
190 | + ch[i+(k+2*l1)*ido] = wtable[i-2+iw2]*di3 | ||
191 | + +wtable[i-1+iw2]*dr3; | ||
192 | + } | ||
193 | + } | ||
194 | + } | ||
195 | + | ||
196 | +/*------------------------------------------------- | ||
197 | + radf4: Real FFT's forward processing of factor 4 | ||
198 | + -------------------------------------------------*/ | ||
199 | + void radf4(int ido, int l1, final double cc[], double ch[], | ||
200 | + final double wtable[], int offset) | ||
201 | + { | ||
202 | + final double hsqt2=0.7071067811865475D; | ||
203 | + int i, k, ic; | ||
204 | + double ci2, ci3, ci4, cr2, cr3, cr4, ti1, ti2, ti3, ti4, tr1, tr2, tr3, tr4; | ||
205 | + int iw1, iw2, iw3; | ||
206 | + iw1 = offset; | ||
207 | + iw2 = offset + ido; | ||
208 | + iw3 = iw2 + ido; | ||
209 | + for(k=0; k<l1; k++) | ||
210 | + { | ||
211 | + tr1=cc[(k+l1)*ido]+cc[(k+3*l1)*ido]; | ||
212 | + tr2=cc[k*ido]+cc[(k+2*l1)*ido]; | ||
213 | + ch[4*k*ido]=tr1+tr2; | ||
214 | + ch[ido-1+(4*k+3)*ido]=tr2-tr1; | ||
215 | + ch[ido-1+(4*k+1)*ido]=cc[k*ido]-cc[(k+2*l1)*ido]; | ||
216 | + ch[(4*k+2)*ido]=cc[(k+3*l1)*ido]-cc[(k+l1)*ido]; | ||
217 | + } | ||
218 | + if(ido<2) return; | ||
219 | + if(ido !=2) | ||
220 | + { | ||
221 | + for(k=0; k<l1; k++) | ||
222 | + { | ||
223 | + for(i=2; i<ido; i+=2) | ||
224 | + { | ||
225 | + ic=ido-i; | ||
226 | + cr2 = wtable[i-2+iw1]*cc[i-1+(k+l1)*ido] | ||
227 | + +wtable[i-1+iw1]*cc[i+(k+l1)*ido]; | ||
228 | + ci2 = wtable[i-2+iw1]*cc[i+(k+l1)*ido] | ||
229 | + -wtable[i-1+iw1]*cc[i-1+(k+l1)*ido]; | ||
230 | + cr3 = wtable[i-2+iw2]*cc[i-1+(k+2*l1)*ido] | ||
231 | + +wtable[i-1+iw2]*cc[i+(k+2*l1)*ido]; | ||
232 | + ci3 = wtable[i-2+iw2]*cc[i+(k+2*l1)*ido] | ||
233 | + -wtable[i-1+iw2]*cc[i-1+(k+2*l1)*ido]; | ||
234 | + cr4 = wtable[i-2+iw3]*cc[i-1+(k+3*l1)*ido] | ||
235 | + +wtable[i-1+iw3]*cc[i+(k+3*l1)*ido]; | ||
236 | + ci4 = wtable[i-2+iw3]*cc[i+(k+3*l1)*ido] | ||
237 | + -wtable[i-1+iw3]*cc[i-1+(k+3*l1)*ido]; | ||
238 | + tr1=cr2+cr4; | ||
239 | + tr4=cr4-cr2; | ||
240 | + ti1=ci2+ci4; | ||
241 | + ti4=ci2-ci4; | ||
242 | + ti2=cc[i+k*ido]+ci3; | ||
243 | + ti3=cc[i+k*ido]-ci3; | ||
244 | + tr2=cc[i-1+k*ido]+cr3; | ||
245 | + tr3=cc[i-1+k*ido]-cr3; | ||
246 | + ch[i-1+4*k*ido]=tr1+tr2; | ||
247 | + ch[ic-1+(4*k+3)*ido]=tr2-tr1; | ||
248 | + ch[i+4*k*ido]=ti1+ti2; | ||
249 | + ch[ic+(4*k+3)*ido]=ti1-ti2; | ||
250 | + ch[i-1+(4*k+2)*ido]=ti4+tr3; | ||
251 | + ch[ic-1+(4*k+1)*ido]=tr3-ti4; | ||
252 | + ch[i+(4*k+2)*ido]=tr4+ti3; | ||
253 | + ch[ic+(4*k+1)*ido]=tr4-ti3; | ||
254 | + } | ||
255 | + } | ||
256 | + if(ido%2==1) return; | ||
257 | + } | ||
258 | + for(k=0; k<l1; k++) | ||
259 | + { | ||
260 | + ti1=-hsqt2*(cc[ido-1+(k+l1)*ido]+cc[ido-1+(k+3*l1)*ido]); | ||
261 | + tr1=hsqt2*(cc[ido-1+(k+l1)*ido]-cc[ido-1+(k+3*l1)*ido]); | ||
262 | + ch[ido-1+4*k*ido]=tr1+cc[ido-1+k*ido]; | ||
263 | + ch[ido-1+(4*k+2)*ido]=cc[ido-1+k*ido]-tr1; | ||
264 | + ch[(4*k+1)*ido]=ti1-cc[ido-1+(k+2*l1)*ido]; | ||
265 | + ch[(4*k+3)*ido]=ti1+cc[ido-1+(k+2*l1)*ido]; | ||
266 | + } | ||
267 | + } | ||
268 | + | ||
269 | +/*------------------------------------------------- | ||
270 | + radb4: Real FFT's backward processing of factor 4 | ||
271 | + -------------------------------------------------*/ | ||
272 | + void radb4(int ido, int l1, final double cc[], double ch[], | ||
273 | + final double wtable[], int offset) | ||
274 | + { | ||
275 | + final double sqrt2=1.414213562373095D; | ||
276 | + int i, k, ic; | ||
277 | + double ci2, ci3, ci4, cr2, cr3, cr4; | ||
278 | + double ti1, ti2, ti3, ti4, tr1, tr2, tr3, tr4; | ||
279 | + int iw1, iw2, iw3; | ||
280 | + iw1 = offset; | ||
281 | + iw2 = iw1 + ido; | ||
282 | + iw3 = iw2 + ido; | ||
283 | + | ||
284 | + for(k=0; k<l1; k++) | ||
285 | + { | ||
286 | + tr1=cc[4*k*ido]-cc[ido-1+(4*k+3)*ido]; | ||
287 | + tr2=cc[4*k*ido]+cc[ido-1+(4*k+3)*ido]; | ||
288 | + tr3=cc[ido-1+(4*k+1)*ido]+cc[ido-1+(4*k+1)*ido]; | ||
289 | + tr4=cc[(4*k+2)*ido]+cc[(4*k+2)*ido]; | ||
290 | + ch[k*ido]=tr2+tr3; | ||
291 | + ch[(k+l1)*ido]=tr1-tr4; | ||
292 | + ch[(k+2*l1)*ido]=tr2-tr3; | ||
293 | + ch[(k+3*l1)*ido]=tr1+tr4; | ||
294 | + } | ||
295 | + if(ido<2) return; | ||
296 | + if(ido !=2) | ||
297 | + { | ||
298 | + for(k=0; k<l1;++k) | ||
299 | + { | ||
300 | + for(i=2; i<ido; i+=2) | ||
301 | + { | ||
302 | + ic=ido-i; | ||
303 | + ti1=cc[i+4*k*ido]+cc[ic+(4*k+3)*ido]; | ||
304 | + ti2=cc[i+4*k*ido]-cc[ic+(4*k+3)*ido]; | ||
305 | + ti3=cc[i+(4*k+2)*ido]-cc[ic+(4*k+1)*ido]; | ||
306 | + tr4=cc[i+(4*k+2)*ido]+cc[ic+(4*k+1)*ido]; | ||
307 | + tr1=cc[i-1+4*k*ido]-cc[ic-1+(4*k+3)*ido]; | ||
308 | + tr2=cc[i-1+4*k*ido]+cc[ic-1+(4*k+3)*ido]; | ||
309 | + ti4=cc[i-1+(4*k+2)*ido]-cc[ic-1+(4*k+1)*ido]; | ||
310 | + tr3=cc[i-1+(4*k+2)*ido]+cc[ic-1+(4*k+1)*ido]; | ||
311 | + ch[i-1+k*ido]=tr2+tr3; | ||
312 | + cr3=tr2-tr3; | ||
313 | + ch[i+k*ido]=ti2+ti3; | ||
314 | + ci3=ti2-ti3; | ||
315 | + cr2=tr1-tr4; | ||
316 | + cr4=tr1+tr4; | ||
317 | + ci2=ti1+ti4; | ||
318 | + ci4=ti1-ti4; | ||
319 | + ch[i-1+(k+l1)*ido] = wtable[i-2+iw1]*cr2 | ||
320 | + -wtable[i-1+iw1]*ci2; | ||
321 | + ch[i+(k+l1)*ido] = wtable[i-2+iw1]*ci2 | ||
322 | + +wtable[i-1+iw1]*cr2; | ||
323 | + ch[i-1+(k+2*l1)*ido] = wtable[i-2+iw2]*cr3 | ||
324 | + -wtable[i-1+iw2]*ci3; | ||
325 | + ch[i+(k+2*l1)*ido] = wtable[i-2+iw2]*ci3 | ||
326 | + +wtable[i-1+iw2]*cr3; | ||
327 | + ch[i-1+(k+3*l1)*ido] = wtable[i-2+iw3]*cr4 | ||
328 | + -wtable[i-1+iw3]*ci4; | ||
329 | + ch[i+(k+3*l1)*ido] = wtable[i-2+iw3]*ci4 | ||
330 | + +wtable[i-1+iw3]*cr4; | ||
331 | + } | ||
332 | + } | ||
333 | + if(ido%2==1) return; | ||
334 | + } | ||
335 | + for(k=0; k<l1; k++) | ||
336 | + { | ||
337 | + ti1=cc[(4*k+1)*ido]+cc[(4*k+3)*ido]; | ||
338 | + ti2=cc[(4*k+3)*ido]-cc[(4*k+1)*ido]; | ||
339 | + tr1=cc[ido-1+4*k*ido]-cc[ido-1+(4*k+2)*ido]; | ||
340 | + tr2=cc[ido-1+4*k*ido]+cc[ido-1+(4*k+2)*ido]; | ||
341 | + ch[ido-1+k*ido]=tr2+tr2; | ||
342 | + ch[ido-1+(k+l1)*ido]=sqrt2*(tr1-ti1); | ||
343 | + ch[ido-1+(k+2*l1)*ido]=ti2+ti2; | ||
344 | + ch[ido-1+(k+3*l1)*ido]=-sqrt2*(tr1+ti1); | ||
345 | + } | ||
346 | + } | ||
347 | + | ||
348 | +/*------------------------------------------------- | ||
349 | + radf5: Real FFT's forward processing of factor 5 | ||
350 | + -------------------------------------------------*/ | ||
351 | + void radf5(int ido, int l1, final double cc[], double ch[], | ||
352 | + final double wtable[], int offset) | ||
353 | + { | ||
354 | + final double tr11=0.309016994374947D; | ||
355 | + final double ti11=0.951056516295154D; | ||
356 | + final double tr12=-0.809016994374947D; | ||
357 | + final double ti12=0.587785252292473D; | ||
358 | + int i, k, ic; | ||
359 | + double ci2, di2, ci4, ci5, di3, di4, di5, ci3, cr2, cr3, dr2, dr3, | ||
360 | + dr4, dr5, cr5, cr4, ti2, ti3, ti5, ti4, tr2, tr3, tr4, tr5; | ||
361 | + int iw1, iw2, iw3, iw4; | ||
362 | + iw1 = offset; | ||
363 | + iw2 = iw1 + ido; | ||
364 | + iw3 = iw2 + ido; | ||
365 | + iw4 = iw3 + ido; | ||
366 | + | ||
367 | + for(k=0; k<l1; k++) | ||
368 | + { | ||
369 | + cr2=cc[(k+4*l1)*ido]+cc[(k+l1)*ido]; | ||
370 | + ci5=cc[(k+4*l1)*ido]-cc[(k+l1)*ido]; | ||
371 | + cr3=cc[(k+3*l1)*ido]+cc[(k+2*l1)*ido]; | ||
372 | + ci4=cc[(k+3*l1)*ido]-cc[(k+2*l1)*ido]; | ||
373 | + ch[5*k*ido]=cc[k*ido]+cr2+cr3; | ||
374 | + ch[ido-1+(5*k+1)*ido]=cc[k*ido]+tr11*cr2+tr12*cr3; | ||
375 | + ch[(5*k+2)*ido]=ti11*ci5+ti12*ci4; | ||
376 | + ch[ido-1+(5*k+3)*ido]=cc[k*ido]+tr12*cr2+tr11*cr3; | ||
377 | + ch[(5*k+4)*ido]=ti12*ci5-ti11*ci4; | ||
378 | + } | ||
379 | + if(ido==1) return; | ||
380 | + for(k=0; k<l1;++k) | ||
381 | + { | ||
382 | + for(i=2; i<ido; i+=2) | ||
383 | + { | ||
384 | + ic=ido-i; | ||
385 | + dr2 = wtable[i-2+iw1]*cc[i-1+(k+l1)*ido] | ||
386 | + +wtable[i-1+iw1]*cc[i+(k+l1)*ido]; | ||
387 | + di2 = wtable[i-2+iw1]*cc[i+(k+l1)*ido] | ||
388 | + -wtable[i-1+iw1]*cc[i-1+(k+l1)*ido]; | ||
389 | + dr3 = wtable[i-2+iw2]*cc[i-1+(k+2*l1)*ido] | ||
390 | + +wtable[i-1+iw2]*cc[i+(k+2*l1)*ido]; | ||
391 | + di3 = wtable[i-2+iw2]*cc[i+(k+2*l1)*ido] | ||
392 | + -wtable[i-1+iw2]*cc[i-1+(k+2*l1)*ido]; | ||
393 | + dr4 = wtable[i-2+iw3]*cc[i-1+(k+3*l1)*ido] | ||
394 | + +wtable[i-1+iw3]*cc[i+(k+3*l1)*ido]; | ||
395 | + di4 = wtable[i-2+iw3]*cc[i+(k+3*l1)*ido] | ||
396 | + -wtable[i-1+iw3]*cc[i-1+(k+3*l1)*ido]; | ||
397 | + dr5 = wtable[i-2+iw4]*cc[i-1+(k+4*l1)*ido] | ||
398 | + +wtable[i-1+iw4]*cc[i+(k+4*l1)*ido]; | ||
399 | + di5 = wtable[i-2+iw4]*cc[i+(k+4*l1)*ido] | ||
400 | + -wtable[i-1+iw4]*cc[i-1+(k+4*l1)*ido]; | ||
401 | + cr2=dr2+dr5; | ||
402 | + ci5=dr5-dr2; | ||
403 | + cr5=di2-di5; | ||
404 | + ci2=di2+di5; | ||
405 | + cr3=dr3+dr4; | ||
406 | + ci4=dr4-dr3; | ||
407 | + cr4=di3-di4; | ||
408 | + ci3=di3+di4; | ||
409 | + ch[i-1+5*k*ido]=cc[i-1+k*ido]+cr2+cr3; | ||
410 | + ch[i+5*k*ido]=cc[i+k*ido]+ci2+ci3; | ||
411 | + tr2=cc[i-1+k*ido]+tr11*cr2+tr12*cr3; | ||
412 | + ti2=cc[i+k*ido]+tr11*ci2+tr12*ci3; | ||
413 | + tr3=cc[i-1+k*ido]+tr12*cr2+tr11*cr3; | ||
414 | + ti3=cc[i+k*ido]+tr12*ci2+tr11*ci3; | ||
415 | + tr5=ti11*cr5+ti12*cr4; | ||
416 | + ti5=ti11*ci5+ti12*ci4; | ||
417 | + tr4=ti12*cr5-ti11*cr4; | ||
418 | + ti4=ti12*ci5-ti11*ci4; | ||
419 | + ch[i-1+(5*k+2)*ido]=tr2+tr5; | ||
420 | + ch[ic-1+(5*k+1)*ido]=tr2-tr5; | ||
421 | + ch[i+(5*k+2)*ido]=ti2+ti5; | ||
422 | + ch[ic+(5*k+1)*ido]=ti5-ti2; | ||
423 | + ch[i-1+(5*k+4)*ido]=tr3+tr4; | ||
424 | + ch[ic-1+(5*k+3)*ido]=tr3-tr4; | ||
425 | + ch[i+(5*k+4)*ido]=ti3+ti4; | ||
426 | + ch[ic+(5*k+3)*ido]=ti4-ti3; | ||
427 | + } | ||
428 | + } | ||
429 | + } | ||
430 | + | ||
431 | +/*------------------------------------------------- | ||
432 | + radb5: Real FFT's backward processing of factor 5 | ||
433 | + -------------------------------------------------*/ | ||
434 | + void radb5(int ido, int l1, final double cc[], double ch[], | ||
435 | + final double wtable[], int offset) | ||
436 | + { | ||
437 | + final double tr11=0.309016994374947D; | ||
438 | + final double ti11=0.951056516295154D; | ||
439 | + final double tr12=-0.809016994374947D; | ||
440 | + final double ti12=0.587785252292473D; | ||
441 | + int i, k, ic; | ||
442 | + double ci2, ci3, ci4, ci5, di3, di4, di5, di2, cr2, cr3, cr5, cr4, | ||
443 | + ti2, ti3, ti4, ti5, dr3, dr4, dr5, dr2, tr2, tr3, tr4, tr5; | ||
444 | + int iw1, iw2, iw3, iw4; | ||
445 | + iw1 = offset; | ||
446 | + iw2 = iw1 + ido; | ||
447 | + iw3 = iw2 + ido; | ||
448 | + iw4 = iw3 + ido; | ||
449 | + | ||
450 | + for(k=0; k<l1; k++) | ||
451 | + { | ||
452 | + ti5=2*cc[(5*k+2)*ido]; | ||
453 | + ti4=2*cc[(5*k+4)*ido]; | ||
454 | + tr2=2*cc[ido-1+(5*k+1)*ido]; | ||
455 | + tr3=2*cc[ido-1+(5*k+3)*ido]; | ||
456 | + ch[k*ido]=cc[5*k*ido]+tr2+tr3; | ||
457 | + cr2=cc[5*k*ido]+tr11*tr2+tr12*tr3; | ||
458 | + cr3=cc[5*k*ido]+tr12*tr2+tr11*tr3; | ||
459 | + ci5=ti11*ti5+ti12*ti4; | ||
460 | + ci4=ti12*ti5-ti11*ti4; | ||
461 | + ch[(k+l1)*ido]=cr2-ci5; | ||
462 | + ch[(k+2*l1)*ido]=cr3-ci4; | ||
463 | + ch[(k+3*l1)*ido]=cr3+ci4; | ||
464 | + ch[(k+4*l1)*ido]=cr2+ci5; | ||
465 | + } | ||
466 | + if(ido==1) return; | ||
467 | + for(k=0; k<l1;++k) | ||
468 | + { | ||
469 | + for(i=2; i<ido; i+=2) | ||
470 | + { | ||
471 | + ic=ido-i; | ||
472 | + ti5=cc[i+(5*k+2)*ido]+cc[ic+(5*k+1)*ido]; | ||
473 | + ti2=cc[i+(5*k+2)*ido]-cc[ic+(5*k+1)*ido]; | ||
474 | + ti4=cc[i+(5*k+4)*ido]+cc[ic+(5*k+3)*ido]; | ||
475 | + ti3=cc[i+(5*k+4)*ido]-cc[ic+(5*k+3)*ido]; | ||
476 | + tr5=cc[i-1+(5*k+2)*ido]-cc[ic-1+(5*k+1)*ido]; | ||
477 | + tr2=cc[i-1+(5*k+2)*ido]+cc[ic-1+(5*k+1)*ido]; | ||
478 | + tr4=cc[i-1+(5*k+4)*ido]-cc[ic-1+(5*k+3)*ido]; | ||
479 | + tr3=cc[i-1+(5*k+4)*ido]+cc[ic-1+(5*k+3)*ido]; | ||
480 | + ch[i-1+k*ido]=cc[i-1+5*k*ido]+tr2+tr3; | ||
481 | + ch[i+k*ido]=cc[i+5*k*ido]+ti2+ti3; | ||
482 | + cr2=cc[i-1+5*k*ido]+tr11*tr2+tr12*tr3; | ||
483 | + | ||
484 | + ci2=cc[i+5*k*ido]+tr11*ti2+tr12*ti3; | ||
485 | + cr3=cc[i-1+5*k*ido]+tr12*tr2+tr11*tr3; | ||
486 | + | ||
487 | + ci3=cc[i+5*k*ido]+tr12*ti2+tr11*ti3; | ||
488 | + cr5=ti11*tr5+ti12*tr4; | ||
489 | + ci5=ti11*ti5+ti12*ti4; | ||
490 | + cr4=ti12*tr5-ti11*tr4; | ||
491 | + ci4=ti12*ti5-ti11*ti4; | ||
492 | + dr3=cr3-ci4; | ||
493 | + dr4=cr3+ci4; | ||
494 | + di3=ci3+cr4; | ||
495 | + di4=ci3-cr4; | ||
496 | + dr5=cr2+ci5; | ||
497 | + dr2=cr2-ci5; | ||
498 | + di5=ci2-cr5; | ||
499 | + di2=ci2+cr5; | ||
500 | + ch[i-1+(k+l1)*ido] = wtable[i-2+iw1]*dr2 | ||
501 | + -wtable[i-1+iw1]*di2; | ||
502 | + ch[i+(k+l1)*ido] = wtable[i-2+iw1]*di2 | ||
503 | + +wtable[i-1+iw1]*dr2; | ||
504 | + ch[i-1+(k+2*l1)*ido] = wtable[i-2+iw2]*dr3 | ||
505 | + -wtable[i-1+iw2]*di3; | ||
506 | + ch[i+(k+2*l1)*ido] = wtable[i-2+iw2]*di3 | ||
507 | + +wtable[i-1+iw2]*dr3; | ||
508 | + ch[i-1+(k+3*l1)*ido] = wtable[i-2+iw3]*dr4 | ||
509 | + -wtable[i-1+iw3]*di4; | ||
510 | + ch[i+(k+3*l1)*ido] = wtable[i-2+iw3]*di4 | ||
511 | + +wtable[i-1+iw3]*dr4; | ||
512 | + ch[i-1+(k+4*l1)*ido] = wtable[i-2+iw4]*dr5 | ||
513 | + -wtable[i-1+iw4]*di5; | ||
514 | + ch[i+(k+4*l1)*ido] = wtable[i-2+iw4]*di5 | ||
515 | + +wtable[i-1+iw4]*dr5; | ||
516 | + } | ||
517 | + } | ||
518 | + } | ||
519 | + | ||
520 | +/*--------------------------------------------------------- | ||
521 | + radfg: Real FFT's forward processing of general factor | ||
522 | + --------------------------------------------------------*/ | ||
523 | + void radfg(int ido, int ip, int l1, int idl1, double cc[], | ||
524 | + double c1[], double c2[], double ch[], double ch2[], | ||
525 | + final double wtable[], int offset) | ||
526 | + { | ||
527 | + final double twopi=2.0D*Math.PI; //6.28318530717959; | ||
528 | + int idij, ipph, i, j, k, l, j2, ic, jc, lc, ik, is, nbd; | ||
529 | + double dc2, ai1, ai2, ar1, ar2, ds2, dcp, arg, dsp, ar1h, ar2h; | ||
530 | + int iw1 = offset; | ||
531 | + | ||
532 | + arg=twopi / (double)ip; | ||
533 | + dcp=Math.cos(arg); | ||
534 | + dsp=Math.sin(arg); | ||
535 | + ipph=(ip+1)/ 2; | ||
536 | + nbd=(ido-1)/ 2; | ||
537 | + if(ido !=1) | ||
538 | + { | ||
539 | + for(ik=0; ik<idl1; ik++) ch2[ik]=c2[ik]; | ||
540 | + for(j=1; j<ip; j++) | ||
541 | + for(k=0; k<l1; k++) | ||
542 | + ch[(k+j*l1)*ido]=c1[(k+j*l1)*ido]; | ||
543 | + if(nbd<=l1) | ||
544 | + { | ||
545 | + is=-ido; | ||
546 | + for(j=1; j<ip; j++) | ||
547 | + { | ||
548 | + is+=ido; | ||
549 | + idij=is-1; | ||
550 | + for(i=2; i<ido; i+=2) | ||
551 | + { | ||
552 | + idij+=2; | ||
553 | + for(k=0; k<l1; k++) | ||
554 | + { | ||
555 | + ch[i-1+(k+j*l1)*ido]= | ||
556 | + wtable[idij-1+iw1]*c1[i-1+(k+j*l1)*ido] | ||
557 | + +wtable[idij+iw1]*c1[i+(k+j*l1)*ido]; | ||
558 | + ch[i+(k+j*l1)*ido]= | ||
559 | + wtable[idij-1+iw1]*c1[i+(k+j*l1)*ido] | ||
560 | + -wtable[idij+iw1]*c1[i-1+(k+j*l1)*ido]; | ||
561 | + } | ||
562 | + } | ||
563 | + } | ||
564 | + } | ||
565 | + else | ||
566 | + { | ||
567 | + is=-ido; | ||
568 | + for(j=1; j<ip; j++) | ||
569 | + { | ||
570 | + is+=ido; | ||
571 | + for(k=0; k<l1; k++) | ||
572 | + { | ||
573 | + idij=is-1; | ||
574 | + for(i=2; i<ido; i+=2) | ||
575 | + { | ||
576 | + idij+=2; | ||
577 | + ch[i-1+(k+j*l1)*ido]= | ||
578 | + wtable[idij-1+iw1]*c1[i-1+(k+j*l1)*ido] | ||
579 | + +wtable[idij+iw1]*c1[i+(k+j*l1)*ido]; | ||
580 | + ch[i+(k+j*l1)*ido]= | ||
581 | + wtable[idij-1+iw1]*c1[i+(k+j*l1)*ido] | ||
582 | + -wtable[idij+iw1]*c1[i-1+(k+j*l1)*ido]; | ||
583 | + } | ||
584 | + } | ||
585 | + } | ||
586 | + } | ||
587 | + if(nbd>=l1) | ||
588 | + { | ||
589 | + for(j=1; j<ipph; j++) | ||
590 | + { | ||
591 | + jc=ip-j; | ||
592 | + for(k=0; k<l1; k++) | ||
593 | + { | ||
594 | + for(i=2; i<ido; i+=2) | ||
595 | + { | ||
596 | + c1[i-1+(k+j*l1)*ido]=ch[i-1+(k+j*l1)*ido]+ch[i-1+(k+jc*l1)*ido]; | ||
597 | + c1[i-1+(k+jc*l1)*ido]=ch[i+(k+j*l1)*ido]-ch[i+(k+jc*l1)*ido]; | ||
598 | + c1[i+(k+j*l1)*ido]=ch[i+(k+j*l1)*ido]+ch[i+(k+jc*l1)*ido]; | ||
599 | + c1[i+(k+jc*l1)*ido]=ch[i-1+(k+jc*l1)*ido]-ch[i-1+(k+j*l1)*ido]; | ||
600 | + } | ||
601 | + } | ||
602 | + } | ||
603 | + } | ||
604 | + else | ||
605 | + { | ||
606 | + for(j=1; j<ipph; j++) | ||
607 | + { | ||
608 | + jc=ip-j; | ||
609 | + for(i=2; i<ido; i+=2) | ||
610 | + { | ||
611 | + for(k=0; k<l1; k++) | ||
612 | + { | ||
613 | + c1[i-1+(k+j*l1)*ido]= | ||
614 | + ch[i-1+(k+j*l1)*ido]+ch[i-1+(k+jc*l1)*ido]; | ||
615 | + c1[i-1+(k+jc*l1)*ido]=ch[i+(k+j*l1)*ido]-ch[i+(k+jc*l1)*ido]; | ||
616 | + c1[i+(k+j*l1)*ido]=ch[i+(k+j*l1)*ido]+ch[i+(k+jc*l1)*ido]; | ||
617 | + c1[i+(k+jc*l1)*ido]=ch[i-1+(k+jc*l1)*ido]-ch[i-1+(k+j*l1)*ido]; | ||
618 | + } | ||
619 | + } | ||
620 | + } | ||
621 | + } | ||
622 | + } | ||
623 | + else | ||
624 | + { | ||
625 | + for(ik=0; ik<idl1; ik++) c2[ik]=ch2[ik]; | ||
626 | + } | ||
627 | + for(j=1; j<ipph; j++) | ||
628 | + { | ||
629 | + jc=ip-j; | ||
630 | + for(k=0; k<l1; k++) | ||
631 | + { | ||
632 | + c1[(k+j*l1)*ido]=ch[(k+j*l1)*ido]+ch[(k+jc*l1)*ido]; | ||
633 | + c1[(k+jc*l1)*ido]=ch[(k+jc*l1)*ido]-ch[(k+j*l1)*ido]; | ||
634 | + } | ||
635 | + } | ||
636 | + | ||
637 | + ar1=1; | ||
638 | + ai1=0; | ||
639 | + for(l=1; l<ipph; l++) | ||
640 | + { | ||
641 | + lc=ip-l; | ||
642 | + ar1h=dcp*ar1-dsp*ai1; | ||
643 | + ai1=dcp*ai1+dsp*ar1; | ||
644 | + ar1=ar1h; | ||
645 | + for(ik=0; ik<idl1; ik++) | ||
646 | + { | ||
647 | + ch2[ik+l*idl1]=c2[ik]+ar1*c2[ik+idl1]; | ||
648 | + ch2[ik+lc*idl1]=ai1*c2[ik+(ip-1)*idl1]; | ||
649 | + } | ||
650 | + dc2=ar1; | ||
651 | + ds2=ai1; | ||
652 | + ar2=ar1; | ||
653 | + ai2=ai1; | ||
654 | + for(j=2; j<ipph; j++) | ||
655 | + { | ||
656 | + jc=ip-j; | ||
657 | + ar2h=dc2*ar2-ds2*ai2; | ||
658 | + ai2=dc2*ai2+ds2*ar2; | ||
659 | + ar2=ar2h; | ||
660 | + for(ik=0; ik<idl1; ik++) | ||
661 | + { | ||
662 | + ch2[ik+l*idl1]+=ar2*c2[ik+j*idl1]; | ||
663 | + ch2[ik+lc*idl1]+=ai2*c2[ik+jc*idl1]; | ||
664 | + } | ||
665 | + } | ||
666 | + } | ||
667 | + for(j=1; j<ipph; j++) | ||
668 | + for(ik=0; ik<idl1; ik++) | ||
669 | + ch2[ik]+=c2[ik+j*idl1]; | ||
670 | + | ||
671 | + if(ido>=l1) | ||
672 | + { | ||
673 | + for(k=0; k<l1; k++) | ||
674 | + { | ||
675 | + for(i=0; i<ido; i++) | ||
676 | + { | ||
677 | + cc[i+k*ip*ido]=ch[i+k*ido]; | ||
678 | + } | ||
679 | + } | ||
680 | + } | ||
681 | + else | ||
682 | + { | ||
683 | + for(i=0; i<ido; i++) | ||
684 | + { | ||
685 | + for(k=0; k<l1; k++) | ||
686 | + { | ||
687 | + cc[i+k*ip*ido]=ch[i+k*ido]; | ||
688 | + } | ||
689 | + } | ||
690 | + } | ||
691 | + for(j=1; j<ipph; j++) | ||
692 | + { | ||
693 | + jc=ip-j; | ||
694 | + j2=2*j; | ||
695 | + for(k=0; k<l1; k++) | ||
696 | + { | ||
697 | + cc[ido-1+(j2-1+k*ip)*ido]=ch[(k+j*l1)*ido]; | ||
698 | + cc[(j2+k*ip)*ido]=ch[(k+jc*l1)*ido]; | ||
699 | + } | ||
700 | + } | ||
701 | + if(ido==1) return; | ||
702 | + if(nbd>=l1) | ||
703 | + { | ||
704 | + for(j=1; j<ipph; j++) | ||
705 | + { | ||
706 | + jc=ip-j; | ||
707 | + j2=2*j; | ||
708 | + for(k=0; k<l1; k++) | ||
709 | + { | ||
710 | + for(i=2; i<ido; i+=2) | ||
711 | + { | ||
712 | + ic=ido-i; | ||
713 | + cc[i-1+(j2+k*ip)*ido]=ch[i-1+(k+j*l1)*ido]+ch[i-1+(k+jc*l1)*ido]; | ||
714 | + cc[ic-1+(j2-1+k*ip)*ido]=ch[i-1+(k+j*l1)*ido]-ch[i-1+(k+jc*l1)*ido]; | ||
715 | + cc[i+(j2+k*ip)*ido]=ch[i+(k+j*l1)*ido]+ch[i+(k+jc*l1)*ido]; | ||
716 | + cc[ic+(j2-1+k*ip)*ido]=ch[i+(k+jc*l1)*ido]-ch[i+(k+j*l1)*ido]; | ||
717 | + } | ||
718 | + } | ||
719 | + } | ||
720 | + } | ||
721 | + else | ||
722 | + { | ||
723 | + for(j=1; j<ipph; j++) | ||
724 | + { | ||
725 | + jc=ip-j; | ||
726 | + j2=2*j; | ||
727 | + for(i=2; i<ido; i+=2) | ||
728 | + { | ||
729 | + ic=ido-i; | ||
730 | + for(k=0; k<l1; k++) | ||
731 | + { | ||
732 | + cc[i-1+(j2+k*ip)*ido]=ch[i-1+(k+j*l1)*ido]+ch[i-1+(k+jc*l1)*ido]; | ||
733 | + cc[ic-1+(j2-1+k*ip)*ido]=ch[i-1+(k+j*l1)*ido]-ch[i-1+(k+jc*l1)*ido]; | ||
734 | + cc[i+(j2+k*ip)*ido]=ch[i+(k+j*l1)*ido]+ch[i+(k+jc*l1)*ido]; | ||
735 | + cc[ic+(j2-1+k*ip)*ido]=ch[i+(k+jc*l1)*ido]-ch[i+(k+j*l1)*ido]; | ||
736 | + } | ||
737 | + } | ||
738 | + } | ||
739 | + } | ||
740 | + } | ||
741 | + | ||
742 | +/*--------------------------------------------------------- | ||
743 | + radbg: Real FFT's backward processing of general factor | ||
744 | + --------------------------------------------------------*/ | ||
745 | + void radbg(int ido, int ip, int l1, int idl1, double cc[], double c1[], | ||
746 | + double c2[], double ch[], double ch2[], final double wtable[], int offset) | ||
747 | + { | ||
748 | + final double twopi=2.0D*Math.PI; //6.28318530717959; | ||
749 | + int idij, ipph, i, j, k, l, j2, ic, jc, lc, ik, is; | ||
750 | + double dc2, ai1, ai2, ar1, ar2, ds2; | ||
751 | + int nbd; | ||
752 | + double dcp, arg, dsp, ar1h, ar2h; | ||
753 | + int iw1 = offset; | ||
754 | + | ||
755 | + arg=twopi / (double)ip; | ||
756 | + dcp=Math.cos(arg); | ||
757 | + dsp=Math.sin(arg); | ||
758 | + nbd=(ido-1)/ 2; | ||
759 | + ipph=(ip+1)/ 2; | ||
760 | + if(ido>=l1) | ||
761 | + { | ||
762 | + for(k=0; k<l1; k++) | ||
763 | + { | ||
764 | + for(i=0; i<ido; i++) | ||
765 | + { | ||
766 | + ch[i+k*ido]=cc[i+k*ip*ido]; | ||
767 | + } | ||
768 | + } | ||
769 | + } | ||
770 | + else | ||
771 | + { | ||
772 | + for(i=0; i<ido; i++) | ||
773 | + { | ||
774 | + for(k=0; k<l1; k++) | ||
775 | + { | ||
776 | + ch[i+k*ido]=cc[i+k*ip*ido]; | ||
777 | + } | ||
778 | + } | ||
779 | + } | ||
780 | + for(j=1; j<ipph; j++) | ||
781 | + { | ||
782 | + jc=ip-j; | ||
783 | + j2=2*j; | ||
784 | + for(k=0; k<l1; k++) | ||
785 | + { | ||
786 | + ch[(k+j*l1)*ido]=cc[ido-1+(j2-1+k*ip)*ido]+cc[ido-1+(j2-1+k*ip)*ido]; | ||
787 | + ch[(k+jc*l1)*ido]=cc[(j2+k*ip)*ido]+cc[(j2+k*ip)*ido]; | ||
788 | + } | ||
789 | + } | ||
790 | + | ||
791 | + if(ido !=1) | ||
792 | + { | ||
793 | + if(nbd>=l1) | ||
794 | + { | ||
795 | + for(j=1; j<ipph; j++) | ||
796 | + { | ||
797 | + jc=ip-j; | ||
798 | + for(k=0; k<l1; k++) | ||
799 | + { | ||
800 | + for(i=2; i<ido; i+=2) | ||
801 | + { | ||
802 | + ic=ido-i; | ||
803 | + ch[i-1+(k+j*l1)*ido]=cc[i-1+(2*j+k*ip)*ido]+cc[ic-1+(2*j-1+k*ip)*ido]; | ||
804 | + ch[i-1+(k+jc*l1)*ido]=cc[i-1+(2*j+k*ip)*ido]-cc[ic-1+(2*j-1+k*ip)*ido]; | ||
805 | + ch[i+(k+j*l1)*ido]=cc[i+(2*j+k*ip)*ido]-cc[ic+(2*j-1+k*ip)*ido]; | ||
806 | + ch[i+(k+jc*l1)*ido]=cc[i+(2*j+k*ip)*ido]+cc[ic+(2*j-1+k*ip)*ido]; | ||
807 | + } | ||
808 | + } | ||
809 | + } | ||
810 | + } | ||
811 | + else | ||
812 | + { | ||
813 | + for(j=1; j<ipph; j++) | ||
814 | + { | ||
815 | + jc=ip-j; | ||
816 | + for(i=2; i<ido; i+=2) | ||
817 | + { | ||
818 | + ic=ido-i; | ||
819 | + for(k=0; k<l1; k++) | ||
820 | + { | ||
821 | + ch[i-1+(k+j*l1)*ido]=cc[i-1+(2*j+k*ip)*ido]+cc[ic-1+(2*j-1+k*ip)*ido]; | ||
822 | + ch[i-1+(k+jc*l1)*ido]=cc[i-1+(2*j+k*ip)*ido]-cc[ic-1+(2*j-1+k*ip)*ido]; | ||
823 | + ch[i+(k+j*l1)*ido]=cc[i+(2*j+k*ip)*ido]-cc[ic+(2*j-1+k*ip)*ido]; | ||
824 | + ch[i+(k+jc*l1)*ido]=cc[i+(2*j+k*ip)*ido]+cc[ic+(2*j-1+k*ip)*ido]; | ||
825 | + } | ||
826 | + } | ||
827 | + } | ||
828 | + } | ||
829 | + } | ||
830 | + | ||
831 | + ar1=1; | ||
832 | + ai1=0; | ||
833 | + for(l=1; l<ipph; l++) | ||
834 | + { | ||
835 | + lc=ip-l; | ||
836 | + ar1h=dcp*ar1-dsp*ai1; | ||
837 | + ai1=dcp*ai1+dsp*ar1; | ||
838 | + ar1=ar1h; | ||
839 | + for(ik=0; ik<idl1; ik++) | ||
840 | + { | ||
841 | + c2[ik+l*idl1]=ch2[ik]+ar1*ch2[ik+idl1]; | ||
842 | + c2[ik+lc*idl1]=ai1*ch2[ik+(ip-1)*idl1]; | ||
843 | + } | ||
844 | + dc2=ar1; | ||
845 | + ds2=ai1; | ||
846 | + ar2=ar1; | ||
847 | + ai2=ai1; | ||
848 | + for(j=2; j<ipph; j++) | ||
849 | + { | ||
850 | + jc=ip-j; | ||
851 | + ar2h=dc2*ar2-ds2*ai2; | ||
852 | + ai2=dc2*ai2+ds2*ar2; | ||
853 | + ar2=ar2h; | ||
854 | + for(ik=0; ik<idl1; ik++) | ||
855 | + { | ||
856 | + c2[ik+l*idl1]+=ar2*ch2[ik+j*idl1]; | ||
857 | + c2[ik+lc*idl1]+=ai2*ch2[ik+jc*idl1]; | ||
858 | + } | ||
859 | + } | ||
860 | + } | ||
861 | + for(j=1; j<ipph; j++) | ||
862 | + { | ||
863 | + for(ik=0; ik<idl1; ik++) | ||
864 | + { | ||
865 | + ch2[ik]+=ch2[ik+j*idl1]; | ||
866 | + } | ||
867 | + } | ||
868 | + for(j=1; j<ipph; j++) | ||
869 | + { | ||
870 | + jc=ip-j; | ||
871 | + for(k=0; k<l1; k++) | ||
872 | + { | ||
873 | + ch[(k+j*l1)*ido]=c1[(k+j*l1)*ido]-c1[(k+jc*l1)*ido]; | ||
874 | + ch[(k+jc*l1)*ido]=c1[(k+j*l1)*ido]+c1[(k+jc*l1)*ido]; | ||
875 | + } | ||
876 | + } | ||
877 | + | ||
878 | + if(ido==1) return; | ||
879 | + if(nbd>=l1) | ||
880 | + { | ||
881 | + for(j=1; j<ipph; j++) | ||
882 | + { | ||
883 | + jc=ip-j; | ||
884 | + for(k=0; k<l1; k++) | ||
885 | + { | ||
886 | + for(i=2; i<ido; i+=2) | ||
887 | + { | ||
888 | + ch[i-1+(k+j*l1)*ido]=c1[i-1+(k+j*l1)*ido]-c1[i+(k+jc*l1)*ido]; | ||
889 | + ch[i-1+(k+jc*l1)*ido]=c1[i-1+(k+j*l1)*ido]+c1[i+(k+jc*l1)*ido]; | ||
890 | + ch[i+(k+j*l1)*ido]=c1[i+(k+j*l1)*ido]+c1[i-1+(k+jc*l1)*ido]; | ||
891 | + ch[i+(k+jc*l1)*ido]=c1[i+(k+j*l1)*ido]-c1[i-1+(k+jc*l1)*ido]; | ||
892 | + } | ||
893 | + } | ||
894 | + } | ||
895 | + } | ||
896 | + else | ||
897 | + { | ||
898 | + for(j=1; j<ipph; j++) | ||
899 | + { | ||
900 | + jc=ip-j; | ||
901 | + for(i=2; i<ido; i+=2) | ||
902 | + { | ||
903 | + for(k=0; k<l1; k++) | ||
904 | + { | ||
905 | + ch[i-1+(k+j*l1)*ido]=c1[i-1+(k+j*l1)*ido]-c1[i+(k+jc*l1)*ido]; | ||
906 | + ch[i-1+(k+jc*l1)*ido]=c1[i-1+(k+j*l1)*ido]+c1[i+(k+jc*l1)*ido]; | ||
907 | + ch[i+(k+j*l1)*ido]=c1[i+(k+j*l1)*ido]+c1[i-1+(k+jc*l1)*ido]; | ||
908 | + ch[i+(k+jc*l1)*ido]=c1[i+(k+j*l1)*ido]-c1[i-1+(k+jc*l1)*ido]; | ||
909 | + } | ||
910 | + } | ||
911 | + } | ||
912 | + } | ||
913 | + for(ik=0; ik<idl1; ik++) c2[ik]=ch2[ik]; | ||
914 | + for(j=1; j<ip; j++) | ||
915 | + for(k=0; k<l1; k++) | ||
916 | + c1[(k+j*l1)*ido]=ch[(k+j*l1)*ido]; | ||
917 | + if(nbd<=l1) | ||
918 | + { | ||
919 | + is=-ido; | ||
920 | + for(j=1; j<ip; j++) | ||
921 | + { | ||
922 | + is+=ido; | ||
923 | + idij=is-1; | ||
924 | + for(i=2; i<ido; i+=2) | ||
925 | + { | ||
926 | + idij+=2; | ||
927 | + for(k=0; k<l1; k++) | ||
928 | + { | ||
929 | + c1[i-1+(k+j*l1)*ido] = wtable[idij-1+iw1]*ch[i-1+(k+j*l1)*ido] | ||
930 | + -wtable[idij+iw1]*ch[i+(k+j*l1)*ido]; | ||
931 | + c1[i+(k+j*l1)*ido] = wtable[idij-1+iw1]*ch[i+(k+j*l1)*ido] | ||
932 | + +wtable[idij+iw1]*ch[i-1+(k+j*l1)*ido]; | ||
933 | + } | ||
934 | + } | ||
935 | + } | ||
936 | + } | ||
937 | + else | ||
938 | + { | ||
939 | + is=-ido; | ||
940 | + for(j=1; j<ip; j++) | ||
941 | + { | ||
942 | + is+=ido; | ||
943 | + for(k=0; k<l1; k++) | ||
944 | + { | ||
945 | + idij=is-1; | ||
946 | + for(i=2; i<ido; i+=2) | ||
947 | + { | ||
948 | + idij+=2; | ||
949 | + c1[i-1+(k+j*l1)*ido] = wtable[idij-1+iw1]*ch[i-1+(k+j*l1)*ido] | ||
950 | + -wtable[idij+iw1]*ch[i+(k+j*l1)*ido]; | ||
951 | + c1[i+(k+j*l1)*ido] = wtable[idij-1+iw1]*ch[i+(k+j*l1)*ido] | ||
952 | + +wtable[idij+iw1]*ch[i-1+(k+j*l1)*ido]; | ||
953 | + } | ||
954 | + } | ||
955 | + } | ||
956 | + } | ||
957 | + } | ||
958 | + | ||
959 | +/*--------------------------------------------------------- | ||
960 | + rfftf1: further processing of Real forward FFT | ||
961 | + --------------------------------------------------------*/ | ||
962 | + void rfftf1(int n, double c[], final double wtable[], int offset) | ||
963 | + { | ||
964 | + int i; | ||
965 | + int k1, l1, l2, na, kh, nf, ip, iw, ido, idl1; | ||
966 | + | ||
967 | + double[] ch = new double[n]; | ||
968 | + System.arraycopy(wtable, offset, ch, 0, n); | ||
969 | + | ||
970 | + nf=(int)wtable[1+2*n+offset]; | ||
971 | + na=1; | ||
972 | + l2=n; | ||
973 | + iw=n-1+n+offset; | ||
974 | + for(k1=1; k1<=nf;++k1) | ||
975 | + { | ||
976 | + kh=nf-k1; | ||
977 | + ip=(int)wtable[kh+2+2*n+offset]; | ||
978 | + l1=l2 / ip; | ||
979 | + ido=n / l2; | ||
980 | + idl1=ido*l1; | ||
981 | + iw-=(ip-1)*ido; | ||
982 | + na=1-na; | ||
983 | + if(ip==4) | ||
984 | + { | ||
985 | + if(na==0) | ||
986 | + { | ||
987 | + radf4(ido, l1, c, ch, wtable, iw); | ||
988 | + } | ||
989 | + else | ||
990 | + { | ||
991 | + radf4(ido, l1, ch, c, wtable, iw); | ||
992 | + } | ||
993 | + } | ||
994 | + else if(ip==2) | ||
995 | + { | ||
996 | + if(na==0) | ||
997 | + { | ||
998 | + radf2(ido, l1, c, ch, wtable, iw); | ||
999 | + } | ||
1000 | + else | ||
1001 | + { | ||
1002 | + radf2(ido, l1, ch, c, wtable, iw); | ||
1003 | + } | ||
1004 | + } | ||
1005 | + else if(ip==3) | ||
1006 | + { | ||
1007 | + if(na==0) | ||
1008 | + { | ||
1009 | + radf3(ido, l1, c, ch, wtable, iw); | ||
1010 | + } | ||
1011 | + else | ||
1012 | + { | ||
1013 | + radf3(ido, l1, ch, c, wtable, iw); | ||
1014 | + } | ||
1015 | + } | ||
1016 | + else if(ip==5) | ||
1017 | + { | ||
1018 | + if(na==0) | ||
1019 | + { | ||
1020 | + radf5(ido, l1, c, ch, wtable, iw); | ||
1021 | + } | ||
1022 | + else | ||
1023 | + { | ||
1024 | + radf5(ido, l1, ch, c, wtable, iw); | ||
1025 | + } | ||
1026 | + } | ||
1027 | + else | ||
1028 | + { | ||
1029 | + if(ido==1) na=1-na; | ||
1030 | + if(na==0) | ||
1031 | + { | ||
1032 | + radfg(ido, ip, l1, idl1, c, c, c, ch, ch, wtable, iw); | ||
1033 | + na=1; | ||
1034 | + } | ||
1035 | + else | ||
1036 | + { | ||
1037 | + radfg(ido, ip, l1, idl1, ch, ch, ch, c, c, wtable, iw); | ||
1038 | + na=0; | ||
1039 | + } | ||
1040 | + } | ||
1041 | + l2=l1; | ||
1042 | + } | ||
1043 | + if(na==1) return; | ||
1044 | + for(i=0; i<n; i++) c[i]=ch[i]; | ||
1045 | + } | ||
1046 | + | ||
1047 | +/*--------------------------------------------------------- | ||
1048 | + rfftb1: further processing of Real backward FFT | ||
1049 | + --------------------------------------------------------*/ | ||
1050 | + void rfftb1(int n, double c[], final double wtable[], int offset) | ||
1051 | + { | ||
1052 | + int i; | ||
1053 | + int k1, l1, l2, na, nf, ip, iw, ido, idl1; | ||
1054 | + | ||
1055 | + double[] ch = new double[n]; | ||
1056 | + System.arraycopy(wtable, offset, ch, 0, n); | ||
1057 | + | ||
1058 | + nf=(int)wtable[1+2*n+offset]; | ||
1059 | + na=0; | ||
1060 | + l1=1; | ||
1061 | + iw=n+offset; | ||
1062 | + for(k1=1; k1<=nf; k1++) | ||
1063 | + { | ||
1064 | + ip=(int)wtable[k1+1+2*n+offset]; | ||
1065 | + l2=ip*l1; | ||
1066 | + ido=n / l2; | ||
1067 | + idl1=ido*l1; | ||
1068 | + if(ip==4) | ||
1069 | + { | ||
1070 | + if(na==0) | ||
1071 | + { | ||
1072 | + radb4(ido, l1, c, ch, wtable, iw); | ||
1073 | + } | ||
1074 | + else | ||
1075 | + { | ||
1076 | + radb4(ido, l1, ch, c, wtable, iw); | ||
1077 | + } | ||
1078 | + na=1-na; | ||
1079 | + } | ||
1080 | + else if(ip==2) | ||
1081 | + { | ||
1082 | + if(na==0) | ||
1083 | + { | ||
1084 | + radb2(ido, l1, c, ch, wtable, iw); | ||
1085 | + } | ||
1086 | + else | ||
1087 | + { | ||
1088 | + radb2(ido, l1, ch, c, wtable, iw); | ||
1089 | + } | ||
1090 | + na=1-na; | ||
1091 | + } | ||
1092 | + else if(ip==3) | ||
1093 | + { | ||
1094 | + if(na==0) | ||
1095 | + { | ||
1096 | + radb3(ido, l1, c, ch, wtable, iw); | ||
1097 | + } | ||
1098 | + else | ||
1099 | + { | ||
1100 | + radb3(ido, l1, ch, c, wtable, iw); | ||
1101 | + } | ||
1102 | + na=1-na; | ||
1103 | + } | ||
1104 | + else if(ip==5) | ||
1105 | + { | ||
1106 | + if(na==0) | ||
1107 | + { | ||
1108 | + radb5(ido, l1, c, ch, wtable, iw); | ||
1109 | + } | ||
1110 | + else | ||
1111 | + { | ||
1112 | + radb5(ido, l1, ch, c, wtable, iw); | ||
1113 | + } | ||
1114 | + na=1-na; | ||
1115 | + } | ||
1116 | + else | ||
1117 | + { | ||
1118 | + if(na==0) | ||
1119 | + { | ||
1120 | + radbg(ido, ip, l1, idl1, c, c, c, ch, ch, wtable, iw); | ||
1121 | + } | ||
1122 | + else | ||
1123 | + { | ||
1124 | + radbg(ido, ip, l1, idl1, ch, ch, ch, c, c, wtable, iw); | ||
1125 | + } | ||
1126 | + if(ido==1) na=1-na; | ||
1127 | + } | ||
1128 | + l1=l2; | ||
1129 | + iw+=(ip-1)*ido; | ||
1130 | + } | ||
1131 | + if(na==0) return; | ||
1132 | + for(i=0; i<n; i++) c[i]=ch[i]; | ||
1133 | + } | ||
1134 | + | ||
1135 | +/*--------------------------------------------------------- | ||
1136 | + rfftf: Real forward FFT | ||
1137 | + --------------------------------------------------------*/ | ||
1138 | + void rfftf(int n, double r[], double wtable[]) | ||
1139 | + { | ||
1140 | + if(n==1) return; | ||
1141 | + rfftf1(n, r, wtable, 0); | ||
1142 | + } /*rfftf*/ | ||
1143 | + | ||
1144 | +/*--------------------------------------------------------- | ||
1145 | + rfftf: Real backward FFT | ||
1146 | + --------------------------------------------------------*/ | ||
1147 | + void rfftb(int n, double r[], double wtable[]) | ||
1148 | + { | ||
1149 | + if(n==1) return; | ||
1150 | + rfftb1(n, r, wtable, 0); | ||
1151 | + } /*rfftb*/ | ||
1152 | + | ||
1153 | +/*--------------------------------------------------------- | ||
1154 | + rffti1: further initialization of Real FFT | ||
1155 | + --------------------------------------------------------*/ | ||
1156 | + void rffti1(int n, double wtable[], int offset) | ||
1157 | + { | ||
1158 | + | ||
1159 | + final int[] ntryh= new int[] {4, 2, 3, 5}; | ||
1160 | + final double twopi=2.0D*Math.PI; | ||
1161 | + double argh; | ||
1162 | + int ntry=0, i, j; | ||
1163 | + double argld; | ||
1164 | + int k1, l1, l2, ib; | ||
1165 | + double fi; | ||
1166 | + int ld, ii, nf, ip, nl, is, nq, nr; | ||
1167 | + double arg; | ||
1168 | + int ido, ipm; | ||
1169 | + int nfm1; | ||
1170 | + | ||
1171 | + nl=n; | ||
1172 | + nf=0; | ||
1173 | + j=0; | ||
1174 | + | ||
1175 | + factorize_loop: | ||
1176 | + while(true) | ||
1177 | + { | ||
1178 | + ++j; | ||
1179 | + if(j<=4) | ||
1180 | + ntry=ntryh[j-1]; | ||
1181 | + else | ||
1182 | + ntry+=2; | ||
1183 | + do | ||
1184 | + { | ||
1185 | + nq=nl / ntry; | ||
1186 | + nr=nl-ntry*nq; | ||
1187 | + if(nr !=0) continue factorize_loop; | ||
1188 | + ++nf; | ||
1189 | + wtable[nf+1+2*n+offset]=ntry; | ||
1190 | + | ||
1191 | + nl=nq; | ||
1192 | + if(ntry==2 && nf !=1) | ||
1193 | + { | ||
1194 | + for(i=2; i<=nf; i++) | ||
1195 | + { | ||
1196 | + ib=nf-i+2; | ||
1197 | + wtable[ib+1+2*n+offset]=wtable[ib+2*n+offset]; | ||
1198 | + } | ||
1199 | + wtable[2+2*n+offset]=2; | ||
1200 | + } | ||
1201 | + }while(nl !=1); | ||
1202 | + break factorize_loop; | ||
1203 | + } | ||
1204 | + wtable[0+2*n+offset] = n; | ||
1205 | + wtable[1+2*n+offset] = nf; | ||
1206 | + argh=twopi /(double)(n); | ||
1207 | + is=0; | ||
1208 | + nfm1=nf-1; | ||
1209 | + l1=1; | ||
1210 | + if(nfm1==0) return; | ||
1211 | + for(k1=1; k1<=nfm1; k1++) | ||
1212 | + { | ||
1213 | + ip=(int)wtable[k1+1+2*n+offset]; | ||
1214 | + ld=0; | ||
1215 | + l2=l1*ip; | ||
1216 | + ido=n / l2; | ||
1217 | + ipm=ip-1; | ||
1218 | + for(j=1; j<=ipm;++j) | ||
1219 | + { | ||
1220 | + ld+=l1; | ||
1221 | + i=is; | ||
1222 | + argld=(double)ld*argh; | ||
1223 | + | ||
1224 | + fi=0; | ||
1225 | + for(ii=3; ii<=ido; ii+=2) | ||
1226 | + { | ||
1227 | + i+=2; | ||
1228 | + fi+=1; | ||
1229 | + arg=fi*argld; | ||
1230 | + wtable[i-2+n+offset] = Math.cos(arg); | ||
1231 | + wtable[i-1+n+offset] = Math.sin(arg); | ||
1232 | + } | ||
1233 | + is+=ido; | ||
1234 | + } | ||
1235 | + l1=l2; | ||
1236 | + } | ||
1237 | + } /*rffti1*/ | ||
1238 | + | ||
1239 | +/*--------------------------------------------------------- | ||
1240 | + rffti: Initialization of Real FFT | ||
1241 | + --------------------------------------------------------*/ | ||
1242 | + void rffti(int n, double wtable[]) /* length of wtable = 2*n + 15 */ | ||
1243 | + { | ||
1244 | + if(n==1) return; | ||
1245 | + rffti1(n, wtable, 0); | ||
1246 | + } /*rffti*/ | ||
1247 | + | ||
1248 | +} |
app/src/main/java/com/example/zhongqiyan/javasource/ca/uol/aig/fftpack/RealDoubleFFT_Odd.java
0 → 100644
1 | +package com.example.zhongqiyan.javasource.ca.uol.aig.fftpack; | ||
2 | +/** | ||
3 | + * sine FFT transform of a real odd sequence. | ||
4 | + * @author Baoshe Zhang | ||
5 | + * @author Astronomical Instrument Group of University of Lethbridge. | ||
6 | +*/ | ||
7 | +public class RealDoubleFFT_Odd extends RealDoubleFFT_Mixed | ||
8 | +{ | ||
9 | +/** | ||
10 | + * <em>norm_factor</em> can be used to normalize this FFT transform. This is because | ||
11 | + * a call of forward transform (<em>ft</em>) followed by a call of backward | ||
12 | + * transform (<em>bt</em>) will multiply the input sequence by <em>norm_factor</em>. | ||
13 | +*/ | ||
14 | + public double norm_factor; | ||
15 | + private double wavetable[]; | ||
16 | + private int ndim; | ||
17 | + | ||
18 | + | ||
19 | +/** | ||
20 | + * Construct a wavenumber table with size <em>n</em>. | ||
21 | + * The sequences with the same size can share a wavenumber table. The prime | ||
22 | + * factorization of <em>n</em> together with a tabulation of the trigonometric functions | ||
23 | + * are computed and stored. | ||
24 | + * | ||
25 | + * @param n the size of a real data sequence. When (<em>n</em>+1) is a multiplication of small | ||
26 | + * numbers (4, 2, 3, 5), this FFT transform is very efficient. | ||
27 | +*/ | ||
28 | + public RealDoubleFFT_Odd(int n) | ||
29 | + { | ||
30 | + ndim = n; | ||
31 | + norm_factor = 2*(n+1); | ||
32 | + int wtable_length = 2*ndim + ndim/2 + 3 + 15; | ||
33 | + if(wavetable == null || wavetable.length != wtable_length) | ||
34 | + { | ||
35 | + wavetable = new double[wtable_length]; | ||
36 | + } | ||
37 | + sinti(ndim, wavetable); | ||
38 | + } | ||
39 | +/** | ||
40 | + * Forward sine FFT transform. It computes the discrete sine transform of | ||
41 | + * an odd sequence. | ||
42 | + * | ||
43 | + * @param x an array which contains the sequence to be transformed. After FFT, | ||
44 | + * <em>x</em> contains the transform coeffients. | ||
45 | +*/ | ||
46 | + public void ft(double x[]) | ||
47 | + { | ||
48 | + sint(ndim, x, wavetable); | ||
49 | + } | ||
50 | +/** | ||
51 | + * Backward sine FFT transform. It is the unnormalized inverse transform of <em>ft</em>. | ||
52 | + * | ||
53 | + * @param x an array which contains the sequence to be transformed. After FFT, | ||
54 | + * <em>x</em> contains the transform coeffients. | ||
55 | +*/ | ||
56 | + public void bt(double x[]) | ||
57 | + { | ||
58 | + sint(ndim, x, wavetable); | ||
59 | + } | ||
60 | + | ||
61 | +/*--------------------------------------- | ||
62 | + sint1: further processing of sine FFT. | ||
63 | + --------------------------------------*/ | ||
64 | + | ||
65 | + void sint1(int n, double war[], double wtable[]) | ||
66 | + { | ||
67 | + final double sqrt3=1.73205080756888; | ||
68 | + int modn, i, k; | ||
69 | + double xhold, t1, t2; | ||
70 | + int kc, np1, ns2; | ||
71 | + int iw1, iw2, iw3; | ||
72 | + double[] wtable_p1 = new double[2*(n+1)+15]; | ||
73 | + iw1=n / 2; | ||
74 | + iw2=iw1+n+1; | ||
75 | + iw3=iw2+n+1; | ||
76 | + | ||
77 | + double[] x = new double[n+1]; | ||
78 | + | ||
79 | + for(i=0; i<n; i++) | ||
80 | + { | ||
81 | + wtable[i+iw1]=war[i]; | ||
82 | + war[i]=wtable[i+iw2]; | ||
83 | + } | ||
84 | + if(n<2) | ||
85 | + { | ||
86 | + wtable[0+iw1]+=wtable[0+iw1]; | ||
87 | + } | ||
88 | + else if(n==2) | ||
89 | + { | ||
90 | + xhold=sqrt3*(wtable[0+iw1]+wtable[1+iw1]); | ||
91 | + wtable[1+iw1]=sqrt3*(wtable[0+iw1]-wtable[1+iw1]); | ||
92 | + wtable[0+iw1]=xhold; | ||
93 | + } | ||
94 | + else | ||
95 | + { | ||
96 | + np1=n+1; | ||
97 | + ns2=n / 2; | ||
98 | + wtable[0+iw2]=0; | ||
99 | + for(k=0; k<ns2; k++) | ||
100 | + { | ||
101 | + kc=n-k-1; | ||
102 | + t1=wtable[k+iw1]-wtable[kc+iw1]; | ||
103 | + t2=wtable[k]*(wtable[k+iw1]+wtable[kc+iw1]); | ||
104 | + wtable[k+1+iw2]=t1+t2; | ||
105 | + wtable[kc+1+iw2]=t2-t1; | ||
106 | + } | ||
107 | + modn=n%2; | ||
108 | + if(modn !=0) | ||
109 | + wtable[ns2+1+iw2]=4*wtable[ns2+iw1]; | ||
110 | + System.arraycopy(wtable, iw1, wtable_p1, 0, n+1); | ||
111 | + System.arraycopy(war, 0, wtable_p1, n+1, n); | ||
112 | + System.arraycopy(wtable, iw3, wtable_p1, 2*(n+1), 15); | ||
113 | + System.arraycopy(wtable, iw2, x, 0, n+1); | ||
114 | + rfftf1(np1, x, wtable_p1, 0); | ||
115 | + System.arraycopy(x, 0, wtable, iw2, n+1); | ||
116 | + wtable[0+iw1]=0.5*wtable[0+iw2]; | ||
117 | + for(i=2; i<n; i+=2) | ||
118 | + { | ||
119 | + wtable[i-1+iw1]=-wtable[i+iw2]; | ||
120 | + wtable[i+iw1]=wtable[i-2+iw1]+wtable[i-1+iw2]; | ||
121 | + } | ||
122 | + if(modn==0) | ||
123 | + wtable[n-1+iw1]=-wtable[n+iw2]; | ||
124 | + } | ||
125 | + for(i=0; i<n; i++) | ||
126 | + { | ||
127 | + wtable[i+iw2]=war[i]; | ||
128 | + war[i]=wtable[i+iw1]; | ||
129 | + } | ||
130 | + } | ||
131 | + | ||
132 | +/*---------------- | ||
133 | + sint: sine FFT | ||
134 | + ---------------*/ | ||
135 | + void sint(int n, double x[], double wtable[]) | ||
136 | + { | ||
137 | + sint1(n, x, wtable); | ||
138 | + } | ||
139 | + | ||
140 | +/*---------------------------------------------------------------------- | ||
141 | + sinti: initialization of sin-FFT | ||
142 | + ----------------------------------------------------------------------*/ | ||
143 | + void sinti(int n, double wtable[]) | ||
144 | + { | ||
145 | + final double pi=Math.PI; //3.14159265358979; | ||
146 | + int k, ns2; | ||
147 | + double dt; | ||
148 | + | ||
149 | + if(n<=1) return; | ||
150 | + ns2=n / 2; | ||
151 | + dt=pi /(double)(n+1); | ||
152 | + for(k=0; k<ns2; k++) | ||
153 | + wtable[k]=2*Math.sin((k+1)*dt); | ||
154 | + rffti1(n+1, wtable, ns2); | ||
155 | + } | ||
156 | + | ||
157 | +} |
-
请 注册 或 登录 后发表评论