Getting raw audio Samples

audioguy
Posts: 5
Joined: Fri Dec 07, 2018 10:22 am

Getting raw audio Samples

Postby audioguy » Fri Dec 07, 2018 10:39 am

What is the best way to obtain raw audiosamples from a pipeline or a streamreader ?
I want to do Spektrum analysis on the Samples with some fft library (se here http://www.robinscheibler.org/2017/12/12/esp32-fft.html )
My hopes are that i can make a audiopipline element that can do this .
i need to get the raw Wav samples form an

Code: Select all

i2s_stream_reader
or a

Code: Select all

 bt_stream_reader
created with

Code: Select all

bluetooth_service_create_stream();
Thanks in advance

water117
Posts: 3
Joined: Fri Dec 14, 2018 9:28 am
Location: BeiJing China

Re: Getting raw audio Samples

Postby water117 » Fri Dec 14, 2018 10:14 am

Use i2s_stream_reader as example.
i2s_stream_reader = i2s_stream_init(&i2s_cfg_read);
audio_element_set_write_cb(i2s_stream_reader, i2s_input_write_cb, NULL);
audio_pipeline_link(pipeline, (const char *[]) {"i2s_read"}, 1);

short pcm_fft[128];
int pcm_wptr=0;

// You can get pcm data in write callback.
int i2s_input_write_cb(audio_element_handle_t el, char *buf, int len, TickType_t wait_time, void *ctx)
{
// use 48KHz, 2ch, 16bits as example

// the buf is pcm raw data
short *pcm2 = (short*)buf;

// mix stereo as mono and do fft
len = (len>>2)<<2; // 2*2 align
int wlen = len;
while (wlen > 0) {
pcm_fft[pcm_wptr] = (pcm2[0]>>1) + (pcm2[1]>>1); // Mix L & R
pcm2 += 2;
wlen -= 4;
pcm_wptr++;
if (pcm_wptr >= 128) {
fft_128_s16(pcm_fft, image, real)
pcm_wptr = 0;
}
}

return len;
}

audioguy
Posts: 5
Joined: Fri Dec 07, 2018 10:22 am

Re: Getting raw audio Samples

Postby audioguy » Sun Dec 16, 2018 9:10 pm

Thank you so much for showing me this method!
I'm currently experimenting with this callbackmethod and I got it to work somewhat.
I'm using this library for the fft https://github.com/fakufaku/esp32-fft
(blogpost:http://www.robinscheibler.org/2017/12/12/esp32-fft.html)
But you are using this

Code: Select all

fft_128_s16(pcm_fft, image, real)
function .
Is that some native library function or just a placeholder for where I should use my implementation.
Also im experiencing the issue, that when applying this callbackfunction to a pipeline it
only seems to work with the last element of the pipeline like referenced in the documentation .
This API allows the application to set a write callback for the last audio_element in the pipeline
but then this element (in my case a

Code: Select all

i2s_stream_writer = i2s_stream_init(&i2s_cfg);
)
does not forward the sound to the heatphonejack anymore.
Maybe you know something about that otherwise I will investigate this further myself.

In any case I will experiment more with this as I find time to do so and I hope I can
come back and ask you for help if I have problems I can't crack myself.

Return to “ESP32 ADF”

Who is online

Users browsing this forum: No registered users and 2 guests