forked from musikinformatik/SuperDirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextBuffer.sc
41 lines (36 loc) · 1.05 KB
/
extBuffer.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
+ Buffer {
/*
This guarantees that buffer info exists before the buffer is on the server.
*/
*readWithInfo { |server, path, startFrame = 0, numFrames = -1, onlyHeader = false, onComplete|
^this.new(server).path_(path).readWithInfo(startFrame, numFrames, onlyHeader, onComplete)
}
readWithInfo { |startFrame = 0, argNumFrames = -1, onlyHeader = false, onComplete|
var failed;
if(server.serverRunning.not) { "server not running - cannot load sound file.".postln; this.throw };
SoundFile.use(path, { |file|
sampleRate = file.sampleRate;
numFrames = file.numFrames;
numChannels = file.numChannels;
});
failed = numFrames == 0;
^if(failed) {
"\n".post; "File reading failed for path: '%'\n\n".format(path).warn;
this.free; // free buffer number
nil
} {
if(onlyHeader.not) {
if(argNumFrames > 0) { numFrames = argNumFrames };
this.allocRead(path, startFrame, numFrames, completionMessage: { |b|
onComplete.value(b)
});
} {
this
}
}
}
// in bytes
memoryFootprint {
^numFrames * numChannels * 4
}
}