失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Java实现pcm与ADpcm互转

Java实现pcm与ADpcm互转

时间:2019-04-22 10:55:09

相关推荐

Java实现pcm与ADpcm互转

文章目录

一、概念二、原理三、优缺点四、转换

参考网址:/MDZhB/jt-adpcm.git

一、概念

1、PCM脉冲编码调制(Pulse Code Modulation,PCM),由A.里弗斯于1937年提出的,这一概念为数字通信奠定了基础,60年代它开始应用于市内电话网以扩充容量,使已有音频电缆的大部分芯线的传输容量扩大24~48倍。

2、ADPCMADPCM (ADPCM Adaptive Differential Pulse Code Modulation),是一种针对16bit (或者更高) 声音波形数据的一种有损压缩算法,它将声音流中每次采样的 16bit 数据以 4bit 存储,所以压缩比1:4。而压缩/解压缩算法非常的简单,所以是一种低空间消耗,高质量声音获得的好途径。

二、原理

1、PCM管道的防腐层和大地之间存在着分布电容耦合效应,且防腐层本身也存在弱而稳定的导电性,信号电流在管道外防腐层完好时的传播过程中呈指数衰减规律,当管道防腐层破损后,管中电流便由破损点流入大地,管中电流会明显衰减,引发地面磁场强度的急剧减小,由此对防腐层的破损进行定位。

2、ADPCM

1)利用自适应的思想改变量化阶的大小,即使用小的量化阶(step-size)去编码小的差值,使用大的量化阶去编码大的差值;

2)使用过去的样本值估算下一个输入样本的预测值,使实际样本值和预测值之间的差值总是最小。

三、优缺点

1、PCM时代全芯设计的芯片在市场中有突出的优点。SPI芯片和现有使用闪存的系统完全兼容并可以直接插入现有系统使用。LPDDR2芯片是第一个效仿DRAM功能的相变存储器,它的设计数据速率达到突出的800 Mb/sec。16Mb的嵌入式相变存储器IP可以用于很多SoC设计,重要的是嵌入式IP完全由北京时代全芯团队设计。

2、ADPCM算法复杂度低,压缩比小,编解码延时最短(相对其它技术)。

四、转换

1、maven

<dependency><groupId>com.github.mdzhb</groupId><artifactId>jt-adpcm</artifactId><version>1.0.1</version></dependency>

2、编码解码

/*** pcm 编码为 AD pcm* @param pcmInput* @param channels* @param sampleRate* @param shape* @return*/ByteBuffer encodePCM(ShortBuffer pcmInput, int channels, int sampleRate, boolean shape) throws IOException {ADPCMEncoderConfig cfg =ADPCMEncoder.configure()// 1 for mono, 2 for stereo.setChannels (channels)// sample rate in Hz.setSampleRate (sampleRate)// noise shaping; true=on, false=off.setNoiseShaping(shape)// compute block size automatically.setBlockSize (ADPCMDecoderConfig.AUTO_BLOCK_SIZE)// create the configuration object.end();// puteOutputSize(ShortBuffer) computes the minimum output buffer sizeByteBuffer adpcmOutput = ByteBuffer.allocate(puteOutputSize(pcmInput));// this returns the adpcmOutput bufferreturn (ByteBuffer) new ADPCMEncoder(cfg).encode(pcmInput, adpcmOutput).rewind();}/*** AD pcm 编码为pcm* @param adpcmInput* @param channels* @param samples* @param sampleRate* @return*/ShortBuffer decodeADPCM(ByteBuffer adpcmInput, int channels, int samples, int sampleRate) throws IOException {ADPCMDecoderConfig cfg =ADPCMDecoder.configure()// 1 for mono, 2 for stereo.setChannels (channels)// sample rate in Hz.setSampleRate(sampleRate)// compute block size with the formula used by the encoder.setBlockSize (ADPCMDecoderConfig.AUTO_BLOCK_SIZE)// create the configuration object.end();// if `samples` is the length of the sound in samples, we need to double the length of the buffer for stereo dataShortBuffer pcmOutput = ShortBuffer.allocate(channels * samples);// this returns the pcmOutput bufferreturn (ShortBuffer) new ADPCMDecoder(cfg).decode(adpcmInput, pcmOutput).rewind();}

pcm在线播放可参考网址:/pkjy/pcm-player.git

如果觉得《Java实现pcm与ADpcm互转》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。