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.

96 lines
2.6KB

  1. /*
  2. Copyright (C) 2006-2011 Nasca Octavian Paul
  3. Author: Nasca Octavian Paul
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License
  6. as published by the Free Software Foundation.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License (version 2) for more details.
  11. You should have received a copy of the GNU General Public License (version 2)
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #pragma once
  16. #include "../globals.h"
  17. #include "../JuceLibraryCode/JuceHeader.h"
  18. class InputS
  19. {
  20. public:
  21. InputS()
  22. {
  23. skipbufsize=1024;
  24. skipbuf.setSize(1, skipbufsize);
  25. };
  26. virtual ~InputS()
  27. {
  28. };
  29. [[nodiscard]] virtual bool openAudioFile(File file)=0;
  30. virtual void close()=0;
  31. virtual int readNextBlock(AudioBuffer<float>& abuf, int smps, int numchans)=0;
  32. void skip(int nsmps)
  33. {
  34. while ((nsmps>0)&&(m_silenceoutputted<1))
  35. {
  36. int readsize=(nsmps<skipbufsize)?nsmps:skipbufsize;
  37. if (skipbuf.getNumSamples() < readsize)
  38. skipbuf.setSize(1, readsize);
  39. readNextBlock(skipbuf,readsize,1);
  40. nsmps-=readsize;
  41. };
  42. };
  43. virtual void seek(double pos, bool immediate)=0;//0=start,1.0=end
  44. struct {
  45. int64_t nsamples=0;
  46. int nchannels=0;
  47. int samplerate=0;
  48. } info;
  49. int getSilenceOutputtedAfterActiveRange()
  50. {
  51. return m_silenceoutputted;
  52. }
  53. Range<double> getActiveRange() { return m_activerange; }
  54. double getLengthSeconds()
  55. {
  56. if (info.nsamples == 0 || info.samplerate==0)
  57. return 0.0;
  58. return (double)info.nsamples / info.samplerate;
  59. }
  60. virtual void setActiveRange(Range<double> rng) = 0;
  61. bool isLooping() { return m_loop_enabled; }
  62. virtual void setLoopEnabled(bool b) = 0;
  63. int64_t getCurrentPosition() { return m_currentsample; }
  64. double getCurrentPositionPercent() { return 1.0 / info.nsamples*m_currentsample; }
  65. virtual bool hasEnded()
  66. {
  67. return m_currentsample >= info.nsamples*m_activerange.getEnd();
  68. }
  69. virtual AudioBuffer<float>* getAudioBuffer()=0;
  70. int64_t getDiskReadSampleCount() { return m_disk_read_count; }
  71. protected:
  72. volatile int64_t m_currentsample = 0;
  73. int m_silenceoutputted = 0;
  74. bool m_loop_enabled = false;
  75. Range<double> m_activerange{ 0.0,1.0 };
  76. int64_t m_disk_read_count = 0;
  77. private:
  78. int skipbufsize;
  79. AudioBuffer<float> skipbuf;
  80. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(InputS)
  81. };