Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: audio board and byte manipulation

  1. #1
    Junior Member
    Join Date
    May 2018
    Posts
    3

    audio board and byte manipulation

    Hello World,

    I would like to manipulate the values from AUDIO_INPUT_LINEIN.
    I use memcpy(buffer, queue1.readBuffer(), 256) to read the values and store them to a byte called buffer.
    But the values are not byte(8 bits) but int16.
    I have to combine them somehow.
    I use this command to do it : intValeurR = (buffer[i+1] << 8) | buffer[i];
    but it doesn't work.

    My question is simple: how to get the integer 16 values from AUDIO_INPUT_LINEIN on the audio board in order to manipulate them the way I want in my program ?

    Thank you all

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,475
    Just create buffer as an array of int16_t.

    Code:
    int16_t buffer[128];
    Then you can access the samples directly from the array. Easy!

  3. #3
    Junior Member
    Join Date
    May 2018
    Posts
    3
    Thanks a lot Paul!!
    Then I think my problem is something else because for both input, left and right I get the same value, and those values don't seems to be right. never change and both the same.
    This is my code:

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>

    // GUItool: begin automatically generated code
    AudioControlSGTL5000 sgtl5000_1;
    AudioInputI2S i2s1; //xy=223,143
    AudioRecordQueue fileL; //xy=632,116
    AudioRecordQueue fileR; //xy=650,182
    AudioConnection patchCord1(i2s1, 0, fileL, 0);
    AudioConnection patchCord2(i2s1, 1, fileR, 0);
    // GUItool: end automatically generated code

    // which input on the audio shield will be used?
    const int myInput = AUDIO_INPUT_LINEIN;
    //Permet de stocker le temps en ms et savoir oł on en est.
    unsigned long ulngTime;

    void setup() {
    AudioMemory(60);
    pinMode(13, OUTPUT);

    //Enable the audio shield
    sgtl5000_1.enable();
    sgtl5000_1.inputSelect(myInput);
    }

    void loop(){
    int16_t bufferL[128];
    int16_t bufferR[128];

    memcpy(bufferL, fileL.readBuffer(), 128);
    fileL.freeBuffer();
    memcpy(bufferR, fileR.readBuffer(), 128);
    fileR.freeBuffer();

    for (int i=0;i<128;i++){
    Serial.println(bufferR[i]);
    delay(1);
    }
    }

  4. #4
    Junior Member
    Join Date
    May 2018
    Posts
    3
    Ok I found my error it was very simple after have read the doc :/
    I had to add this line in setup :
    fileR.begin();
    of course

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,475
    You should also call available() and only attempt to read when it tell you 1 or more buffers are actually waiting in the queue for you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •