MCPcopy Create free account
hub / github.com/LabSound/LabSound / RenderGranulation

Method RenderGranulation

src/extended/GranulationNode.cpp:80–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80bool GranulationNode::RenderGranulation(ContextRenderLock & r, AudioBus * out_bus, int destinationFrameOffset, int numberOfFrames)
81{
82 if (!r.context())
83 return false;
84
85 // Sanity check destinationFrameOffset, numberOfFrames.
86 const int destinationLength = out_bus->length();
87
88 bool isLengthGood = destinationLength <= 4096 && numberOfFrames <= 4096;
89 ASSERT(isLengthGood);
90 if (!isLengthGood)
91 return false;
92
93 bool isOffsetGood = destinationFrameOffset <= destinationLength && destinationFrameOffset + numberOfFrames <= destinationLength;
94 ASSERT(isOffsetGood);
95 if (!isOffsetGood)
96 return false;
97
98 if (!out_bus) return false;
99
100 float * mono_destination = out_bus->channel(0)->mutableData();
101
102 // @fixme - this vector
103 std::vector<float> grain_sum_buffer(numberOfFrames, 0.f);
104
105 {
106 for (int i = 0; i < grain_pool.size(); ++i)
107 {
108 grain_pool[i].tick(grain_sum_buffer.data(), static_cast<int>(grain_sum_buffer.size()));
109 }
110
111 for (int f = 0; f < numberOfFrames; ++f)
112 {
113 grain_sum_buffer[f] /= static_cast<float>(grain_pool.size());
114 mono_destination[f] = grain_sum_buffer[f]; // @todo - memcpy
115 }
116
117 // Optional grain culling when they're "done"
118 // if (!grain_pool.empty())
119 // {
120 // auto it = std::remove_if(std::begin(grain_pool), std::end(grain_pool), [this](const grain & g)
121 // {
122 // return g.in_use;
123 // });
124 // grain_pool.erase(it, std::end(grain_pool));
125 // }
126 }
127
128 out_bus->clearSilentFlag();
129
130 return true;
131}
132
133bool GranulationNode::setGrainSource(ContextRenderLock & r, std::shared_ptr<AudioBus> buffer)
134{

Callers

nothing calls this directly

Calls 8

mutableDataMethod · 0.80
channelMethod · 0.80
sizeMethod · 0.80
tickMethod · 0.80
contextMethod · 0.45
lengthMethod · 0.45
dataMethod · 0.45
clearSilentFlagMethod · 0.45

Tested by

no test coverage detected