quantumVERB  1.0.0
A FOSS convolution reverb plugin
IRBank.cpp
1 /*
2  ==============================================================================
3 
4  IRBank.cpp
5 
6  ==============================================================================
7 */
8 
9 #include "IRBank.h"
10 
11 namespace reverb
12 {
13 
14  //==============================================================================
15  /**
16  * Global IRBank object
17  */
19  {
20  static IRBank irBank;
21  return irBank;
22  }
23 
24  //==============================================================================
25  /**
26  * @brief Construct IR bank
27  *
28  * Sets public buffer & sample rate references and calls build() method to populate
29  * IR bank.
30  */
33  {
34  build();
35  }
36 
37  //==============================================================================
38  /**
39  * @brief Build IR bank from binary data
40  *
41  * Finds all audio resources and builds sample buffers for each. Rejects any
42  * resources with the wrong format (only keep WAVE or AIFF).
43  */
44  void IRBank::build()
45  {
46  if (!buffersModifiable.empty() && !sampleRatesModifiable.empty())
47  {
48  return;
49  }
50  else if (buffersModifiable.size() != sampleRatesModifiable.size())
51  {
52  buffersModifiable.clear();
53  sampleRatesModifiable.clear();
54  }
55 
56  // Register basic audio formats
57  juce::AudioFormatManager formatMgr;
58  formatMgr.registerBasicFormats();
59 
60  for (int i = 0; i < BinaryData::namedResourceListSize; ++i)
61  {
62  // Prepare memory input stream
63  int dataSize;
64  const char * data;
65 
66  data = BinaryData::getNamedResource(BinaryData::namedResourceList[i], dataSize);
67  auto dataStream = new juce::MemoryInputStream(data, dataSize, false);
68 
69  // Attempt to create an audio format reader for stream
70  std::unique_ptr<juce::AudioFormatReader> reader(formatMgr.createReaderFor(dataStream));
71 
72  // If reader was successfully created, this is a valid audio resource
73  if (reader)
74  {
75  int numChannels = reader->numChannels;
76  int numSamples = (int)reader->lengthInSamples;
77 
78  buffersModifiable[BinaryData::namedResourceList[i]] = juce::AudioSampleBuffer(numChannels, numSamples);
79  reader->read(&buffersModifiable[BinaryData::namedResourceList[i]], 0, numSamples, 0, true, true);
80 
81  sampleRatesModifiable[BinaryData::namedResourceList[i]] = reader->sampleRate;
82  }
83  }
84  }
85 
86 }
IRBank()
Construct IR bank.
Definition: IRBank.cpp:31
float getParam(const juce::AudioProcessorValueTreeState &params, const juce::String &blockId) const
Internal method used to get (and check) a parameter&#39;s value.
Definition: Task.h:111
static const IRBank & getInstance()
Definition: IRBank.cpp:18
void build()
Build IR bank from binary data.
Definition: IRBank.cpp:44