Jump to content

Recommended Posts

I'm using PAmpEQ with REW to EQ my car.   Importing cleaned up txt files from REW works.  I want to EQ the left and right channels independently.  I set the channels and exported the EQ. After examining the JSON I had chatgtp help generate a script to combine a left and right file from REW and generate a new JSON with the channel field set appropriately.  I'm stuck.  When I import the file the EQ selector breaks.  The search dialog shows no results, and nothing works until I clear data/cache. I tried eliminating spaces out of the name, making sure the default high and low pass filters are there, and messed with the colors some.   Not sure where I'm screwing up.  Help would be appreciated.

Sample json

[
  {
    "name": "ATest",
    "preamp": 0,
    "parametric": true,
    "bands": [
      {
        "type": 0,
        "channels": 0,
        "frequency": 90,
        "q": 0,
        "gain": 0,
        "color": 0
      },
      {
        "type": 1,
        "channels": 0,
        "frequency": 10000,
        "q": 0,
        "gain": 0,
        "color": 0
      },
      {
        "type": 2,
        "channels": 1,
        "frequency": 61.8,
        "q": 7.27,
        "gain": -6.1,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 1,
        "frequency": 64.4,
        "q": 7.376,
        "gain": 6,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 1,
        "frequency": 71.8,
        "q": 8.693,
        "gain": -4.2,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 1,
        "frequency": 94.3,
        "q": 6.725,
        "gain": -4.3,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 1,
        "frequency": 111.5,
        "q": 6.783,
        "gain": -11.1,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 1,
        "frequency": 141.5,
        "q": 5.342,
        "gain": -7.7,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 1,
        "frequency": 219,
        "q": 4.865,
        "gain": -7.6,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 1,
        "frequency": 324,
        "q": 4.998,
        "gain": -6,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 1,
        "frequency": 666,
        "q": 4.99,
        "gain": -1.1,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 1,
        "frequency": 771,
        "q": 4.989,
        "gain": -7.6,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 1,
        "frequency": 4604,
        "q": 4.999,
        "gain": -4.9,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 2,
        "frequency": 61.8,
        "q": 7.27,
        "gain": -6.1,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 2,
        "frequency": 64.4,
        "q": 7.376,
        "gain": 6,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 2,
        "frequency": 71.8,
        "q": 8.693,
        "gain": -4.2,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 2,
        "frequency": 94.3,
        "q": 6.725,
        "gain": -4.3,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 2,
        "frequency": 111.5,
        "q": 6.783,
        "gain": -11.1,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 2,
        "frequency": 141.5,
        "q": 5.342,
        "gain": -7.7,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 2,
        "frequency": 219,
        "q": 4.865,
        "gain": -7.6,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 2,
        "frequency": 324,
        "q": 4.998,
        "gain": -6,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 2,
        "frequency": 666,
        "q": 4.99,
        "gain": -1.1,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 2,
        "frequency": 771,
        "q": 4.989,
        "gain": -7.6,
        "color": -15649895
      },
      {
        "type": 2,
        "channels": 2,
        "frequency": 4604,
        "q": 4.999,
        "gain": -4.9,
        "color": -15649895
      }
    ]
  }
]

 

 

Code

const fs = require('fs');
 
// Read the left channel EQ filter export file
const leftFilePath = 'left.txt'; // Update with the actual file path for the left channel
const leftEqFilterExport = fs.readFileSync(leftFilePath, 'utf-8');
 
// Read the right channel EQ filter export file
const rightFilePath = 'right.txt'; // Update with the actual file path for the right channel
const rightEqFilterExport = fs.readFileSync(rightFilePath, 'utf-8');
 
// Parse the left channel EQ filter export and extract the filter settings
const leftFilterSettings = leftEqFilterExport.split('\n').filter(line => line.startsWith('Filter'));
const leftFilters = leftFilterSettings.map(setting => {
  const [, index, status, type, frequency, gain, q] = setting.match(/Filter\s+(\d+): (\w+)\s+([a-zA-Z]+)?(?:\s+Fc\s+([\d.]+) Hz\s+Gain\s+([\d.-]+) dB\s+Q\s+([\d.]+))?/) || [];
  if (type === 'None') return null;
  return { index: parseInt(index), status: status === 'ON', type: type || '', frequency: parseFloat(frequency || '0'), gain: parseFloat(gain || '0'), q: parseFloat(q || '0'), color: 'blue' };
}).filter(Boolean);
 
// Parse the right channel EQ filter export and extract the filter settings
const rightFilterSettings = rightEqFilterExport.split('\n').filter(line => line.startsWith('Filter'));
const rightFilters = rightFilterSettings.map(setting => {
  const [, index, status, type, frequency, gain, q] = setting.match(/Filter\s+(\d+): (\w+)\s+([a-zA-Z]+)?(?:\s+Fc\s+([\d.]+) Hz\s+Gain\s+([\d.-]+) dB\s+Q\s+([\d.]+))?/) || [];
  if (type === 'None') return null;
  return { index: parseInt(index), status: status === 'ON', type: type || '', frequency: parseFloat(frequency || '0'), gain: parseFloat(gain || '0'), q: parseFloat(q || '0'), color: 'red' };
}).filter(Boolean);
 
// Combine the left and right channel filters
const combinedFilters = [...leftFilters, ...rightFilters];
 
// Create the output object
const output = {
  name: 'ATest',
  preamp: 0.0,
  parametric: true,
  bands: []
};
 
output.bands.push({
    "type": 0,
    "channels": 0,
    "frequency": 90,
    "q": 0,
    "gain": 0,
    "color": 0
  });
 
  output.bands.push({
    "type": 1,
    "channels": 0,
    "frequency": 10000,
    "q": 0,
    "gain": 0,
    "color": 0
  });
 
// Add the EQ filters to the output preset
combinedFilters.forEach(filter => {
  const { index, status, type, frequency, gain, q, color } = filter;
  if (status) {
    const band = {
      type: 2,
      channels: 1 + (color === 'red' ? 1 : 0),
      frequency,
      q,
      gain,
      color: -15649895
    };
    output.bands.push(band);
  }
});
 
// Convert the output object to JSON
const jsonOutput = JSON.stringify([output], null, 2);
 
// Write the JSON output to a file
const outputFilePath = 'output.json'; // Update with the desired output file path
fs.writeFileSync(outputFilePath, jsonOutput, 'utf-8');

You used ChatGPT to generate script code? Good luck with that!

I just created a very simple EQ preset in PA (bass boost at 100Hz on left channel, and treble boost at 8kHz on right) and this is the JSON it exported:

[{
    "name": "TEST BASS-TREB",
    "preamp": 0.0,
    "parametric": true,
    "bands": [
        {
            "type": 0,
            "channels": 0,
            "frequency": 90,
            "q": 0.800000011920929,
            "gain": 0.0,
            "color": 0
        },
        {
            "type": 1,
            "channels": 0,
            "frequency": 10000,
            "q": 0.6000000238418579,
            "gain": 0.0,
            "color": 0
        },
        {
            "type": 0,
            "channels": 1,
            "frequency": 100,
            "q": 0.9988598823547363,
            "gain": 7.0,
            "color": -11206656
        },
        {
            "type": 1,
            "channels": 2,
            "frequency": 8000,
            "q": 0.9957138299942017,
            "gain": 7.001068115234375,
            "color": -16764160
        }
    ]
}
]

I have no idea why there are two initial unused centred entries for 90Hz and 10kHz though, but only the correct 100Hz/8kHz L/R panned items are brought in if I re-import the file.

Andre

The 2 initial entries are for the tone controls.

Using chatgtp works out until it doesn't.  It invariably gets stuck in an endless loop of f***ing up. For this script it generated the same bad code for dealing with empty filters 4 times in a row, until I pointed out what it was doing.  It also missed dealing with leading white space in the filter index number.  As a hobbyist, it is a bit of a time saver.  Anyone trying to cheat for their job is going to go hungry quick.

F***! My frequencies are not integers. Just saw it.

Edited by andrewilley
Removed profanity
25 minutes ago, Kenneth Mitchell said:

The 2 initial entries are for the tone controls.

Ah yes, could be, that would fit with the 90/10k values. I don't think they used to be exported in the earlier releases of the feature.

Andre

So that was it, if frequency is a float then import breaks the eq selection interface.  So Poweramp should probably do some sanity checks, considering how bad it breaks stuff, not that anyone is likely to encounter the problem.  TY

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...