Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bwhitman/amy
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhitman committed Jun 14, 2024
2 parents fd6d305 + 05550c0 commit 1438dbd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
13 changes: 13 additions & 0 deletions amy.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ def preset(which,osc=0, **kwargs):
send(wave=ALGO, patch=62, filter_freq="125,0,0,4", resonance=2.5, filter_type=FILTER_LPF, bp0="1,1,500,0,0,0")


# Return a millis() epoch number for use in AMY timing
# On most computers, this uses ms since midnight using datetime
# On things like Tulip, this use ms since boot
def millis():
try:
import datetime
d = datetime.datetime.now()
return int((datetime.datetime.utcnow() - datetime.datetime(d.year, d.month, d.day)).total_seconds()*1000)
except ImportError:
import tulip
return tulip.ticks_ms()


# Removes trailing 0s and x.0000s from floating point numbers to trim wire message size
# Fun historical trivia: this function caused a bug so bad that Dan had to file a week-long PR for micropython
# https://github.com/micropython/micropython/pull/8905
Expand Down
14 changes: 11 additions & 3 deletions src/amy.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,11 @@ void amy_add_event_internal(struct event e, uint16_t base_osc) {
parse_algorithm_source(&t, e.algo_source);
for(uint8_t i=0;i<MAX_ALGO_OPS;i++) {
d.param = ALGO_SOURCE_START + i;
d.data = t.algo_source[i] + base_osc;
if (AMY_IS_SET(t.algo_source[i])) {
d.data = t.algo_source[i] + base_osc;
} else{
d.data = t.algo_source[i];
}
add_delta_to_queue(d);
}
}
Expand Down Expand Up @@ -766,6 +770,9 @@ void show_debug(uint8_t type) {
fprintf(stderr,"mod osc %d: amp: %f, logfreq %f duty %f filter_logfreq %f resonance %f fb/bw %f pan %f \n", i, msynth[i].amp, msynth[i].logfreq, msynth[i].duty, msynth[i].filter_logfreq, msynth[i].resonance, msynth[i].feedback, msynth[i].pan);
}
}
if (type > 4) {
patches_debug();
}
fprintf(stderr, "\n");
}
}
Expand Down Expand Up @@ -1331,8 +1338,9 @@ int16_t * amy_fill_buffer() {
// One-pole high-pass filter to remove large low-frequency excursions from
// some FM patches. b = [1 -1]; a = [1 -0.995]
//SAMPLE new_state = fsample + SMULR6(F2S(0.995f), amy_global.hpf_state); // High-output-range, rounded MUL is critical here.
#ifdef HPF_OUTPUT
SAMPLE new_state = fsample + amy_global.hpf_state - SHIFTR(amy_global.hpf_state + (1 << 7), 8); // i.e. 0.9961*hpf_state
#ifdef AMY_HPF_OUTPUT
SAMPLE new_state = fsample + amy_global.hpf_state
- SHIFTR(amy_global.hpf_state + SHIFTR(F2S(1.0), 16), 8); // i.e. 0.9961*hpf_state
fsample = new_state - amy_global.hpf_state;
amy_global.hpf_state = new_state;
#endif
Expand Down
1 change: 1 addition & 0 deletions src/amy.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ extern void partials_note_off(uint16_t osc);
extern void patches_load_patch(struct event e);
extern void patches_event_has_voices(struct event e);
extern void patches_reset();
extern void patches_debug();
extern void patches_store_patch(char * message);

extern SAMPLE render_partials(SAMPLE *buf, uint16_t osc);
Expand Down
2 changes: 2 additions & 0 deletions src/amy_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ extern const uint16_t pcm_samples;
#define PCM_AMY_SAMPLE_RATE 22050
#define AMY_EVENT_FIFO_LEN 2400

//#define AMY_HPF_OUTPUT 1 // To remove large DC excursions from some FM voices.

//If using an ESP, tell us how to allocate ram here. Not used on other platforms.
#ifdef ESP_PLATFORM
#include <esp_heap_caps.h>
Expand Down
22 changes: 22 additions & 0 deletions src/patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ uint16_t memory_patch_oscs[MEMORY_PATCHES];
uint8_t osc_to_voice[AMY_OSCS];
uint16_t voice_to_base_osc[MAX_VOICES];

void patches_debug() {
for(uint8_t v=0;v<MAX_VOICES;v++) {
if (AMY_IS_SET(voice_to_base_osc[v]))
fprintf(stderr, "voice %d base osc %d\n", v, voice_to_base_osc[v]);
}
fprintf(stderr, "osc_to_voice:\n");
for(uint16_t i=0;i<AMY_OSCS;) {
uint16_t j = 0;
fprintf(stderr, "%d: ", i);
for (j=0; j < 16; ++j) {
if ((i + j) >= AMY_OSCS) break;
fprintf(stderr, "%d ", osc_to_voice[i + j]);
}
i += j;
fprintf(stderr, "\n");
}
for(uint8_t i=0;i<MEMORY_PATCHES;i++) {
if(memory_patch_oscs[i])
fprintf(stderr, "memory_patch %d oscs %d patch %s\n", i, memory_patch_oscs[i], memory_patch[i]);
}
}

void patches_init() {
for(uint8_t i=0;i<MEMORY_PATCHES;i++) {
memory_patch_oscs[i] = 0;
Expand Down

0 comments on commit 1438dbd

Please sign in to comment.