y-brehm / waveAlign

Python repo for audio loudness matching in order to end the loudness war between DJs.
3 stars 0 forks source link

optimize caching #30

Closed y-brehm closed 3 weeks ago

y-brehm commented 2 months ago

Our caching can be optimized in various ways:

y-brehm commented 1 month ago

Point 2 was already solved by @SimonZimmer in the scope of #35.

Regarding point 3: Thinking about this, I can see an edge case where this could lead to an error: If a user for example waveAligns their USB stick and afterwards adds some files to the stick as well as changes the loudness target and waveAligns again, we would actually process with wrong data. Recordbox does not replace the original files that are already existent on the stick, so we would process files that were already waveAligned, but considering the original levels. It is not impossible to solve this: We would need to save more data or some kind of processing history. But since this can easily become a big pain in the butt, I would suggest to skip this for now. Any opinions @maosi100 @sabjorn @SimonZimmer?

sabjorn commented 1 month ago

@y-brehm agreed about 3. Since it’s a “destructive” process, limiting users’ ability to completely crush their tracks.

Although — you could run a process beforehand to check the current settings against the cache and warn the user—requiring user input to proceed. The warning could include:

warning — the audio tracks you are trying to process have already been processed and the new settings could cause issues. If you are processing copies of your audio (for example—a Rekordbox USB stick) — consider replacing the copies with the originals and re-run this process.

A -f flag could then be added to override.

It is unfortunate because some audio formats do have support for a gain level in the metadata but it seems as though no audio players support it (CDJs and Rekordbox included).

SimonZimmer commented 1 month ago

@y-brehm @sabjorn Hmmm, so this would be the use-case:

In this case, wavealign would read the cache file in and recognize that the target level has changed from -12 to -10dbLUFS for all entries. Therefore it will use the original peak and LUFS values for each entry, adjust the gain to the difference between that LUFS and the -10, encode the files and replace the target LUFS value with the new one, leaving the original peak/LUFS values. It also recognizes there are new files added and therefore processes those from scratch, making entries for each.

Because each destination given by the -o flag gets it's own .wavealign_cache.yml, this can be repeated for as usb sticks as possible. So as long as we stick with the paradigm "align USB sticks not the library" I think this feature would be just fine. Am I missing something?

maosi100 commented 1 month ago

I'd also follow @SimonZimmer's suggestions on this topic.

However I want to use this place to raise another issue. Caching does not seem to work properly on my machine and I assume this is due to the last modified date of the file not being the same as written into the cache.

Starting with a new file:

last modified cache: None
last modified file: 1594487240.0

A new file does not have a cache entry and only it's native last modified date.

Processing the same file again:

last modified cache: 1594487240.0
last modified file: 1718106214.1836145

The cache date was written with the native last modified date. Not the date of the modification via wavealign. The data within the file represents the time of modification.

Processing the same file again:

last modified cache: 1718106214.1836145
last modified file: 1718106257.9980752

The cache data represents the data of the penultimate processing, not the last one whiche would be the same as the last modified date within the file.

Does it work on your machines? If not I suggest to implement a fix by who's currently working on the caching topic.. @y-brehm ?

SimonZimmer commented 1 month ago

I spoke a bit with @y-brehm today and we reached the conclusion that the caching should only need to hold two fields of data:

str: filename float: lufs_level

This would solve the initial issue of using any wrong original data since the only thing that is being read from the cache is the resulting lufs after the last processing along with the filename that it belongs to. It might also solve the problem @maosi100 pointed out, since we won't have any date information present in the cache file anymore.