Created
March 20, 2024 21:31
-
-
Save saaj/533a974683106faed746176ae2ceb8d6 to your computer and use it in GitHub Desktop.
Update Pulseeffects output preset JSON from AutoEq txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"source": [ | |
"eq = '''\n", | |
"Preamp: -6.81 dB\n", | |
"Filter 1: ON LSC Fc 105.0 Hz Gain -9.2 dB Q 0.70\n", | |
"Filter 2: ON PK Fc 24.4 Hz Gain -2.2 dB Q 1.56\n", | |
"Filter 3: ON PK Fc 36.9 Hz Gain -1.9 dB Q 2.47\n", | |
"Filter 4: ON PK Fc 121.2 Hz Gain 0.6 dB Q 2.62\n", | |
"Filter 5: ON PK Fc 148.0 Hz Gain -3.8 dB Q 1.52\n", | |
"Filter 6: ON PK Fc 306.4 Hz Gain -2.2 dB Q 2.58\n", | |
"Filter 7: ON PK Fc 1769.9 Hz Gain 2.0 dB Q 2.08\n", | |
"Filter 8: ON PK Fc 2442.2 Hz Gain 6.0 dB Q 2.39\n", | |
"Filter 9: ON PK Fc 9948.0 Hz Gain 1.4 dB Q 3.07\n", | |
"Filter 10: ON HSC Fc 10000.0 Hz Gain 5.2 dB Q 0.70\n", | |
"'''" | |
], | |
"outputs": [], | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false, | |
"outputHidden": false, | |
"inputHidden": false | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"config_file = '~/.config/PulseEffects/output/MOMENTUM4.json'" | |
], | |
"outputs": [], | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false, | |
"outputHidden": false, | |
"inputHidden": false | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"from collections import namedtuple\n", | |
"from decimal import Decimal\n", | |
"\n", | |
"# Filter 2: ON PK Fc 64.8 Hz Gain 4.0 dB Q 1.10\n", | |
"Band = namedtuple('Band', ['type', 'frequency', 'gain', 'q'])\n", | |
"\n", | |
"def parse_eq(s):\n", | |
" preamp_line, *filter_lines = s.strip().splitlines()\n", | |
" bands = []\n", | |
" for filter_line in filter_lines:\n", | |
" parts = filter_line.split()\n", | |
" bands.append(\n", | |
" Band(parts[3], Decimal(parts[5]), Decimal(parts[8]), Decimal(parts[11]))\n", | |
" ) \n", | |
" return Decimal(preamp_line.split()[1]), bands" | |
], | |
"outputs": [], | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false, | |
"outputHidden": false, | |
"inputHidden": true | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"equalizer_tpl = {\n", | |
" 'state': 'true',\n", | |
" 'mode': 'IIR',\n", | |
" 'num-bands': '10',\n", | |
" 'input-gain': '0',\n", | |
" 'output-gain': '0',\n", | |
" 'split-channels': 'false',\n", | |
" 'left': {},\n", | |
" 'right': {},\n", | |
"}\n", | |
"band_tpl = {\n", | |
" 'type': 'Bell',\n", | |
" 'mode': 'RLC (BT)',\n", | |
" 'slope': 'x1',\n", | |
" 'solo': 'false',\n", | |
" 'mute': 'false',\n", | |
" 'gain': '-3',\n", | |
" 'frequency': '98',\n", | |
" 'q': '1',\n", | |
"}\n", | |
"preamp, bands = parse_eq(eq)\n", | |
"\n", | |
"equalizer = equalizer_tpl.copy()\n", | |
"equalizer['num-bands'] = str(len(bands))\n", | |
"equalizer['input-gain'] = str(preamp)\n", | |
"for i, band in enumerate(bands):\n", | |
" equalizer['left'][f'band{i}'] = equalizer['right'][f'band{i}'] = {\n", | |
" **band_tpl,\n", | |
" 'type': {'LSC': 'Lo-shelf', 'HSC': 'Hi-shelf', 'PK': 'Bell'}.get(band.type),\n", | |
" 'frequency': str(band.frequency),\n", | |
" 'gain': str(band.gain),\n", | |
" 'q': str(band.q), \n", | |
" }" | |
], | |
"outputs": [], | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false, | |
"outputHidden": false, | |
"inputHidden": true | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"from IPython.display import JSON\n", | |
"\n", | |
"JSON(equalizer)" | |
], | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 5, | |
"data": { | |
"text/plain": [ | |
"<IPython.core.display.JSON object>" | |
], | |
"application/json": { | |
"state": "true", | |
"mode": "IIR", | |
"num-bands": "10", | |
"input-gain": "-6.81", | |
"output-gain": "0", | |
"split-channels": "false", | |
"left": { | |
"band0": { | |
"type": "Lo-shelf", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "-9.2", | |
"frequency": "105.0", | |
"q": "0.70" | |
}, | |
"band1": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "-2.2", | |
"frequency": "24.4", | |
"q": "1.56" | |
}, | |
"band2": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "-1.9", | |
"frequency": "36.9", | |
"q": "2.47" | |
}, | |
"band3": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "0.6", | |
"frequency": "121.2", | |
"q": "2.62" | |
}, | |
"band4": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "-3.8", | |
"frequency": "148.0", | |
"q": "1.52" | |
}, | |
"band5": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "-2.2", | |
"frequency": "306.4", | |
"q": "2.58" | |
}, | |
"band6": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "2.0", | |
"frequency": "1769.9", | |
"q": "2.08" | |
}, | |
"band7": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "6.0", | |
"frequency": "2442.2", | |
"q": "2.39" | |
}, | |
"band8": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "1.4", | |
"frequency": "9948.0", | |
"q": "3.07" | |
}, | |
"band9": { | |
"type": "Hi-shelf", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "5.2", | |
"frequency": "10000.0", | |
"q": "0.70" | |
} | |
}, | |
"right": { | |
"band0": { | |
"type": "Lo-shelf", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "-9.2", | |
"frequency": "105.0", | |
"q": "0.70" | |
}, | |
"band1": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "-2.2", | |
"frequency": "24.4", | |
"q": "1.56" | |
}, | |
"band2": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "-1.9", | |
"frequency": "36.9", | |
"q": "2.47" | |
}, | |
"band3": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "0.6", | |
"frequency": "121.2", | |
"q": "2.62" | |
}, | |
"band4": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "-3.8", | |
"frequency": "148.0", | |
"q": "1.52" | |
}, | |
"band5": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "-2.2", | |
"frequency": "306.4", | |
"q": "2.58" | |
}, | |
"band6": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "2.0", | |
"frequency": "1769.9", | |
"q": "2.08" | |
}, | |
"band7": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "6.0", | |
"frequency": "2442.2", | |
"q": "2.39" | |
}, | |
"band8": { | |
"type": "Bell", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "1.4", | |
"frequency": "9948.0", | |
"q": "3.07" | |
}, | |
"band9": { | |
"type": "Hi-shelf", | |
"mode": "RLC (BT)", | |
"slope": "x1", | |
"solo": "false", | |
"mute": "false", | |
"gain": "5.2", | |
"frequency": "10000.0", | |
"q": "0.70" | |
} | |
} | |
} | |
}, | |
"metadata": { | |
"application/json": { | |
"expanded": false, | |
"root": "root" | |
} | |
} | |
} | |
], | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false, | |
"outputHidden": false, | |
"inputHidden": true | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import json\n", | |
"import os.path\n", | |
"\n", | |
"with open(os.path.expanduser(config_file), 'r+') as f:\n", | |
" pulseeffect_config = json.load(f)\n", | |
" pulseeffect_config['output']['equalizer'] = equalizer\n", | |
" \n", | |
" f.seek(0)\n", | |
" f.truncate()\n", | |
" json.dump(pulseeffect_config, f, indent=4)\n", | |
"print('OK')" | |
], | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"OK\n" | |
] | |
} | |
], | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false, | |
"outputHidden": false, | |
"inputHidden": true | |
} | |
} | |
], | |
"metadata": { | |
"kernel_info": { | |
"name": "python3" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.8.10", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"language": "python", | |
"display_name": "Python 3" | |
}, | |
"nteract": { | |
"version": "0.14.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment