Search code examples
caudiosampling

Reading audio rlp


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?


Solution

  • 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.