Skip to content

Commit e18c297

Browse files
committed
ios: coreaudio microphone shutdown fix
1 parent 87e6c77 commit e18c297

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

audio/audio_driver.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,9 +2163,6 @@ static void mic_driver_microphone_handle_init(retro_microphone_t *microphone,
21632163
unsigned microphone_sample_rate = settings->uints.microphone_sample_rate;
21642164
microphone->microphone_context = NULL;
21652165
microphone->flags = MICROPHONE_FLAG_ACTIVE;
2166-
microphone->sample_buffer = NULL;
2167-
microphone->sample_buffer_length = 0;
2168-
21692166
microphone->requested_params.rate = params ? params->rate : microphone_sample_rate;
21702167
microphone->actual_params.rate = 0;
21712168
/* We don't set the actual parameters until we actually open the mic.
@@ -2195,13 +2192,6 @@ static void mic_driver_microphone_handle_free(retro_microphone_t *microphone, bo
21952192
microphone->microphone_context = NULL;
21962193
}
21972194

2198-
if (microphone->sample_buffer)
2199-
{
2200-
memalign_free(microphone->sample_buffer);
2201-
microphone->sample_buffer = NULL;
2202-
microphone->sample_buffer_length = 0;
2203-
}
2204-
22052195
if (microphone->outgoing_samples)
22062196
{
22072197
fifo_free(microphone->outgoing_samples);
@@ -2236,6 +2226,9 @@ bool microphone_driver_init_internal(void *settings_data)
22362226
if (!settings->bools.microphone_enable)
22372227
{
22382228
mic_st->flags &= ~MICROPHONE_DRIVER_FLAG_ACTIVE;
2229+
/* Ensure microphone struct is clean to prevent crashes on deinit
2230+
* if there was stale data from a previous session */
2231+
memset(&mic_st->microphone, 0, sizeof(mic_st->microphone));
22392232
return false;
22402233
}
22412234

@@ -2329,13 +2322,6 @@ static bool mic_driver_open_mic_internal(retro_microphone_t* microphone)
23292322
if (!microphone || !mic_driver || !(mic_st->flags & MICROPHONE_DRIVER_FLAG_ACTIVE))
23302323
return false;
23312324

2332-
microphone->sample_buffer_length = max_samples * sizeof(int16_t);
2333-
microphone->sample_buffer =
2334-
(int16_t*)memalign_alloc(64, microphone->sample_buffer_length);
2335-
2336-
if (!microphone->sample_buffer)
2337-
goto error;
2338-
23392325
microphone->outgoing_samples = fifo_new(max_samples * sizeof(int16_t));
23402326
if (!microphone->outgoing_samples)
23412327
goto error;

audio/drivers/coreaudio_mic_ios.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ static void coreaudio_microphone_set_format(coreaudio_microphone_t *microphone,
358358
AudioComponentInstanceDispose(microphone->audio_unit);
359359
microphone->audio_unit = nil;
360360
}
361-
free(microphone);
361+
if (microphone->sample_buffer)
362+
fifo_free(microphone->sample_buffer);
363+
/* Don't free microphone - it's the driver context, freed by coreaudio_microphone_free */
362364
}
363365
return NULL;
364366
}
@@ -378,8 +380,11 @@ static void coreaudio_microphone_close_mic(void *driver_context, void *microphon
378380
microphone->audio_unit = nil;
379381
}
380382
if (microphone->sample_buffer)
383+
{
381384
fifo_free(microphone->sample_buffer);
382-
free(microphone);
385+
microphone->sample_buffer = NULL;
386+
}
387+
/* Don't free microphone - it's the driver context, freed by coreaudio_microphone_free */
383388
}
384389
else
385390
{

audio/microphone_driver.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,6 @@ struct retro_microphone
135135
*/
136136
void *microphone_context;
137137

138-
/**
139-
* Pointer to the data that will be copied to cores.
140-
*/
141-
int16_t* sample_buffer;
142-
143-
/**
144-
* Length of \c sample_buffer in bytes, \em not samples.
145-
*/
146-
size_t sample_buffer_length;
147-
148138
/**
149139
* Bit flags that describe the state of this microphone.
150140
*

0 commit comments

Comments
 (0)