Skip to content

Commit 45b98a5

Browse files
committed
modify read me
1 parent 644a23d commit 45b98a5

3 files changed

Lines changed: 38 additions & 9 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# AndroidPcmResample
2-
an pcm resample library for Android
2+
an pcm resample library for Android based on [hutm/JSSRC](https://github.com/hutm/JSSRC)
33

4-
安卓上pcm数据(wav文件舍弃前44个字节即可)重新采样的库
4+
安卓上pcm数据重新采样的库
5+
如果是wav文件舍弃前44个字节之后 就是pcm数据
56

7+
8+
## 使用
9+
```java
10+
11+
File file = new File(getExternalFilesDir(null), "50waystosaygoodbye.pcm");
12+
//重新采样后生成的文件路径
13+
File targetWaveFile = new File(getExternalFilesDir(null), "50waystosaygoodbye_8.pcm");
14+
//源文件的采样率、通道数、采样位数
15+
PcmResample.AudioFileConfig srcFileConfig = new PcmResample.AudioFileConfig(file.getAbsolutePath(), 44100, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT);
16+
//生成文件的采样率、通道数(必须和源文件一样)、采样位数(必须和源文件一样)
17+
PcmResample.AudioFileConfig targetFileConfig = new PcmResample.AudioFileConfig(targetWaveFile.getAbsolutePath(), 8000, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT);
18+
//开始重新采样 采样回调在工作线程 非UI线程
19+
PcmResample.resample(srcFileConfig, targetFileConfig, reSampleListener);
20+
```
21+
22+
23+
## 感谢
24+
[hutm/JSSRC](https://github.com/hutm/JSSRC)

app/src/main/java/tech/oom/androidpcmresample/MainActivity.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package tech.oom.androidpcmresample;
22

3+
import android.app.ProgressDialog;
34
import android.media.AudioFormat;
45
import android.os.Bundle;
56
import android.os.Handler;
@@ -18,19 +19,22 @@
1819
import tech.oom.resample.ReSampleListener;
1920

2021
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
22+
private ProgressDialog dialog;
2123
private Handler mHandler = new Handler() {
22-
@Override
23-
public void handleMessage(Message msg) {
24+
@Override
25+
public void handleMessage(Message msg) {
2426

25-
}
26-
};
27+
}
28+
};
2729

2830
@Override
2931
protected void onCreate(Bundle savedInstanceState) {
3032
super.onCreate(savedInstanceState);
3133
setContentView(R.layout.activity_main);
3234
copyAssetsToFile();
3335
findViewById(R.id.resample_btn).setOnClickListener(this);
36+
dialog = new ProgressDialog(this);
37+
dialog.setMessage("resample in progress,please waite for a while");
3438
}
3539

3640
private void copyAssetsToFile() {
@@ -51,10 +55,15 @@ private void copyAssetsToFile() {
5155

5256

5357
private void resample() {
58+
//需要重新采样的源文件路径
5459
File file = new File(getExternalFilesDir(null), "50waystosaygoodbye.pcm");
60+
//重新采样后生成的文件路径
5561
File targetWaveFile = new File(getExternalFilesDir(null), "50waystosaygoodbye_8.pcm");
62+
//源文件的采样率、通道数、采样位数
5663
PcmResample.AudioFileConfig srcFileConfig = new PcmResample.AudioFileConfig(file.getAbsolutePath(), 44100, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT);
64+
//生成文件的采样率、通道数(必须和源文件一样)、采样位数(必须和源文件一样)
5765
PcmResample.AudioFileConfig targetFileConfig = new PcmResample.AudioFileConfig(targetWaveFile.getAbsolutePath(), 8000, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT);
66+
//开始重新采样 采样回调在工作线程 非UI线程
5867
PcmResample.resample(srcFileConfig, targetFileConfig, new ReSampleListener() {
5968
@Override
6069
public void onResampleError(String error) {
@@ -64,11 +73,12 @@ public void onResampleError(String error) {
6473
@Override
6574
public void onResampleStart() {
6675
System.out.println("start");
76+
6777
mHandler.post(new Runnable() {
6878
@Override
6979
public void run() {
7080
Toast.makeText(MainActivity.this, "Resample start", Toast.LENGTH_SHORT).show();
71-
81+
dialog.show();
7282
}
7383
});
7484
}
@@ -80,7 +90,7 @@ public void onResampleFinish(final PcmResample.AudioFileConfig targetConfig) {
8090
@Override
8191
public void run() {
8292
Toast.makeText(MainActivity.this, "Finish !The saved file path " + targetConfig.getFilePath(), Toast.LENGTH_SHORT).show();
83-
93+
dialog.dismiss();
8494
}
8595
});
8696
}

0 commit comments

Comments
 (0)