Created
October 25, 2022 02:10
-
-
Save LukeGary462/52ab47b842e2f1d149e218db4ef6765b to your computer and use it in GitHub Desktop.
normalize adc codes for general audio processing. quick 'n dirty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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