| 39 | */ |
| 40 | |
| 41 | struct BeepGenerator : public choc::audio::io::AudioMIDICallback |
| 42 | { |
| 43 | BeepGenerator() : sineWave() |
| 44 | { |
| 45 | sineWave.setFrequency (440.0f, 44100.0f); |
| 46 | } |
| 47 | |
| 48 | void sampleRateChanged (double newRate) override |
| 49 | { |
| 50 | std::cout << "Sample rate changed to: " << newRate << " Hz" << std::endl; |
| 51 | sineWave.setFrequency (440.0f, static_cast<float> (newRate)); |
| 52 | maxSamples = static_cast<uint32_t> (2 * newRate); |
| 53 | } |
| 54 | |
| 55 | void startBlock() override |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | void processSubBlock (const choc::audio::AudioMIDIBlockDispatcher::Block& block, |
| 60 | bool replaceOutput) override |
| 61 | { |
| 62 | auto& output = block.audioOutput; |
| 63 | |
| 64 | if (! isPlaying) |
| 65 | { |
| 66 | if (replaceOutput) |
| 67 | output.clear(); |
| 68 | |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | auto numFrames = output.getNumFrames(); |
| 73 | auto numChannels = output.getNumChannels(); |
| 74 | |
| 75 | for (uint32_t frame = 0; frame < numFrames; ++frame) |
| 76 | { |
| 77 | if (samplesPlayed >= maxSamples) |
| 78 | { |
| 79 | isPlaying = false; |
| 80 | |
| 81 | for (uint32_t channel = 0; channel < numChannels; ++channel) |
| 82 | output.getSample (channel, frame) = 0.0f; |
| 83 | |
| 84 | continue; |
| 85 | } |
| 86 | |
| 87 | auto sample = sineWave.getSample() * 0.1f; |
| 88 | |
| 89 | for (uint32_t channel = 0; channel < numChannels; ++channel) |
| 90 | { |
| 91 | if (replaceOutput) |
| 92 | output.getSample (channel, frame) = sample; |
| 93 | else |
| 94 | output.getSample (channel, frame) += sample; |
| 95 | } |
| 96 | |
| 97 | ++samplesPlayed; |
| 98 | } |
nothing calls this directly
no outgoing calls
no test coverage detected