Convert Figma logo to code with AI

mackron logodr_libs

Audio decoding libraries for C/C++, each in a single source file.

1,411
218
1,411
10

Top Related Projects

29,169

stb single-file public domain libraries for C/C++

67,317

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

27,462

A simple and easy-to-use library to enjoy videogames programming

12,965

Simple Directmedia Layer

The official Allegro 5 git repository. Pull requests welcome!

10,132

A single-header ANSI C immediate mode cross-platform GUI library

Quick Overview

Dr_libs is a collection of single-file public domain libraries for C and C++. It provides a set of lightweight, easy-to-use libraries for various purposes, including audio processing, image loading, and data compression. The project aims to offer simple, cross-platform solutions for common programming tasks.

Pros

  • Single-file libraries for easy integration into projects
  • Public domain license, allowing unrestricted use
  • Cross-platform compatibility
  • Wide range of functionality, from audio to image processing

Cons

  • Limited documentation for some libraries
  • May lack advanced features found in more specialized libraries
  • Potential for inconsistent coding style across different libraries
  • Some libraries may not be actively maintained

Code Examples

  1. Loading and decoding an audio file:
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"

// Load and decode entire WAV file
unsigned int channels;
unsigned int sampleRate;
drwav_uint64 totalPCMFrameCount;
float* pSampleData = drwav_open_file_and_read_pcm_frames_f32("my_file.wav", &channels, &sampleRate, &totalPCMFrameCount, NULL);

if (pSampleData != NULL) {
    // Audio data is now in pSampleData
    // ...

    drwav_free(pSampleData, NULL);
}
  1. Loading an image:
#define DR_IMAGE_IMPLEMENTATION
#include "dr_image.h"

int width;
int height;
int channels;
unsigned char* imageData = dr_image_load_file("image.png", &width, &height, &channels, 0);

if (imageData != NULL) {
    // Image data is now in imageData
    // ...

    dr_image_free(imageData);
}
  1. Compressing data using zlib:
#define DR_ZLIBEX_IMPLEMENTATION
#include "dr_zlibex.h"

const char* inputData = "Hello, World!";
size_t inputSize = strlen(inputData);
size_t compressedSize = dr_zlibex_compress_bound(inputSize);
void* compressedData = malloc(compressedSize);

if (dr_zlibex_compress(compressedData, &compressedSize, inputData, inputSize, DR_ZLIBEX_DEFAULT_COMPRESSION_LEVEL) == DR_ZLIBEX_SUCCESS) {
    // Data is now compressed in compressedData
    // ...

    free(compressedData);
}

Getting Started

To use dr_libs in your project:

  1. Download the desired library file(s) from the GitHub repository.
  2. Include the file(s) in your project directory.
  3. In one source file, define the implementation macro before including the header:
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"

// Your code here
  1. In other source files, simply include the header without the implementation macro:
#include "dr_wav.h"

// Your code here

Now you can use the library functions in your project.

Competitor Comparisons

29,169

stb single-file public domain libraries for C/C++

Pros of stb

  • Wider range of utilities, including image loading, font rendering, and more
  • Generally more popular and widely adopted in the game development community
  • Simpler integration with a single-file header approach for most libraries

Cons of stb

  • Less focused on audio processing compared to dr_libs
  • May have larger compile times due to the single-file header approach
  • Some utilities might be less optimized or feature-complete than specialized libraries

Code Comparison

stb (image loading):

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

int width, height, channels;
unsigned char *img = stbi_load("image.png", &width, &height, &channels, 0);

dr_libs (audio loading):

#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"

unsigned int channels, sampleRate;
drwav_uint64 totalPCMFrameCount;
float* pSampleData = drwav_open_file_and_read_pcm_frames_f32("audio.wav", &channels, &sampleRate, &totalPCMFrameCount, NULL);

Both libraries offer simple, header-only solutions for their respective domains. stb provides a broader range of utilities, while dr_libs focuses more on audio processing. The choice between them depends on the specific needs of your project and the balance between simplicity and specialization you're looking for.

67,317

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

Pros of ImGui

  • Comprehensive GUI toolkit with a wide range of UI elements and features
  • Extensive documentation and large community support
  • Designed specifically for immediate mode GUI rendering in games and applications

Cons of ImGui

  • Larger codebase and potentially higher learning curve
  • May have more overhead for simple projects that don't require a full GUI system

Code Comparison

ImGui example:

ImGui::Begin("Hello, world!");
ImGui::Text("This is some useful text.");
if (ImGui::Button("Save"))
    MySaveFunction();
ImGui::End();

dr_libs example (using dr_wav):

drwav wav;
drwav_init_file(&wav, "my_sound.wav", NULL);
drwav_int16* pSampleData = malloc(wav.totalPCMFrameCount * wav.channels * sizeof(drwav_int16));
drwav_read_pcm_frames_s16(&wav, wav.totalPCMFrameCount, pSampleData);
drwav_uninit(&wav);

Summary

ImGui is a feature-rich immediate mode GUI library, while dr_libs is a collection of single-file libraries for various audio and utility functions. ImGui is better suited for projects requiring complex user interfaces, while dr_libs excels in simplicity and ease of integration for specific audio and utility tasks.

27,462

A simple and easy-to-use library to enjoy videogames programming

Pros of raylib

  • Comprehensive game development framework with built-in graphics, audio, and input handling
  • Extensive documentation and examples for easier learning and implementation
  • Cross-platform support for desktop, web, and mobile platforms

Cons of raylib

  • Larger codebase and potentially higher resource usage
  • Less flexibility for integrating specific components into existing projects
  • Steeper learning curve for developers who only need specific audio or graphics functionality

Code Comparison

raylib:

#include "raylib.h"

int main() {
    InitWindow(800, 450, "raylib example");
    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText("Hello, raylib!", 190, 200, 20, LIGHTGRAY);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

dr_libs:

#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"

int main() {
    drwav wav;
    drwav_init_file(&wav, "audio.wav", NULL);
    // Process audio data
    drwav_uninit(&wav);
    return 0;
12,965

Simple Directmedia Layer

Pros of SDL

  • Comprehensive multimedia library with support for audio, video, input devices, and more
  • Cross-platform compatibility across multiple operating systems and devices
  • Large community and extensive documentation

Cons of SDL

  • Larger codebase and potential overhead for simple projects
  • Steeper learning curve for beginners compared to single-header libraries

Code Comparison

SDL (initializing audio):

SDL_Init(SDL_INIT_AUDIO);
SDL_AudioSpec want, have;
SDL_AudioDeviceID dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);

dr_libs (initializing audio):

#define DR_AUDIO_IMPLEMENTATION
#include "dr_audio.h"
drAudioDevice* pDevice = drAudioDeviceOpen(NULL, NULL);

SDL offers a more comprehensive solution for multimedia applications, including audio, video, and input handling across multiple platforms. It has a larger community and extensive documentation, making it suitable for complex projects.

dr_libs, on the other hand, provides a simpler, single-header library approach, which can be easier to integrate into smaller projects or when only specific functionality is needed. It has a lower learning curve and potentially less overhead for basic audio tasks.

The code comparison shows that SDL requires more setup steps for audio initialization, while dr_libs offers a more straightforward approach with its single-header design.

The official Allegro 5 git repository. Pull requests welcome!

Pros of Allegro5

  • Full-featured game programming library with graphics, audio, input, and more
  • Cross-platform support for Windows, macOS, Linux, Android, and iOS
  • Active community and ongoing development

Cons of Allegro5

  • Larger footprint and more complex API compared to dr_libs
  • Steeper learning curve for beginners
  • May include unnecessary features for audio-only projects

Code Comparison

Allegro5 (audio playback):

ALLEGRO_SAMPLE *sample;
ALLEGRO_SAMPLE_INSTANCE *instance;

sample = al_load_sample("audio.wav");
instance = al_create_sample_instance(sample);
al_play_sample_instance(instance);

dr_libs (audio playback):

drwav wav;
drwav_init_file(&wav, "audio.wav", NULL);
drwav_int16 *pSampleData = malloc(wav.totalPCMFrameCount * wav.channels * sizeof(drwav_int16));
drwav_read_pcm_frames_s16(&wav, wav.totalPCMFrameCount, pSampleData);
// Play audio using your preferred audio API

Summary

Allegro5 is a comprehensive game development library, while dr_libs focuses on audio decoding. Allegro5 offers more features but has a larger footprint, while dr_libs is lightweight and specialized for audio tasks. Choose based on your project requirements and complexity needs.

10,132

A single-header ANSI C immediate mode cross-platform GUI library

Pros of Nuklear

  • Focused on immediate mode GUI, providing a comprehensive set of UI widgets
  • Cross-platform compatibility with support for various rendering backends
  • Lightweight and single-header library, easy to integrate into existing projects

Cons of Nuklear

  • Limited to GUI functionality, unlike dr_libs which covers audio and other domains
  • May require more manual layout management compared to retained mode GUI libraries
  • Steeper learning curve for developers unfamiliar with immediate mode GUI concepts

Code Comparison

Nuklear (UI creation):

if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
    nk_layout_row_dynamic(ctx, 30, 1);
    if (nk_button_label(ctx, "Button"))
        fprintf(stdout, "Button pressed!\n");
}
nk_end(ctx);

dr_libs (Audio playback):

drwav wav;
if (drwav_init_file(&wav, "sound.wav", NULL)) {
    drwav_int16* pSampleData = malloc(wav.totalPCMFrameCount * wav.channels * sizeof(drwav_int16));
    drwav_read_pcm_frames_s16(&wav, wav.totalPCMFrameCount, pSampleData);
    drwav_uninit(&wav);
}

This comparison highlights the different focus areas of the two libraries, with Nuklear specializing in GUI creation and dr_libs offering a broader range of audio-related functionalities.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Public domain, single file audio decoding libraries for C and C++.

discord

All development of released libraries happens on the master branch. There may exist some decoder-specific branches for work in progress. Check tags for the latest version of a particular library.

LibraryDescription
dr_flacFLAC audio decoder.
dr_mp3MP3 audio decoder. Based off minimp3.
dr_wavWAV audio loader and writer.

Other Libraries

Below are some of my other libraries you may be interested in.

LibraryDescription
miniaudioA public domain, single file library for audio playback and recording.