tta: move code that will be shared with encoder to separate file