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

Method process

src/extended/NoiseNode.cpp:54–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54void NoiseNode::process(ContextRenderLock &r, int bufferSize)
55{
56 AudioBus * outputBus = output(0)->bus(r);
57
58 if (!isInitialized() || !outputBus->numberOfChannels())
59 {
60 outputBus->zero();
61 return;
62 }
63
64 int quantumFrameOffset = _scheduler._renderOffset;
65 int nonSilentFramesToProcess = _scheduler._renderLength;
66
67 if (!nonSilentFramesToProcess)
68 {
69 outputBus->zero();
70 return;
71 }
72
73 float * destP = outputBus->channel(0)->mutableData();
74
75 // Start rendering at the correct offset.
76 destP += quantumFrameOffset;
77 int n = nonSilentFramesToProcess;
78
79 switch (NoiseType(_type->valueUint32()))
80 {
81 // reference: http://noisehack.com/generate-noise-web-audio-api/
82 case WHITE:
83 while (n--)
84 {
85 float white = ((float) ((whiteSeed & 0x7fffffff) - 0x40000000)) * (float) (1.0f / 0x40000000);
86 white = (white * 0.5f) - 1.0f;
87 *destP++ = white;
88 whiteSeed = whiteSeed * 435898247 + 382842987;
89 }
90 break;
91 case PINK:
92 while (n--)
93 {
94 float white = ((float) ((whiteSeed & 0x7fffffff) - 0x40000000)) * (float) (1.0f / 0x40000000);
95 white = (white * 0.5f) - 1.0f;
96 whiteSeed = whiteSeed * 435898247 + 382842987;
97
98 pink0 = 0.99886f * pink0 + white * 0.0555179f;
99 pink1 = 0.99332f * pink1 + white * 0.0750759f;
100 pink2 = 0.96900f * pink2 + white * 0.1538520f;
101 pink3 = 0.86650f * pink3 + white * 0.3104856f;
102 pink4 = 0.55000f * pink4 + white * 0.5329522f;
103 pink5 = -0.7616f * pink5 - white * 0.0168980f;
104 *destP++ = (pink0 + pink1 + pink2 + pink3 + pink4 + pink5 + pink6 + (white * 0.5362f)) * 0.11f; // .11 roughly compensates gain
105 pink6 = white * 0.115926f;
106 }
107 break;
108 case BROWN:
109 while (n--)
110 {
111 float white = ((float) ((whiteSeed & 0x7fffffff) - 0x40000000)) * (float) (1.0f / 0x40000000);

Callers

nothing calls this directly

Calls 8

NoiseTypeEnum · 0.85
mutableDataMethod · 0.80
channelMethod · 0.80
valueUint32Method · 0.80
busMethod · 0.45
numberOfChannelsMethod · 0.45
zeroMethod · 0.45
clearSilentFlagMethod · 0.45

Tested by

no test coverage detected