1. The background
In the recent project, we need to realize unchangeable tone and tune-change of audio. We have consulted the open source library, mainly Soundtouch.
The official Android Demo source is Eclipse, and the native code path is also relative. This article mainly records the migration of Android Demo to Android Studio, the successful compilation of so file, and the normal running of Demo.
2. Migrate to Android Studio
- Download the latest soundTouch code
git clone https://gitlab.com/soundtouch/soundtouch.git
Copy the code
- Open Android Studio and import Android Demo
The android Demo path is as follows:
/Users/mac/work/code/android/soundtouch/source/Android-lib
Copy the code
Open Android Studio and select Import Project (Gradle, Eclipse ADT, etc.) to Import the project
- At this point Android Studio automatically converts the Eclipse project to the Android Studio project format
- The project is called SoundTouchAndroidLib.
- Configure the NDK environment
(1) in the project SoundTouchAndroidLib/gradle. The properties of new
android.useDeprecatedNdk=true
Copy the code
If you don’t have gradle.properties, create one and (2) download the NDK
- Select Cmake, LLDB, NDK and click Apply to download the corresponding files. (3) Configure the NDK path for the project
Configure the NDK path (4) in/Users/MAC/work/code/SoundTouchAndroidLib/app/build. Gradle added
sourceSets.main {
jni.srcDirs = ['libs']}Copy the code
(5) Copy SoudnTouch Native code to the project
New directory/Users/MAC/work/code/SoundTouchAndroidLib/app/SRC/main/jni/SoundTouch, copy native code, mainly including
-
soundtouch/source/SoundTouch
-
soundtouch/source/SoundStretch
-
soundtouch/include
(6) Find the sttypes. h header and remove the original comment #define ST_NO_EXCEPTION_HANDLING 1.
(7) Modify the. H reference path
-
Open the jni/source – the jni. CPP, will
#include ".. /.. /.. /include/SoundTouch.h"
#include ".. /source/SoundStretch/WavFile.h"
Copy the code
Modified to
#include "SoundTouch/include/SoundTouch.h"
#include "SoundTouch/SoundStretch/WavFile.h"
Copy the code
- Open jni/Android.mk and will
LOCAL_MODULE := soundtouch LOCAL_SRC_FILES := soundtouch-jni.cpp .. /.. /SoundTouch/AAFilter.cpp .. /.. /SoundTouch/FIFOSampleBuffer.cpp \ .. /.. /SoundTouch/FIRFilter.cpp .. /.. /SoundTouch/cpu_detect_x86.cpp \ .. /.. /SoundTouch/sse_optimized.cpp .. /.. /SoundStretch/WavFile.cpp \ .. /.. /SoundTouch/RateTransposer.cpp .. /.. /SoundTouch/SoundTouch.cpp \ .. /.. /SoundTouch/InterpolateCubic.cpp .. /.. /SoundTouch/InterpolateLinear.cpp \ .. /.. /SoundTouch/InterpolateShannon.cpp .. /.. /SoundTouch/TDStretch.cpp \ .. /.. /SoundTouch/BPMDetect.cpp .. /.. /SoundTouch/PeakFinder.cpp# for native audio
LOCAL_SHARED_LIBRARIES += -lgcc
Copy the code
Modified to
LOCAL_MODULE := soundtouch LOCAL_SRC_FILES := soundtouch-jni.cpp \ SoundTouch/SoundTouch/AAFilter.cpp \ SoundTouch/SoundTouch/FIFOSampleBuffer.cpp \ SoundTouch/SoundTouch/FIRFilter.cpp \ SoundTouch/SoundTouch/cpu_detect_x86.cpp \ SoundTouch/SoundTouch/sse_optimized.cpp \ SoundTouch/SoundStretch/WavFile.cpp \ SoundTouch/SoundTouch/RateTransposer.cpp \ SoundTouch/SoundTouch/SoundTouch.cpp \ SoundTouch/SoundTouch/InterpolateCubic.cpp \ SoundTouch/SoundTouch/InterpolateLinear.cpp \ SoundTouch/SoundTouch/InterpolateShannon.cpp \ SoundTouch/SoundTouch/TDStretch.cpp \ SoundTouch/SoundTouch/BPMDetect.cpp \ SoundTouch/SoundTouch/PeakFinder.cpp \# for native audio
# LOCAL_SHARED_LIBRARIES += -lgcc
Copy the code
== Notice the line ==-lgcc is commented out
3. NDK compiles so file
(1) Run the Terminal tool to compile so
/Users/mac/work/code/env/android-ndk-r20/ndk-build NDK_PROJECT_PATH=/Users/mac/work/code/SoundTouchAndroidLib/app/src/main
Copy the code
(2) an error wrong path/Users/MAC/work/code/SoundTouchAndroidLib/app/SRC/main/jni/SoundTouch/SoundTouch/xx. H file include path needs to be modified.
- I’m compiling at a time, found an error to change a path, a little silly. (3) output so if xx.h file include path modification, should be able to get so file.
(4) Sweep the tail
- / Users/MAC/work/code/SoundTouchAndroidLib/app/SRC/main/renamed jniLibs libs folder
- / Users/MAC/work/code/SoundTouchAndroidLib/app/SRC/main/obj file to delete
4. Run Demo to verify the tuning effect
- Find a WAV file to verify the effect.
5. To summarize
- Practice is the mother of wisdom
6. Reference materials
- Soundtouch website
- Soundtouch source
- Android SoundTouch(Handling Audio)
- The article source