@@ -80,6 +80,11 @@ class I2SCodecStream : public AudioStream {
80
80
return false ;
81
81
}
82
82
is_active = i2s.begin (cfg);
83
+
84
+ // if setvolume was called before begin
85
+ if (is_active && volume>0 .0f ) {
86
+ setVolume (volume);
87
+ }
83
88
return is_active;
84
89
}
85
90
@@ -102,14 +107,15 @@ class I2SCodecStream : public AudioStream {
102
107
// / updates the sample rate dynamically
103
108
virtual void setAudioInfo (AudioInfo info) {
104
109
TRACEI ();
105
- AudioStream::setAudioInfo (info);
106
- float vol = -1 .0f ;
107
110
// save volume if possible
108
- if (is_active) vol = getVolume ( );
111
+ AudioStream::setAudioInfo (info );
109
112
beginCodec (info);
110
113
i2s.setAudioInfo (info);
111
- // restore volume
112
- if (vol>0 .0f ) setVolume (vol);
114
+ // restore volume
115
+ if (volume > 0 .0f ) {
116
+ LOGI (" restoring volume: %f" , volume);
117
+ setVolume (volume);
118
+ }
113
119
}
114
120
115
121
// / Writes the audio data to I2S
@@ -131,7 +137,8 @@ class I2SCodecStream : public AudioStream {
131
137
132
138
// / sets the volume (range 0.0 - 1.0)
133
139
bool setVolume (float vol) {
134
- if (p_board == nullptr )
140
+ volume = vol;
141
+ if (!is_active || p_board == nullptr )
135
142
return false ;
136
143
return p_board->setVolume (vol * 100.0 );
137
144
}
@@ -199,6 +206,7 @@ class I2SCodecStream : public AudioStream {
199
206
I2SCodecConfig cfg_driver; // last driver state
200
207
AudioBoard *p_board = nullptr ;
201
208
bool is_active = false ;
209
+ float volume = -1 .0f ;
202
210
203
211
// / We use the board pins if they are available
204
212
void setupI2SPins () {
0 commit comments