Skip to content

Commit 452a02b

Browse files
committed
AudioProcessor: Stabilize the work, and fixed loop end of XQOA files
1 parent 3ddd1e8 commit 452a02b

3 files changed

Lines changed: 45 additions & 9 deletions

File tree

_common/AudioProcessor/audio_processor.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ int64_t MoondustAudioProcessor::getBytesWrittenStat() const
264264

265265
int64_t MoondustAudioProcessor::getSamplesReadStat() const
266266
{
267+
if(!m_in_file.get())
268+
return 0;
269+
267270
const auto &source = m_in_file->getSpec();
268271
size_t sample_in = (SDL_AUDIO_BITSIZE(source.m_sample_format) / 8) * source.m_channels;
269272

@@ -272,6 +275,9 @@ int64_t MoondustAudioProcessor::getSamplesReadStat() const
272275

273276
int64_t MoondustAudioProcessor::getSamplesWrittenStat() const
274277
{
278+
if(!m_out_file.get())
279+
return 0;
280+
275281
const auto &obtained = m_out_file->getSpec();
276282
size_t sample_out = (SDL_AUDIO_BITSIZE(obtained.m_sample_format) / 8) * obtained.m_channels;
277283

@@ -300,7 +306,11 @@ bool MoondustAudioProcessor::runChunk(bool dry)
300306
{
301307
filled = SDL_AudioStreamGet(m_cvt_stream, m_out_buffer.data(), m_out_buffer.size());
302308
if(filled != 0)
309+
{
310+
if(filled < 0)
311+
return false;
303312
break;
313+
}
304314

305315
amount = m_in_file->readChunk(m_in_buffer.data(), m_in_buffer.size(), &spec_changed);
306316

_common/AudioProcessor/codec/audio_qoa.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,17 @@ bool MDAudioQOA::close()
398398
if(m_file)
399399
{
400400
if(sample_data_pos > 0)
401+
{
402+
if(m_spec.m_loop_len != 0)
403+
{
404+
// Extra samples to make loop end to not fail
405+
if(sample_data_pos + 4 <= sample_data_len)
406+
sample_data_pos += 4;
407+
else
408+
sample_data_pos = sample_data_len;
409+
}
401410
encode_frame(); // Finish the data that was left
411+
}
402412

403413
// Finalize the written data and update the header
404414
SDL_RWseek(m_file, qoa_file_begin, SEEK_SET);

test/Maintainer/AudioConverterTest/coverter_dialogue.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ void CoverterDialogue::on_runCvt_clicked()
9393
else // Otherwise, just write down as-is
9494
{
9595
m_phase = PHASE_CONVERSION;
96+
}
9697

97-
if(!m_cvt.openOutFile(ui->fileOut->text().toStdString(), ui->dstFormat->currentData().toInt(), m_dstSpec))
98-
{
99-
qWarning() << "Failed to open output file" << ui->fileOut->text() << QString::fromStdString(m_cvt.getLastError());
100-
return;
101-
}
98+
if(!m_cvt.openOutFile(ui->fileOut->text().toStdString(), ui->dstFormat->currentData().toInt(), m_dstSpec))
99+
{
100+
qWarning() << "Failed to open output file" << ui->fileOut->text() << QString::fromStdString(m_cvt.getLastError());
101+
return;
102102
}
103103

104104
m_runner = QtConcurrent::run<void>(this, &CoverterDialogue::runner);
@@ -137,7 +137,12 @@ void CoverterDialogue::runner()
137137
switch(m_phase)
138138
{
139139
case PHASE_LENGHT_MEASURE:
140-
m_cvt.runChunk(true);
140+
if(!m_cvt.runChunk(true))
141+
{
142+
qWarning() << "Conversion failed: (Phase Measure) can't read source file";
143+
emit workFinished();
144+
return;
145+
}
141146

142147
if(prev_progress != m_cvt.curChunk())
143148
{
@@ -161,7 +166,7 @@ void CoverterDialogue::runner()
161166

162167
m_cvt.rewindRead();
163168

164-
if(!m_cvt.openOutFile(ui->fileOut->text().toStdString(), FORMAT_OGG_VORBIS, m_dstSpec))
169+
if(!m_cvt.openOutFile(ui->fileOut->text().toStdString(), ui->dstFormat->currentData().toInt(), m_dstSpec))
165170
{
166171
qWarning() << "Failed to open output file" << ui->fileOut->text();
167172
emit workFinished();
@@ -173,7 +178,12 @@ void CoverterDialogue::runner()
173178

174179
break;
175180
case PHASE_CONVERSION:
176-
m_cvt.runChunk(false);
181+
if(!m_cvt.runChunk(false))
182+
{
183+
qWarning() << "Conversion failed: (Phase Conversion) can't read source file";
184+
emit workFinished();
185+
return;
186+
}
177187

178188
if(prev_progress != m_cvt.curChunk())
179189
{
@@ -187,7 +197,13 @@ void CoverterDialogue::runner()
187197
}
188198
else
189199
{
190-
m_cvt.runChunk();
200+
if(!m_cvt.runChunk())
201+
{
202+
qWarning() << "Conversion failed: can't read source file";
203+
emit workFinished();
204+
return;
205+
}
206+
191207
emit updateProgress(m_cvt.curChunk());
192208
}
193209
}

0 commit comments

Comments
 (0)