Skip to content

i2s stream into Maximilian #1338

Answered by pschatzmann
twillging asked this question in Q&A
Discussion options

You must be logged in to vote

This should not be too difficult: Just open the I2SStream with RXTX_MODE. Then you can also read the values from it. All you have to do yourself is to convert the values to float!

If you have stereo 16 bits data, you can do something like this

float* readFloat(Stream &in, float volume=1.0){
   static float result[2];
   int16_t in_data[2];
   result[0] = 0.0f;
   result[1] = 0.0f;
   int bytes = 2*sizeof(int16_t);
   if (in.readBytes((uint8_t*)in_data, bytes)==bytes){
       result[0] = static_cast<float>(in_data[0]) / 32768.0 * volume;
       result[1] = static_cast<float>(in_data[1]) / 32768.0 * volume;
   }
  return result;
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pschatzmann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants