资源简介
很牛逼的算法,网上很难找到。我找了好久才找到的,希望大家支持~~
代码片段和文件信息
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
public class VoxConvert {
private int convertFormat = 1;
private int convertRate = 8000;
private int convertBits = 1;
private final int WAV_HEAD = 36;// wav文件头长度
private static final int VF_ADPCM = 1;// 编码格式
private static final int BIT_RATE_VB_8 = 1;// 每个样本位数
private static final int BIT_RATE_VB_16 = 2;// 每个样本位数
private final int RESET_VALUE = 48;
private byte out_val;
/**
*
* @param inFile
* @param outFile
* @param voxFormat
* 格式 取值范围:VF_ADPCM = 1 VF_MULAW = 2 VF_ALAW = 3
* @param voxRate
* 采样率 取值范围:VR_6K = 6000 VR_8K = 8000
* @param bit_rate
* 位数 取值范围:VB_8 = 1 VB_16 = 2
* @return
*/
public VoxConvert(String inFile String outFile int voxFormat
int voxRate int bit_rate) throws Exception {
if (voxFormat != 0) {
convertFormat = voxFormat;
}
if (voxRate != 0) {
convertRate = voxRate;
}
if (bit_rate != 0) {
convertBits = bit_rate;
}
if (outFile == null) {
outFile = inFile.substring(0 inFile.length() - 3);
outFile = outFile + “wav“;
}
File outF = new File(outFile);
File inF = new File(inFile);
long inFileSize = inF.length();
if (voxFormat == VF_ADPCM) { // if using ADPCM input format...
inFileSize = inFileSize * 2;
}// change from bytes to samples
FileOutputStream filewriter = new FileOutputStream(outF false);
String wavBegin = “RIFF“;
filewriter.write(wavBegin.getBytes());// WAV 文件头
long wavLength = inFileSize * bit_rate + WAV_HEAD;
byte[] tmpArr = new byte[4];
longToIntBinary(wavLength tmpArr 0);
filewriter.write(tmpArr);// 文件总长度
String wavTag = “WAVEfmt “;
filewriter.write(wavTag.getBytes());// WAV 文件标识
int headLength = 16;
tmpArr = new byte[4];
longToIntBinary(headLength tmpArr 0);
filewriter.write(tmpArr);// size of .WAV file header
int wFormatTag = 1; // format tag (01 = Windows PCM)
tmpArr = new byte[2];
toShortBinary(wFormatTag tmpArr 0);
filewriter.write(tmpArr);// format tag (01 = Windows PCM)
int nChannels = 1; // channels (1=mono 2=stereo)
tmpArr = new byte[2];
toShortBinary(nChannels tmpArr 0);
filewriter.write(tmpArr);// channels (1=mono 2=stereo)
int nSamplesPerSec = voxRate; // samples per second
tmpArr = new byte[4];
longToIntBinary(nSamplesPerSec tmpArr 0);
filewriter.write(tmpArr);
int nAvgBytesPerSec = voxRate * bit_rate; // bytes per second
// during play
tmpArr = new byte[4];
longToIntBinary(nAvgBytesPerSec tmpArr 0);
filewriter.write(tmpArr);
int nBlockAlign = bit_rate; // bytes per sample
tmpArr = new byte[2];
toShortBinary(nBlockAlign tmpArr 0);
filewriter.write(tmpArr);// bytes per sample
int wBitsPerSample = 8 * bit_rate; // bits per sample
tmpArr = new byte[2];
toShortBinary(
- 上一篇:android 小说阅读器demo
- 下一篇:Java实现的单态登陆
相关资源
- Java实现的单态登陆
- java-多线程器支持断点续传、线程加减
- 3D坦克java
- oracle 数据表转成java pojo
- Javaweb学生信息管理系统244326
- 哈工大LTP java动态链接库 64位可用
- Java用jdbc连接数据库源码简单操作,包
- RSA算法的Java实现
- java实现融云web端聊天代码
- java代码生成数字证书
- J2EE的13种核心模式
- Java记事本 基本功能 查找 撤销 替换
- javacc编译原理实习
- jpcap资源
- RSAJava实现代码
- Student_Manage.zip
- Java通过WTC调Tuxedo服务(String)
- 东北大学计算机考研Java知识点笔记
- java使用HttpClient通过url文件到本地
- java调用Cloudera Manager Api
- JAVA毕业设计外文翻译 中英对照版
- java下进行抓包使用的jpcap.dll和jpcap.
- java swing-jtree的用法
- JAVA实现a*算法八数码问题
- Java简单计算器Swing版
- java-根据网站链接url生成二维码qrcod
- 基于Java的坦克大战游戏含代码和报告
- voiipui开发设计详细
- java 简易计算器的实现
- uc浏览器java手机版UC8.6 java通用版本
评论
共有 条评论