-
-
Notifications
You must be signed in to change notification settings - Fork 326
How to pad signal #546
-
Hello,
I have 16bits per sample signal and I would like to convert it to I2S 24bits with 8 bits of padding at the right. What is the best strategy to achieve this? I tried modifying the NumberConverter but it seems that the sample rate doesn't match and my stream is drifting.
Thanks for the Help!
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments 8 replies
-
Integer format conversion is done by the NumberFormatConverterStream or NumberFormatConverterStreamT, but I never tested the 24 bit functionality and I suggest that you prefer 32bits instead.
When I implemented it I was under the assumption that we would need to write 3 bytes. But I think the esp32 expects int32_t values.
Feel free to correct the functionality.
Beta Was this translation helpful? Give feedback.
All reactions
-
Sorry I wasn't clear.
I meant:
[24bit signal][8 bits padding] for a total of 32 bits per sample. (This is to interface with some annoying DSPs).
This is what i ended up with:
size_t readBytes(uint8_t *data, size_t size) override {
if (p_stream==nullptr) return 0;
size_t samples = size / sizeof(TTo);
TTo *data_target = (TTo *)data;
TFrom source;
for (size_t j=0;j<samples;j++){
source = 0;
p_stream->readBytes((uint8_t*)&source, sizeof(TFrom));
data_target[j]= ((int32_t) source) << 8;;
}
return size;
}
But I get very weird results when piping this to I2S. (the zero padding doesn't seem to be at the end of each word. I paste the output of my logic analyzer if that can help.
Thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions
-
did you try it in 2 steps
for (size_t j=0;j<samples;j++){
source = 0;
p_stream->readBytes((uint8_t*)&source, sizeof(TFrom));
TFrom *pt_from = (TFrom *) source;
data_target[j] = *pt_from;
data_target[j] = data_target[j] << 8;
}
Beta Was this translation helpful? Give feedback.
All reactions
-
The Duty cycle and frequency is correct, it's just that there seem to be a random phase shift. Is there something that needs to be done when piping A2DP to I2S to synchronize them maybe ?
Beta Was this translation helpful? Give feedback.
All reactions
-
What is the datatype of source ?
Beta Was this translation helpful? Give feedback.
All reactions
-
Are you sure that you do something with the data_target. To me it looks as if you output the input data.
Beta Was this translation helpful? Give feedback.
All reactions
-
In my second example I just do this:
data_target[j] = -1; data_target[j]= data_target[j] << 8;
So I don't think the problem is with the source
Beta Was this translation helpful? Give feedback.
All reactions
-
My gut feeling point me towards an alignment issue between the data and the LRCLK signal.
Beta Was this translation helpful? Give feedback.
All reactions
-
In this case you can try different I2SFormat values
Beta Was this translation helpful? Give feedback.
All reactions
-
Unfortunately the shift is different at every reboot and I have to follow the I2S format of the DSP I'm using. I think I got something to work with the basic A2DP API though !
Beta Was this translation helpful? Give feedback.