diff --git a/README.MD b/README.MD index c6c5904..b7dc0e2 100644 --- a/README.MD +++ b/README.MD @@ -1,5 +1,7 @@ ## Android NDK +当前相关开发主要是为[Mp3Recorder](https://github.com/SheTieJun/Mp3Recorder) 服务 + ### [LAME](lame) - Lame官网(lame.sourceforge.io/index.php) diff --git a/lame/README.MD b/lame/README.MD index ecfceb5..a0d3555 100644 --- a/lame/README.MD +++ b/lame/README.MD @@ -1,4 +1,7 @@ ## Lame - Lame官网(lame.sourceforge.io/index.php) -- LAME是一个高质量的MPEG音频层III (MP3)编码器,在LGPL下授权 \ No newline at end of file +- LAME是一个高质量的MPEG音频层III (MP3)编码器,在LGPL下授权 + + +### [Mp3Recorder](https://github.com/SheTieJun/Mp3Recorder) \ No newline at end of file diff --git a/soundTouch/README.MD b/soundTouch/README.MD index 932fac4..186b67b 100644 --- a/soundTouch/README.MD +++ b/soundTouch/README.MD @@ -7,6 +7,8 @@ - 下载地址(https://codeberg.org/soundtouch/soundtouch) +### [Mp3Recorder](https://github.com/SheTieJun/Mp3Recorder)-recorder-st + ## SoundTouch公开函数与参数的说明 - version:2.3.1 [SoundTouch.cpp](src/main/cpp/soundtouch/SoundTouch.cpp) @@ -54,11 +56,13 @@ setRate(double newRate) //指定播放速率 fun setRate(speed: Float) + //一般用来设置倍速,我们变音,默认 1.0就好 fun setTempo(tempo: Float) //在原速1.0基础上,按百分比做增量,取值(-50 .. +100 %) fun setRateChange(@FloatRange(from = -50.0, to = 100.0) rateChange: Float) + //在原速1.0基础上 源tempo=1.0,小于1则变慢;大于1变快 tempo (-50 .. +100 %) fun setTempoChange(@FloatRange(from = -50.0, to = 100.0) tempoChange: Float) @@ -73,14 +77,12 @@ setRate(double newRate) fun processFile(inputFile: String, outputFile: String): Boolean //实时处理PCM 流 - fun processSamples( - input: ByteArray?, - samples: Int, - output: ByteArray?, - ) + fun putSamples(samples: ShortArray, len: Int) + + fun receiveSamples(outputBuf: ShortArray): Int //获取最后一段数据 - fun flush(mp3buf: ByteArray): Int + fun flush(mp3buf: ShortArray): Int fun close() ``` \ No newline at end of file diff --git a/soundTouch/src/main/cpp/soundtouch-jni.cpp b/soundTouch/src/main/cpp/soundtouch-jni.cpp index 96eaf34..0ffe679 100644 --- a/soundTouch/src/main/cpp/soundtouch-jni.cpp +++ b/soundTouch/src/main/cpp/soundtouch-jni.cpp @@ -268,8 +268,9 @@ Java_me_shetj_ndk_soundtouch_SoundTouch_putSamples(JNIEnv *env, jobject thiz, try { jboolean isArrayCopied = false; jshort *samplesArray = env->GetShortArrayElements(samples, &isArrayCopied); + int channel = pSoundTouch->numChannels(); - pSoundTouch->putSamples((SAMPLETYPE *) samplesArray, (uint) size); + pSoundTouch->putSamples((SAMPLETYPE *) samplesArray, size/channel); if (isArrayCopied) { env->ReleaseShortArrayElements(samples, samplesArray, 0); @@ -290,15 +291,16 @@ Java_me_shetj_ndk_soundtouch_SoundTouch_receiveSamples(JNIEnv *env, jobject thiz try { jboolean isArrayCopied = false; const jsize buf_size = env->GetArrayLength(output); + int channel = pSoundTouch->numChannels(); jshort *samplesArray = env->GetShortArrayElements(output, &isArrayCopied); - int nSamples = pSoundTouch->receiveSamples((SAMPLETYPE *) samplesArray, (uint) buf_size); + int nSamples = pSoundTouch->receiveSamples((SAMPLETYPE *) samplesArray,buf_size/channel); if (nSamples == 0) { return 0; } if (isArrayCopied) { env->ReleaseShortArrayElements(output, samplesArray, 0); } - return nSamples; + return nSamples*channel; } catch (const runtime_error &e) { const char *err = e.what(); @@ -319,13 +321,6 @@ Java_me_shetj_ndk_soundtouch_SoundTouch_flush(JNIEnv *env, jobject thiz, return -1; } pSoundTouch->flush(); //flush,然后处理最后的数据,可能处理不完,后续再测试一下,或者修改一下 - SAMPLETYPE sampleBuffer[BUFF_SIZE]; - int nSamples = pSoundTouch->receiveSamples(sampleBuffer, BUFF_SIZE); - - // 局部引用,创建一个short数组 - jshortArray receiveSamples = env->NewShortArray(nSamples); - // 给short数组设置值 - env->SetShortArrayRegion(outArray, 0, nSamples, (jshort *) sampleBuffer); return 0; } catch (const runtime_error &e) { const char *err = e.what(); diff --git a/soundTouch/src/main/libs/arm64-v8a/libsoundTouch.so b/soundTouch/src/main/libs/arm64-v8a/libsoundTouch.so index a150f19..2863234 100644 Binary files a/soundTouch/src/main/libs/arm64-v8a/libsoundTouch.so and b/soundTouch/src/main/libs/arm64-v8a/libsoundTouch.so differ diff --git a/soundTouch/src/main/libs/armeabi-v7a/libsoundTouch.so b/soundTouch/src/main/libs/armeabi-v7a/libsoundTouch.so index 8cde346..01c9d51 100644 Binary files a/soundTouch/src/main/libs/armeabi-v7a/libsoundTouch.so and b/soundTouch/src/main/libs/armeabi-v7a/libsoundTouch.so differ diff --git a/soundTouch/src/main/libs/x86/libsoundTouch.so b/soundTouch/src/main/libs/x86/libsoundTouch.so index e110e1d..6dbf39d 100644 Binary files a/soundTouch/src/main/libs/x86/libsoundTouch.so and b/soundTouch/src/main/libs/x86/libsoundTouch.so differ diff --git a/soundTouch/src/main/libs/x86_64/libsoundTouch.so b/soundTouch/src/main/libs/x86_64/libsoundTouch.so index 8b9d069..1ac17c2 100644 Binary files a/soundTouch/src/main/libs/x86_64/libsoundTouch.so and b/soundTouch/src/main/libs/x86_64/libsoundTouch.so differ