Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/raudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ typedef struct tagBITMAPINFOHEADER {
// Defines and Macros
//----------------------------------------------------------------------------------
#ifndef AUDIO_DEVICE_FORMAT
#define AUDIO_DEVICE_FORMAT ma_format_f32 // Device output format (float-32bit)
#define AUDIO_DEVICE_FORMAT ma_format_s32 // Device output format (signed-32bit)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a potentially breaking change for many raylib users, did you consider that?

@Q-Wa-Ha Q-Wa-Ha Jun 17, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to revert the format back to normal. Please see below for more details.

#endif
#ifndef AUDIO_DEVICE_CHANNELS
#define AUDIO_DEVICE_CHANNELS 2 // Device output channels: stereo
Expand Down Expand Up @@ -395,6 +395,9 @@ typedef struct AudioData {
AudioBuffer *last; // Pointer to last AudioBuffer in the list
int defaultSize; // Default audio buffer size for audio streams
} Buffer;
struct {
bool isStreaming;
} Capture;
rAudioProcessor *mixedProcessor;
} AudioData;

Expand All @@ -408,7 +411,8 @@ static AudioData AUDIO = { // Global AUDIO context
// standard double-buffering system, a 4096 samples buffer has been chosen, it should be enough
// In case of music-stalls, increase this number
.Buffer.defaultSize = 0,
.mixedProcessor = NULL
.mixedProcessor = NULL,
.Capture.isStreaming = false
};

//----------------------------------------------------------------------------------
Expand Down Expand Up @@ -477,10 +481,13 @@ void InitAudioDevice(void)

// Init audio device
// NOTE: Using the default device. Format is floating point because it simplifies mixing
ma_device_config config = ma_device_config_init(ma_device_type_playback);
ma_device_config config = ma_device_config_init(ma_device_type_duplex);
config.playback.pDeviceID = NULL; // NULL for the default playback AUDIO.System.device
config.playback.format = AUDIO_DEVICE_FORMAT;
config.playback.channels = AUDIO_DEVICE_CHANNELS;
config.capture.pDeviceID = NULL;
config.capture.format = AUDIO_DEVICE_FORMAT;
config.capture.channels = AUDIO_DEVICE_CHANNELS;
config.sampleRate = AUDIO_DEVICE_SAMPLE_RATE;
config.periodSizeInFrames = AUDIO_DEVICE_PERIOD_SIZE_IN_FRAMES;
config.dataCallback = OnSendAudioDataToDevice;
Expand Down Expand Up @@ -2369,6 +2376,21 @@ void DetachAudioMixedProcessor(AudioCallback process)
ma_mutex_unlock(&AUDIO.System.lock);
}

//----------------------------------------------------------------------------------
// Module Functions Definition - Capture streaming
//----------------------------------------------------------------------------------
// Start streaming capture device (e.g. microphone) to speakers
void StartCaptureStream(void)
{
AUDIO.Capture.isStreaming = true;
}

// Stop streaming caputre device (e.g. microphone) to speakers
void StopCaptureStream(void)
{
AUDIO.Capture.isStreaming = false;
}

//----------------------------------------------------------------------------------
// Module Internal Functions Definition
//----------------------------------------------------------------------------------
Expand Down Expand Up @@ -2650,6 +2672,11 @@ static void OnSendAudioDataToDevice(ma_device *pDevice, void *pFramesOut, const
processor = processor->next;
}

if(AUDIO.Capture.isStreaming)
{
memcpy(pFramesOut, pFramesInput, frameCount * ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels));
}

ma_mutex_unlock(&AUDIO.System.lock);
}

Expand Down
4 changes: 4 additions & 0 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,10 @@ RLAPI void DetachAudioStreamProcessor(AudioStream stream, AudioCallback processo
RLAPI void AttachAudioMixedProcessor(AudioCallback processor); // Attach audio stream processor to the entire audio pipeline, receives frames x 2 samples as 'float' (stereo)
RLAPI void DetachAudioMixedProcessor(AudioCallback processor); // Detach audio stream processor from the entire audio pipeline

// Capture streaming functions
RLAPI void StartCaptureStream(void); // Start streaming capture device (e.g. microphone) to speakers
RLAPI void StopCaptureStream(void); // Stop streaming caputre device (e.g. microphone) to speakers

#if defined(__cplusplus)
}
#endif
Expand Down