Skip to content

Commit 0738d3c

Browse files
authored
switch: cleanup SWITCHAUDIO_OpenDevice (#112)
- use calloc instead of malloc + SDL_zero - no need for the SDL_First/NextAudioFormat loop since there is only one supported audio-format (which is always in the list)
1 parent e5940b7 commit 0738d3c

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

src/audio/switch/SDL_switchaudio.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,14 @@ static int
4747
SWITCHAUDIO_OpenDevice(_THIS, const char *devname)
4848
{
4949
static const u8 sink_channels[] = {0, 1};
50-
SDL_bool supported_format = SDL_FALSE;
51-
SDL_AudioFormat test_format;
5250
Result res;
5351
u32 size;
5452
int mpid;
5553

56-
this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc(sizeof(*this->hidden));
54+
this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*this->hidden));
5755
if (this->hidden == NULL) {
5856
return SDL_OutOfMemory();
5957
}
60-
SDL_zerop(this->hidden);
6158

6259
res = audrenInitialize(&arConfig);
6360
if (R_FAILED(res)) {
@@ -71,20 +68,7 @@ SWITCHAUDIO_OpenDevice(_THIS, const char *devname)
7168
}
7269
this->hidden->audr_driver = true;
7370

74-
test_format = SDL_FirstAudioFormat(this->spec.format);
75-
while ((!supported_format) && (test_format)) {
76-
if (test_format == AUDIO_S16SYS) {
77-
supported_format = SDL_TRUE;
78-
}
79-
else {
80-
test_format = SDL_NextAudioFormat();
81-
}
82-
}
83-
if (!supported_format) {
84-
return SDL_SetError("Unsupported audio format");
85-
}
86-
87-
this->spec.format = test_format;
71+
this->spec.format = AUDIO_S16SYS;
8872
SDL_CalculateAudioSpec(&this->spec);
8973

9074
size = (u32) ((this->spec.size * 2) + 0xfff) & ~0xfff;

0 commit comments

Comments
 (0)