loop from flash

audiophil
Posts: 4
Joined: Thu Apr 02, 2020 2:36 pm

loop from flash

Postby audiophil » Thu Apr 02, 2020 2:44 pm

I am trying to seamlessly loop a tone from flash.

I started from play_tone_mp3_example but I cannot get the tone to loop.

I made my own version of tone_stream.c and tried to reset the byte postition in the read function. But whatever I do, the stream stops after all bytes have been played. How can I start the stream from the beginning when it reaches the end?

Any hints or examples are highly appreciated

davidbbs
Posts: 4
Joined: Wed Jan 01, 2020 12:56 am

Re: loop from flash

Postby davidbbs » Thu Apr 02, 2020 8:27 pm

Hi audiophil.

It would help if you post the code you've changed. I just had a look, and was able to loop successfully by making this change:

Modify tone_stream.c at line 196, from:

Code: Select all

    if (info.byte_pos + len > info.total_bytes) {
        len = info.total_bytes - info.byte_pos;
    }
to:

Code: Select all

    if (info.byte_pos == info.total_bytes) {
    	info.byte_pos = 0;
    } else
    if (info.byte_pos + len > info.total_bytes) {
        len = info.total_bytes - info.byte_pos;
    }
David.

audiophil
Posts: 4
Joined: Thu Apr 02, 2020 2:36 pm

Re: loop from flash

Postby audiophil » Sat Apr 04, 2020 7:21 pm

Thank you very much, David, your answer worked for looping an mp3 file from flash. Unfortunately, it does not work to seamlessly loop the file. I tried to modify the example to work with a wav file and wav decoder. But the same code plays the wav file only once and produces the following output:

Code: Select all

I (416) MY_TONE_WAV_EXAMPLE: [3.1] Listening event from all elements of pipeline
I (426) MY_TONE_WAV_EXAMPLE: [ 4 ] Start audio_pipeline
E (426) AUDIO_ELEMENT: IN-[my_tone] AEL_STATUS_ERROR_INPUT
E (436) AUDIO_ELEMENT: [my_tone] ERROR_PROCESS, AEL_IO_FAIL
E (436) AUDIO_ELEMENT: [my_tone] AEL_MSG_CMD_ERROR
E (446) AUDIO_ELEMENT: [my_tone] AEL_MSG_CMD_ERROR
W (456) AUDIO_ELEMENT: IN-[wav] AEL_IO_ABORT
I (456) MY_TONE_WAV_EXAMPLE: [ 4 ] Listen for all pipeline events
W (486) MY_TONE_WAV_EXAMPLE: [ * ] Stop event received
I (486) MY_TONE_WAV_EXAMPLE: [ 5 ] Stop audio_pipeline
Furthermore, I don't understand why none of the LOGI statements I put in tone_stream.c cause an output (although changes to the code have an effect)

davidbbs
Posts: 4
Joined: Wed Jan 01, 2020 12:56 am

Re: loop from flash

Postby davidbbs » Sun Apr 05, 2020 9:26 pm

Can you share the code changes you're making so I can have a look at what's happening?

audiophil
Posts: 4
Joined: Thu Apr 02, 2020 2:36 pm

Re: loop from flash

Postby audiophil » Tue Apr 07, 2020 5:49 pm

Changes I made in play_tone_mp3_example.c:

line 19:

Code: Select all

#include "mp3_decoder.h"
to

Code: Select all

#include "wav_decoder.h"
line 23-27:

Code: Select all

#if __has_include("audio_tone_uri.h")
    #include "audio_tone_uri.h"
#else
    #error "please refer the README, and then make the tone file"
#endif
to

Code: Select all

#include "audio_tone_uri.h"
because

Code: Select all

#if __has_include("audio_tone_uri.h")
caused the build to fail

line 34:

Code: Select all

    audio_element_handle_t tone_stream_reader, i2s_stream_writer, mp3_decoder;
to

Code: Select all

    audio_element_handle_t tone_stream_reader, i2s_stream_writer, wav_decoder;
line64:

Code: Select all

    audio_pipeline_register(pipeline, mp3_decoder, "mp3");
to

Code: Select all

    audio_pipeline_register(pipeline, wav_decoder, "wav");
line 68:

Code: Select all

    audio_pipeline_link(pipeline, (const char *[]) {"tone", "mp3", "i2s"}, 3);
to

Code: Select all

audio_pipeline_link(pipeline, (const char *[]) {"tone", "wav", "i2s"}, 3);
line 92:

Code: Select all

if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT && msg.source == (void *) mp3_decoder
to

Code: Select all

        if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT && msg.source == (void *) wav_decoder
line 95:

Code: Select all

            audio_element_getinfo(mp3_decoder, &music_info);
to

Code: Select all

            audio_element_getinfo(wav_decoder, &music_info);
line 119:

Code: Select all

    audio_pipeline_unregister(pipeline, mp3_decoder);
to

Code: Select all

    audio_pipeline_unregister(pipeline, wav_decoder);
line 131:

Code: Select all

    audio_element_deinit(mp3_decoder);
to

Code: Select all

    audio_element_deinit(wav_decoder);
the changes I made in tone_stream.c are exactly as you suggested.

davidbbs
Posts: 4
Joined: Wed Jan 01, 2020 12:56 am

Re: loop from flash

Postby davidbbs » Wed Apr 08, 2020 10:44 pm

Thanks. I'm not sure what's going on. It looks like the _flash_read is returning ESP_FAIL although I'm not sure as I would be expecting to see a log statement. Not sure why you don't see these.

If _flash_read fails, it _may_ be because you have problem with the generation of audio-esp.bin and the include file. But I can just speculate... Did you "make clean" and recompiled everything after these changes?

audiophil
Posts: 4
Joined: Thu Apr 02, 2020 2:36 pm

Re: loop from flash

Postby audiophil » Thu Apr 09, 2020 5:14 pm

Thank you,

Yes, it's indeed strange that no log ouput is generated from that file. Do I need to setup the logging somehow? I tested another example and it seems like no LOG output is sent to the serial monitor from other files than the "main" c file.

I don't think that the generation of audio-esp fails because the tone plays fine once. Furthermore I tried another wav format (float instead of int16), which generated an error output that 32bit wav files would not not supported.

I cleaned the build several times but this did not help either.

Who is online

Users browsing this forum: No registered users and 15 guests