diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-03 10:11:31 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-03 10:11:31 +0100 |
| commit | 99261b26c836dae82f108e3ca1e8a60b7e02be63 (patch) | |
| tree | e136a6c8a45de9298aa55d5b58dbb753229de9cc /scripts/gen_spectrograms.sh | |
| parent | 805f993293bd61625fe69172e2abeb7088ee5a80 (diff) | |
feat(assets): Add new drum samples and improve conversion script
Created a new script, scripts/gen_spectrograms.sh, to robustly convert all audio files in assets/originals to .spec format. The new script is more portable and provides better feedback. Added the newly generated drum and bass samples to the asset list, organizing them by type for clarity. This completes the requested sub-task.
Diffstat (limited to 'scripts/gen_spectrograms.sh')
| -rwxr-xr-x | scripts/gen_spectrograms.sh | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/scripts/gen_spectrograms.sh b/scripts/gen_spectrograms.sh new file mode 100755 index 0000000..7eb6bdc --- /dev/null +++ b/scripts/gen_spectrograms.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# This script converts all .wav and .aif files from assets/originals +# into .spec files in assets/final using the spectool utility. + +set -euo pipefail + +# --- Configuration --- +PROJECT_ROOT=$(git rev-parse --show-toplevel) +SOURCE_DIR="${PROJECT_ROOT}/assets/originals" +DEST_DIR="${PROJECT_ROOT}/assets/final" +SPECTOOL_PATH="${PROJECT_ROOT}/build/spectool" +TEMP_WAV_DIR=$(mktemp -d) + +# --- Pre-flight Checks --- +if ! command -v ffmpeg &> /dev/null; then + echo "Error: ffmpeg is not installed or not in your PATH." + echo "Please install it to handle .aif files." + exit 1 +fi + +if [ ! -f "${SPECTOOL_PATH}" ]; then + echo "Error: spectool not found at ${SPECTOOL_PATH}" + echo "Please build the project first (e.g., cmake -S . -B build && cmake --build build)" + exit 1 +fi + +echo "Source directory: ${SOURCE_DIR}" +echo "Destination directory: ${DEST_DIR}" +echo "Using spectool: ${SPECTOOL_PATH}" + +# --- Processing --- +process_file() { + local input_file="$1" + local base_name + base_name=$(basename "$input_file") + + local output_name + output_name=$(echo "${base_name%.*}" | tr '[:lower:]' '[:upper:]' | tr ' ' '_') + local spec_file="${DEST_DIR}/${output_name}.spec" + + local file_to_process="$input_file" + + # Convert .aif to .wav if necessary + if echo "${base_name}" | tr '[:upper:]' '[:lower:]' | grep -q ".aif$"; then + echo "Converting AIF to WAV: ${base_name}" + temp_wav="${TEMP_WAV_DIR}/${output_name}.wav" + ffmpeg -i "$input_file" -y "$temp_wav" &> /dev/null + file_to_process="$temp_wav" + fi + + echo "Generating spectrogram: ${base_name} -> ${output_name}.spec" + "${SPECTOOL_PATH}" analyze "$file_to_process" "$spec_file" +} + +# Find and process all audio files +find "$SOURCE_DIR" -type f \( -name "*.wav" -o -name "*.aif" \) | while read -r audio_file; do + process_file "$audio_file" +done + +# --- Cleanup --- +rm -rf "$TEMP_WAV_DIR" + +echo "Spectrogram generation complete." |
