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

Method play

examples/src/Examples.hpp:1108–1265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1106struct ex_redalert_synthesis : public labsound_example
1107{
1108 virtual void play(int argc, char ** argv) override
1109 {
1110 const auto defaultAudioDeviceConfigurations = GetDefaultAudioDeviceConfiguration();
1111 context = lab::MakeRealtimeAudioContext(defaultAudioDeviceConfigurations.second, defaultAudioDeviceConfigurations.first);
1112 lab::AudioContext& ac = *context.get();
1113
1114 std::shared_ptr<FunctionNode> sweep;
1115 std::shared_ptr<FunctionNode> outputGainFunction;
1116
1117 std::shared_ptr<OscillatorNode> osc;
1118 std::shared_ptr<GainNode> oscGain;
1119 std::shared_ptr<OscillatorNode> resonator;
1120 std::shared_ptr<GainNode> resonatorGain;
1121 std::shared_ptr<GainNode> resonanceSum;
1122
1123 std::shared_ptr<DelayNode> delay[5];
1124
1125 std::shared_ptr<GainNode> delaySum;
1126 std::shared_ptr<GainNode> filterSum;
1127
1128 std::shared_ptr<BiquadFilterNode> filter[5];
1129
1130 {
1131 ContextRenderLock r(context.get(), "ex_redalert_synthesis");
1132
1133 sweep = std::make_shared<FunctionNode>(ac, 1);
1134 sweep->setFunction([](ContextRenderLock & r, FunctionNode * me, int channel, float * values, size_t framesToProcess) {
1135 double dt = 1.0 / r.context()->sampleRate();
1136 double now = fmod(me->now(), 1.2f);
1137
1138 for (size_t i = 0; i < framesToProcess; ++i)
1139 {
1140 //0 to 1 in 900 ms with a 1200ms gap in between
1141 if (now > 0.9)
1142 {
1143 values[i] = 487.f + 360.f;
1144 }
1145 else
1146 {
1147 values[i] = std::sqrt((float) now * 1.f / 0.9f) * 487.f + 360.f;
1148 }
1149
1150 now += dt;
1151 }
1152 });
1153
1154 sweep->start(0);
1155
1156 outputGainFunction = std::make_shared<FunctionNode>(ac, 1);
1157 outputGainFunction->setFunction([](ContextRenderLock & r, FunctionNode * me, int channel, float * values, size_t framesToProcess) {
1158 double dt = 1.0 / r.context()->sampleRate();
1159 double now = fmod(me->now(), 1.2f);
1160
1161 for (size_t i = 0; i < framesToProcess; ++i)
1162 {
1163 //0 to 1 in 900 ms with a 1200ms gap in between
1164 if (now > 0.9)
1165 {

Callers

nothing calls this directly

Calls 15

MakeRealtimeAudioContextFunction · 0.85
getMethod · 0.80
setFunctionMethod · 0.80
setValueMethod · 0.80
connectParamMethod · 0.80
setFloatMethod · 0.80
qMethod · 0.80
deviceMethod · 0.80
sampleRateMethod · 0.45
contextMethod · 0.45
nowMethod · 0.45

Tested by

no test coverage detected