You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

766 lines
32KB

  1. /*
  2. Copyright (C) 2006-2011 Nasca Octavian Paul
  3. Author: Nasca Octavian Paul
  4. Copyright (C) 2017 Xenakios
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of version 2 of the GNU General Public License
  7. as published by the Free Software Foundation.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License (version 2) for more details.
  12. You should have received a copy of the GNU General Public License (version 2)
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #include "PluginProcessor.h"
  17. #include "PluginEditor.h"
  18. #include <set>
  19. #ifdef WIN32
  20. #undef min
  21. #undef max
  22. #endif
  23. String g_plugintitle{ "PaulXStretch 1.0.0 preview 6" };
  24. std::set<PaulstretchpluginAudioProcessor*> g_activeprocessors;
  25. struct PresetEntry
  26. {
  27. PresetEntry(String name, String data) : m_name(name), m_data(data) {}
  28. String m_name;
  29. String m_data;
  30. };
  31. const int g_num_presets = 4;
  32. static const PresetEntry g_presets[g_num_presets] =
  33. {
  34. {"Factory reset","cGF1bHN0cmV0Y2gzcGx1Z2luc3RhdGUAASZtYWludm9sdW1lMAABCQQAAACAi1cewHN0cmV0Y2hhbW91bnQwAAEJBAAAACAAAPA/ZmZ0c2l6ZTAAAQkEAAAAYGZm5j9waXRjaHNoaWZ0MAABCQQAAAAAAAAAAGZyZXFzaGlmdDAAAQkEAAAAAAAAAABwbGF5cmFuZ2Vfc3RhcnQwAAEJBAAAAAAAAAAAcGxheXJhbmdlX2VuZDAAAQkEAAAAAAAA8D9zcHJlYWQwAAEJBAAAAAAAAAAAY29tcHJlc3MwAAEJBAAAAAAAAAAAbG9vcHhmYWRlbGVuMAABCQQAAABA4XqEP251bWhhcm1vbmljczAAAQ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JkZXIyAAEFAQEAAABzcGVjb3JkZXIzAAEFAQIAAABzcGVjb3JkZXI0AAEFAQQAAABzcGVjb3JkZXI1AAEFAQUAAABzcGVjb3JkZXI2AAEFAQYAAABzcGVjb3JkZXI3AAEFAQcAAAAAzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N"}
  38. };
  39. int get_optimized_updown(int n, bool up) {
  40. int orig_n = n;
  41. while (true) {
  42. n = orig_n;
  43. while (!(n % 11)) n /= 11;
  44. while (!(n % 7)) n /= 7;
  45. while (!(n % 5)) n /= 5;
  46. while (!(n % 3)) n /= 3;
  47. while (!(n % 2)) n /= 2;
  48. if (n<2) break;
  49. if (up) orig_n++;
  50. else orig_n--;
  51. if (orig_n<4) return 4;
  52. };
  53. return orig_n;
  54. };
  55. int optimizebufsize(int n) {
  56. int n1 = get_optimized_updown(n, false);
  57. int n2 = get_optimized_updown(n, true);
  58. if ((n - n1)<(n2 - n)) return n1;
  59. else return n2;
  60. };
  61. inline AudioParameterFloat* make_floatpar(String id, String name, float minv, float maxv, float defv, float step, float skew)
  62. {
  63. return new AudioParameterFloat(id, name, NormalisableRange<float>(minv, maxv, step, skew), defv);
  64. }
  65. //==============================================================================
  66. PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor()
  67. : m_bufferingthread("pspluginprebufferthread")
  68. #ifndef JucePlugin_PreferredChannelConfigurations
  69. : AudioProcessor (BusesProperties()
  70. #if ! JucePlugin_IsMidiEffect
  71. #if ! JucePlugin_IsSynth
  72. .withInput ("Input", AudioChannelSet::stereo(), true)
  73. #endif
  74. .withOutput ("Output", AudioChannelSet::stereo(), true)
  75. #endif
  76. )
  77. #endif
  78. {
  79. g_activeprocessors.insert(this);
  80. m_recbuffer.setSize(2, 44100);
  81. m_recbuffer.clear();
  82. if (m_afm->getNumKnownFormats()==0)
  83. m_afm->registerBasicFormats();
  84. m_thumb = std::make_unique<AudioThumbnail>(512, *m_afm, *m_thumbcache);
  85. // The default priority of 2 is a bit too low in some cases, it seems...
  86. m_thumbcache->getTimeSliceThread().setPriority(3);
  87. m_stretch_source = std::make_unique<StretchAudioSource>(2, m_afm);
  88. m_stretch_source->setOnsetDetection(0.0);
  89. m_stretch_source->setLoopingEnabled(true);
  90. m_stretch_source->setFFTWindowingType(1);
  91. addParameter(make_floatpar("mainvolume0", "Main volume", -24.0, 12.0, -3.0, 0.1, 1.0));
  92. addParameter(make_floatpar("stretchamount0", "Stretch amount", 0.1, 1024.0, 2.0, 0.1, 0.25));
  93. addParameter(make_floatpar("fftsize0", "FFT size", 0.0, 1.0, 0.7, 0.01, 1.0));
  94. addParameter(make_floatpar("pitchshift0", "Pitch shift", -24.0f, 24.0f, 0.0f, 0.1,1.0)); // 3
  95. addParameter(make_floatpar("freqshift0", "Frequency shift", -1000.0f, 1000.0f, 0.0f, 1.0, 1.0)); // 4
  96. addParameter(make_floatpar("playrange_start0", "Sound start", 0.0f, 1.0f, 0.0f, 0.0001,1.0)); // 5
  97. addParameter(make_floatpar("playrange_end0", "Sound end", 0.0f, 1.0f, 1.0f, 0.0001,1.0)); // 6
  98. addParameter(new AudioParameterBool("freeze0", "Freeze", false)); // 7
  99. addParameter(make_floatpar("spread0", "Frequency spread", 0.0f, 1.0f, 0.0f, 0.001,1.0)); // 8
  100. addParameter(make_floatpar("compress0", "Compress", 0.0f, 1.0f, 0.0f, 0.001,1.0)); // 9
  101. addParameter(make_floatpar("loopxfadelen0", "Loop xfade length", 0.0f, 1.0f, 0.01f, 0.001, 1.0)); // 10
  102. addParameter(new AudioParameterInt("numharmonics0", "Num harmonics", 1, 100, 10)); // 11
  103. addParameter(make_floatpar("harmonicsfreq0", "Harmonics base freq", 1.0, 5000.0, 128.0, 0.1, 0.5));
  104. addParameter(make_floatpar("harmonicsbw0", "Harmonics bandwidth", 0.1f, 200.0f, 25.0f, 0.01, 1.0)); // 13
  105. addParameter(new AudioParameterBool("harmonicsgauss0", "Gaussian harmonics", false)); // 14
  106. addParameter(make_floatpar("octavemixm2_0", "2 octaves down level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 15
  107. addParameter(make_floatpar("octavemixm1_0", "Octave down level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 16
  108. addParameter(make_floatpar("octavemix0_0", "Normal pitch level", 0.0f, 1.0f, 1.0f, 0.001, 1.0)); // 17
  109. addParameter(make_floatpar("octavemix1_0", "1 octave up level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 18
  110. addParameter(make_floatpar("octavemix15_0", "1 octave and fifth up level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 19
  111. addParameter(make_floatpar("octavemix2_0", "2 octaves up level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 20
  112. addParameter(make_floatpar("tonalvsnoisebw_0", "Tonal vs Noise BW", 0.74f, 1.0f, 0.74f, 0.001, 1.0)); // 21
  113. addParameter(make_floatpar("tonalvsnoisepreserve_0", "Tonal vs Noise preserve", -1.0f, 1.0f, 0.5f, 0.001, 1.0)); // 22
  114. auto filt_convertFrom0To1Func = [](float rangemin, float rangemax, float value)
  115. {
  116. if (value < 0.5f)
  117. return jmap<float>(value, 0.0f, 0.5f, 20.0f, 1000.0f);
  118. return jmap<float>(value, 0.5f, 1.0f, 1000.0f, 20000.0f);
  119. };
  120. auto filt_convertTo0To1Func = [](float rangemin, float rangemax, float value)
  121. {
  122. if (value < 1000.0f)
  123. return jmap<float>(value, 20.0f, 1000.0f, 0.0f, 0.5f);
  124. return jmap<float>(value, 1000.0f, 20000.0f, 0.5f, 1.0f);
  125. };
  126. addParameter(new AudioParameterFloat("filter_low_0", "Filter low",
  127. NormalisableRange<float>(20.0f, 20000.0f,
  128. filt_convertFrom0To1Func, filt_convertTo0To1Func), 20.0f)); // 23
  129. addParameter(new AudioParameterFloat("filter_high_0", "Filter high",
  130. NormalisableRange<float>(20.0f, 20000.0f,
  131. filt_convertFrom0To1Func,filt_convertTo0To1Func), 20000.0f));; // 24
  132. addParameter(make_floatpar("onsetdetect_0", "Onset detection", 0.0f, 1.0f, 0.0f, 0.01, 1.0)); // 25
  133. addParameter(new AudioParameterBool("capture_enabled0", "Capture", false)); // 26
  134. m_outchansparam = new AudioParameterInt("numoutchans0", "Num output channels", 2, 8, 2); // 27
  135. addParameter(m_outchansparam); // 27
  136. addParameter(new AudioParameterBool("pause_enabled0", "Pause", false)); // 28
  137. addParameter(new AudioParameterFloat("maxcapturelen_0", "Max capture length", 1.0f, 120.0f, 10.0f)); // 29
  138. addParameter(new AudioParameterBool("passthrough0", "Pass input through", false)); // 30
  139. auto& pars = getParameters();
  140. for (const auto& p : pars)
  141. m_reset_pars.push_back(p->getValue());
  142. setPreBufferAmount(2);
  143. startTimer(1, 50);
  144. }
  145. PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor()
  146. {
  147. g_activeprocessors.erase(this);
  148. m_thumb->removeAllChangeListeners();
  149. m_thumb = nullptr;
  150. m_bufferingthread.stopThread(1000);
  151. }
  152. void PaulstretchpluginAudioProcessor::resetParameters()
  153. {
  154. ScopedLock locker(m_cs);
  155. for (int i = 0; i < m_reset_pars.size(); ++i)
  156. {
  157. if (i!=cpi_main_volume && i!=cpi_passthrough)
  158. setParameter(i, m_reset_pars[i]);
  159. }
  160. }
  161. void PaulstretchpluginAudioProcessor::setPreBufferAmount(int x)
  162. {
  163. int temp = jlimit(0, 5, x);
  164. if (temp != m_prebuffer_amount || m_use_backgroundbuffering == false)
  165. {
  166. m_use_backgroundbuffering = true;
  167. m_prebuffer_amount = temp;
  168. m_recreate_buffering_source = true;
  169. ScopedLock locker(m_cs);
  170. m_prebuffering_inited = false;
  171. m_cur_num_out_chans = *m_outchansparam;
  172. //Logger::writeToLog("Switching to use " + String(m_cur_num_out_chans) + " out channels");
  173. String err;
  174. startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) },
  175. m_cur_num_out_chans, m_curmaxblocksize, err);
  176. m_prebuffering_inited = true;
  177. }
  178. }
  179. int PaulstretchpluginAudioProcessor::getPreBufferAmount()
  180. {
  181. if (m_use_backgroundbuffering == false)
  182. return -1;
  183. return m_prebuffer_amount;
  184. }
  185. ValueTree PaulstretchpluginAudioProcessor::getStateTree(bool ignoreoptions, bool ignorefile)
  186. {
  187. ValueTree paramtree("paulstretch3pluginstate");
  188. for (int i = 0; i<getNumParameters(); ++i)
  189. {
  190. auto par = getFloatParameter(i);
  191. if (par != nullptr)
  192. {
  193. paramtree.setProperty(par->paramID, (double)*par, nullptr);
  194. }
  195. }
  196. paramtree.setProperty(m_outchansparam->paramID, (int)*m_outchansparam, nullptr);
  197. if (m_current_file != File() && ignorefile == false)
  198. {
  199. paramtree.setProperty("importedfile", m_current_file.getFullPathName(), nullptr);
  200. }
  201. auto specorder = m_stretch_source->getSpectrumProcessOrder();
  202. paramtree.setProperty("numspectralstages", (int)specorder.size(), nullptr);
  203. for (int i = 0; i < specorder.size(); ++i)
  204. {
  205. paramtree.setProperty("specorder" + String(i), specorder[i].m_index, nullptr);
  206. paramtree.setProperty("specstepenabled" + String(i), specorder[i].m_enabled, nullptr);
  207. }
  208. if (ignoreoptions == false)
  209. {
  210. if (m_use_backgroundbuffering)
  211. paramtree.setProperty("prebufamount", m_prebuffer_amount, nullptr);
  212. else
  213. paramtree.setProperty("prebufamount", -1, nullptr);
  214. paramtree.setProperty("loadfilewithstate", m_load_file_with_state, nullptr);
  215. }
  216. return paramtree;
  217. }
  218. void PaulstretchpluginAudioProcessor::setStateFromTree(ValueTree tree)
  219. {
  220. if (tree.isValid())
  221. {
  222. {
  223. ScopedLock locker(m_cs);
  224. m_load_file_with_state = tree.getProperty("loadfilewithstate", true);
  225. if (tree.hasProperty("numspectralstages"))
  226. {
  227. std::vector<SpectrumProcess> order;
  228. int ordersize = tree.getProperty("numspectralstages");
  229. for (int i = 0; i < ordersize; ++i)
  230. {
  231. bool step_enabled = tree.getProperty("specstepenabled" + String(i));
  232. order.push_back({ (int)tree.getProperty("specorder" + String(i)), step_enabled });
  233. }
  234. m_stretch_source->setSpectrumProcessOrder(order);
  235. }
  236. for (int i = 0; i < getNumParameters(); ++i)
  237. {
  238. auto par = getFloatParameter(i);
  239. if (par != nullptr)
  240. {
  241. double parval = tree.getProperty(par->paramID, (double)*par);
  242. *par = parval;
  243. }
  244. }
  245. if (tree.hasProperty(m_outchansparam->paramID))
  246. *m_outchansparam = tree.getProperty(m_outchansparam->paramID, 2);
  247. }
  248. int prebufamt = tree.getProperty("prebufamount", 2);
  249. if (prebufamt == -1)
  250. m_use_backgroundbuffering = false;
  251. else
  252. setPreBufferAmount(prebufamt);
  253. if (m_load_file_with_state == true)
  254. {
  255. String fn = tree.getProperty("importedfile");
  256. if (fn.isEmpty() == false)
  257. {
  258. File f(fn);
  259. setAudioFile(f);
  260. }
  261. }
  262. m_state_dirty = true;
  263. }
  264. }
  265. //==============================================================================
  266. const String PaulstretchpluginAudioProcessor::getName() const
  267. {
  268. return JucePlugin_Name;
  269. }
  270. bool PaulstretchpluginAudioProcessor::acceptsMidi() const
  271. {
  272. #if JucePlugin_WantsMidiInput
  273. return true;
  274. #else
  275. return false;
  276. #endif
  277. }
  278. bool PaulstretchpluginAudioProcessor::producesMidi() const
  279. {
  280. #if JucePlugin_ProducesMidiOutput
  281. return true;
  282. #else
  283. return false;
  284. #endif
  285. }
  286. bool PaulstretchpluginAudioProcessor::isMidiEffect() const
  287. {
  288. #if JucePlugin_IsMidiEffect
  289. return true;
  290. #else
  291. return false;
  292. #endif
  293. }
  294. double PaulstretchpluginAudioProcessor::getTailLengthSeconds() const
  295. {
  296. return 0.0;
  297. //return (double)m_bufamounts[m_prebuffer_amount]/getSampleRate();
  298. }
  299. int PaulstretchpluginAudioProcessor::getNumPrograms()
  300. {
  301. return g_num_presets;
  302. }
  303. int PaulstretchpluginAudioProcessor::getCurrentProgram()
  304. {
  305. return m_cur_program;
  306. }
  307. void PaulstretchpluginAudioProcessor::setCurrentProgram (int index)
  308. {
  309. index = jlimit(0, g_num_presets-1, index);
  310. m_cur_program = index;
  311. bool temp = m_load_file_with_state;
  312. m_load_file_with_state = false;
  313. MemoryBlock mb;
  314. MemoryOutputStream stream(mb, true);
  315. if (Base64::convertFromBase64(stream, g_presets[index].m_data)==true)
  316. {
  317. ValueTree tree = ValueTree::readFromData(mb.getData(), mb.getSize());
  318. tree.setProperty("loadfilewithstate", false, nullptr);
  319. setStateFromTree(tree);
  320. }
  321. m_load_file_with_state = temp;
  322. }
  323. const String PaulstretchpluginAudioProcessor::getProgramName (int index)
  324. {
  325. index = jlimit(0, g_num_presets-1, index);
  326. return g_presets[index].m_name;
  327. }
  328. void PaulstretchpluginAudioProcessor::changeProgramName (int index, const String& newName)
  329. {
  330. }
  331. void PaulstretchpluginAudioProcessor::setFFTSize(double size)
  332. {
  333. if (m_prebuffer_amount == 5)
  334. m_fft_size_to_use = pow(2, 7.0 + size * 14.5);
  335. else m_fft_size_to_use = pow(2, 7.0 + size * 10.0); // chicken out from allowing huge FFT sizes if not enough prebuffering
  336. int optim = optimizebufsize(m_fft_size_to_use);
  337. m_fft_size_to_use = optim;
  338. m_stretch_source->setFFTSize(optim);
  339. //Logger::writeToLog(String(m_fft_size_to_use));
  340. }
  341. void PaulstretchpluginAudioProcessor::startplay(Range<double> playrange, int numoutchans, int maxBlockSize, String& err)
  342. {
  343. m_stretch_source->setPlayRange(playrange, true);
  344. int bufamt = m_bufamounts[m_prebuffer_amount];
  345. if (m_buffering_source != nullptr && numoutchans != m_buffering_source->getNumberOfChannels())
  346. m_recreate_buffering_source = true;
  347. if (m_recreate_buffering_source == true)
  348. {
  349. m_buffering_source = std::make_unique<MyBufferingAudioSource>(m_stretch_source.get(),
  350. m_bufferingthread, false, bufamt, numoutchans, false);
  351. m_recreate_buffering_source = false;
  352. }
  353. if (m_bufferingthread.isThreadRunning() == false)
  354. m_bufferingthread.startThread();
  355. m_stretch_source->setNumOutChannels(numoutchans);
  356. m_stretch_source->setFFTSize(m_fft_size_to_use);
  357. m_stretch_source->setProcessParameters(&m_ppar);
  358. m_last_outpos_pos = 0.0;
  359. m_last_in_pos = playrange.getStart()*m_stretch_source->getInfileLengthSeconds();
  360. m_buffering_source->prepareToPlay(maxBlockSize, getSampleRateChecked());
  361. }
  362. void PaulstretchpluginAudioProcessor::setParameters(const std::vector<double>& pars)
  363. {
  364. ScopedLock locker(m_cs);
  365. for (int i = 0; i < getNumParameters(); ++i)
  366. {
  367. if (i<pars.size())
  368. setParameter(i, pars[i]);
  369. }
  370. }
  371. double PaulstretchpluginAudioProcessor::getSampleRateChecked()
  372. {
  373. if (m_cur_sr < 1.0)
  374. return 44100.0;
  375. return m_cur_sr;
  376. }
  377. void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
  378. {
  379. ScopedLock locker(m_cs);
  380. m_cur_sr = sampleRate;
  381. m_curmaxblocksize = samplesPerBlock;
  382. m_input_buffer.setSize(2, samplesPerBlock);
  383. int numoutchans = *m_outchansparam;
  384. if (numoutchans != m_cur_num_out_chans)
  385. m_prebuffering_inited = false;
  386. if (m_using_memory_buffer == true)
  387. {
  388. int len = jlimit(100,m_recbuffer.getNumSamples(),
  389. int(getSampleRateChecked()*(*getFloatParameter(cpi_max_capture_len))));
  390. m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer,
  391. getSampleRateChecked(),
  392. len);
  393. m_thumb->reset(m_recbuffer.getNumChannels(), sampleRate, len);
  394. }
  395. if (m_prebuffering_inited == false)
  396. {
  397. setFFTSize(*getFloatParameter(cpi_fftsize));
  398. m_stretch_source->setProcessParameters(&m_ppar);
  399. m_stretch_source->setFFTWindowingType(1);
  400. String err;
  401. startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) },
  402. numoutchans, samplesPerBlock, err);
  403. m_cur_num_out_chans = numoutchans;
  404. m_prebuffering_inited = true;
  405. }
  406. else
  407. {
  408. m_buffering_source->prepareToPlay(samplesPerBlock, getSampleRateChecked());
  409. }
  410. }
  411. void PaulstretchpluginAudioProcessor::releaseResources()
  412. {
  413. //m_control->stopplay();
  414. //m_ready_to_play = false;
  415. }
  416. #ifndef JucePlugin_PreferredChannelConfigurations
  417. bool PaulstretchpluginAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
  418. {
  419. #if JucePlugin_IsMidiEffect
  420. ignoreUnused (layouts);
  421. return true;
  422. #else
  423. // This is the place where you check if the layout is supported.
  424. // In this template code we only support mono or stereo.
  425. if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
  426. && layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
  427. return false;
  428. // This checks if the input layout matches the output layout
  429. #if ! JucePlugin_IsSynth
  430. if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
  431. return false;
  432. #endif
  433. return true;
  434. #endif
  435. }
  436. #endif
  437. void copyAudioBufferWrappingPosition(const AudioBuffer<float>& src, AudioBuffer<float>& dest, int destbufpos, int maxdestpos)
  438. {
  439. for (int i = 0; i < dest.getNumChannels(); ++i)
  440. {
  441. int channel_to_copy = i % src.getNumChannels();
  442. if (destbufpos + src.getNumSamples() > maxdestpos)
  443. {
  444. int wrappos = (destbufpos + src.getNumSamples()) % maxdestpos;
  445. int partial_len = src.getNumSamples() - wrappos;
  446. dest.copyFrom(channel_to_copy, destbufpos, src, channel_to_copy, 0, partial_len);
  447. dest.copyFrom(channel_to_copy, partial_len, src, channel_to_copy, 0, wrappos);
  448. }
  449. else
  450. {
  451. dest.copyFrom(channel_to_copy, destbufpos, src, channel_to_copy, 0, src.getNumSamples());
  452. }
  453. }
  454. }
  455. void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  456. {
  457. ScopedLock locker(m_cs);
  458. AudioPlayHead* phead = getPlayHead();
  459. if (phead != nullptr)
  460. {
  461. phead->getCurrentPosition(m_playposinfo);
  462. }
  463. else
  464. m_playposinfo.isPlaying = false;
  465. ScopedNoDenormals noDenormals;
  466. double srtemp = getSampleRate();
  467. if (srtemp != m_cur_sr)
  468. m_cur_sr = srtemp;
  469. const int totalNumInputChannels = getTotalNumInputChannels();
  470. const int totalNumOutputChannels = getTotalNumOutputChannels();
  471. for (int i = 0; i < totalNumInputChannels; ++i)
  472. m_input_buffer.copyFrom(i, 0, buffer, i, 0, buffer.getNumSamples());
  473. for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
  474. buffer.clear (i, 0, buffer.getNumSamples());
  475. if (m_prebuffering_inited == false)
  476. return;
  477. if (m_is_recording == true)
  478. {
  479. if (m_playposinfo.isPlaying == false && m_capture_when_host_plays == true)
  480. return;
  481. int recbuflenframes = m_max_reclen * getSampleRate();
  482. copyAudioBufferWrappingPosition(buffer, m_recbuffer, m_rec_pos, recbuflenframes);
  483. m_thumb->addBlock(m_rec_pos, buffer, 0, buffer.getNumSamples());
  484. m_rec_pos = (m_rec_pos + buffer.getNumSamples()) % recbuflenframes;
  485. return;
  486. }
  487. jassert(m_buffering_source != nullptr);
  488. jassert(m_bufferingthread.isThreadRunning());
  489. if (m_last_host_playing == false && m_playposinfo.isPlaying)
  490. {
  491. m_stretch_source->seekPercent(*getFloatParameter(cpi_soundstart));
  492. m_last_host_playing = true;
  493. }
  494. else if (m_last_host_playing == true && m_playposinfo.isPlaying == false)
  495. {
  496. m_last_host_playing = false;
  497. }
  498. if (m_play_when_host_plays == true && m_playposinfo.isPlaying == false)
  499. return;
  500. m_stretch_source->setMainVolume(*getFloatParameter(cpi_main_volume));
  501. m_stretch_source->setRate(*getFloatParameter(cpi_stretchamount));
  502. setFFTSize(*getFloatParameter(cpi_fftsize));
  503. m_ppar.pitch_shift.cents = *getFloatParameter(cpi_pitchshift) * 100.0;
  504. m_ppar.freq_shift.Hz = *getFloatParameter(cpi_frequencyshift);
  505. m_ppar.spread.bandwidth = *getFloatParameter(cpi_spreadamount);
  506. m_ppar.compressor.power = *getFloatParameter(cpi_compress);
  507. m_ppar.harmonics.nharmonics = *getIntParameter(cpi_numharmonics);
  508. m_ppar.harmonics.freq = *getFloatParameter(cpi_harmonicsfreq);
  509. m_ppar.harmonics.bandwidth = *getFloatParameter(cpi_harmonicsbw);
  510. m_ppar.harmonics.gauss = getParameter(cpi_harmonicsgauss);
  511. m_ppar.octave.om2 = *getFloatParameter(cpi_octavesm2);
  512. m_ppar.octave.om1 = *getFloatParameter(cpi_octavesm1);
  513. m_ppar.octave.o0 = *getFloatParameter(cpi_octaves0);
  514. m_ppar.octave.o1 = *getFloatParameter(cpi_octaves1);
  515. m_ppar.octave.o15 = *getFloatParameter(cpi_octaves15);
  516. m_ppar.octave.o2 = *getFloatParameter(cpi_octaves2);
  517. m_ppar.filter.low = *getFloatParameter(cpi_filter_low);
  518. m_ppar.filter.high = *getFloatParameter(cpi_filter_high);
  519. m_ppar.tonal_vs_noise.bandwidth = *getFloatParameter(cpi_tonalvsnoisebw);
  520. m_ppar.tonal_vs_noise.preserve = *getFloatParameter(cpi_tonalvsnoisepreserve);
  521. m_stretch_source->setOnsetDetection(*getFloatParameter(cpi_onsetdetection));
  522. m_stretch_source->setLoopXFadeLength(*getFloatParameter(cpi_loopxfadelen));
  523. double t0 = *getFloatParameter(cpi_soundstart);
  524. double t1 = *getFloatParameter(cpi_soundend);
  525. if (t0 > t1)
  526. std::swap(t0, t1);
  527. if (t1 - t0 < 0.001)
  528. t1 = t0 + 0.001;
  529. m_stretch_source->setPlayRange({ t0,t1 }, true);
  530. m_stretch_source->setFreezing(getParameter(cpi_freeze));
  531. m_stretch_source->setPaused(getParameter(cpi_pause_enabled));
  532. m_stretch_source->setProcessParameters(&m_ppar);
  533. AudioSourceChannelInfo aif(buffer);
  534. if (isNonRealtime() || m_use_backgroundbuffering == false)
  535. {
  536. m_stretch_source->getNextAudioBlock(aif);
  537. }
  538. else
  539. {
  540. m_buffering_source->getNextAudioBlock(aif);
  541. }
  542. if (getParameter(cpi_passthrough) > 0.5f)
  543. {
  544. for (int i = 0; i < totalNumInputChannels; ++i)
  545. {
  546. buffer.addFrom(i, 0, m_input_buffer, i, 0, buffer.getNumSamples());
  547. }
  548. }
  549. for (int i = 0; i < buffer.getNumChannels(); ++i)
  550. {
  551. for (int j = 0; j < buffer.getNumSamples(); ++j)
  552. {
  553. float sample = buffer.getSample(i,j);
  554. if (std::isnan(sample) || std::isinf(sample))
  555. ++m_abnormal_output_samples;
  556. }
  557. }
  558. }
  559. //==============================================================================
  560. bool PaulstretchpluginAudioProcessor::hasEditor() const
  561. {
  562. return true; // (change this to false if you choose to not supply an editor)
  563. }
  564. AudioProcessorEditor* PaulstretchpluginAudioProcessor::createEditor()
  565. {
  566. return new PaulstretchpluginAudioProcessorEditor (*this);
  567. }
  568. //==============================================================================
  569. void PaulstretchpluginAudioProcessor::getStateInformation (MemoryBlock& destData)
  570. {
  571. ValueTree paramtree = getStateTree(false,false);
  572. MemoryOutputStream stream(destData,true);
  573. paramtree.writeToStream(stream);
  574. }
  575. void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
  576. {
  577. ValueTree tree = ValueTree::readFromData(data, sizeInBytes);
  578. setStateFromTree(tree);
  579. }
  580. void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b)
  581. {
  582. ScopedLock locker(m_cs);
  583. int lenbufframes = getSampleRateChecked()*m_max_reclen;
  584. if (b == true)
  585. {
  586. m_using_memory_buffer = true;
  587. m_current_file = File();
  588. m_recbuffer.setSize(2, m_max_reclen*getSampleRateChecked()+4096,false,false,true);
  589. m_recbuffer.clear();
  590. m_rec_pos = 0;
  591. m_thumb->reset(m_recbuffer.getNumChannels(), getSampleRateChecked(), lenbufframes);
  592. m_is_recording = true;
  593. }
  594. else
  595. {
  596. if (m_is_recording == true)
  597. {
  598. finishRecording(lenbufframes);
  599. }
  600. }
  601. }
  602. double PaulstretchpluginAudioProcessor::getRecordingPositionPercent()
  603. {
  604. if (m_is_recording==false)
  605. return 0.0;
  606. return 1.0 / m_recbuffer.getNumSamples()*m_rec_pos;
  607. }
  608. String PaulstretchpluginAudioProcessor::setAudioFile(File f)
  609. {
  610. //if (f==File())
  611. // return String();
  612. //if (f==m_current_file && f.getLastModificationTime()==m_current_file_date)
  613. // return String();
  614. auto ai = unique_from_raw(m_afm->createReaderFor(f));
  615. if (ai != nullptr)
  616. {
  617. if (ai->numChannels > 32)
  618. {
  619. //MessageManager::callAsync([cb, file]() { cb("Too many channels in file " + file.getFullPathName()); });
  620. return "Too many channels in file "+f.getFullPathName();
  621. }
  622. if (ai->bitsPerSample>32)
  623. {
  624. //MessageManager::callAsync([cb, file]() { cb("Too high bit depth in file " + file.getFullPathName()); });
  625. return "Too high bit depth in file " + f.getFullPathName();
  626. }
  627. m_thumb->setSource(new FileInputSource(f));
  628. ScopedLock locker(m_cs);
  629. m_stretch_source->setAudioFile(f);
  630. //Range<double> currange{ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) };
  631. //if (currange.contains(m_stretch_source->getInfilePositionPercent())==false)
  632. m_stretch_source->seekPercent(*getFloatParameter(cpi_soundstart));
  633. m_current_file = f;
  634. m_current_file_date = m_current_file.getLastModificationTime();
  635. m_using_memory_buffer = false;
  636. return String();
  637. //MessageManager::callAsync([cb, file]() { cb(String()); });
  638. }
  639. return "Could not open file " + f.getFullPathName();
  640. }
  641. Range<double> PaulstretchpluginAudioProcessor::getTimeSelection()
  642. {
  643. return { *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) };
  644. }
  645. double PaulstretchpluginAudioProcessor::getPreBufferingPercent()
  646. {
  647. if (m_buffering_source==nullptr)
  648. return 0.0;
  649. return m_buffering_source->getPercentReady();
  650. }
  651. void PaulstretchpluginAudioProcessor::timerCallback(int id)
  652. {
  653. if (id == 1)
  654. {
  655. bool capture = getParameter(cpi_capture_enabled);
  656. if (capture == false && m_max_reclen != *getFloatParameter(cpi_max_capture_len))
  657. {
  658. m_max_reclen = *getFloatParameter(cpi_max_capture_len);
  659. //Logger::writeToLog("Changing max capture len to " + String(m_max_reclen));
  660. }
  661. if (capture == true && m_is_recording == false)
  662. {
  663. setRecordingEnabled(true);
  664. return;
  665. }
  666. if (capture == false && m_is_recording == true)
  667. {
  668. setRecordingEnabled(false);
  669. return;
  670. }
  671. if (m_cur_num_out_chans != *m_outchansparam)
  672. {
  673. jassert(m_curmaxblocksize > 0);
  674. ScopedLock locker(m_cs);
  675. m_prebuffering_inited = false;
  676. m_cur_num_out_chans = *m_outchansparam;
  677. //Logger::writeToLog("Switching to use " + String(m_cur_num_out_chans) + " out channels");
  678. String err;
  679. startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) },
  680. m_cur_num_out_chans, m_curmaxblocksize, err);
  681. m_prebuffering_inited = true;
  682. }
  683. }
  684. }
  685. void PaulstretchpluginAudioProcessor::finishRecording(int lenrecording)
  686. {
  687. m_is_recording = false;
  688. m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer, getSampleRateChecked(), lenrecording);
  689. m_stretch_source->setPlayRange({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }, true);
  690. }
  691. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  692. {
  693. return new PaulstretchpluginAudioProcessor();
  694. }