| 1543 | struct ex_poly_blep : public labsound_example |
| 1544 | { |
| 1545 | virtual void play(int argc, char** argv) override final |
| 1546 | { |
| 1547 | const auto defaultAudioDeviceConfigurations = GetDefaultAudioDeviceConfiguration(); |
| 1548 | context = lab::MakeRealtimeAudioContext(defaultAudioDeviceConfigurations.second, defaultAudioDeviceConfigurations.first); |
| 1549 | lab::AudioContext& ac = *context.get(); |
| 1550 | |
| 1551 | std::shared_ptr<PolyBLEPNode> polyBlep = std::make_shared<PolyBLEPNode>(ac); |
| 1552 | std::shared_ptr<GainNode> gain = std::make_shared<GainNode>(ac); |
| 1553 | |
| 1554 | gain->gain()->setValue(1.0f); |
| 1555 | context->connect(gain, polyBlep, 0, 0); |
| 1556 | context->connect(context->device(), gain, 0, 0); |
| 1557 | |
| 1558 | polyBlep->frequency()->setValue(220.f); |
| 1559 | polyBlep->setType(PolyBLEPType::TRIANGLE); |
| 1560 | polyBlep->start(0.0f); |
| 1561 | |
| 1562 | std::vector<PolyBLEPType> blepWaveforms = |
| 1563 | { |
| 1564 | PolyBLEPType::TRIANGLE, |
| 1565 | PolyBLEPType::SQUARE, |
| 1566 | PolyBLEPType::RECTANGLE, |
| 1567 | PolyBLEPType::SAWTOOTH, |
| 1568 | PolyBLEPType::RAMP, |
| 1569 | PolyBLEPType::MODIFIED_TRIANGLE, |
| 1570 | PolyBLEPType::MODIFIED_SQUARE, |
| 1571 | PolyBLEPType::HALF_WAVE_RECTIFIED_SINE, |
| 1572 | PolyBLEPType::FULL_WAVE_RECTIFIED_SINE, |
| 1573 | PolyBLEPType::TRIANGULAR_PULSE, |
| 1574 | PolyBLEPType::TRAPEZOID_FIXED, |
| 1575 | PolyBLEPType::TRAPEZOID_VARIABLE |
| 1576 | }; |
| 1577 | |
| 1578 | _nodes.push_back(polyBlep); |
| 1579 | _nodes.push_back(gain); |
| 1580 | |
| 1581 | double now_in_ms = 0; |
| 1582 | int waveformIndex = 0; |
| 1583 | while (true) |
| 1584 | { |
| 1585 | const uint32_t delay_time_ms = 500; |
| 1586 | now_in_ms += delay_time_ms; |
| 1587 | |
| 1588 | auto waveform = blepWaveforms[waveformIndex % blepWaveforms.size()]; |
| 1589 | polyBlep->setType(waveform); |
| 1590 | |
| 1591 | Wait(delay_time_ms); |
| 1592 | |
| 1593 | waveformIndex++; |
| 1594 | if (now_in_ms >= 10000) break; |
| 1595 | } |
| 1596 | } |
| 1597 | }; |
| 1598 | |
| 1599 |
nothing calls this directly
no test coverage detected