Browse Source

audio engine..

tmp1
heck 2 years ago
parent
commit
c0a861dbe1
  1. 24
      src/cppmain.cc
  2. 2
      src/cppmain.h
  3. 4
      src/init.c

24
src/cppmain.cc

@ -9,7 +9,7 @@
#include <sstream>
#include <iomanip>
#define SAMPLE_FREQ 44200
#define SAMPLE_FREQ 42000
#define SAMPLE_MAX 4096
#define BUFFER_SIZE 256
#define BLOCK_SIZE 128
@ -25,8 +25,6 @@ static volatile bool process_block2{ true };
// time
static u64 inf_phasor{ 0 };
// misc
static volatile int freq = 100;
namespace Heck {
bool debug_suspend_active = false;
@ -69,7 +67,6 @@ namespace Heck {
void irq1_cb()
{
debug_suspend_continue();
freq += 10;
}
void timer3_cb()
@ -159,16 +156,27 @@ namespace Heck {
}
u32 saw(u64 t, float freq_hz)
{
u32 ret{ 0 };
u32 samps = hz_to_samps(freq_hz);
u32 normalizing_factor = SAMPLE_MAX / samps;
ret = t % samps;
ret *= normalizing_factor;
return ret;
}
void calculate_audio()
{
// log("calculate_audio time: ");
u32 *b = block;
u64 t = inf_phasor;
u32 samps = hz_to_samps(freq);
u32 val{ 0 };
for (int i = 0; i < BLOCK_SIZE; i++) {
val = t % samps;
b[i] = val * 8;
b[i] = saw(t, 80);
// b[i] *= saw(t, 20);
t++;
}
}

2
src/cppmain.h

@ -30,6 +30,8 @@ extern "C" {
#include <cstdint>
#include <string>
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;

4
src/init.c

@ -171,7 +171,7 @@ void dac_init(void)
htim_dac1.Instance = TIM2;
htim_dac1.Init.Prescaler = 0;
htim_dac1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim_dac1.Init.Period = 2000;// * 10000;
htim_dac1.Init.Period = 2000;// *100;
htim_dac1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim_dac1) != HAL_OK) {
Error_Handler();
@ -325,6 +325,6 @@ void heck_init()
// heck_debug_suspend();
blinky_led_init();
dac_init();
adc_init();
// adc_init();
rng_init();
}

Loading…
Cancel
Save