| 50 | void audio_callback(void*, Uint8*, int); |
| 51 | |
| 52 | Beeper::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 | |
| 86 | Beeper::~Beeper() { |
| 87 | SDL_CloseAudio(); |
nothing calls this directly
no test coverage detected