Skip to content

Commit

Permalink
Fix flush and update README.MD
Browse files Browse the repository at this point in the history
  • Loading branch information
SheTieJun committed Nov 10, 2021
1 parent 34b0766 commit 2c826b9
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Android NDK

当前相关开发主要是为[Mp3Recorder](https://github.com/SheTieJun/Mp3Recorder) 服务

### [LAME](lame)

- Lame官网(lame.sourceforge.io/index.php)
Expand Down
5 changes: 4 additions & 1 deletion lame/README.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Lame
- Lame官网(lame.sourceforge.io/index.php)

- LAME是一个高质量的MPEG音频层III (MP3)编码器,在LGPL下授权
- LAME是一个高质量的MPEG音频层III (MP3)编码器,在LGPL下授权


### [Mp3Recorder](https://github.com/SheTieJun/Mp3Recorder)
14 changes: 8 additions & 6 deletions soundTouch/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
```
15 changes: 5 additions & 10 deletions soundTouch/src/main/cpp/soundtouch-jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Binary file modified soundTouch/src/main/libs/arm64-v8a/libsoundTouch.so
Binary file not shown.
Binary file modified soundTouch/src/main/libs/armeabi-v7a/libsoundTouch.so
Binary file not shown.
Binary file modified soundTouch/src/main/libs/x86/libsoundTouch.so
Binary file not shown.
Binary file modified soundTouch/src/main/libs/x86_64/libsoundTouch.so
Binary file not shown.

0 comments on commit 2c826b9

Please sign in to comment.