jakebesworth / Simple Sdl2 Audio
A simple SDL2 audio library without SDL_Mixer for playing music and multiple sounds natively in SDL2
Stars: β 111
Programming Languages
c
50402 projects - #5 most used programming language
Projects that are alternatives of or similar to Simple Sdl2 Audio
Blipkit
C library for creating the beautiful sound of old sound chips
Stars: β 23 (-79.28%)
Mutual labels: sdl, audio, music, sound
Matchering
ποΈ Open Source Audio Matching and Mastering
Stars: β 398 (+258.56%)
Mutual labels: audio, music, sound
Dx7 Supercollider
My accurate Yamaha DX-7 clone. Programmed in Supercollider.
Stars: β 395 (+255.86%)
Mutual labels: audio, music, sound
Webaudiofont
Use full GM set of musical instruments to play MIDI and single sounds or effects. Support for reverberation and equaliser. No plugins, no Flash. Pure HTML5 implementation compatible with desktop and mobile browser. See live examples.
Stars: β 600 (+440.54%)
Mutual labels: audio, music, sound
Supercollider
An audio server, programming language, and IDE for sound synthesis and algorithmic composition.
Stars: β 4,036 (+3536.04%)
Mutual labels: audio, music, sound
Supercolliderjs
The JavaScript client library for SuperCollider
Stars: β 381 (+243.24%)
Mutual labels: audio, music, sound
Romplayer
AudioKit Sample Player (ROM Player) - EXS24, Sound Font, Wave Player
Stars: β 445 (+300.9%)
Mutual labels: audio, music, sound
Swift Radio Pro
Professional Radio Station App for iOS!
Stars: β 2,644 (+2281.98%)
Mutual labels: audio, music, sound
Awesome Music Production
A curated list of software, services and resources to create and distribute music.
Stars: β 340 (+206.31%)
Mutual labels: audio, music, sound
Minibae
The platform-neutral Beatnik Audio Engine, Mini Edition (miniBAE) is an exceptionally mature, well-rounded, and reliable computer music and sound system specially customized for small-footprint and embedded applications.
Stars: β 82 (-26.13%)
Mutual labels: audio, music, sound
Daisysp
A Powerful, Open Source DSP Library in C++
Stars: β 291 (+162.16%)
Mutual labels: audio, music, sound
Beats
A command-line drum machine. Convert a beat notated in YAML into a *.wav file.
Stars: β 389 (+250.45%)
Mutual labels: audio, music, sound
Godot Mixing Desk
A complete audio solution for Godot 3.2.x, making procedural sound and adaptive/procedural music possible with a few nodes and a couple lines of code.
Stars: β 240 (+116.22%)
Mutual labels: audio, music, sound
Audiomentations
A Python library for audio data augmentation. Inspired by albumentations. Useful for machine learning.
Stars: β 439 (+295.5%)
Mutual labels: audio, music, sound
Mimium
mimium (MInimal Musical medIUM) a programming language as an infrastructure for sound and music.
Stars: β 212 (+90.99%)
Mutual labels: audio, music, sound
Gwion
π΅ strongly-timed musical programming language
Stars: β 235 (+111.71%)
Mutual labels: audio, music, sound
Minimp3
Minimalistic MP3 decoder single header library
Stars: β 898 (+709.01%)
Mutual labels: audio, music, sound
Pandoraplayer
π
ΏοΈ PandoraPlayer is a lightweight music player for iOS, based on AudioKit and completely written in Swift.
Stars: β 1,037 (+834.23%)
Mutual labels: audio, music, sound
Simple SDL2 Audio
About
- A simple native SDL2 Audio library that has 2 files, and an easy to use interface.
- This library works without SDL2 Mixer, and plays a single music file at a time, and unlimited sounds (Mixes audio natively without Mixer)
Install
- Include
src/audio.c
andsrc/audio.h
in your project
Examples
-
src/test.c
shows all the functionality possible:
Basic use case:
// Initialize SDL2 Audio only
SDL_Init(SDL_INIT_AUDIO);
// Initialize Simple-SDL2-Audio
initAudio();
// Play music and a sound
playMusic("music/highlands.wav", SDL_MIX_MAXVOLUME);
playSound("sounds/door1.wav", SDL_MIX_MAXVOLUME / 2);
// Let play for 1 second
SDL_Delay(1000);
// End Simple-SDL2-Audio
endAudio();
// End SDL2
SDL_Quit();
API Functions:
// Initialize Simple-SDL2-Audio on default audio device
void initAudio(void);
// Play many Sounds or single Musics
void playSound(const char * filename, int volume);
void playMusic(const char * filename, int volume);
// Clean up Simple-SDL2-Audio
void endAudio(void);
// Pause or Unpause running audio
void pauseAudio(void);
void unpauseAudio(void);
// Advanced functions used for caching WAV files in memory, create, play many times, free
Audio * createAudio(const char * filename, uint8_t loop, int volume);
void playSoundFromMemory(Audio * audio, int volume);
void playMusicFromMemory(Audio * audio, int volume);
void freeAudio(Audio * audio);
Difference between Music vs Sound
-
Only one music can play at a time, and it loops (to close music you can just run
endAudio()
, or usepauseAudio()
andunpauseAudio()
).- If you add another music when one is playing, the first one fades out before ending, and then playing the second.
- If you play more than 2 music at once, the first fades as expected, only the last music queued before the first fade out is used
-
Any number of sounds can be played at once, but obviously the more, can become distorted
- Can change
AUDIO_MAX_SOUNDS
insrc/audio.c
to limit how many sounds can be played at once to reduce distortion from too many playing
- Can change
Caveats
- This implementation uses SDL_MixAudioFormat for mixing for simplicity. It's noted "Do not use this function for mixing together more than two streams of sample data". While only playing 1 music removes a lot of these issues, if you need something more powerful you should write your own mixing function.
- This implementation ONLY plays WAV files, and they should all be the same format, but can have differing formats if you play around with
SDL_AUDIO_ALLOW_CHANGES
insrc/audio.c
, see the top ofsrc/audio.c
to set the format, stereo vs mono etc... No conversion - Caching: Using the standard
playMusic()
functions makes a disk read each call. To only make one disk read, cache, and play the audio from memory, use thecreateAudio(); playSoundFromMemory(); freeAudio();
functions (recommend storing the Audio* object in a dictionary / hashmap)
Features to add
- Pause / unpause only music, only sound or
both - Current implementation uses callback method, however in SDL 2.0.4 there exists
SDL_QueueAudio()
(no callback) - For gSoundCount check for duplicate sounds
Windows 7 Compatability
SDL2.0.6 updated how audio was handled, for Windows 7 using a later release of SDL2, you need to set #define SDL_AUDIO_ALLOW_CHANGES SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_CHANNELS_CHANGE
which is a flag near the top of the file.
Emscripten Compatibility
Resources
- I made this project as a more modern version of https://gist.github.com/armornick/3447121
- https://davidgow.net/handmadepenguin/ch7.html
- http://rerwarwar.weebly.com/sdl2-audio.html
Contributors
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].