读取音频rlp

发布于 2025-01-08 02:51:27 字数 742 浏览 2 评论 0原文

我正在尝试通过 Fez Panda 2 从麦克风获取声音样本。我正在使用 rlp 来实现这一点。这是我的代码:

int GHAL_AnalogIn_Read(unsigned char channel)
{
        return ((*((int*)(ADC_DATA_BASE_ADDRESS) + channel)) >>8) & 0x3FF;
}
int ReadAudio(unsigned int *generalArray, void **args, unsigned int argsCount ,unsigned int *argSize)
{
        unsigned char *buffer = (unsigned char*)args[0];
        int buffer_lengh = argSize[0];
        unsigned char channel = *(unsigned char*)args[1];
        int i=0;
        while(i<buffer_lengh)
        {
           buffer[i] = GHAL_AnalogIn_Read(channel);
           i++;
           RLPext->Delay(100);
        }
        return 0;
}

问题是我需要浮点值而不是无符号字符,因为我正在对这些声音样本执行 fft。所以我需要修改来为我提供浮点值。有什么想法吗?

I am tring to get sound samples from microphone through Fez Panda 2. I am using rlp to accomplish that. Here is my code:

int GHAL_AnalogIn_Read(unsigned char channel)
{
        return ((*((int*)(ADC_DATA_BASE_ADDRESS) + channel)) >>8) & 0x3FF;
}
int ReadAudio(unsigned int *generalArray, void **args, unsigned int argsCount ,unsigned int *argSize)
{
        unsigned char *buffer = (unsigned char*)args[0];
        int buffer_lengh = argSize[0];
        unsigned char channel = *(unsigned char*)args[1];
        int i=0;
        while(i<buffer_lengh)
        {
           buffer[i] = GHAL_AnalogIn_Read(channel);
           i++;
           RLPext->Delay(100);
        }
        return 0;
}

The problem is that I need float values not unsigned char because I'm performing fft on these sound samples. So I need modification that will provide me float values. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽梦忆笙歌 2025-01-15 02:51:27

你有使用C语言的经验吗?尤其是*&的含义? *表示:获取地址指向的值。所以 void ** args 表示类似“获取从地址获得的值所指向的值”之类的内容。 void 用于自由输入任何你喜欢的内容。由于您无法将整个结构或对象放入参数中,因此您需要提供指向结构或对象的指针(地址)。通过使用*,您可以获取参数地址上的值。

在 C 中,您不会在参数中传递整个数组,而是传递第一个索引的地址。

现在您可以简单地将函数重构为如下所示:

int ReadAudio(unsigned int *generalArray, float arg, unsigned int argsCount ,unsigned int *argSize)

但是由于 void **args 现在指向缓冲区,我认为您应该知道要对收集的数据执行什么操作。模拟读取总是会为您提供一个整数,大多数 ADC(模拟 - 数字 - 转换器)都是 10 位左右。

如果浮点数在 32 位系统上为 4 字节,则您希望在 4 字节边界内破坏数据 (unsigned char *buffer)。

编辑:我在文档中忽略了这一点:注意:RLP 代码文件中所有函数的参数必须具有以下格式:注意:RLP 代码文件中所有函数的参数必须具有以下格式:。只需将缓冲区字节转换为 4 字节边界的浮点数,我想你会做得很好。

Have you got experience with C? Especially with the meaning of * and &? * means: get the value pointed by address. So void ** args says someting like 'get the value pointed by the value obtained from address'. void is used to freely input anything you like. As you can not put whole structures or objects in an argument, you provide the pointer (an address) to a structure or object. By using the * you obtain the value on the address of the argument.

In C you do not pass whole arrays in an argument, you pass on the address of the first index.

Now you could simply re-factor your function to be something like:

int ReadAudio(unsigned int *generalArray, float arg, unsigned int argsCount ,unsigned int *argSize)

But as void **args is pointing to a buffer now, I think you should know what operation you want to perform on the data collected. An analog read will always provide you with an integer, most ADC (analog - digital - converter) are 10-bit or so.

If a float is 4 bytes on a 32-bit system, you want to mangle your data (unsigned char *buffer) in a 4-byte boundary.

EDIT: I have overlooked this in the documentatio: Note: Parameter of all function in RLP code file must have format follow this:Note: Parameter of all function in RLP code file must have format follow this:. Just cast the buffer bytes to a float by 4 byte boundary and I think you will do fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文