Skip to content

Instantly share code, notes, and snippets.

@LukeGary462
Created October 25, 2022 02:10
Show Gist options
  • Select an option

  • Save LukeGary462/52ab47b842e2f1d149e218db4ef6765b to your computer and use it in GitHub Desktop.

Select an option

Save LukeGary462/52ab47b842e2f1d149e218db4ef6765b to your computer and use it in GitHub Desktop.
normalize adc codes for general audio processing. quick 'n dirty
// https://paiza.io/projects/OrgoRimpHHbdu59tfAsmoQ
#include <stdint.h>
#include <stdio.h>
#define ADC_MAX_CODE (0x0FFFu)
static float convert_to_normalized(uint16_t sample);
static float convert_to_normalized(uint16_t sample)
{
return (((2.0f)/(float)ADC_MAX_CODE) * (float)sample) - 1.0f;
}
int main(void){
printf("min - %f\n", convert_to_normalized(0));
printf("mid - %f\n", convert_to_normalized((ADC_MAX_CODE/2)));
printf("max - %f\n", convert_to_normalized(ADC_MAX_CODE));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment