MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / Beeper

Method Beeper

test/browser/test_sdl2_audio_beep.cpp:52–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50void audio_callback(void*, Uint8*, int);
51
52Beeper::Beeper(int frequency_, int numChannels_, int sdlAudioFormat_) {
53 phase = 0.0;
54 mutedChannel = 1;
55
56 SDL_AudioSpec desiredSpec;
57
58 desiredSpec.freq = frequency_;
59 desiredSpec.format = sdlAudioFormat_;
60 desiredSpec.channels = numChannels_;
61 desiredSpec.samples = 1024; // This is samples per channel.
62 desiredSpec.callback = audio_callback;
63 desiredSpec.userdata = this;
64
65 SDL_AudioSpec obtainedSpec;
66
67 // you might want to look for errors here
68 SDL_OpenAudio(&desiredSpec, &obtainedSpec);
69
70 // In this test, we require *exactly* the identical SDL result that we provide, since we test
71 // all various configurations individually.
72 if (obtainedSpec.freq != desiredSpec.freq || obtainedSpec.format != desiredSpec.format
73 || obtainedSpec.channels != desiredSpec.channels || obtainedSpec.samples != desiredSpec.samples) {
74 SDL_CloseAudio();
75 throw std::runtime_error("Failed to initialize desired SDL_OpenAudio!");
76 }
77
78 frequency = obtainedSpec.freq;
79 numChannels = obtainedSpec.channels;
80 sdlAudioFormat = obtainedSpec.format;
81
82 // Immediately start producing audio.
83 SDL_PauseAudio(0);
84}
85
86Beeper::~Beeper() {
87 SDL_CloseAudio();

Callers

nothing calls this directly

Calls 1

runtime_errorFunction · 0.85

Tested by

no test coverage detected