pschatzmann / arduino-audio-tools

Arduino Audio Tools (a powerful Audio library not only for Arduino)
GNU General Public License v3.0
1.47k stars 227 forks source link

Issue when trying to connect AudioPlayer to a internet Radio. After first AudiCopy the sample rate, port and mode are changed #789

Closed urrudelu30 closed 1 year ago

urrudelu30 commented 1 year ago

Hi, I am trying to connect my Esp32 with a different Radio over the internet.

I am configuring the i2s in the setup of my program as: I set port to 1 due to I have other state using the port 0 of i2s with A2DP.

auto config = i2s.defaultConfig(TX_MODE);// Test con tx mode config.port_no = 1; i2s.begin(config);

I call the player.begin() in the first state of my machine state as: (only once) player.begin(); player.setAudioInfo(i2s.audioInfo());

Then in the Loop, I am calling the player.copy().

I can see that I am configuring a TX mode in my i2s but unfortunately, I am seeing that once the first Audicopy is called[I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops, then the mode is changed to RX mode. Besides the sample rate is different and the port has changed.

The traces are these: [I] AudioPlayer.h : 352 - setVolume(1.000000) [I] VolumeStream.h : 191 - setVolume: 1.000000 [I] VolumeStream.h : 191 - setVolume: 1.000000 [I] MetaDataID3.h : 564 - virtual void audio_tools::MetaDataID3::begin() [I] AudioSource.h : 175 - selectStream: 0/4 -> http://streaming.swisstxt.ch/m/drsvirus/mp3_128 [I] URLStream.h : 89 - virtual bool audio_tools::URLStream::begin(const char, const char, MethodID, const char, const char): http://streaming.swisstxt.ch/m/drsvirus/mp3_128 [I] Url.h : 74 - Url::parse [I] Url.h : 110 - url->http://streaming.swisstxt.ch/m/drsvirus/mp3_128 [I] Url.h : 111 - host->streaming.swisstxt.ch [I] Url.h : 112 - protocol->http [I] Url.h : 113 - path->/m/drsvirus/mp3_128 [I] Url.h : 114 - port->80 [I] URLStream.h : 314 - void audio_tools::URLStream::login() [I] URLStream.h : 290 - WiFiClient [I] HttpRequest.h : 215 - process connecting to host streaming.swisstxt.ch port 80 [I] HttpRequest.h : 202 - connected 1 timeout 60000 [I] HttpRequest.h : 226 - Free heap: 95112 [I] HttpHeader.h : 360 - HttpRequestHeader::setValues - path: /m/drsvirus/mp3_128 [I] HttpHeader.h : 126 - Content-Length 0 [I] HttpHeader.h : 257 - HttpHeader::write [I] HttpHeader.h : 369 - HttpRequestHeader::write1stLine [I] HttpHeader.h : 384 - -> GET /m/drsvirus/mp3_128 HTTP/1.1 [I] HttpHeader.h : 192 - -> Content-Length: 0 [I] HttpHeader.h : 192 - -> Host: streaming.swisstxt.ch [I] HttpHeader.h : 192 - -> Connection: close [I] HttpHeader.h : 192 - -> Accept: audio/mp3 [I] HttpHeader.h : 300 - -> [I] HttpRequest.h : 263 - Request written ... waiting for reply [I] HttpHeader.h : 225 - HttpHeader::read [W] HttpHeader.h : 232 - Waiting for data... [I] HttpHeader.h : 162 - HttpHeader::readLine -> HTTP/1.1 200 OK [I] HttpHeader.h : 162 - HttpHeader::readLine -> Content-Type: audio/mpeg [I] HttpHeader.h : 162 - HttpHeader::readLine -> Date: Thu, 20 Apr 2023 14:12:41 GMT [I] HttpHeader.h : 162 - HttpHeader::readLine -> icy-br:128 [I] HttpHeader.h : 162 - HttpHeader::readLine -> ice-audio-info: bitrate=128 [I] HttpHeader.h : 162 - HttpHeader::readLine -> icy-br:128 [I] HttpHeader.h : 162 - HttpHeader::readLine -> icy-description:SRF-Virus_MP3@128Kbps [I] HttpHeader.h : 162 - HttpHeader::readLine -> icy-genre:Entertainment [I] HttpHeader.h : 162 - HttpHeader::readLine -> icy-mimetype:audio/mpeg [I] HttpHeader.h : 162 - HttpHeader::readLine -> icy-name:/SRF-Virus_Room2 [I] HttpHeader.h : 162 - HttpHeader::readLine -> icy-pub:0 [I] HttpHeader.h : 162 - HttpHeader::readLine -> icy-url:www.srgssr.ch [I] HttpHeader.h : 162 - HttpHeader::readLine -> Server: Icecast 2.4.0-kh10 [I] HttpHeader.h : 162 - HttpHeader::readLine -> Cache-Control: no-cache, no-store [I] HttpHeader.h : 162 - HttpHeader::readLine -> Access-Control-Allow-Origin: * [I] HttpHeader.h : 162 - HttpHeader::readLine -> Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type [I] HttpHeader.h : 162 - HttpHeader::readLine -> Access-Control-Allow-Methods: GET, OPTIONS, HEAD [I] HttpHeader.h : 162 - HttpHeader::readLine -> Connection: Close [I] HttpHeader.h : 162 - HttpHeader::readLine -> Expires: Mon, 26 Jul 1997 05:00:00 GMT [I] HttpHeader.h : 162 - HttpHeader::readLine -> [W] HttpRequest.h : 167 - no CONTENT_LENGTH found in reply [I] URLStream.h : 110 - size: 0 [I] URLStream.h : 331 - virtual bool audio_tools::URLStream::waitForData() [I] AudioCopy.h : 71 - buffer_size=1024 [I] AudioPlayer.h : 243 - sample_rate: 22050 [I] AudioPlayer.h : 244 - bits_per_sample: 16 [I] AudioPlayer.h : 245 - channels: 2 [I] VolumeStream.h : 191 - setVolume: 1.000000 [I] VolumeStream.h : 191 - setVolume: 1.000000 [I] AudioTypes.h : 63 - sample_rate: 22050 [I] AudioTypes.h : 64 - channels: 2 [I] AudioTypes.h : 65 - bits_per_sample: 16 [I] I2SStream.h : 74 - virtual void audio_tools::I2SStream::setAudioInfo(audio_tools::AudioBaseInfo) [I] AudioTypes.h : 63 - sample_rate: 22050 [I] AudioTypes.h : 64 - channels: 2 [I] AudioTypes.h : 65 - bits_per_sample: 16 [I] I2SConfig.h : 106 - rx/tx mode: TX_MODE [I] I2SConfig.h : 107 - port_no: 1 [I] I2SConfig.h : 108 - is_master: Master [I] I2SConfig.h : 109 - sample rate: 22050 [I] I2SConfig.h : 110 - bits per sample: 16 [I] I2SConfig.h : 111 - number of channels: 2 [I] I2SConfig.h : 112 - i2s_format: I2S_STD_FORMAT [I] I2SConfig.h : 114 - auto_clear: true [I] I2SConfig.h : 116 - use_apll: true [I] I2SConfig.h : 121 - buffer_count:6 [I] I2SConfig.h : 122 - buffer_size:512 [I] I2SConfig.h : 126 - pin_bck: 4 [I] I2SConfig.h : 128 - pin_ws: 25 [I] I2SConfig.h : 130 - pin_data: 21 [I] I2SConfig.h : 106 - rx/tx mode: TX_MODE [I] I2SConfig.h : 107 - port_no: 1 [I] I2SConfig.h : 108 - is_master: Master [I] I2SConfig.h : 109 - sample rate: 22050 [I] I2SConfig.h : 110 - bits per sample: 16 [I] I2SConfig.h : 111 - number of channels: 2 [I] I2SConfig.h : 112 - i2s_format: I2S_STD_FORMAT [I] I2SConfig.h : 114 - auto_clear: true [I] I2SConfig.h : 116 - use_apll: true [I] I2SConfig.h : 121 - buffer_count:6 [I] I2SConfig.h : 122 - buffer_size:512 [I] I2SConfig.h : 126 - pin_bck: 4 [I] I2SConfig.h : 128 - pin_ws: 25 [I] I2SConfig.h : 130 - pin_data: 21 [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioPlayer.h : 352 - setVolume(0.100000) [I] VolumeStream.h : 191 - setVolume: 0.100000 [I] VolumeStream.h : 191 - setVolume: 0.100000 [I] AudioPlayer.h : 243 - sample_rate: 48000 [I] AudioPlayer.h : 244 - bits_per_sample: 16 [I] AudioPlayer.h : 245 - channels: 2 [I] VolumeStream.h : 191 - setVolume: 1.000000 [I] VolumeStream.h : 191 - setVolume: 1.000000 [I] AudioTypes.h : 63 - sample_rate: 48000 [I] AudioTypes.h : 64 - channels: 2 [I] AudioTypes.h : 65 - bits_per_sample: 16 [I] I2SStream.h : 74 - virtual void audio_tools::I2SStream::setAudioInfo(audio_tools::AudioBaseInfo) [I] AudioTypes.h : 63 - sample_rate: 48000 [I] AudioTypes.h : 64 - channels: 2 [I] AudioTypes.h : 65 - bits_per_sample: 16 [I] I2SConfig.h : 106 - rx/tx mode: RX_MODE [I] I2SConfig.h : 107 - port_no: 0 [I] I2SConfig.h : 108 - is_master: Master [I] I2SConfig.h : 109 - sample rate: 48000 [I] I2SConfig.h : 110 - bits per sample: 16 [I] I2SConfig.h : 111 - number of channels: 2 [I] I2SConfig.h : 112 - i2s_format: I2S_STD_FORMAT [I] I2SConfig.h : 114 - auto_clear: false [I] I2SConfig.h : 116 - use_apll: true [I] I2SConfig.h : 121 - buffer_count:6 [I] I2SConfig.h : 122 - buffer_size:512 [I] I2SConfig.h : 126 - pin_bck: 4 [I] I2SConfig.h : 128 - pin_ws: 25 [I] I2SConfig.h : 130 - pin_data: 32 E (10698) I2S: i2s_driver_uninstall(2047): I2S port 0 has not installed [I] I2SConfig.h : 106 - rx/tx mode: RX_MODE [I] I2SConfig.h : 107 - port_no: 0 [I] I2SConfig.h : 108 - is_master: Master [I] I2SConfig.h : 109 - sample rate: 48000 [I] I2SConfig.h : 110 - bits per sample: 16 [I] I2SConfig.h : 111 - number of channels: 2 [I] I2SConfig.h : 112 - i2s_format: I2S_STD_FORMAT [I] I2SConfig.h : 114 - auto_clear: false [I] I2SConfig.h : 116 - use_apll: true [I] I2SConfig.h : 121 - buffer_count:6 [I] I2SConfig.h : 122 - buffer_size:512 [I] I2SConfig.h : 126 - pin_bck: 4 [I] I2SConfig.h : 128 - pin_ws: 25 [I] I2SConfig.h : 130 - pin_data: 32 [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops

pschatzmann commented 1 year ago

There is no way I can help because I have no clue what you are doing. Please submit a small sketch that demonstrates the problem with a description how I can reproduce it.

urrudelu30 commented 1 year ago

Hi, I found out what is the problem.

I have two instances of player, one for taking data from the internet and the other for taking data over mp3.:

I2SStream i2s; //DAC output MP3DecoderHelix decoder; URLStream urlStream (wifi, password);// Usaremos el wifi para movernos por internet AudioSourceURL source(urlStream, urls, "audio/mp3"); // Cogemos archivos mp3 de internet AudioPlayer player (source, i2s, decoder);

const char startFilePath="/"; const char ext="mp3"; AudioSourceSDFAT sourcemp3(startFilePath, ext); I2SStream i2smp3; MP3DecoderHelix decodermp3; AudioPlayer playermp3(sourcemp3, i2smp3, decodermp3);

When I comment on the mp3 player the code works, but when I put these instances the code don't work and also shows me the following:

AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [E] Fade.h : 271 - setAudioInfo not called [E] Fade.h : 271 - setAudioInfo not called [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [E] Fade.h : 271 - setAudioInfo not called [E] Fade.h : 271 - setAudioInfo not called [E] Fade.h : 271 - setAudioInfo not called [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops [E] Fade.h : 271 - setAudioInfo not called [E] Fade.h : 271 - setAudioInfo not called [E] Fade.h : 271 - setAudioInfo not called [I] AudioCopy.h : 136 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops

pschatzmann commented 1 year ago

The message is pretty speaking: setAudioInfo()! I don't know what more I should say... ps. I don't see any reason why you would have two instances AudioPlayer.

urrudelu30 commented 1 year ago

what should I do instead of having two instances?

pschatzmann commented 1 year ago

Just use one and change the source or output when you need to! And ff the system can't automatically determine the AudioInfo provide it to the player.