musicmouse/espmusicmouse/host_driver/effect_debug.ipynb

241 lines
16 KiB
Plaintext
Raw Normal View History

2023-01-03 20:49:14 +01:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"id": "b5d8a856-d466-4102-8bfc-2a9014ab0767",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import importlib.util\n",
"from ipywidgets import interactive\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c4fc1c81-3f08-4cd8-bb38-3566b033318a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 11,
"id": "39d0f384-6533-41e0-8093-b1b2a9d59608",
"metadata": {},
"outputs": [],
"source": [
"def load_test(path):\n",
" spec = importlib.util.spec_from_file_location(\"test\", path)\n",
" module = importlib.util.module_from_spec(spec)\n",
" spec.loader.exec_module(module)\n",
" for sym in ['r', 'g', 'b', 'h', 's', 'v']:\n",
" a = np.array(getattr(module, sym))\n",
" setattr(module, sym, a)\n",
" return module\n",
"\n",
"path = \"/home/martin/code/musicmouse/espmusicmouse/.pio/build/native/swipe.py\"\n",
"path = \"/home/martin/code/musicmouse/espmusicmouse/.pio/build/native/reverse_swipe.py\"\n",
"res = load_test(path)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "bb3bc44d-2523-43d5-87eb-2cded8d0d8c2",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "09617018b02c449d912ef07757fcc8c6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(IntSlider(value=99, description='t', max=199), Output(layout=Layout(height='350px'))), _…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def plot_v(t):\n",
" plt.figure(2)\n",
" plt.ylim(-0.1, 1.1) \n",
" plt.plot(res.v[t], label=f\"v at {t}\")\n",
" plt.legend()\n",
" plt.show()\n",
"\n",
"interactive_plot = interactive(plot_v, t=(0, len(res.v)-1))\n",
"output = interactive_plot.children[-1]\n",
"output.layout.height = '350px'\n",
"interactive_plot"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "2ef27efb-b021-42b7-8cb5-c84add88ab17",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2,\n",
" 2, 1, 1, 1, 1, 1, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 1])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res.r[70]"
]
},
{
"cell_type": "markdown",
"id": "817d4771-f210-48e9-a342-0b0d238d0e11",
"metadata": {},
"source": [
"## Bell Curve"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "763b5ffe-4224-4dec-a147-40be2aaa0d41",
"metadata": {},
"outputs": [],
"source": [
"def bell_curve_approximation_old(x, inverse_width):\n",
" if x < 0:\n",
" x = -x\n",
" \n",
" nx = x * inverse_width * 4\n",
" if nx > 2:\n",
" return 0\n",
" \n",
" x2 = nx * nx\n",
" x3 = x2 * nx\n",
" res = 1 + 0.2760695894 * x3 - 0.8021391 * x2\n",
" \n",
" return res if res > 0 else 0\n",
"\n",
"\n",
"def bell_curve_approximation(x, inverse_width): \n",
" nx = x * inverse_width * 4\n",
" x2 = nx * nx\n",
" x3 = x2 * nx\n",
" res = 1 + 0.2760695894 * x3 - 0.8021391 * x2\n",
" \n",
" return res if res > 0 else 0\n",
"\n",
"# // Function start at 0 (x=0) and goes smoothly up to 1 and arrives 1 at x=width\n",
"# // inverse width has to be 1 / width (should be cached outside)\n",
"def step_function(x, width, inverse_width):\n",
" if x < 0:\n",
" return 0\n",
" if x >= width:\n",
" return 1\n",
" bell_inv_width = inverse_width * 0.5\n",
" nx = (-x + width) * bell_inv_width * 4\n",
" x2 = nx * nx\n",
" x3 = x2 * nx\n",
" res = 1 + 0.2760695894 * x3 - 0.8021391 * x2\n",
" return res"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "be193428-3fec-4a2f-9903-4dbfa4ad19e3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 15,
"id": "de8b9ee1-6232-4cab-8a1a-b62ec723b4f4",
"metadata": {},
"outputs": [],
"source": [
"x = np.linspace(-1, 10, 20)\n",
"y = np.array([step_function(x_i, 8, 1 / 8) for x_i in x])"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "db9bddcc-ae89-462c-b8f4-56384a36a1df",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7fa511346af0>]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAeS0lEQVR4nO3deXhU9dnG8e+TjRB2CIgQAgiIIgKBCKhttWpbXLF1AURerQhu4Nb6Vm3V1i6vS2tdilpcqiKruICKUrW4KxBC2EXClgRQwhK2ELI97x8ZbUSQCBNOZub+XBdX5pw5zNwDyc3hd875HXN3REQk8sUFHUBERMJDhS4iEiVU6CIiUUKFLiISJVToIiJRIiGoN05NTfUOHToE9fYiIhFp3rx5m9y95b6eC6zQO3ToQFZWVlBvLyISkcxs7f6e05CLiEiUUKGLiEQJFbqISJRQoYuIRAkVuohIlDhgoZvZ02a20cwW7+d5M7OHzSzXzBaaWe/wxxQRkQOpyR76M8CA73j+TKBL6NdI4LFDjyUiIt/XAc9Dd/f3zazDd2wyEHjOq+bh/dTMmprZke6+IVwhRSR27CmvYEdJOdt3l7GjpLzqcUkZO0r+uxzp036ffuwR9GzX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0HJH9qskeel8g191XuXspMAkYuNc2I4Ax7r4VwN03hjemSDAqKp0bJuVQWl7JI0MydLMKqdNqUuhtgfxqywWhddUdDRxtZh+Z2admNmBfL2RmI80sy8yyCgsLDy6xyGH0yH9WMGf1Fu4e2J2jWup8c6nbwnWYPgHoApwKDAGeMLOme2/k7mPdPdPdM1u2bBm
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(x, y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad451aa5-8645-4432-a0e8-821eb4826f19",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}