Skip to content

Commit

Permalink
音频修改工具
Browse files Browse the repository at this point in the history
  • Loading branch information
AxeChen committed Jan 2, 2018
1 parent c39ac50 commit 8ba9f38
Show file tree
Hide file tree
Showing 62 changed files with 6,601 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
46 changes: 46 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

find_library( log-lib
log )

set(my_lib_path ${CMAKE_SOURCE_DIR}/libs)

# 添加三方的so库
add_library(libfmod
SHARED
IMPORTED )
# 指名第三方库的绝对路径
set_target_properties( libfmod
PROPERTIES IMPORTED_LOCATION
${my_lib_path}/${ANDROID_ABI}/libfmod.so )

add_library(libfmodL
SHARED
IMPORTED )

set_target_properties( libfmodL
PROPERTIES IMPORTED_LOCATION
${my_lib_path}/${ANDROID_ABI}/libfmodL.so )

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

# 添加我们需要写代码的路径
add_library(changeVoice
SHARED
src/main/cpp/changeVoice.cpp )

# 导入路径,为了让编译时能够寻找到这个文件夹
include_directories(src/main/cpp/inc)

# 链接好三个路径
target_link_libraries( changeVoice
libfmod
libfmodL

${log-lib} )

48 changes: 48 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
applicationId "com.mg.axechen.changevoice"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
}
}

ndk {
abiFilters "armeabi","x86"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}

sourceSets.main {
jniLibs.srcDirs = ['libs']
jni.srcDirs = []
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Binary file added app/libs/armeabi/libfmod.so
Binary file not shown.
Binary file added app/libs/armeabi/libfmodL.so
Binary file not shown.
Binary file added app/libs/fmod.jar
Binary file not shown.
Binary file added app/libs/x86/libfmod.so
Binary file not shown.
Binary file added app/libs/x86/libfmodL.so
Binary file not shown.
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mg.axechen.changevoice;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.mg.axechen.changevoice", appContext.getPackageName());
}
}
23 changes: 23 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mg.axechen.changevoice">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
113 changes: 113 additions & 0 deletions app/src/main/cpp/changeVoice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include "com_mg_axechen_changevoice_VoiceTools.h"
#include "fmod.hpp"
#include <unistd.h>
#include <android/log.h>
using namespace FMOD;

// 定义五种不同的模式
#define MODE_NORMAL 0
#define MODE_LUOLI 1
#define MODE_DASHU 2
#define MODE_JINGSONG 3
#define MODE_GAOGUAI 4
#define MODE_KONGLING 5

#define LOGI(FORMAT,...) __android_log_print(ANDROID_LOG_INFO,"axe",FORMAT,##__VA_ARGS__);
#define LOGE(FORMAT,...) __android_log_print(ANDROID_LOG_ERROR,"axe",FORMAT,##__VA_ARGS__);
extern "C"

JNICALL
JNIEXPORT void JNICALL Java_com_mg_axechen_changevoice_VoiceTools_changeVoice
(JNIEnv *jniEnv, jclass jclass, jstring jstring,jint mode){

// 初始化fmod
FMOD::System *system;
FMOD::System_Create(&system);
Sound *sound;
// 通道(声音是由多种音效组成)
Channel *channel;
DSP *pDSP;
float frequency;

system->init(32,FMOD_INIT_NORMAL,NULL);

// 将 jstring转为 char
const char *path = jniEnv->GetStringUTFChars(jstring,NULL);

system->createSound(path,FMOD_DEFAULT,NULL,&sound);



try {
switch (mode){
case MODE_NORMAL:
LOGI("%s","正常");
system->playSound(sound,NULL, false,&channel);
break;
case MODE_DASHU:
system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT,&pDSP);
pDSP->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH,0.7);
system->playSound(sound,NULL, false,&channel);
channel->addDSP(0,pDSP);
LOGI("%s","正常");
break;
case MODE_LUOLI:
system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT,&pDSP);
pDSP->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH,3);
system->playSound(sound,NULL, false,&channel);
channel->addDSP(0,pDSP);
LOGI("%s","萝莉");
break;
case MODE_GAOGUAI:
LOGI("%s","搞怪");
system->createDSPByType(FMOD_DSP_TYPE_NORMALIZE, &pDSP);
system->playSound(sound, NULL, false, &channel);
channel->addDSP(0, pDSP);
channel->getFrequency(&frequency);
frequency = frequency*1.6;
channel->setFrequency(frequency);
break;
case MODE_JINGSONG:
// FMOD_DSP_TYPE_TREMOLO 颤抖

system->createDSPByType(FMOD_DSP_TYPE_TREMOLO, &pDSP);
pDSP->setParameterFloat(FMOD_DSP_TREMOLO_SKEW,0.5);

system->playSound(sound, NULL, false, &channel);
channel->addDSP(0, pDSP);
LOGI("%s","惊悚");
break;
case MODE_KONGLING:
LOGI("%s","空灵");
system->createDSPByType(FMOD_DSP_TYPE_ECHO, &pDSP);
pDSP->setParameterFloat(FMOD_DSP_ECHO_DELAY,300);
pDSP->setParameterFloat(FMOD_DSP_ECHO_FEEDBACK,20);
system->playSound(sound, NULL, false, &channel);
channel->addDSP(0, pDSP);
break;

}


system->update();
bool isPlaying = true;
// 需要等待,等声音全部播放完成
// 检查是否播放完成
while (isPlaying){
channel ->isPlaying(&isPlaying);
usleep(1000);
}
}catch (...){
goto end;
}

// 回收内存
end:
system->close();
system->release();
jniEnv ->ReleaseStringUTFChars(jstring,path);

}



22 changes: 22 additions & 0 deletions app/src/main/cpp/com_mg_axechen_changevoice_VoiceTools.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8ba9f38

Please sign in to comment.