Skip to content

Commit 3aa8db2

Browse files
committed
(Audio) SOme control flow changes (no functional changes) and some cleanups
1 parent e3a5c5e commit 3aa8db2

File tree

12 files changed

+179
-199
lines changed

12 files changed

+179
-199
lines changed

audio/common/mmdevice_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "../../verbosity.h"
2626

27-
static const char* mmdevice_data_flow_name(unsigned data_flow)
27+
static const char *mmdevice_data_flow_name(unsigned data_flow)
2828
{
2929
switch (data_flow)
3030
{

audio/drivers/alsathread.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,10 @@ static void alsa_microphone_worker_thread(void *mic_context)
214214

215215
static int alsa_thread_microphone_read(void *driver_context, void *mic_context, void *s, size_t len)
216216
{
217+
snd_pcm_state_t state;
218+
size_t _len = 0;
217219
alsa_thread_microphone_t *alsa = (alsa_thread_microphone_t*)driver_context;
218220
alsa_thread_microphone_handle_t *mic = (alsa_thread_microphone_handle_t*)mic_context;
219-
snd_pcm_state_t state;
220221

221222
if (!alsa || !mic || !s) /* If any of the parameters were invalid... */
222223
return -1;
@@ -245,28 +246,23 @@ static int alsa_thread_microphone_read(void *driver_context, void *mic_context,
245246
if (alsa->nonblock)
246247
{
247248
size_t avail;
248-
size_t write_amt;
249249

250250
/* "Hey, I'm gonna borrow the queue." */
251251
slock_lock(mic->info.fifo_lock);
252252

253253
avail = FIFO_READ_AVAIL(mic->info.buffer);
254-
write_amt = MIN(avail, len);
254+
_len = MIN(avail, len);
255255

256256
/* "It's okay if you don't have any new samples, I'll just check in on you later." */
257-
fifo_read(mic->info.buffer, s, write_amt);
257+
fifo_read(mic->info.buffer, s, _len);
258258

259259
/* "Here, take this queue back." */
260260
slock_unlock(mic->info.fifo_lock);
261-
262-
return (int)write_amt;
263261
}
264262
else
265263
{
266-
size_t read = 0;
267-
268264
/* Until we've read all requested samples (or we're told to stop)... */
269-
while (read < len && !mic->info.thread_dead)
265+
while (_len < len && !mic->info.thread_dead)
270266
{
271267
size_t avail;
272268

@@ -294,21 +290,20 @@ static int alsa_thread_microphone_read(void *driver_context, void *mic_context,
294290
}
295291
else
296292
{
297-
size_t read_amt = MIN(len - read, avail);
293+
size_t read_amt = MIN(len - _len, avail);
298294

299295
/* "I'll just go ahead and consume all these samples..."
300296
* (As many as will fit in s, or as many as are available.) */
301-
fifo_read(mic->info.buffer,s + read, read_amt);
297+
fifo_read(mic->info.buffer,s + _len, read_amt);
302298

303299
/* "I'm done, you can take the queue back now." */
304300
slock_unlock(mic->info.fifo_lock);
305-
read += read_amt;
301+
_len += read_amt;
306302
}
307-
308303
/* "I'll be right back..." */
309304
}
310-
return (int)read;
311305
}
306+
return _len;
312307
}
313308

314309
static bool alsa_thread_microphone_mic_alive(const void *driver_context, const void *mic_context);
@@ -475,8 +470,9 @@ static void alsa_worker_thread(void *data)
475470

476471
frames = snd_pcm_writei(alsa->info.pcm, buf, alsa->info.stream_info.period_frames);
477472

478-
if (frames == -EPIPE || frames == -EINTR ||
479-
frames == -ESTRPIPE)
473+
if ( frames == -EPIPE
474+
|| frames == -EINTR
475+
|| frames == -ESTRPIPE)
480476
{
481477
if (snd_pcm_recover(alsa->info.pcm, frames, false) < 0)
482478
{
@@ -625,7 +621,6 @@ static bool alsa_thread_alive(void *data)
625621
static bool alsa_thread_stop(void *data)
626622
{
627623
alsa_thread_t *alsa = (alsa_thread_t*)data;
628-
629624
if (alsa)
630625
alsa->is_paused = true;
631626
return true;

audio/drivers/audioio.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,26 @@ static void *audioio_init(const char *device, unsigned rate, unsigned latency,
3636
unsigned block_frames, unsigned *new_out_rate)
3737
{
3838
struct audio_info info;
39-
const char *audiodev = device ? device : DEFAULT_DEV;
40-
int *fd = (int*)calloc(1, sizeof(int));
39+
const char *audiodev = device ? device : DEFAULT_DEV;
40+
int *fd = (int*)calloc(1, sizeof(int));
4141

4242
if (!fd)
4343
return NULL;
4444

4545
AUDIO_INITINFO(&info);
4646

4747
#ifdef AUMODE_PLAY_ALL
48-
info.mode = AUMODE_PLAY_ALL;
48+
info.mode = AUMODE_PLAY_ALL;
4949
#elif defined(AUMODE_PLAY)
50-
info.mode = AUMODE_PLAY;
50+
info.mode = AUMODE_PLAY;
5151
#endif
5252
info.play.sample_rate = rate;
53-
info.play.channels = 2;
54-
info.play.precision = 16;
53+
info.play.channels = 2;
54+
info.play.precision = 16;
5555
#ifdef AUDIO_ENCODING_SLINEAR
56-
info.play.encoding = AUDIO_ENCODING_SLINEAR;
56+
info.play.encoding = AUDIO_ENCODING_SLINEAR;
5757
#else
58-
info.play.encoding = AUDIO_ENCODING_LINEAR;
58+
info.play.encoding = AUDIO_ENCODING_LINEAR;
5959
#endif
6060

6161
if ((*fd = open(audiodev, O_WRONLY)) < 0)

audio/drivers/audioworklet.c

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ static void audioworklet_thread_inited_cb(EMSCRIPTEN_WEBAUDIO_T context, bool su
149149
audioworklet_data_t *audioworklet = (audioworklet_data_t*)data;
150150
WebAudioWorkletProcessorCreateOptions opts = { "retroarch", 0 };
151151

152-
if (!success)
152+
if (success)
153+
emscripten_create_wasm_audio_worklet_processor_async(context, &opts,
154+
audioworklet_processor_inited_cb, audioworklet);
155+
else
153156
{
154157
RARCH_ERR("[AudioWorklet] Failed to init worklet thread! Is the worklet file in the right place?\n");
155158
audioworklet->init_error = true;
156159
audioworklet->init_done = true;
157-
return;
158160
}
159-
160-
emscripten_create_wasm_audio_worklet_processor_async(context, &opts, audioworklet_processor_inited_cb, audioworklet);
161161
}
162162

163163
static void audioworklet_ctx_statechange_cb(void *data, bool state)
@@ -190,9 +190,9 @@ static void audioworklet_ctx_create(void *data)
190190

191191
static void audioworklet_alloc_buffer(void *data)
192192
{
193+
size_t buffer_size;
193194
audioworklet_data_t *audioworklet = (audioworklet_data_t*)data;
194195

195-
size_t buffer_size;
196196
audioworklet->visible_buffer_size = (audioworklet->latency * audioworklet->rate * 2 * sizeof(float)) / 1000;
197197
buffer_size = audioworklet->visible_buffer_size;
198198
#ifdef EMSCRIPTEN_AUDIO_EXTERNAL_WRITE_BLOCK
@@ -239,9 +239,9 @@ static void *audioworklet_init(const char *device, unsigned rate,
239239
return NULL;
240240
}
241241
RARCH_LOG("[AudioWorklet] Reusing old context.\n");
242-
audioworklet = audioworklet_static_data;
242+
audioworklet = audioworklet_static_data;
243243
audioworklet->latency = latency;
244-
*new_rate = audioworklet->rate;
244+
*new_rate = audioworklet->rate;
245245
RARCH_LOG("[AudioWorklet] Device rate: %d Hz.\n", *new_rate);
246246
audioworklet_alloc_buffer(audioworklet);
247247
audioworklet_resume_ctx(audioworklet);
@@ -259,7 +259,7 @@ static void *audioworklet_init(const char *device, unsigned rate,
259259

260260
audioworklet->latency = latency;
261261
platform_emscripten_run_on_browser_thread_sync(audioworklet_ctx_create, audioworklet);
262-
*new_rate = audioworklet->rate;
262+
*new_rate = audioworklet->rate;
263263
RARCH_LOG("[AudioWorklet] Device rate: %d Hz.\n", *new_rate);
264264
audioworklet->initing = true;
265265
audioworklet_alloc_buffer(audioworklet);
@@ -295,10 +295,10 @@ static ssize_t audioworklet_write(void *data, const void *s, size_t ss)
295295
size_t max_write;
296296
size_t to_write_frames;
297297
size_t to_write_bytes;
298-
size_t _len = 0;
298+
size_t _len = 0;
299299
audioworklet_data_t *audioworklet = (audioworklet_data_t*)data;
300300
const float *samples = (const float*)s;
301-
size_t num_frames = ss / 2 / sizeof(float);
301+
size_t num_frames = ss / 2 / sizeof(float);
302302

303303
/* too early! might happen with external blocking */
304304
if (!audioworklet->driver_running)
@@ -382,51 +382,51 @@ bool audioworklet_external_block(void)
382382
{
383383
audioworklet_data_t *audioworklet = audioworklet_static_data;
384384

385-
if (!audioworklet)
386-
return false;
387-
385+
if (audioworklet)
386+
{
388387
#ifdef EMSCRIPTEN_AUDIO_FAKE_BLOCK
389-
if (!audioworklet->block_requested)
390-
return false;
388+
if (!audioworklet->block_requested)
389+
return false;
391390
#endif
392391

393-
while (audioworklet->initing && !audioworklet->init_done)
392+
while (audioworklet->initing && !audioworklet->init_done)
394393
#ifdef EMSCRIPTEN_AUDIO_ASYNC_BLOCK
395-
retro_sleep(1);
394+
retro_sleep(1);
396395
#else
397-
return true;
396+
return true;
398397
#endif
399-
if (audioworklet->init_done && !audioworklet->driver_running)
400-
{
401-
audioworklet->initing = false;
402-
if (audioworklet->init_error)
398+
if (audioworklet->init_done && !audioworklet->driver_running)
403399
{
404-
audioworklet_init_error(audioworklet);
405-
abort();
406-
return false;
400+
audioworklet->initing = false;
401+
if (audioworklet->init_error)
402+
{
403+
audioworklet_init_error(audioworklet);
404+
abort();
405+
return false;
406+
}
407+
audioworklet->driver_running = true;
407408
}
408-
audioworklet->driver_running = true;
409-
}
410409
#ifdef EMSCRIPTEN_AUDIO_EXTERNAL_WRITE_BLOCK
411-
if (!audioworklet->driver_running)
412-
return false;
410+
if (!audioworklet->driver_running)
411+
return false;
413412

414-
while (emscripten_atomic_load_u32(&audioworklet->write_avail_bytes) < audioworklet->write_avail_diff)
415-
{
416-
audioworklet_resume_ctx(audioworklet);
413+
while (emscripten_atomic_load_u32(&audioworklet->write_avail_bytes) < audioworklet->write_avail_diff)
414+
{
415+
audioworklet_resume_ctx(audioworklet);
417416
#ifdef EMSCRIPTEN_AUDIO_ASYNC_BLOCK
418-
retro_sleep(1);
417+
retro_sleep(1);
419418
#else
420-
return true;
419+
return true;
421420
#endif
422-
}
421+
}
423422
#endif
424423

425424
#ifdef EMSCRIPTEN_AUDIO_FAKE_BLOCK
426-
audioworklet->block_requested = false;
427-
platform_emscripten_exit_fake_block();
428-
return true; /* return to RAF if needed */
425+
audioworklet->block_requested = false;
426+
platform_emscripten_exit_fake_block();
427+
return true; /* return to RAF if needed */
429428
#endif
429+
}
430430
return false;
431431
}
432432
#endif

0 commit comments

Comments
 (0)