From: Christos Zoulas Date: Tue, 12 Sep 2017 15:55:16 +0000 (+0000) Subject: From: Ronald van Engelen X-Git-Tag: FILE5_33~102 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbbdc39fa43724c3c0006c05ff2c353dcd77bab9;p=file From: Ronald van Engelen Completed common sample frequencies for pcm encoded audio in flac containers using bash script "scripts/create_filemagic_flac" --- diff --git a/magic/Magdir/audio b/magic/Magdir/audio index 0330bbfa..1ea19524 100644 --- a/magic/Magdir/audio +++ b/magic/Magdir/audio @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: audio,v 1.80 2017/08/13 00:21:47 christos Exp $ +# $File: audio,v 1.81 2017/09/12 15:55:16 christos Exp $ # audio: file(1) magic for sound formats (see also "iff") # # Jan Nicolai Langfeldt (janl@ifi.uio.no), Dan Quinlan (quinlan@yggdrasil.com), @@ -468,20 +468,25 @@ >>20 byte&0xe 0xa \b, 6 channels >>20 byte&0xe 0xc \b, 7 channels >>20 byte&0xe 0xe \b, 8 channels -# some common sample rates ->>17 belong&0xfffff0 0x2ee000 \b, 192 kHz ->>17 belong&0xfffff0 0x158880 \b, 88.2 kHz ->>17 belong&0xfffff0 0x0ac440 \b, 44.1 kHz ->>17 belong&0xfffff0 0x0bb800 \b, 48 kHz ->>17 belong&0xfffff0 0x07d000 \b, 32 kHz ->>17 belong&0xfffff0 0x056220 \b, 22.05 kHz ->>17 belong&0xfffff0 0x05dc00 \b, 24 kHz ->>17 belong&0xfffff0 0x03e800 \b, 16 kHz ->>17 belong&0xfffff0 0x02b110 \b, 11.025 kHz ->>17 belong&0xfffff0 0x02ee00 \b, 12 kHz ->>17 belong&0xfffff0 0x01f400 \b, 8 kHz ->>17 belong&0xfffff0 0x177000 \b, 96 kHz ->>17 belong&0xfffff0 0x0fa000 \b, 64 kHz +# sample rates derived from known oscillator frequencies; +# 24.576 MHz (video/fs=48kHz), 22.5792 (audio/fs=44.1kHz) and +# 16.384 (other/fs=32kHz). +>>17 belong&0xfffff0 0x02b110 \b, 11.025 kHz +>>17 belong&0xfffff0 0x03e800 \b, 16 kHz ++>>17 belong&0xfffff0 0x056220 \b, 22.05 kHz +>>17 belong&0xfffff0 0x05dc00 \b, 24 kHz +>>17 belong&0xfffff0 0x07d000 \b, 32 kHz +>>17 belong&0xfffff0 0x0ac440 \b, 44.1 kHz +>>17 belong&0xfffff0 0x0bb800 \b, 48 kHz +>>17 belong&0xfffff0 0x0fa000 \b, 64 kHz +>>17 belong&0xfffff0 0x158880 \b, 88.2 kHz +>>17 belong&0xfffff0 0x177000 \b, 96 kHz +>>17 belong&0xfffff0 0x1f4000 \b, 128 kHz +>>17 belong&0xfffff0 0x2b1100 \b, 176.4 kHz +>>17 belong&0xfffff0 0x2ee000 \b, 192 kHz +>>17 belong&0xfffff0 0x3e8000 \b, 256 kHz +>>17 belong&0xfffff0 0x562200 \b, 352.8 kHz +>>17 belong&0xfffff0 0x5dc000 \b, 384 kHz >>21 byte&0xf >0 \b, >4G samples >>21 byte&0xf 0 \b >>>22 belong >0 \b, %u samples diff --git a/magic/scripts/create_filemagic_flac b/magic/scripts/create_filemagic_flac new file mode 100755 index 00000000..27303031 --- /dev/null +++ b/magic/scripts/create_filemagic_flac @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +## bash script to generate file magic support for flac. +## https://github.com/file/file/blob/master/magic/Magdir/audio +## below "#some common sample rates" (line 471), ie: +## >>17 belong&0xfffff0 0x2ee000 \b, 192 kHz + +LANG=C + +target=magic/Magdir/audio + +## construct static list of sample rates based on standard crystal +## oscillator frequencies. +## 16.384 MHz Unknown audio application +## (16384 kHz = 32 kHz * 512 = 32 * 2^9) +## 22.5792 MHz Redbook/CD +## (22579.2 kHz = 44.1kHz * 512 = 44.1 * 2^9) +## also used: 11.2896, 16.9344, 33.8688 and 45.1584 +## 24.576 MHz DAT/Video +## (24576 kHz = 48 kHz * 512 = 48 * 2^9) +## also used: 49.1520 + +## 33.8688 > 16.9344 +## 36.864 > 18.432000 +declare -a a_ground_fs=(16384000 22579200 24576000) + +## multiply ground clock frequencies by 1953 to get usable base +## frequencies, for instance: +## DAT/video: 24.576 MHz * 1000000 / 512 = 48000Hz +## Redbook/CD: 22.5792 MHz * 1000000 / 512 = 44100Hz +## use base rates for calculating derived rates +declare -a samplerates +## min divider: fs/n +def_fs_n=512 +min_fs_n=4 +## start at base_fs/(def_fs*min_fs) +## add each derived sample rate to the array +for base_fs in "${a_ground_fs[@]}"; do + min_fs=$( echo "${base_fs} / ( ${def_fs_n} * ${min_fs_n} )" | bc) + ## max multiplier: fs*n*min_fs + max_fs_n=$(( 8 * min_fs_n )) + n=${max_fs_n} + while [[ ${n} -ge 1 ]]; do + sample_rate=$(( min_fs * n )) + samplerates+=(${sample_rate}) + n=$(( n / 2 )) + done +done + +declare -a stripped_rates +declare -a lines +for samplerate in "${samplerates[@]}"; do + ## use bc with sed to convert and format Hz to kHz + stripped_rate="$(LANG=C bc <<< "scale=5; ${samplerate} / 1000" | \ + sed 's#[0\.]*$##g')" + ## only add uniq sample rates (should be neccessary + if [[ ! "${stripped_rates[@]}" =~ ${stripped_rate} ]]; then + printf -v line ">>17\tbelong&%#-15x\t%#08x\t%s, %s kHz\n" \ + "16777200" \ + "$(( samplerate * 16 ))" \ + "\b" \ + "${stripped_rate}" + stripped_rates+=("${stripped_rate}") + lines+=("${line}") + fi + +done +printf "## start cutting >>> \n" +## print out the formatted lines +printf "%s" "${lines[@]}" | sort -k5 -n +printf "## <<< stop cutting\n"