资源简介
vox转wav文件Java实现,其中的实现是参考c的实现方法。经过自己调试改为Java版的,能成功转换vox文件,这个不只是改文件后缀。具体的算法是参考别人的。自己花时间调试的,所以分要高点,网上搜索了下没有Java版本的vox转换代码,说以写了个。
代码片段和文件信息
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
class Adpcm_status {
int last;
int step_index;
}
class Adpcmcode {
static short step_size[]= { 16 17 19 21 23 25 28 31 34 37 41
45 50 55 60 66 73 80 88 97 107 118 130 143 157 173
190 209 230 253 279 307 337 371 408 449 494 544 598 658
724 796 876 963 1060 1166 1282 1408 1552 };
//short step_adjust ( char );
void adpcm_init( Adpcm_status stat ) {
stat.last = 0;
stat.step_index = 0;
return;
}
/*
* Decode Linear to ADPCM
*/
short adpcm_decode( byte code Adpcm_status stat ) {
short diff E SS samp;
SS = step_size[stat.step_index];
E = (short) (SS/8);
if ( (code & 0x01)!=0 )
E += SS/4;
if ( (code & 0x02)!=0 )
E += SS/2;
if ( (code & 0x04)!=0 )
E += SS;
diff = ((code & 0x08)!=0) ? (short) -E : E;
samp = (short) (stat.last + diff);
if( samp > 2048 ) samp = 2048;
if( samp < -2048 ) samp = -2048;
stat.last = samp;
stat.step_index += step_adjust((char) code);
if( stat.step_index < 0 ) stat.step_index = 0;
if( stat.step_index > 48 ) stat.step_index = 48;
return ( samp );
}
/*
* adjust the step for use on the next sample.
*/
short step_adjust ( char code ) {
switch( code & 0x07 ) {
case 0x00:
return(-1);
case 0x01:
return(-1);
case 0x02:
return(-1);
case 0x03:
return(-1);
case 0x04:
return(2);
case 0x05:
return(4);
case 0x06:
return(6);
case 0x07:
return(8);
default:
return 0;
}
}
};
public class AudioUtil {
public static void convertAudioFiles(String srcString targt) {
/* String src=“C:\\Users\\anyone\\Desktop\\9.vox“;
String targt=“C:\\Users\\anyone\\Desktop\\a.wav“;*/
FileInputStream fis = null;
FileOutputStream fos = null;
try {
int i j;
int n;
int buffer_size;
short buffer12[];
byte adpcm[];
Adpcm_status coder_stat=new Adpcm_status();
Adpcmcode adpcmcode=new Adpcmcode();
buffer_size = 512;
buffer12= new short[buffer_size];
byte[] buffer8=new byte[buffer_size];
adpcm=new byte[buffer_size/2];
//开始
fis = new FileInputStream(new File(src));
fos = new FileOutputStream(new File(targt));
adpcmcode.adpcm_init( coder_stat );//初始化
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5263 2015-09-10 13:49 AudioUtil.java
文件 55 2015-09-10 13:50 vox转wav使用.txt
文件 2034 2015-09-10 13:51 WaveHeader.java
评论
共有 条评论