From dfd71e4d375b937b39b3de6ed427b7234df14f1c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 8 Nov 2025 20:09:00 +0000 Subject: [PATCH] Add FLAC analysis scripts for click detection - detect_clicks.sh: Batch analysis of all cached FLAC files - analyze_flac.sh: Detailed analysis of a single FLAC file These tools help verify audio quality and detect encoding issues like clicks caused by buffer underruns. --- analyze_flac.sh | 31 ++++++++++++++++++++ detect_clicks.sh | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100755 analyze_flac.sh create mode 100755 detect_clicks.sh diff --git a/analyze_flac.sh b/analyze_flac.sh new file mode 100755 index 00000000..28ef4187 --- /dev/null +++ b/analyze_flac.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Affiche toutes les stats d'un fichier FLAC + +if [ $# -eq 0 ]; then + echo "Usage: $0 " + exit 1 +fi + +FILE="$1" + +if [ ! -f "$FILE" ]; then + echo "Error: File not found: $FILE" + exit 1 +fi + +echo "=== Analyzing: $(basename "$FILE") ===" +echo "" +echo "--- SoX Statistics ---" +sox "$FILE" -n stat 2>&1 + +echo "" +echo "--- File Info ---" +file "$FILE" + +echo "" +echo "--- FLAC Metadata ---" +metaflac --list "$FILE" 2>/dev/null || echo "metaflac not installed" + +echo "" +echo "--- Audio Integrity Check ---" +flac -t "$FILE" 2>&1 || echo "flac not installed" diff --git a/detect_clicks.sh b/detect_clicks.sh new file mode 100755 index 00000000..31999d26 --- /dev/null +++ b/detect_clicks.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# Script pour détecter les clics dans les fichiers FLAC du cache + +CACHE_DIR="${1:-/tmp/pmomusic_test/audio_cache}" + +if [ ! -d "$CACHE_DIR" ]; then + echo "Error: Cache directory not found: $CACHE_DIR" + exit 1 +fi + +echo "=== FLAC Click Detection Tool ===" +echo "Scanning: $CACHE_DIR" +echo "" + +# Vérifier que sox est installé +if ! command -v sox &> /dev/null; then + echo "Error: sox is not installed. Install it with: sudo apt install sox" + exit 1 +fi + +count=0 +suspicious=0 + +for file in "$CACHE_DIR"/*.orig.flac; do + if [ ! -f "$file" ]; then + echo "No FLAC files found in $CACHE_DIR" + exit 0 + fi + + filename=$(basename "$file") + echo "Analyzing: $filename" + + # Obtenir toutes les stats + stats=$(sox "$file" -n stat 2>&1) + + # Extraire les valeurs importantes + pk_lev=$(echo "$stats" | grep "Pk lev dB" | awk '{print $4}') + rms_lev=$(echo "$stats" | grep "RMS lev dB" | awk '{print $4}') + crest=$(echo "$stats" | grep "Crest factor" | awk '{print $3}') + + echo " Peak level: ${pk_lev:-N/A} dB" + echo " RMS level: ${rms_lev:-N/A} dB" + echo " Crest factor: ${crest:-N/A} dB" + + # Analyser la variance d'amplitude (détection de clics) + # On compte le nombre de pics au-dessus d'un seuil + peaks=$(sox "$file" -n stats 2>&1 | grep "Maximum amplitude" | awk '{print $3}') + + if [ -n "$peaks" ]; then + # Si le peak est proche de 1.0 (clipping), c'est suspect + is_clipping=$(echo "$peaks > 0.95" | bc -l 2>/dev/null) + if [ "$is_clipping" = "1" ]; then + echo " ⚠️ WARNING: Possible clipping detected!" + suspicious=$((suspicious + 1)) + else + echo " ✓ OK" + fi + else + echo " ✓ OK" + fi + + echo "" + count=$((count + 1)) +done + +echo "=== Summary ===" +echo "Files scanned: $count" +echo "Suspicious files: $suspicious" + +if [ $suspicious -gt 0 ]; then + echo "" + echo "⚠️ Some files may have issues. Listen to them carefully." + exit 1 +fi + +exit 0