Atlas - testaudioinfo.c

Home / ext / SDL / test Lines: 1 | Size: 3873 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 3 4 This software is provided 'as-is', without any express or implied 5 warranty. In no event will the authors be held liable for any damages 6 arising from the use of this software. 7 8 Permission is granted to anyone to use this software for any purpose, 9 including commercial applications, and to alter it and redistribute it 10 freely. 11*/ 12#include <SDL3/SDL.h> 13#include <SDL3/SDL_main.h> 14#include <SDL3/SDL_test.h> 15 16static void 17print_devices(bool recording) 18{ 19 SDL_AudioSpec spec; 20 const char *typestr = (recording ? "recording" : "playback"); 21 int n = 0; 22 int frames; 23 SDL_AudioDeviceID *devices = recording ? SDL_GetAudioRecordingDevices(&n) : SDL_GetAudioPlaybackDevices(&n); 24 25 if (!devices) { 26 SDL_Log(" Driver failed to report %s devices: %s", typestr, SDL_GetError()); 27 SDL_Log("%s", ""); 28 } else if (n == 0) { 29 SDL_Log(" No %s devices found.", typestr); 30 SDL_Log("%s", ""); 31 } else { 32 int i; 33 SDL_Log("Found %d %s device%s:", n, typestr, n != 1 ? "s" : ""); 34 for (i = 0; i < n; i++) { 35 const char *name = SDL_GetAudioDeviceName(devices[i]); 36 if (name) { 37 SDL_Log(" %d: %s", i, name); 38 } else { 39 SDL_Log(" %d Error: %s", i, SDL_GetError()); 40 } 41 42 if (SDL_GetAudioDeviceFormat(devices[i], &spec, &frames)) { 43 SDL_Log(" Sample Rate: %d", spec.freq); 44 SDL_Log(" Channels: %d", spec.channels); 45 SDL_Log(" SDL_AudioFormat: %X", spec.format); 46 SDL_Log(" Buffer Size: %d frames", frames); 47 } 48 } 49 SDL_Log("%s", ""); 50 } 51 SDL_free(devices); 52} 53 54int main(int argc, char **argv) 55{ 56 SDL_AudioSpec spec; 57 int i; 58 int n; 59 int frames; 60 SDLTest_CommonState *state; 61 62 /* Initialize test framework */ 63 state = SDLTest_CommonCreateState(argv, 0); 64 if (!state) { 65 return 1; 66 } 67 68 /* Parse commandline */ 69 if (!SDLTest_CommonDefaultArgs(state, argc, argv)) { 70 return 1; 71 } 72 73 /* Load the SDL library */ 74 if (!SDL_Init(SDL_INIT_AUDIO)) { 75 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s", SDL_GetError()); 76 return 1; 77 } 78 79 /* Print available audio drivers */ 80 n = SDL_GetNumAudioDrivers(); 81 if (n == 0) { 82 SDL_Log("No built-in audio drivers"); 83 SDL_Log("%s", ""); 84 } else { 85 SDL_Log("Built-in audio drivers:"); 86 for (i = 0; i < n; ++i) { 87 SDL_Log(" %d: %s", i, SDL_GetAudioDriver(i)); 88 } 89 SDL_Log("Select a driver with the SDL_AUDIO_DRIVER environment variable."); 90 } 91 92 SDL_Log("Using audio driver: %s", SDL_GetCurrentAudioDriver()); 93 SDL_Log("%s", ""); 94 95 print_devices(false); 96 print_devices(true); 97 98 if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, &frames)) { 99 SDL_Log("Default Playback Device:"); 100 SDL_Log("Sample Rate: %d", spec.freq); 101 SDL_Log("Channels: %d", spec.channels); 102 SDL_Log("SDL_AudioFormat: %X", spec.format); 103 SDL_Log("Buffer Size: %d frames", frames); 104 } else { 105 SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default playback): %s", SDL_GetError()); 106 } 107 108 if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_RECORDING, &spec, &frames)) { 109 SDL_Log("Default Recording Device:"); 110 SDL_Log("Sample Rate: %d", spec.freq); 111 SDL_Log("Channels: %d", spec.channels); 112 SDL_Log("SDL_AudioFormat: %X", spec.format); 113 SDL_Log("Buffer Size: %d frames", frames); 114 } else { 115 SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default recording): %s", SDL_GetError()); 116 } 117 118 SDL_Quit(); 119 SDLTest_CommonDestroyState(state); 120 return 0; 121} 122 123
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.