Do offline render in a thread, show render progress etc

This commit is contained in:
xenakios 2018-02-26 19:55:32 +02:00
parent 46a74c2c51
commit ba067f7d4a
3 changed files with 28 additions and 15 deletions

View File

@ -274,7 +274,9 @@ void PaulstretchpluginAudioProcessorEditor::timerCallback(int id)
if (processor.m_playposinfo.isPlaying)
infotext += " "+String(processor.m_playposinfo.timeInSeconds,1);
if (processor.m_show_technical_info)
infotext += " " + String(m_wavecomponent.m_image_init_count) + " " + String(m_wavecomponent.m_image_update_count);
infotext += " " + String(m_wavecomponent.m_image_init_count) + " " + String(m_wavecomponent.m_image_update_count)+ " ";
if (processor.m_offline_render_state >= 0 && processor.m_offline_render_state <= 100)
infotext += String(processor.m_offline_render_state)+"%";
m_info_label.setText(infotext, dontSendNotification);
m_perfmeter.repaint();
}
@ -358,7 +360,8 @@ void PaulstretchpluginAudioProcessorEditor::showSettingsMenu()
menu.addItem(6, "Dump preset to clipboard", true, false);
#endif
menu.addItem(7, "Show technical info", true, processor.m_show_technical_info);
menu.addItem(8, "Offline render...", true, false);
menu.addItem(8, "Offline render...",
processor.m_offline_render_state == 200 || processor.m_offline_render_state == -1, false);
int r = menu.show();
if (r >= 200 && r < 210)
{

View File

@ -417,8 +417,7 @@ String PaulstretchpluginAudioProcessor::offlineRender(File outputfile)
int numoutchans = *getIntParameter(cpi_num_outchans);
auto ss = std::make_shared<StretchAudioSource>(numoutchans,m_afm);
int blocksize = 2048;
int64_t outlen = 10 * getSampleRateChecked();
int64_t outcounter = 0;
ss->setAudioFile(m_current_file);
ProcessParameters renderpars;
updateStretchParametersFromPluginParameters(renderpars);
@ -438,9 +437,9 @@ String PaulstretchpluginAudioProcessor::offlineRender(File outputfile)
ss->setPaused(getParameter(cpi_pause_enabled));
ss->setSpectrumProcessOrder(m_stretch_source->getSpectrumProcessOrder());
ss->setFFTSize(m_fft_size_to_use);
ss->prepareToPlay(blocksize, getSampleRateChecked());
AudioBuffer<float> renderbuffer(numoutchans, blocksize);
ss->setMainVolume(*getFloatParameter(cpi_main_volume));
double outsr = getSampleRateChecked();
ss->prepareToPlay(blocksize, outsr);
WavAudioFormat wavformat;
FileOutputStream* outstream = outputfiletouse.createOutputStream();
if (outstream == nullptr)
@ -451,15 +450,25 @@ String PaulstretchpluginAudioProcessor::offlineRender(File outputfile)
delete outstream;
return "Could not create WAV writer";
}
AudioSourceChannelInfo asci(renderbuffer);
while (outcounter < outlen)
auto rendertask = [ss,writer,blocksize,numoutchans, outsr, this]()
{
ss->setMainVolume(*getFloatParameter(cpi_main_volume));
ss->getNextAudioBlock(asci);
writer->writeFromAudioSampleBuffer(renderbuffer,0,blocksize);
outcounter += blocksize;
}
delete writer;
AudioBuffer<float> renderbuffer(numoutchans, blocksize);
int64_t outlen = 50 * outsr;
int64_t outcounter = 0;
AudioSourceChannelInfo asci(renderbuffer);
m_offline_render_state = 0;
while (outcounter < outlen)
{
ss->getNextAudioBlock(asci);
writer->writeFromAudioSampleBuffer(renderbuffer, 0, blocksize);
outcounter += blocksize;
m_offline_render_state = 100.0 / outlen * outcounter;
}
m_offline_render_state = 200;
delete writer;
};
std::thread th(rendertask);
th.detach();
return "Rendered OK";
}

View File

@ -162,6 +162,7 @@ public:
ValueTree getStateTree(bool ignoreoptions, bool ignorefile);
void setStateFromTree(ValueTree tree);
String offlineRender(File outputfile);
std::atomic<int> m_offline_render_state{ -1 };
bool m_state_dirty = false;
std::unique_ptr<AudioThumbnail> m_thumb;
bool m_show_technical_info = false;