| 81 | } |
| 82 | |
| 83 | static void |
| 84 | iteration() |
| 85 | { |
| 86 | SDL_Event e; |
| 87 | SDL_AudioDeviceID dev; |
| 88 | while (SDL_PollEvent(&e)) { |
| 89 | if (e.type == SDL_QUIT) { |
| 90 | done = 1; |
| 91 | } else if (e.type == SDL_KEYUP) { |
| 92 | if (e.key.keysym.sym == SDLK_ESCAPE) |
| 93 | done = 1; |
| 94 | } else if (e.type == SDL_AUDIODEVICEADDED) { |
| 95 | int index = e.adevice.which; |
| 96 | int iscapture = e.adevice.iscapture; |
| 97 | const char *name = SDL_GetAudioDeviceName(index, iscapture); |
| 98 | if (name != NULL) |
| 99 | SDL_Log("New %s audio device at index %u: %s\n", devtypestr(iscapture), (unsigned int) index, name); |
| 100 | else { |
| 101 | SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Got new %s device at index %u, but failed to get the name: %s\n", |
| 102 | devtypestr(iscapture), (unsigned int) index, SDL_GetError()); |
| 103 | continue; |
| 104 | } |
| 105 | if (!iscapture) { |
| 106 | positions[posindex] = 0; |
| 107 | spec.userdata = &positions[posindex++]; |
| 108 | spec.callback = fillerup; |
| 109 | dev = SDL_OpenAudioDevice(name, 0, &spec, NULL, 0); |
| 110 | if (!dev) { |
| 111 | SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open '%s': %s\n", name, SDL_GetError()); |
| 112 | } else { |
| 113 | SDL_Log("Opened '%s' as %u\n", name, (unsigned int) dev); |
| 114 | SDL_PauseAudioDevice(dev, 0); |
| 115 | } |
| 116 | } |
| 117 | } else if (e.type == SDL_AUDIODEVICEREMOVED) { |
| 118 | dev = (SDL_AudioDeviceID) e.adevice.which; |
| 119 | SDL_Log("%s device %u removed.\n", devtypestr(e.adevice.iscapture), (unsigned int) dev); |
| 120 | SDL_CloseAudioDevice(dev); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | #ifdef __EMSCRIPTEN__ |
| 126 | void |
no test coverage detected