README
¶
fakeflac-go
A command-line tool to detect "fake" lossless audio files and optionally plot their frequency distribution. Analysis of lossy files is also supported.
fakeflac-go estimates the percentage of the audio spectrum effectively remaining after a bad transcode from a lossy source.
Algorithm ported from mevdschee/fakeflac with some adjustments; scores may not match. This algorithm is known to produce false negatives, see Limitations.
Features
- Numeric audio spectrum quality scores
- Optional plotting of audio spectrum
- Multithreaded batch processing of multiple input files
- Many lossless and lossy audio formats supported
- Tunable frequency cutoff detection parameters
- Portable single binary
- Embedded WASM ffmpeg build
Requirements
- Linux/UNIX, Windows 10+, or MacOS 10.15+
- x86_64, ARM v6/v7/64, or Apple Silicon CPU
- 1-4 GB of free RAM for most operations
- Source installation: Go >= v1.21
Note: ffmpeg is embedded in fakeflac-go and thus not required to build or run
Installation
Source installation
go install github.com/drichline/fakeflac-go@v0.0.2
Binary installation
Untested prebuilt binaries for Linux x86/ARM, MacOS Intel/ARM, and Windows 10+ are provided on the releases page; use at your own risk.
Quick Start
$ fakeflac-go fake.flac real.flac
fake.flac: 73
real.flac: 100
Usage
fakeflac-go accepts a space-separated list of filenames, and will ignore unsupported (e.g. text) files. Both lossless (e.g. .flac, .alac, .wav) and lossy (e.g. .mp3) formats are supported. For each file, fakeflac-go will output a score of 0-100 to the terminal, with 100 being a "perfect flac."
The resulting numeric score represents the percentage of "real" frequencies up to 22 kHz present in the input file. Note that scores are only an estimate and may not be accurate for some edge-cases and lossy encoders, see Limitations.
-plot saves the spectrum plot of each file to the current directory, named after the input file with .png appended.
-threads sets the maximum number of active Goroutine workers. Note that by default, GOMAXPROCS limits the maximum number of active workers to the number of logical CPU cores, regardless of the limit set with -threads.
-boxcardx, -diff, -dx, and -limit: see Tuning
Usage: fakeflac-go [OPTIONS] [FILE]
Options:
-plot
Enable spectrum plot output
-threads int
Limit number of concurrent processes
-boxcardx int
Number of boxcar filter spectrum bins (default 500)
-diff float
Lowpass cutoff magnitude drop test limit (default 1.25)
-dx int
Lowpass cutoff test window size in Hz (default 441)
-limit float
Lowpass cutoff magnitude ratio test limit (default 1.1)
Supported file types
All input files are resampled to a 44.1 kHz 16 bit PCM stream by ffmpeg, so that the frequency range is normalized to 22 kHz (the upper limit of human ears).
".flac", ".wav", ".w64", ".aif", ".aiff", ".aifc", ".au", ".snd",
".mp3", ".mp2", ".aac", ".m4a", ".m4b", ".mp4", ".ac3", ".eac3",
".ogg", ".oga", ".opus", ".spx", ".mka", ".weba", ".webm",
".wma", ".ape", ".wv", ".tta", ".tak", ".shn", ".mpc",
".caf", ".amr", ".dts", ".voc", ".dsf", ".dff", ".alac"
Known limitations
Similar to the original fakeflac.py, fakeflac.go tends to produce false negatives (i.e. incorrect scores of 100) for some lossy encodes. Specifically, encodes that have sufficiently low magnitude at mid-high frequencies relative to the noise floor, and lack a steep drop-off in magnitude at the cutoff point. This can occur when audio is badly transcoded several times, very poor quality, or naturally very quiet in the upper frequencies, e.g. piano music.
Future versions of fakeflac-go may include improved cutoff detection tests that use e.g. variance to detect a lowpassed noise floor.
Left: Fake flac spectrum that produces a false negative (score 100)
Right: Fake flac spectrum that produces a true positive (score 70)
Tuning
The default constants included in fakeflac-go are empirical and based on those used in the original fakeflac.py. Tuning of these parameters may improve detection of lossy transcodes. Note that a frequency cutoff is only detected when both the limit and drop tests are satisfied.
Run fakeflac-go -help to see defaults
- dx: Number of frequencies, in Hz, to span while applying the limit and drop tests
- diff: Minimum magnitude difference between frequencies
dxHz apart to trigger drop test - limit: Maximum difference ratio allowed between magnitude at 22 kHz and current tested frequency to trigger limit test
- boxcardx: Number of bins the spectrum is divided into by the boxcar filter; lower numbers reduce noise and variation at the expense of a blocky "step response"
Images
fakeflac-go-generated spectrum plot of "fake" versus real flac
Example spectrograms of "fake" and real flacs, generated using sox
Documentation
¶
There is no documentation for this package.