Skip to content

Instantly share code, notes, and snippets.

@jrmoserbaltimore
jrmoserbaltimore / mycore.py
Last active March 12, 2024 05:29
MiSTer core template rewrite in Python with Amaranth (boredom) (FSM version)
from amaranth import *
from amaranth.lib.coding import *
from numpy import log2, ceil
# FIXME: New Amaranth release indicates we should be deriving from Component, not
# Elaboratable
class MyCore(Elaboratable):
def __init__(self):
self.clock = Signal(1)
@jrmoserbaltimore
jrmoserbaltimore / pipe.py
Last active January 29, 2024 02:59
pipeline for Amaranth
with FSM():
with m.State("Begin"):
with m.If(self.strobe):
m.next = "Process"
with m.State("Process"):
# Automatically create pipe.mult, pipe.shift
with m.Pipeline([self.mult, self.shift]) as pipe:
with pipe.Stage():
# manually set up pipe.xor
@jrmoserbaltimore
jrmoserbaltimore / dsvf.py
Created January 21, 2023 20:46
Attempt at Chamberlin DSVF
# Python 3.10 required
import numpy as np
from numpy import pi, sin, tan
from typing import Optional
import matplotlib.pyplot as plt
import scipy.fft as fft
class FilterModes:
DSVF_CHAMBERLIN = 'Chamberlin'
DSVF_LAZZARINI_TIMONEY = 'Lazzarini-Timoney'
@jrmoserbaltimore
jrmoserbaltimore / cordic-test.sv
Created January 16, 2022 21:55
CORDIC slows as pipeline grows
`default_nettype uwire
interface ICORDIC
#(
parameter width=40 // 48 max
)
(
wire logic [width-1:0] x,
wire logic [width-1:0] y,
wire logic [width-1:0] z,
@jrmoserbaltimore
jrmoserbaltimore / 6-op.md
Created June 20, 2021 06:28
6-op circuit
             +----------------------------------------------+
             |                                         /|   |
             |             +------------------------->| |   |
             |    +----+   |     /|            +----->| |---+
             +--->|    |   |    | |--->Acc1    | +--->| |
                  |Op 1|---+--->| |--->Acc2    | |     \|
                  +----+   |    | |--->Acc3    | |
               +-----------+     \|            | |
               |                               | |

| +-------------------+ |

@jrmoserbaltimore
jrmoserbaltimore / fm-step-by-step.md
Last active April 20, 2024 02:42
Step-by-step FM synthesis explanation

An attempt to explain step-by-step how FM synthesis calculation works.

OPL3

Using the OPL3 as an example, there are several components:

  • Vibrato feeds into the phase generator (PG) to modulate its frequency
  • Tremolo feeds into the envelope generator (EG) to modulate its amplitude
  • PG and EG feed into the operator
  • Operator outputs to the next operator
@jrmoserbaltimore
jrmoserbaltimore / arXiv-social-choice.md
Created May 31, 2021 18:01
Social choice theory papers on arXiv

These papers cover social choice, public choice, and voting theory. See the Handbook of Social Choice and Voting by Heckelman and Miller; or Collective Decisions and Voting by Nicolaus Tideman.

Voting rules and analysis

These are analyses of voting rules or other theoretical analysis independent of political conditions. This stretches as far as analyzing how and when voters behave strategically under particular systems, although that's more blurry.

Ordered preferences X≻A → if X is not a candidate, voter votes for A

14: Alex≻Bobbie≻Chris≻Dane  \
12: Bobbie≻Alex≻Chris≻Dane   | ← 51% majority, doesn't count.
25: Chris≻Bobbie≻Alex≻Dane  /
49: Dane≻Chris≻Bobbie≻Alex  ← Most votes, wins plurality

Instant runoff voting:

// Not valid
namespace Boilerplate
{
public boilerplate BCompareOperators<T>
{
bool operator >(T lhs, T rhs) => lhs.CompareTo(rhs) > 0;
bool operator <(T lhs, T rhs) => lhs.CompareTo(rhs) < 0;
bool operator >=(T lhs, T rhs) => lhs.CompareTo(rhs) >= 0;
bool operator <=(T lhs, T rhs) => lhs.CompareTo(rhs) <= 0;
protected virtual void OrderVotes()
{
int priorValue = 0;
Votes.Sort();
/* One vote, always rank 1 */
if (Votes.Count >= 1 && Votes[0].Value != 1)
{
priorValue = Votes[0].Value;
Votes[0] = new Vote(Votes[0].Candidate, 1);
}