1
0
Fork 0
forked from len0rd/rockbox

SDL: Allow the audio device used to be specified on the command line

To aid this we display the list of allowed drivers and devices at startup

Change-Id: If27fc2c4873b56cd220a3e3e1ad78e9ede1979e7
This commit is contained in:
Solomon Peachy 2024-12-09 21:06:05 -05:00
parent b3dac27aa6
commit 65d94ecd08
2 changed files with 32 additions and 5 deletions

View file

@ -24,6 +24,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
#include <SDL.h> #include <SDL.h>
#include "config.h" #include "config.h"
#include "debug.h" #include "debug.h"
@ -47,10 +48,12 @@
#include "logf.h" #include "logf.h"
#ifdef DEBUG #ifdef DEBUG
#include <stdio.h>
extern bool debug_audio; extern bool debug_audio;
#endif #endif
extern const char *audiodev;
static int cvt_status = -1; static int cvt_status = -1;
static const void *pcm_data; static const void *pcm_data;
@ -101,8 +104,8 @@ static void pcm_dma_apply_settings_nolock(void)
if (pcm_devid) if (pcm_devid)
SDL_CloseAudioDevice(pcm_devid); SDL_CloseAudioDevice(pcm_devid);
/* Open the audio device and start playing sound! */ /* Open the audio device and start playing sound! */
if((pcm_devid = SDL_OpenAudioDevice(NULL, 0, &wanted_spec, &obtained, 0)) == 0) { if((pcm_devid = SDL_OpenAudioDevice(audiodev, 0, &wanted_spec, &obtained, 0)) == 0) {
DEBUGF("Unable to open audio: %s\n", SDL_GetError()); panicf("Unable to open audio: %s\n", SDL_GetError());
return; return;
} }
switch (obtained.format) switch (obtained.format)
@ -122,7 +125,7 @@ static void pcm_dma_apply_settings_nolock(void)
pcm_channel_bytes = 4; pcm_channel_bytes = 4;
break; break;
default: default:
DEBUGF("Unknown sample format obtained: %u\n", panicf("Unknown sample format obtained: %u\n",
(unsigned)obtained.format); (unsigned)obtained.format);
return; return;
} }
@ -365,10 +368,23 @@ void pcm_play_dma_init(void)
{ {
if (SDL_InitSubSystem(SDL_INIT_AUDIO)) if (SDL_InitSubSystem(SDL_INIT_AUDIO))
{ {
DEBUGF("Could not initialize SDL audio subsystem!\n"); panicf("Could not initialize SDL audio subsystem!\n");
return; return;
} }
#ifdef SIMULATOR
int cnt = SDL_GetNumAudioDrivers();
printf("SDL Audio Drivers supported:\n");
for (int i = 0 ; i < cnt ; i++) {
printf(" %s %s\n", SDL_GetAudioDriver(i), SDL_GetAudioDriver(i) == SDL_GetCurrentAudioDriver() ? "(active)" : "");
}
cnt = SDL_GetNumAudioDevices(0);
printf("SDL Audio Devices present:\n");
for (int i = 0 ; i < cnt ; i++) {
printf(" '%s'\n", SDL_GetAudioDeviceName(i, 0));
}
#endif
audio_lock = SDL_CreateMutex(); audio_lock = SDL_CreateMutex();
if (!audio_lock) if (!audio_lock)

View file

@ -58,6 +58,7 @@ bool background = true; /* use backgrounds by default */
bool showremote = true; /* include remote by default */ bool showremote = true; /* include remote by default */
#endif #endif
bool mapping = false; bool mapping = false;
const char *audiodev = NULL;
bool debug_buttons = false; bool debug_buttons = false;
bool lcd_display_redraw = true; /* Used for player simulator */ bool lcd_display_redraw = true; /* Used for player simulator */
@ -388,6 +389,15 @@ void sys_handle_argv(int argc, char *argv[])
debug_buttons = true; debug_buttons = true;
printf("Printing background button clicks.\n"); printf("Printing background button clicks.\n");
} }
else if (!strcmp("--audiodev", argv[x]))
{
x++;
if (x < argc)
{
audiodev = argv[x];
printf("Audio device: '%s'\n", audiodev);
}
}
else else
{ {
printf("rockboxui\n"); printf("rockboxui\n");
@ -405,6 +415,7 @@ void sys_handle_argv(int argc, char *argv[])
printf(" --alarm \t Simulate a wake-up on alarm\n"); printf(" --alarm \t Simulate a wake-up on alarm\n");
printf(" --root [DIR]\t Set root directory\n"); printf(" --root [DIR]\t Set root directory\n");
printf(" --mapping \t Output coordinates and radius for mapping backgrounds\n"); printf(" --mapping \t Output coordinates and radius for mapping backgrounds\n");
printf(" --audiodev [NAME] \t Audio device name to use\n");
exit(0); exit(0);
} }
} }