Skip to content

Commit ce05980

Browse files
committed
clean up some extra logging
1 parent 56243c5 commit ce05980

File tree

1 file changed

+14
-122
lines changed

1 file changed

+14
-122
lines changed

audio/drivers_microphone/coreaudio_mic_macos.m

Lines changed: 14 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -167,36 +167,22 @@ static OSStatus coreaudio_macos_input_callback(void *inRefCon,
167167

168168
static int coreaudio_macos_microphone_read(void *driver_data, void *mic_data, void *buf, size_t samples)
169169
{
170-
static int read_call_count = 0;
171-
read_call_count++;
172-
173-
/* Reduce logging to avoid timing issues */
174-
if (read_call_count <= 3 || read_call_count % 1000 == 0)
175-
{
176-
RARCH_LOG("[CoreAudio Mic Read]: *** READ CALLED #%d *** samples requested: %zu\n", read_call_count, samples);
177-
}
178-
179170
coreaudio_macos_microphone_t *mic = (coreaudio_macos_microphone_t *)mic_data;
180171

181172
if (!mic || !mic->audio_unit || !mic->buffer_list || !mic->buffer_list->mBuffers[0].mData)
182173
{
183-
if (read_call_count <= 3)
184-
RARCH_ERR("[CoreAudio Mic Read]: Invalid mic_data, audio_unit, or buffer_list setup.\n");
174+
RARCH_ERR("[CoreAudio Mic]: Invalid mic_data or setup\n");
185175
return -1;
186176
}
187177

188178
if (mic->format.mBytesPerFrame == 0)
189179
{
190-
if (read_call_count <= 3)
191-
RARCH_ERR("[CoreAudio Mic Read]: mBytesPerFrame is 0. Cannot process audio frames.\n");
180+
RARCH_ERR("[CoreAudio Mic]: mBytesPerFrame is 0\n");
192181
return -1;
193182
}
194183

195184
if (!atomic_load(&mic->is_running))
196185
{
197-
if (read_call_count <= 3)
198-
RARCH_LOG("[CoreAudio Mic Read]: AudioUnit not running according to our flag. Checking actual state...\n");
199-
200186
/* Check AudioUnit's actual running state and try to restart if needed */
201187
UInt32 au_is_actually_running = 0;
202188
UInt32 property_size = sizeof(au_is_actually_running);
@@ -206,111 +192,52 @@ static int coreaudio_macos_microphone_read(void *driver_data, void *mic_data, vo
206192
0,
207193
&au_is_actually_running,
208194
&property_size);
209-
210-
if (read_call_count <= 3)
211-
{
212-
RARCH_LOG("[CoreAudio Mic Read]: AudioUnit actual running state: %u (status: %d)\n",
213-
(unsigned)au_is_actually_running, (int)status);
214-
}
215195

216196
if (status == noErr && !au_is_actually_running)
217197
{
218198
/* Try to restart the AudioUnit */
219-
if (read_call_count <= 3)
220-
RARCH_LOG("[CoreAudio Mic Read]: Attempting to restart AudioUnit...\n");
221199
OSStatus start_status = AudioOutputUnitStart(mic->audio_unit);
222200
if (start_status == noErr) {
223-
if (read_call_count <= 3)
224-
RARCH_LOG("[CoreAudio macOS Mic Read]: Successfully started AudioUnit\n");
225201
atomic_store(&mic->is_running, true);
226-
} else {
227-
if (read_call_count <= 3)
228-
RARCH_ERR("[CoreAudio macOS Mic Read]: Failed to start AudioUnit: %d\n", (int)start_status);
229202
}
230203
}
231204

232205
if (!atomic_load(&mic->is_running))
233206
{
234-
if (read_call_count <= 3)
235-
RARCH_LOG("[CoreAudio Mic Read]: Still not running, returning 0\n");
236207
return 0; /* Still not running, no data */
237208
}
238209
}
239210

240-
/* With push model, we just read from the FIFO that's populated by the callback */
241211
size_t bytes_to_read = samples * mic->format.mBytesPerFrame;
212+
242213
pthread_mutex_lock(&mic->fifo_lock);
243-
244214
/* Get available number of bytes */
245215
size_t available_bytes = FIFO_READ_AVAIL(mic->fifo);
246216

247-
if (read_call_count <= 3)
248-
{
249-
RARCH_LOG("[CoreAudio Mic Read]: FIFO has %zu bytes available, need %zu bytes (%zu samples * %u bytes/frame)\n",
250-
available_bytes, bytes_to_read, samples, (unsigned)mic->format.mBytesPerFrame);
251-
}
252-
253217
/* Read at most bytes_to_read, but could be less if available_bytes is less */
254218
size_t bytes_to_actually_read = bytes_to_read;
255219
if (available_bytes < bytes_to_read)
256220
bytes_to_actually_read = available_bytes;
257-
258-
/* Perform the actual read */
221+
259222
fifo_read(mic->fifo, buf, bytes_to_actually_read);
260223
size_t bytes_read = bytes_to_actually_read;
261224
pthread_mutex_unlock(&mic->fifo_lock);
262225

263-
if (read_call_count <= 3)
264-
{
265-
RARCH_LOG("[CoreAudio Mic Read]: Read %zu bytes from FIFO\n", bytes_read);
266-
}
267-
268-
/* Check if we got silence by examining the first few bytes */
269-
if (bytes_read > 0 && buf)
270-
{
271-
bool is_silence = true;
272-
uint8_t *byte_buf = (uint8_t*)buf;
273-
size_t check_bytes = bytes_read < 16 ? bytes_read : 16; /* Check first 16 bytes */
274-
275-
for (size_t i = 0; i < check_bytes; i++)
276-
{
277-
if (byte_buf[i] != 0)
278-
{
279-
is_silence = false;
280-
break;
281-
}
282-
}
283-
284-
if (read_call_count <= 3)
285-
{
286-
RARCH_LOG("[CoreAudio Mic Read]: Data appears to be %s (checked %zu bytes)\n",
287-
is_silence ? "SILENCE" : "AUDIO", check_bytes);
288-
}
289-
}
290-
291226
/* Return zero in nonblocking mode when no data available */
292-
if (bytes_read == 0 && mic->nonblock)
227+
if (bytes_read == 0)
293228
{
294-
if (read_call_count <= 3)
295-
RARCH_LOG("[CoreAudio Mic Read]: Nonblock mode, no data available, returning 0\n");
296229
return 0;
297230
}
298231

299-
/* For silence generation when no actual mic data is available but we need to return something */
232+
/* Fill with silence if we didn't get enough data */
300233
if (bytes_read == 0 && buf)
301234
{
302-
if (read_call_count <= 3)
303-
RARCH_LOG("[CoreAudio Mic Read]: No data available, filling with silence\n");
304-
/* To reduce CPU usage when no data is available, fill with silence instead */
235+
/* Fill with silence instead of returning 0 */
305236
memset(buf, mic->format.mFormatFlags & kAudioFormatFlagIsFloat ? 0 : 128, bytes_to_read);
306237
bytes_read = bytes_to_read;
307238
}
308239

309240
size_t frames_read = bytes_read / mic->format.mBytesPerFrame;
310-
if (read_call_count <= 3)
311-
{
312-
RARCH_LOG("[CoreAudio Mic Read]: Returning %zu frames (%zu bytes)\n", frames_read, bytes_read);
313-
}
314241
return frames_read;
315242
}
316243

@@ -728,7 +655,6 @@ static void coreaudio_macos_microphone_device_list_free(const void *data, struct
728655
}
729656

730657
/* 4. Set stream format */
731-
RARCH_LOG("[CoreAudio macOS Mic]: About to call coreaudio_macos_microphone_set_format with mic->sample_rate = %u Hz\n", mic->sample_rate);
732658
coreaudio_macos_microphone_set_format(mic, false /* use int16 for better compatibility */);
733659

734660
RARCH_LOG("[CoreAudio macOS Mic]: After format setup - mic->format.mSampleRate = %.0f Hz\n", mic->format.mSampleRate);
@@ -743,7 +669,7 @@ static void coreaudio_macos_microphone_device_list_free(const void *data, struct
743669
&device_format,
744670
&prop_size);
745671
if (format_status != noErr) {
746-
RARCH_WARN("[CoreAudio macOS Mic]: Could not get device native format from input bus: %d. Using default format.\n", (int)format_status);
672+
RARCH_WARN("[CoreAudio macOS Mic]: Could not get device native format from input bus: %d. Using default format.\n", (int)format_status);
747673
} else {
748674
RARCH_LOG("[CoreAudio macOS Mic]: Device native format (input bus) - Sample rate: %.0f, Channels: %u, Bits: %u\n",
749675
device_format.mSampleRate,
@@ -769,13 +695,7 @@ static void coreaudio_macos_microphone_device_list_free(const void *data, struct
769695
(unsigned)mic->format.mBytesPerFrame);
770696
}
771697

772-
/* Set our desired client format on the OUTPUT scope of the INPUT bus (bus 1) */
773-
/* This is the format we want to receive in our callback */
774-
RARCH_LOG("[CoreAudio macOS Mic]: Setting client format on OUTPUT scope of INPUT bus - Sample rate: %.0f, Format: %s, Channels: %u\n",
775-
mic->format.mSampleRate,
776-
mic->use_float ? "Float" : "Int16",
777-
(unsigned)mic->format.mChannelsPerFrame);
778-
698+
RARCH_LOG("[CoreAudio macOS Mic]: Setting client format on OUTPUT scope of INPUT bus\n");
779699
OSStatus set_format_status = AudioUnitSetProperty(mic->audio_unit,
780700
kAudioUnitProperty_StreamFormat,
781701
kAudioUnitScope_Output, /* Output scope - what we receive */
@@ -784,25 +704,19 @@ static void coreaudio_macos_microphone_device_list_free(const void *data, struct
784704
sizeof(AudioStreamBasicDescription));
785705
if (set_format_status != noErr)
786706
{
787-
RARCH_ERR("[CoreAudio macOS Mic]: Failed to set client stream format on input bus (output scope): %d\n", (int)set_format_status);
707+
RARCH_ERR("[CoreAudio macOS Mic]: Failed to set client stream format: %d\n", (int)set_format_status);
788708
AudioComponentInstanceDispose(mic->audio_unit);
789709
if (mic->device_name) free(mic->device_name);
790710
pthread_mutex_destroy(&mic->fifo_lock);
791711
free(mic);
792712
return NULL;
793713
}
794-
795-
RARCH_LOG("[CoreAudio macOS Mic]: Successfully set client stream format on input bus (output scope).\n");
796714

797-
/* 5. Set up input callback - REQUIRED for AUHAL input capture */
715+
/* Set up input callback */
798716
AURenderCallbackStruct callback_struct;
799717
callback_struct.inputProc = coreaudio_macos_input_callback;
800718
callback_struct.inputProcRefCon = mic;
801719

802-
RARCH_LOG("[CoreAudio macOS Mic]: Setting up INPUT callback function pointer: %p with context: %p\n",
803-
(void*)coreaudio_macos_input_callback, mic);
804-
805-
RARCH_LOG("[CoreAudio macOS Mic]: Setting kAudioOutputUnitProperty_SetInputCallback property (for microphone input)\n");
806720
status = AudioUnitSetProperty(mic->audio_unit,
807721
kAudioOutputUnitProperty_SetInputCallback,
808722
kAudioUnitScope_Global,
@@ -811,16 +725,14 @@ static void coreaudio_macos_microphone_device_list_free(const void *data, struct
811725
sizeof(callback_struct));
812726
if (status != noErr)
813727
{
814-
RARCH_ERR("[CoreAudio macOS Mic]: Failed to set INPUT callback property: %d (0x%x)\n", (int)status, (unsigned)status);
728+
RARCH_ERR("[CoreAudio macOS Mic]: Failed to set INPUT callback: %d\n", (int)status);
815729
AudioComponentInstanceDispose(mic->audio_unit);
816730
if (mic->device_name) free(mic->device_name);
817731
pthread_mutex_destroy(&mic->fifo_lock);
818732
free(mic);
819733
return NULL;
820734
}
821735

822-
RARCH_LOG("[CoreAudio macOS Mic]: Successfully set INPUT callback\n");
823-
824736
RARCH_LOG("[CoreAudio macOS Mic]: Initializing AudioUnit %p\n", mic->audio_unit);
825737
status = AudioUnitInitialize(mic->audio_unit);
826738
if (status != noErr)
@@ -836,7 +748,6 @@ static void coreaudio_macos_microphone_device_list_free(const void *data, struct
836748
RARCH_LOG("[CoreAudio macOS Mic]: AudioUnit successfully initialized.\n");
837749

838750
/* Initialize FIFO buffer for audio data */
839-
RARCH_LOG("[CoreAudio macOS Mic]: Allocating FIFO buffer for audio data\n");
840751
size_t fifo_size = mic->format.mSampleRate * mic->format.mBytesPerFrame * 2; /* 2 seconds of audio buffer */
841752
mic->fifo = fifo_new(fifo_size);
842753
if (!mic->fifo)
@@ -849,11 +760,8 @@ static void coreaudio_macos_microphone_device_list_free(const void *data, struct
849760
free(mic);
850761
return NULL;
851762
}
852-
RARCH_LOG("[CoreAudio macOS Mic]: FIFO buffer allocated successfully: %p with size %u bytes\n",
853-
mic->fifo, (unsigned)fifo_size);
854763

855764
/* Allocate AudioBufferList for AudioUnitRender in the callback */
856-
RARCH_LOG("[CoreAudio macOS Mic]: Allocating AudioBufferList for AudioUnitRender\n");
857765

858766
/* Calculate proper buffer size based on format */
859767
UInt32 max_frames_prop_size = sizeof(mic->max_frames_per_slice);
@@ -864,12 +772,9 @@ static void coreaudio_macos_microphone_device_list_free(const void *data, struct
864772
&mic->max_frames_per_slice,
865773
&max_frames_prop_size);
866774
if (prop_status != noErr) {
867-
RARCH_WARN("[CoreAudio macOS Mic]: Failed to get maximum frames per slice, using default buffer size\n");
868775
mic->max_frames_per_slice = mic->format.mSampleRate / 4; /* Default to 1/4 second */
869776
}
870777

871-
RARCH_LOG("[CoreAudio macOS Mic]: Max frames per slice: %u\n", (unsigned)mic->max_frames_per_slice);
872-
873778
/* Allocate AudioBufferList with memory for the actual audio data */
874779
mic->buffer_list = (AudioBufferList*)calloc(1, sizeof(AudioBufferList));
875780
if (!mic->buffer_list)
@@ -892,9 +797,6 @@ static void coreaudio_macos_microphone_device_list_free(const void *data, struct
892797
/* Allocate buffer using max_frames_per_slice from the AudioUnit */
893798
size_t buffer_size = mic->max_frames_per_slice * mic->format.mBytesPerFrame;
894799
mic->buffer_size = buffer_size; /* Store for later use */
895-
RARCH_LOG("[CoreAudio macOS Mic]: Allocating audio buffer with size %u bytes (%u frames)\n",
896-
(unsigned)buffer_size, (unsigned)mic->max_frames_per_slice);
897-
898800
mic->buffer_list->mBuffers[0].mDataByteSize = buffer_size;
899801
mic->buffer_list->mBuffers[0].mData = calloc(1, buffer_size);
900802
if (!mic->buffer_list->mBuffers[0].mData)
@@ -911,9 +813,6 @@ static void coreaudio_macos_microphone_device_list_free(const void *data, struct
911813
free(mic);
912814
return NULL;
913815
}
914-
915-
RARCH_LOG("[CoreAudio macOS Mic]: Buffer memory allocated successfully: %p with size %u bytes\n",
916-
mic->buffer_list->mBuffers[0].mData, (unsigned)buffer_size);
917816

918817
RARCH_LOG("[CoreAudio macOS Mic]: COMPLETE CONFIG - Sample rate: %.0f Hz, Format: %s, Channels: %u\n",
919818
mic->format.mSampleRate,
@@ -1019,16 +918,15 @@ static bool coreaudio_macos_microphone_start_mic(void *data, void *mic_data)
1019918
RARCH_LOG("[CoreAudio macOS Mic]: Default input device ID: %u\n", (unsigned)default_input_device);
1020919
}
1021920

1022-
RARCH_LOG("[CoreAudio macOS Mic]: About to start AudioUnit: %p\n", mic->audio_unit);
1023921
pthread_mutex_lock(&mic->fifo_lock);
1024922
fifo_clear(mic->fifo);
1025923
pthread_mutex_unlock(&mic->fifo_lock);
1026-
RARCH_LOG("[CoreAudio macOS Mic]: Cleared FIFO buffer before starting\n");
924+
1027925
OSStatus status = AudioOutputUnitStart(mic->audio_unit);
1028926
if (status == noErr)
1029927
{
1030928
atomic_store(&mic->is_running, true);
1031-
RARCH_LOG("[CoreAudio macOS Mic]: *** AudioUnit started successfully - microphone should now be capturing ***\n");
929+
RARCH_LOG("[CoreAudio macOS Mic]: Microphone started successfully\n");
1032930
return true;
1033931
}
1034932
else
@@ -1041,17 +939,14 @@ static bool coreaudio_macos_microphone_start_mic(void *data, void *mic_data)
1041939

1042940
static bool coreaudio_macos_microphone_stop_mic(void *data, void *mic_data)
1043941
{
1044-
RARCH_LOG("[CoreAudio macOS Mic]: stop_mic called. Mic context: %p\n", mic_data);
1045942
coreaudio_macos_microphone_t *mic = (coreaudio_macos_microphone_t *)mic_data;
1046943
if (!mic || !mic->audio_unit)
1047944
{
1048-
RARCH_LOG("[CoreAudio macOS Mic]: Cannot stop - mic not opened or no AudioUnit.\n");
1049945
return true; /* Considered stopped if not valid */
1050946
}
1051947

1052948
if (!atomic_load(&mic->is_running))
1053949
{
1054-
RARCH_LOG("[CoreAudio macOS Mic]: Already stopped.\n");
1055950
return true;
1056951
}
1057952

@@ -1065,7 +960,6 @@ static bool coreaudio_macos_microphone_stop_mic(void *data, void *mic_data)
1065960
fifo_clear(mic->fifo);
1066961
pthread_mutex_unlock(&mic->fifo_lock);
1067962
}
1068-
RARCH_LOG("[CoreAudio macOS Mic]: AudioUnit stopped successfully and FIFO cleared.\n");
1069963
return true;
1070964
}
1071965
else
@@ -1080,10 +974,8 @@ static bool coreaudio_macos_microphone_stop_mic(void *data, void *mic_data)
1080974
static bool coreaudio_macos_microphone_mic_use_float(const void *data, const void *mic_data)
1081975
{
1082976
(void)data;
1083-
RARCH_LOG("[CoreAudio macOS Mic]: mic_use_float called. Mic context: %p\n", mic_data);
1084977
coreaudio_macos_microphone_t *mic = (coreaudio_macos_microphone_t *)mic_data;
1085978
bool result = mic && mic->use_float;
1086-
RARCH_LOG("[CoreAudio macOS Mic]: mic_use_float returning: %s\n", result ? "true" : "false");
1087979
return result;
1088980
}
1089981

0 commit comments

Comments
 (0)