Skip to content

[raudio] Audio recording#5941

Open
jn-jairo wants to merge 2 commits into
raysan5:masterfrom
jn-jairo:audio-recording
Open

[raudio] Audio recording#5941
jn-jairo wants to merge 2 commits into
raysan5:masterfrom
jn-jairo:audio-recording

Conversation

@jn-jairo

Copy link
Copy Markdown
Contributor

This PR adds basic audio recording.

Notes:

  • Separated from audio playback
  • InitAudioRecordingDevice() uses defines for config (the same one from playback)
  • InitAudioRecordingDeviceEx() uses custom sampleRate, sampleSize and channels
  • Callback to receive data is set with SetAudioRecordingCallback()
  • Added AudioRecordingCallback callback instead of using AudioCallback because the input data is const void * instead of the void * of the output and the compiler was showing a warning, if it's ok to use AudioCallback and ignore the warning I can change it
  • Added function to get the recording configs GetAudioRecordingSampleRate(), GetAudioRecordingSampleSize() and GetAudioRecordingChannels() because it is needed to process the data as shown in the example
  • StartAudioRecording() and StopAudioRecording() use the ma_device_start() and ma_device_stop(), so the capture device is not always running like the playback one, and the recording status is if the device is started
  • Added an example that records up to 5 seconds of audio and play it back

This interface is the simplest I got that enables all use cases I could imagine.

In games audio recording is mainly for voice chat and a stream of data is all you need.

For other softwares like audio recording/editing, you would need to be able to set the sample rate and so on at runtime, that is why I added this option, and creating a wave is trivial if you have the stream of data like shown in the example, so we don't need to have it builtin in raylib.

Please let me know if there is anything I need to change. I tested in Linux (kubuntu 24.04) with zig and make, I didn't commit the changes in the makefile because I believe there is a rexm to manage that but it is crashing when I try to add the example.


InitAudioDevice();
InitAudioRecordingDevice();
// InitAudioRecordingDeviceEx(24000, 16, 1);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's an example of an alternative method to initialize the audio recording device.

@raysan5 raysan5 added the new feature This is an addition to the library label Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature This is an addition to the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants