Skip to content

Instantly share code, notes, and snippets.

View dlandahl's full-sized avatar

dlandahl

  • Sony Interactive Entertainment
  • England
View GitHub Profile
@dlandahl
dlandahl / avx_sine.c
Last active October 12, 2021 11:06
Fast lookup table based oscillator using AVX2 Gather
#if AVX2_ENABLED
__m256 read_vector(__m256 phase) {
phase = _mm256_mul_ps(phase, _mm256_set1_ps(TABLE_SIZE));
__m256i a = _mm256_cvtps_epi32(_mm256_floor_ps(phase));
__m256i b = _mm256_cvtps_epi32(_mm256_floor_ps(_mm256_add_ps(phase, _mm256_set1_ps(1))));
__m256 t = _mm256_sub_ps(phase, _mm256_cvtepi32_ps(a));
__m256 lower = _mm256_i32gather_ps(sin_table, a, 4);
__m256 upper = _mm256_i32gather_ps(sin_table, b, 4);
(setq byte-compile-warnings '(cl-functions))
(require 'package)
;; Any add to list for package-archives (to add marmalade or melpa) goes here
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(set-frame-font "Fira Mono-11" nil t)
(setq inhibit-startup-screen t
@dlandahl
dlandahl / Delightful_ASM.cc
Last active January 16, 2021 18:05
Interpreting the RISC instruction set from H.S. Warren Jr.'s book "Hacker's Delight"
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <iostream>
namespace DASM {
using u64 = uint64_t;
@dlandahl
dlandahl / ALSA_Sine.cc
Created February 7, 2020 22:38
Generate tone with alsa
#include <cmath>
#include <random>
#include <iostream>
#include "alsa/asoundlib.h"
unsigned const size = 1024;
unsigned const rate = 44100;
float const circle = 6.28318530;
#include <math.h>
#include <iostream>
#include "SDL2/SDL.h"
uint16_t const screen_width = 48 * 5;
uint16_t const screen_height = 32 * 5;
float const circle = 6.28318530;
template <typename T> struct vec2
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dlandahl
dlandahl / wind.py
Created December 10, 2018 20:31
Python sound synthesis
import random, pyaudio
from math import sin, cos, pi
from array import array
p = pyaudio.PyAudio()
τ = 2 * pi
SAMPLE_RATE = 44100
LEN = SAMPLE_RATE * 4
@dlandahl
dlandahl / dsound_tone.cpp
Last active December 10, 2018 20:34
Making sound with DirectSound
#include <cmath>
#include <iostream>
#include <string>
#include "dsound.h"
#include "mmreg.h"
#include "cguid.h"
HWND get_console_window();
void hresult_log(HRESULT, std::string);
@dlandahl
dlandahl / repeat_string.cpp
Created November 4, 2018 23:19
Repeat a string with multiplication operator
#include <iostream>
#include <string>
std::string operator*(std::string lhs, int rhs)
{
std::string instance = lhs;
for (unsigned n = 1; n < abs(rhs); n++)
lhs.append(instance);