Short answer: Use Signal, not Wavetable, for this.
Why? As hemiketal said, Wavetable is a special format reserved for Osc (or OscN, COsc, VOsc, VOsc3) and Shaper. It does not just give you the sample values. If you’re using Phasor and BufRd, Wavetable is inappropriate. You need just the sample values, which will be provided by Signal.
w = Signal.sineFill(512, 1.0 / [1]);
w.plot;
b = Buffer.alloc(s, 512, 1);
b.loadCollection(w);
b.plot;
(
a = {
var idx = Phasor.ar(Impulse.ar(1), 1, start:0, end:b.numFrames);
BufRd.ar(1, b.bufnum, idx, 1, 2) * 0.1;
}.play;
)
a.release;
b.free;
There are a couple more gotchas.
-
Buffer.alloc
and loadCollection
are language operations. They do cause things to happen on the server, but they can be triggered only from the language. It isn’t a good idea to write them into a synthesis function. (In the examples in this post, I’m moving buffer preparation outside of the synthesis function.)
-
Documentation is not clear on this point, but a Wavetable will be twice the size of the number of samples requested.
w = Wavetable.sineFill(512, 1.0/[1]);
w.size; // 1024 (!)
So when you try to load this into a 512-sample buffer, you’re losing the last half of the wavetable. (So that’s two things that would make b.plot
look different – wavetable format, and keeping only half the data.) This problem disappears by using Signal.
If you really want to use Wavetable, it would look like this – just like SinOsc, you can drive a wavetable oscillator by specifying 0 frequency and calculating phase yourself.
w = Wavetable.sineFill(512, 1.0/[1]);
// note that this will allocate 1024 samples
// by checking w.size internally
// so that's one less mistake you can make
b = Buffer.loadCollection(s, w, 1);
// at this point, b.plot will look funny, but that's OK...
(
a = {
var freq = 440;
// for this usage, phase must be in radians
var phase = Phasor.ar(0, (2pi * SampleDur.ir) * freq, 0, 2pi, 0);
(Osc.ar(b, 0, phase) * 0.1).dup
}.play;
)
// Osc makes a clean sine tone ;->
a.release;
b.free;
hjh