@@ -73,6 +73,37 @@ bool MoondustAudioProcessor::init_cvt_stream()
7373
7474 m_curChunk = 0 ;
7575
76+ m_cvt_in_channels = spec_src.m_channels ;
77+ m_cvt_in_sample_format = spec_src.m_sample_format ;
78+ m_cvt_in_sample_rate = spec_src.m_sample_rate ;
79+
80+ m_cvt_out_channels = spec_dst.m_channels ;
81+ m_cvt_out_sample_format = spec_dst.m_sample_format ;
82+ m_cvt_out_sample_rate = spec_dst.m_sample_rate ;
83+
84+ return true ;
85+ }
86+
87+ bool MoondustAudioProcessor::update_cvt_stream ()
88+ {
89+ if (!m_cvt_stream)
90+ return init_cvt_stream ();
91+
92+ const auto &spec_src = m_in_file->getSpec ();
93+ const auto &spec_dst = m_out_file->getSpec ();
94+
95+ if (m_cvt_in_channels != spec_src.m_channels ||
96+ m_cvt_in_sample_format != spec_src.m_sample_format ||
97+ m_cvt_in_sample_rate != spec_src.m_sample_rate ||
98+ m_cvt_out_channels != spec_dst.m_channels ||
99+ m_cvt_out_sample_format != spec_dst.m_sample_format ||
100+ m_cvt_out_sample_rate != spec_dst.m_sample_rate )
101+ {
102+ return init_cvt_stream ();
103+ }
104+
105+ SDL_AudioStreamClear (m_cvt_stream);
106+
76107 return true ;
77108}
78109
@@ -352,7 +383,7 @@ bool MoondustAudioProcessor::openOutFile(const std::string &file, int dstFormat,
352383 return false ;
353384 }
354385
355- if (!init_cvt_stream ())
386+ if (!update_cvt_stream ())
356387 {
357388 m_out_file.reset (nullptr );
358389 SDL_RWclose (m_rw_out);
@@ -451,7 +482,7 @@ bool MoondustAudioProcessor::rewindRead()
451482 m_stat_read = 0 ;
452483 m_curChunk = 0.0 ;
453484
454- if (!init_cvt_stream ())
485+ if (!update_cvt_stream ())
455486 return false ;
456487
457488 return m_in_file->readRewind ();
0 commit comments