Android的PCM到ULAW编码的WAV文件 [英] Android PCM to Ulaw encoding wav file

查看:291
本文介绍了Android的PCM到ULAW编码的WAV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接code原始的PCM数据ULAW,以节省传输语音数据所需的带宽。

I'm trying to encode raw pcm data as uLaw to save on the bandwidth required to transmit speech data.

我所遇到的一类叫做 UlawEn coderInputStream 的<一个href="http://www.devdaily.com/java/jwarehouse/android/core/java/android/speech/srec/UlawEn$c$crInputStream.java.shtml">This页面但没有文件! :(

I have come across a class called UlawEncoderInputStream on This page but there is no documentation! :(

构造函数的输入流和最大的PCM值(无论是)。

The constructor takes an input stream and a max pcm value (whatever that is).

  /**
     * Create an InputStream which takes 16 bit pcm data and produces ulaw data.
     * @param in InputStream containing 16 bit pcm data.
     * @param max pcm value corresponding to maximum ulaw value.
     */
    public UlawEncoderInputStream(InputStream in, int max) {

在翻翻code,我怀疑我应该使用提供的函数计算这个最大值: maxAbsPcm 。问题是,我真的不明白我的意思传递到了!我记录我的原始PCM到一个文件的SD卡,所以我不要有一个数据连续驻留内存阵列传递到这一点。

After looking through the code, I suspect that i should calculate this "max" value using a supplied function: maxAbsPcm. Problem is, i dont really understand what I'm meant to pass into it! I am recording my raw pcm to a file on the sdcard so I dont have one continuous memory resident array of data to pass to this.

  /**
     * Compute the maximum of the absolute value of the pcm samples.
     * The return value can be used to set ulaw encoder scaling.
     * @param pcmBuf array containing 16 bit pcm data.
     * @param offset offset of start of 16 bit pcm data.
     * @param length number of pcm samples (not number of input bytes)
     * @return maximum abs of pcm data values
     */
    public static int maxAbsPcm(byte[] pcmBuf, int offset, int length) {

我已经使用这个code的另一个问题是,我不能确定什么样的价值观写出来的ULAW数据的标题。如何确定差多少字节的数据存在与ULAW编码后?

Another problem I have using this code is I am unsure what values to write out for the header for uLaw data. How do i determine how much less byte data there is after encoding with uLaw?

我听过的(潜在的)ULAW之一,恩,我在VLC媒体播放器(唯一的球员,我有这将试图读取文件)和它的声音讨厌的,坏了,clicky,但创造codeD文件还是可以做出来的声音。

I have listened to one of the (potentially) uLaw encoded files that I created in VLC media player (the only player i have that will attempt to read the file) and its sounds nasty, broken and clicky but can still make out the voice.

我使用code与类相似我发现叫WaveHeader可以找到<一写我的波头href="http://gitorious.org/android-eeepc/base/blobs/48276ab989a4d775961ce30a43635a317052672a/core/java/android/speech/srec/WaveHeader.java">Here!

I am writing my wave header using code similar to a class I found called WaveHeader which can be found Here!

如果任何人有关于此事的任何想法,我将不胜感激听到他们的声音!)

If anyone has any thoughts on this matter I would be most grateful to hear them!:)

非常感谢 德克斯特

推荐答案

最高在构造函数中的PCM数据的最大幅度。它用于生成输出之前缩放输入。如果输入是非常响亮的,你需​​要一个更高的价值,如果它是安静的,你需要一个较低。如果传入 0 的EN codeR会使用 8192 默认情况下,这可能是不够好。

The max in the constructor is the maximum amplitude in the PCM data. It is used to scale the input before generating the output. If the input is very loud you need a higher value, if it's quiet you need a lower one. If you pass in 0 the encoder will use 8192 by default, which may be good enough.

在其他方法中的长度是要从中找出最大振幅16位采样的数量。这个类假定输入PCM数据总是连接codeD,16位采样,这意味着每个样品跨越两个字节:如果你输入的是2000字节长,你有1000个样品

The length in the other method is the number of 16-bit samples from which you want to find the maximum amplitude. This class assumes that the input PCM data is always encoded with 16-bit samples, which means that each sample spans two bytes: if your input is 2000 bytes long you have 1000 samples.

带连接codeR在这个类产生的每个16位PCM样本一个8位μ律样本,所以在字节大小减半。

The encoder in this class produces one 8-bit µ-Law sample for every 16-bit PCM sample, so the size in bytes is halved.

这篇关于Android的PCM到ULAW编码的WAV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆