@@ -39,6 +39,15 @@ namespace SoLoud
3939 {
4040 std::lock_guard<std::mutex> lock (buffer_lock_mutex);
4141
42+ // When using BufferType::AUTO, samplerate and channels are got from the stream. Hence we need to update them
43+ // regardless of how are set by setBufferStream. But these parameters need to be set after the play
44+ // function is called and the instance of this class is created.
45+ if (mParent ->autoTypeSamplerate != 0 .f ) {
46+ mBaseSamplerate = mParent ->autoTypeSamplerate ;
47+ mSamplerate = mParent ->autoTypeSamplerate ;
48+ mChannels = mParent ->autoTypeChannels ;
49+ }
50+
4251 // This happens when using RELEASED buffer type
4352 if (mParent ->mBuffer .getFloatsBufferSize () == 0 )
4453 {
@@ -226,6 +235,9 @@ namespace SoLoud
226235 if (pcmFormat.dataType == BufferType::OPUS)
227236 pcmFormat.dataType = BufferType::AUTO;
228237
238+ mInstance = nullptr ;
239+ autoTypeChannels = 0 ;
240+ autoTypeSamplerate = 0 .f ;
229241 mBytesReceived = 0 ;
230242 mUncompressedBytesReceived = 0 ;
231243 mSampleCount = 0 ;
@@ -317,7 +329,7 @@ namespace SoLoud
317329 static_cast <const unsigned char *>(aData) + aDataLen);
318330 mBytesReceived += aDataLen;
319331 // Performing some buffering. We need some data to be added expecially when using opus or mp3.
320- if (buffer.size () > 1024 * 16 ) // 16 KB of data.
332+ if (buffer.size () > 1024 * 32 ) // 16 KB of data.
321333 {
322334 // For PCM data we must align the data to the bytes per sample.
323335 if (!(mPCMformat .dataType == BufferType::AUTO))
@@ -381,14 +393,13 @@ namespace SoLoud
381393 {
382394 mPCMformat .sampleRate = sampleRate;
383395 mBaseSamplerate = sampleRate;
384- mInstance ->mSamplerate = sampleRate;
385- mInstance ->mBaseSamplerate = sampleRate;
396+ autoTypeSamplerate = sampleRate;
386397 }
387398 if (channels != -1 )
388399 {
389400 mPCMformat .channels = channels;
390401 mChannels = channels;
391- mInstance -> mChannels = channels;
402+ autoTypeChannels = channels;
392403 }
393404 }
394405
0 commit comments