# Automated Personalized Loudness Control for Multi-Track Recordings
## 2 Materials and Methods
### Genetic Algorithm for Loudness Optimization  
We propose the utilization of genetic algorithms [25; 26] to effectively handle this complex and multi-solution problem. Our approach leverages a genetic algorithm to iteratively refine the mixing coefficients, driving towards an optimal mix. The algorithm mimics natural selection, evolving solutions over generations to arrive at a superior mix. The genetic algorithm begins with a population of randomly generated solutions (mixing coefficient sets). Through processes akin to biological evolution--selection, crossover and mutation--this population evolves over generations. A generic pseudo-code for genetic algorithms is represented in Algorithm 1. ```
1:Set: Population size, chromosome length
2:Init: Create population using random bounded values
3:while stop criterion not met do
4:Evaluation: Calculate the fitness of each individual in the population
5:Parents selection: Choose individuals for reproduction based on their fitness
6:for i = 0 to length list of parents do
7: Choose pair of parents
8:if random probability crossover \(\leq\) crossover probability then
9: Crossover: Perform crossover between parents to create a new offspring
10:else
11: Select a parent as the new offspring
12:endif
13:endfor
14:for each offspring do
15:for each gene in offspring do
16:if random probability mutation \(\leq\) mutation probability then
17: Mutation: Apply random mutation to introduce changes in the offspring
18:endif
19:endfor
20:endfor
21: Update: Create a new population based on the generated offsprings
22:endwhile
```  
**Algorithm 1** Genetic Algorithm  
Our customized genetic algorithm ensures that only the fittest solutions (those producing the most harmonious mixes) survive and propagate their traits. Given the unique demands of music mixing, we customize the standard genetic algorithm to suit our specific needs:  
* Population and Solution Representation--the population consists of vectors of mixing coefficients (chromosomes). Each vector represents a potential solution for the problem, where one element (gene) corresponds to a coefficient for a track. For our problem, each solution will always be represented by a vector of 66 elements. Instead of creating a high population, we chose to use a highly competitive small population of only 5 chromosomes, in order to extract the optimal solution from this group of best candidates. Using the model described in Equation (1), we define a chromosome based on the vector representation specified in Equation (2):\[c=[\lambda_{0},\lambda_{1},\ldots,\lambda_{65}]. \tag{2}\]
* Fitness Function--our fitness function evaluates the quality of a mix based on the Mean Absolute Error (MAE) between the desired and produced audio samples across tracks. The main difference is that instead of computing the loss function for each song and average all the errors, we instead compute the error for each track in all songs (Equations (3) and (4)), in order to better approximate the track coefficients. \[e_{i}^{k}=\frac{1}{T^{k}}\sum_{t=0}^{T^{k}-1}|y_{i}^{k}(t)-\lambda_{i}x_{i}^{k }(t)|=\text{MAE }\left(y_{i}^{k},y_{i}^{k}\right),\] (3) \[e_{i}=\sum_{k=1}^{M}e_{i}^{k},\] (4) where \(k\in[1,M]\) represents the index of a song out of \(M\) possible examples, and \(T^{k}\) is the length of the signal \(k\). At each track \(i\) for a song \(k\), the error \(e_{i}^{k}\) (MAE function) is calculated between the original track \(y_{i}^{k}\) and the product of coefficient \(\lambda_{i}\) and input track \(x_{i}^{k}\) at \(-45\) LUFS, which represents the predicted track \(\hat{y}_{i}^{k}\). The MAE function, defined in both Equations (3) and (5), measures the differences between the ground truth track samples \(y_{i}^{k}\) and predicted samples \(\hat{y}_{i}^{k}\). Summing these errors on a track level helps us better minimize a loss function as the average of the track errors over all songs \(M\). In other words, we are trying to reduce the differences between the loudness of the predicted track and the original one, for all available musical pieces.