Fix build for ms compiler

This commit is contained in:
Dmitry Marakasov 2017-07-07 22:34:28 +03:00
parent 913b219256
commit 41c96ba25b
2 changed files with 7 additions and 3 deletions

View File

@ -33,15 +33,17 @@ using namespace SDL2pp;
int main(int, char*[]) try { int main(int, char*[]) try {
SDL sdl(SDL_INIT_AUDIO); SDL sdl(SDL_INIT_AUDIO);
constexpr int samplerate = 48000; // XXX: these should be constexpr and not captured in lambda
constexpr float frequency = 2093.00f; // C7 tone // below, but that fails on microsoft crapiler
int samplerate = 48000;
float frequency = 2093.00f; // C7 tone
int64_t nsample = 0; int64_t nsample = 0;
// Setup audio device, and provide callback which plays sine wave with specified frequency // Setup audio device, and provide callback which plays sine wave with specified frequency
AudioSpec spec(samplerate, AUDIO_S16SYS, 1, 4096); AudioSpec spec(samplerate, AUDIO_S16SYS, 1, 4096);
// Open audio device // Open audio device
AudioDevice dev(NullOpt, 0, spec, [&nsample](Uint8* stream, int len) { AudioDevice dev(NullOpt, 0, spec, [&nsample, samplerate, frequency](Uint8* stream, int len) {
// fill provided buffer with sine wave // fill provided buffer with sine wave
for (Uint8* ptr = stream; ptr < stream + len; ptr += 2) for (Uint8* ptr = stream; ptr < stream + len; ptr += 2)
*(Uint16*)ptr = (Uint16)(32766.0f * sin(nsample++ / (float)samplerate * frequency)); *(Uint16*)ptr = (Uint16)(32766.0f * sin(nsample++ / (float)samplerate * frequency));

View File

@ -33,6 +33,8 @@ int main(int, char*[]) try {
SDL sdl(SDL_INIT_AUDIO); SDL sdl(SDL_INIT_AUDIO);
Mixer mixer(MIX_DEFAULT_FREQUENCY, AUDIO_S16SYS, 1, 4096); Mixer mixer(MIX_DEFAULT_FREQUENCY, AUDIO_S16SYS, 1, 4096);
// XXX: this should be constexpr and not captured in lambda
// below, but that fails on microsoft crapiler
float frequency = 2093.00f; // C7 tone float frequency = 2093.00f; // C7 tone
int64_t nsample = 0; int64_t nsample = 0;