Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to use 2 Audio at the same time #822

Open
AntoineLep opened this issue Aug 28, 2024 · 4 comments
Open

Possibility to use 2 Audio at the same time #822

AntoineLep opened this issue Aug 28, 2024 · 4 comments
Labels

Comments

@AntoineLep
Copy link

Hi,

I would like to use 2 audios at the same time to play a WAV voice feedback when I do a specific action while listening to a main audio MP3 file but It actually doesn't work when declaring:

Audio audio;
Audio audio2;

I got the following errors:

E (1231) i2s_common: i2s_new_channel(812): no available channel found
E (1231) i2s_std: i2s_channel_init_std_mode(199): input parameter 'handle' is NULL
E (1233) i2s_common: i2s_channel_enable(999): input parameter 'handle' is NULL

Then one audio can't play at all.

I've tried using a single Audio but it can't handle audio file switch quick enough for me. MP3 loading is always something like 2-3 sec long and I have to reposition it which is not very precise.

Have you any idea how I can workaround this issue ?

Thanks,

Antoine

@AntoineLep
Copy link
Author

AntoineLep commented Aug 29, 2024

I ve found a workaround but had to add a method to your code to get the I2S tx handle

Open .pio/libdeps/esp32/ESP32-audioI2S/src/Audio.h

Add the following to Audio class public declarations

#if ESP_IDF_VERSION_MAJOR == 5
    i2s_chan_handle_t getI2sTxHandle();
#endif

Open .pio/libdeps/esp32/ESP32-audioI2S/src/Audio.cpp

Add the following at the very bottom of the file

#if ESP_IDF_VERSION_MAJOR == 5
i2s_chan_handle_t Audio::getI2sTxHandle() {
    return m_i2s_tx_handle;
}
#endif

Then I can switch the I2S config like this:

void setI2SConfigMP3() {
    if(currentI2SConfigType != MP3_CT) {
        _amp_mute();
        currentI2SConfigType = MP3_CT;
        audio.setI2SCommFMT_LSB(false);
        audio.audioFileSeek(1);
    };
}

void setI2SConfigWav() {
    if(currentI2SConfigType != WAV_CT) {
        _amp_mute();
        currentI2SConfigType = WAV_CT;
        i2s_channel_disable(audio.getI2sTxHandle());
        i2s_channel_reconfig_std_clock(audio.getI2sTxHandle(), &wav_i2sStdCfg.clk_cfg);
        i2s_channel_reconfig_std_slot(audio.getI2sTxHandle(), &wav_i2sStdCfg.slot_cfg);
        i2s_channel_enable(audio.getI2sTxHandle());
    };
}

@jie326513988
Copy link

Can two audio streams be played simultaneously, which is equivalent to mixing?

@AntoineLep
Copy link
Author

Well, here I don't want to mix 2 audios.
I just want to pause audio1 and then play audio2
And then playback audio1 when audio2 is finished

Copy link

github-actions bot commented Oct 4, 2024

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants