资讯详情

Java实现pcm与ADpcm互转

文章目录

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

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

一、概念

1、PCM脉冲编码调制(Pulse Code Modulation,PCM),由A.里弗斯于1937年提出,这一概念为数字通信奠定了基础。20世纪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芯片与现有闪存系统完全兼容,可直接插入现有系统。LPDDR芯片是第一个效仿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(); // ADPCMEncoderConfig.computeOutputSize(ShortBuffer) computes the minimum output buffer size ByteBuffer adpcmOutput = ByteBuffer.allocate(cfg.computeOutputSize(pcmInput)); // this returns the adpcmOutput buffer return (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 data ShortBuffer pcmOutput = ShortBuffer.allocate(channels * samples); // this returns the pcmOutput buffer return (ShortBuffer) new ADPCMDecoder(cfg).decode(adpcmInput, pcmOutput).rewind(); } 

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

标签: 电容471jt

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台