Skip to content

Instantly share code, notes, and snippets.

View Kolcha's full-sized avatar
😢
very sad

Nick Korotysh Kolcha

😢
very sad
View GitHub Profile
// color1 and color2 are R4G4B4 12bit RGB color values, alpha is 0-255
uint16_t blend_12bit( uint16_t color1, uint16_t color2, uint8_t alpha ) {
uint64_t c1 = (uint64_t) color1;
uint64_t c2 = (uint64_t) color2;
uint64_t a = (uint64_t)( alpha >> 4 );
// bit magic to alpha blend R G B with single mul
c1 = ( c1 | ( c1 << 12 ) ) & 0x0f0f0f;
c2 = ( c2 | ( c2 << 12 ) ) & 0x0f0f0f;
uint32_t o = ( ( ( ( c2 - c1 ) * a ) >> 4 ) + c1 ) & 0x0f0f0f;
@mattiasgustavsson
mattiasgustavsson / bass_and_treble.h
Created January 30, 2025 13:06
Audio filters for a stereo widening effect and for simple bass/treble eq
/*
------------------------------------------------------------------------------
Licensing information can be found at the end of the file.
------------------------------------------------------------------------------
bass_and_treble.h - v1.0 - Simple audio filter to boost bass and treble.
Do this:
#define BASS_AND_TREBLE_IMPLEMENTATION
before you include this file in *one* C/C++ file to create the implementation.