1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #include <stdio.h>
- #include <stdint.h>
- #include <math.h>
- #include "esp_log.h"
- #include "freertos/FreeRTOS.h"
- #include "sdkconfig.h"
- #define LUT_SIZE 256
- #define DAC_MAX 64
- static float delta_phi, delta_phi_1, delta_phi_2;
- static float phase = 0;
- static uint8_t phase_i = 0;
- static DRAM_ATTR int8_t LUT[LUT_SIZE];
- static uint8_t IRAM_ATTR afsk_get_phase(uint8_t tone)
- {
- if ( tone )
- delta_phi = delta_phi_1;
- else
- delta_phi = delta_phi_2;
- phase_i = (uint8_t)phase;
- phase += delta_phi;
- if (phase >= (float)LUT_SIZE)
- phase -= (float)LUT_SIZE;
- return phase_i;
- }
- void afsk_mod_init(uint32_t sample_rate, uint32_t freq0, uint32_t freq1)
- {
-
- delta_phi_1 = (float) freq0 / sample_rate * LUT_SIZE;
- delta_phi_2 = (float) freq1 / sample_rate * LUT_SIZE;
-
- uint32_t i=0;
- for (i=0; i<LUT_SIZE; ++i)
- {
- LUT[i] = (int8_t)roundf(DAC_MAX * sinf(2.0f * M_PI * (float)i / LUT_SIZE));
- }
- }
- int8_t IRAM_ATTR afsk_get_amplitude(uint8_t tone)
- {
- return LUT[afsk_get_phase(tone)];
- }
|