Adding Music To My Raylib App

min read

At 175 words per minute.

2025-03-13 Back to posts

raylib and C logo

Adding audio to a C application is easy with raylib!

Adding Music To My Raylib App

For some reason, the musician in me awoke today.

I decided to use my Novation LaunchKey Mini [MK3] to compose and write a simple tune for an app I made last year that has garnered interest from the public on Github.

The app in question is a snowfall simulation using raylib, compiled on Linux Mint with GCC.

In this blog post, I’m going to be breaking down the code and the music composition!

Let’s dive in.

Programming

I decided to tackle the programming first, I’m more comfortable in VSCode compared to Ableton.

Adding the button

I added a button under the other buttons already on the screen, it simply toggles the music on and off. More on the logic later.

Vector2 playMusicPos = {padding + 10, padding + 170};
DrawRectangle(playMusicPos.x, playMusicPos.y, buttonWidth, buttonHeight, GRAY);
DrawText("Toggle Music", playMusicPos.x + buttonWidth / 2 - MeasureText("Toggle Music", 10) / 2, 
                         playMusicPos.y + buttonHeight / 2 - 5, 11, WHITE);

We make use of various functions/classes built into raylib here, including DrawRectangle();, Vector2, and DrawText();.

These built in functions/classes allow us to build UIs in C easily!

The button (red arrow)

Photo of the button

Adding the logic to play music

Adding the control flow to play the music when the button is clicked was simple.

Rectangle playMusicButton = {10, 170, 75, 30};
    if (CheckCollisionPointRec(mousePos, playMusicButton))
    {
        if (soundPlaying) 
        {
            soundPlaying = false;
            StopSound(sound);
        } 
        else
        {
            soundPlaying = true;
            PlaySound(sound);
        }
    }

and in our header file:

bool soundPlaying = false;

Within our main function, we check if the left mouse button is being pressed and grab the mouse position at the time its clicked.

From there, we can simply stop the sound, or play it!

That was basically all the code I had to write (besides a small refactor) in order to play the music.

Now onto the music.

Music Composition

For music production, I use Ableton Live 12 Lite and a Launchkey Mini MK3.

The LaunchKey Mini MK3

  1. Creating a Soft Pad: I started by creating a soft, ambient pad for the background. This pad will give the track a dreamy atmosphere that blends well with the falling snow.

  2. Adding Chord Progression: For a relaxing vibe, I laid down a repetitive chord progression. Something soft & organic, like C - G - A - F, played on the pad.

  3. Adding Drums and Bassline: To keep it chill but moving, I added a slow 808 drum pattern with a simple kick, snare, and hi-hat pattern.

  4. Fine-Tuning Effects: I added some reverb and delay to the pad to give it a spacious, ambient feel.

You can listen to the song I made below 👇

Conclusion

Adding music to my raylib app wasn’t as difficult as I thought it would be.

Thanks to the simplicity of raylib, I was able to integrate it quickly with just a few lines of code.

The music itself was a fun challenge, especially with my Launchkey Mini guiding me through the composition process in Ableton.

If you’re looking to add music to your own project, I hope this breakdown gives you inspiration!

View the full code on Github!

Nick Stambaugh is a writer, entrepreneur, and enterprise software engineer

Recent Posts

Learn Lua With Tests

Today I started working on my first book, Learn Lua With Tests

2026-05-17

Read more →

#Lua #Coding #Tech

On Brevity

Why using fewer words at the right moment is the ultimate competitive advantage.

2026-05-15

Read more →

#Philosophy #SelfHelp

Selling an html file for a few grand

While the tech around us is constantly evolving, that doesn't mean what is new is always the correct tool for the job.

2026-05-15

Read more →

#Business #Tech

I Don't Follow, I Subscribe

For over 7 years, I have almost never engaged with social media. I'm sharing my story to help those who are addicted to social media or need direction in their careers.

2026-04-09

Read more →

#SelfHelp #SocialMedia

Why I Let GitHub Actions Maintain My GitHub Profile README

How manually updating your GitHub profile README quietly fails at scale, and how I use GitHub Actions to keep it accurate, current, and maintenance-free.

2026-01-06

Read more →

#Automation #DevOps #Engineering

Why Your Astro JavaScript Works in Chrome but Breaks in Firefox

How browser inconsistencies in JavaScript APIs can silently tank your Astro site, and why engineers often miss them.

2025-12-25

Read more →

#WebDev #Astro #Frontend #JavaScript