Skip to content

Instantly share code, notes, and snippets.

@alexsarmiento
Last active September 13, 2023 15:23
Show Gist options
  • Save alexsarmiento/d1c8f8a86eac0be551eb878b3a332811 to your computer and use it in GitHub Desktop.
Save alexsarmiento/d1c8f8a86eac0be551eb878b3a332811 to your computer and use it in GitHub Desktop.
Python script to convert generic REW eq files to pipewire native filters.
#!/usr/bin/env python
import json
from pprint import pp
import argparse
import re
parser = argparse.ArgumentParser(
description="Convert REW Generic EQ file to Pipewire configuration file."
)
parser.add_argument("input", help="Generic EQ .txt file from REW.")
args = parser.parse_args()
with open(args.input, "r") as f:
data = [l.rstrip("\n") for l in f.readlines()]
def get_val(word,mlist):
try:
return mlist[mlist.index(word)+1]
except ValueError:
return False
eq_nodes = []
fildic = {'LS':'bq_lowshelf','HS':'bq_highshelf','PK':'bq_peaking','LSQ':'bq_lowshelf','HSQ':'bq_highshelf','LPQ':'bq_lowpass','HPQ':'bq_highpass'}
i = 0
# generate node graphs
for line in data:
e = list(filter(None,re.split(" ", line)))
if ("Filter" in line) and ("ON" in line):
i = i + 1
fc = get_val("Fc",e)
gain = get_val("Gain",e)
ft = get_val("ON",e)
q = get_val("Q",e)
node_dic = {'type':'builtin','name':'eq_band_'+str(i),'label':fildic[ft]}
eq_control = {'Freq':int(fc)}
eq_control['Q'] = float(q)
eq_control['Gain'] = float(gain)
node_dic['control'] = eq_control
eq_nodes.append(node_dic)
elif ("Preamp:" in line):
preamp = float(get_val("Preamp:",e))
node_dic = {'type':'builtin','name':'pre_gain','label':'bq_highshelf'}
eq_control = {'Freq':0,'Q':1.0,'Gain':preamp}
node_dic['control'] = eq_control
eq_nodes.append(node_dic)
# generate node links
node_links = []
i=0
while i < len(eq_nodes)-1:
d = {}
d['output'] = eq_nodes[i]['name']+':Out'
d['input'] = eq_nodes[i+1]['name']+':In'
node_links.append(d)
i = i +1
#
filter_graph = {'nodes':eq_nodes,'links':node_links}
args = {
'node.description': 'EqualizerSink',
'media.name': 'EqualizerSink',
'filter.graph':filter_graph,
'audio.channles': 2,
'audio.position':['FL','FR'],
'capture.props':{'node.name':'effect_input.EQ','media.class':'Audio/Sink'},
'playback.props':{'node.name':'effect_output.EQ','node.passive':False}
}
context_modules = [{'name':'libpipewire-module-filter-chain','args':args}]
pw_conf = {'context.modules':context_modules}
print(json.dumps(pw_conf,indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment