mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 02:45:57 -04:00
Mark constants as constexpr, capture implicitly
This commit is contained in:
parent
310c545722
commit
867219a0a1
@ -33,15 +33,15 @@ using namespace SDL2pp;
|
||||
int main(int, char*[]) try {
|
||||
SDL sdl(SDL_INIT_AUDIO);
|
||||
|
||||
const int samplerate = 48000;
|
||||
float frequency = 2093.00f; // C7 tone
|
||||
constexpr int samplerate = 48000;
|
||||
constexpr float frequency = 2093.00f; // C7 tone
|
||||
int64_t nsample = 0;
|
||||
|
||||
// Setup audio device, and provide callback which plays sine wave with specified frequency
|
||||
AudioSpec spec(samplerate, AUDIO_S16SYS, 1, 4096);
|
||||
|
||||
// Open audio device
|
||||
AudioDevice dev(NullOpt, 0, spec, [&nsample, frequency, samplerate](Uint8* stream, int len) {
|
||||
AudioDevice dev(NullOpt, 0, spec, [&nsample](Uint8* stream, int len) {
|
||||
// fill provided buffer with sine wave
|
||||
for (Uint8* ptr = stream; ptr < stream + len; ptr += 2)
|
||||
*(Uint16*)ptr = (Uint16)(32766.0f * sin(nsample++ / (float)samplerate * frequency));
|
||||
|
Loading…
x
Reference in New Issue
Block a user