更改音频采样率,通过这个code目前改变位深度? [英] Change Audio Samplerate through this code which currently changed Bit depth?

查看:490
本文介绍了更改音频采样率,通过这个code目前改变位深度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧couldn't想出了一个很好的话题。

Okay couldn´t come up with a good topic.

问题的关键是,我有一个code,我得到了与that's更改位深度从32位系统到16位的帮助,不知道它是如何工作的,但我认为它只是简单地删除所有其他位,没有什么花哨

The point is, i have a code which i got help with that´s changing the bit depth from 32bit to 16bit, not sure how it works, but i think it simply just removes every other bit, nothing fancy.

因此​​,如果汇入作业可能做到这一点与code,它应该可能改变采样率。
另外我不想要的东西,看中这里作为更汇入作业用于调试的用途,我只想把它做成一些其他的采样率,它doesn't必须是一个重采样。

So if it´s possible to do that with the code, it should be possible to change the samplerate. Also i don´t want something fancy here as it´s more for debugging uses, i just want to make it into some other samplerate, it doesn´t have to be a "resampling".

含义,例如,如果音频为48kHz,我重新取样它,而它起着至47khz,它不需额外声音一样,它仍然认为48kHz的汇入作业,这意味着它将发挥更慢。

Meaning for example, if the audio is 48khz, and i resample it while it plays to 47khz, it won´t sound the same as it still think it´s 48khz, meaning it will play it slower.

因此​​,换句话说我要去使用它用于改变音频的速度在一个很简单的方法

So in other words i am going to use it for changing the speed of the audio in a very simple way.

这里是code键更改位深,我希望能为这个被重用。

here is the code to change bit depth which i hope can be reused for this.

Int32 bytesrecorded = e.BytesRecorded;
byte[] newArray16Bit = new byte[bytesrecorded / 2];
fixed (byte* sourcePtr = e.Buffer)
fixed (byte* targetPtr = newArray16Bit)
{
    float* sourceTyped = (float*)sourcePtr;
    short* targetTyped = (short*)targetPtr;

    Int32 count = bytesrecorded / 4;
    for (int i = 0; i < count; i++)
    {
        targetTyped[i] = (Int16)(sourceTyped[i] * Int16.MaxValue);
    }
}

e.Bytesrecorded =音频缓冲区的大小,

e.Bytesrecorded = the size of the audio buffer,

e.Buffer =实际的缓冲

由于我不完全理解这一点,我只是看一下/ 2,并假设它只是把规模考核的长度,则/ 4部分将围绕移动字节,使其适合。

As i don´t fully understand this, i simply look at the /2 and assume it just divides teh length of the size, then the /4 part will be moving the bytes around to make it fit.

虽然我不知道我可以用它来改变采样率,因为这只是个字节走动,它shouldn't是努力使事情的采样率。

Though i don´t know how i can use this to change the samplerate, as this is just bytes moving around, it shouldn´t be to hard to make something for the samplerate.

感谢

推荐答案

如果要调整的速度,有几个可能的解决方案:

If you want to adjust the speed, there are a few possible solutions:


  1. 使用一个重采样,从如重新取样的轨道44100Hz到
    50000Hz但还是告诉音频驱动程序与44100Hz进行播放。

  2. 只需更改文件的采样率但不是的内容
    文件。例如修改波头和改变采样率。
    Audioplayers将读取波头的采样率和意志
    与例如采样率播放44100Hz的轨道60000Hz。

  3. 使用专业的DSP算法来调整速度。

这篇关于更改音频采样率,通过这个code目前改变位深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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