MCPcopy Create free account
hub / github.com/stemdeckapp/stemdeck / _fetchChunk

Function _fetchChunk

static/js/chunkedAudioEngine.js:192–223  ·  view source on GitHub ↗
(chunkIdx)

Source from the content-addressed store, hash-verified

190 // Returns a Promise<Map<name, AudioBuffer>>. Deduplicates: if a fetch for
191 // chunkIdx is already in flight, returns the same promise.
192 function _fetchChunk(chunkIdx) {
193 const hit = _cache.get(chunkIdx);
194 if (hit) return hit.promise;
195
196 const entry = { promise: null, result: null };
197 entry.promise = (async () => {
198 const pairs = await Promise.all(
199 [...stemMap.entries()]
200 .filter(([, s]) => s.header)
201 .map(async ([name, stem]) => {
202 try {
203 const pcm = await _fetchPcm(stem, chunkIdx);
204 if (!pcm) return [name, null];
205 return [name, _pcmToAudioBuffer(ctx, pcm, stem.header)];
206 } catch (e) {
207 console.warn(`[chunked] chunk ${chunkIdx} stem ${name}:`, e);
208 return [name, null];
209 }
210 })
211 );
212 const map = new Map(pairs.filter(([, b]) => b));
213 entry.result = map;
214 // Keep at most the previous chunk + current in cache to bound memory.
215 for (const k of _cache.keys()) {
216 if (k < chunkIdx - 1) _cache.delete(k);
217 }
218 return map;
219 })();
220
221 _cache.set(chunkIdx, entry);
222 return entry.promise;
223 }
224
225 // --- node lifecycle ---
226

Callers 4

_scheduleNextFunction · 0.85
startWithFunction · 0.85
playFunction · 0.85
createChunkedAudioEngineFunction · 0.85

Calls 2

_fetchPcmFunction · 0.85
_pcmToAudioBufferFunction · 0.85

Tested by

no test coverage detected