Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to pad signal #546

GuillaumeLeclerc started this conversation in General
Discussion options

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!

You must be logged in to vote

Replies: 3 comments 8 replies

Comment options

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.

You must be logged in to vote
1 reply
Comment options

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!

Comment options

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;
 }
You must be logged in to vote
6 replies
Comment options

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 ?

Comment options

What is the datatype of source ?

Comment options

Are you sure that you do something with the data_target. To me it looks as if you output the input data.

Comment options

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

Comment options

My gut feeling point me towards an alignment issue between the data and the LRCLK signal.

Comment options

In this case you can try different I2SFormat values

You must be logged in to vote
1 reply
Comment options

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /