SOUND CARD設定用のプラグインをもう少しだけ頑張ってみる
ここの過去ログ見るとお分かりでしょうが、v.0.9.3では私がお手伝いしたサウンドカード設定のプラグインを公式で拡張して採用頂いております。
ただ、サポートで動作確認の素晴らしい表があるのだから、これを使って選択できるようにしたい(そんなに頻繁に変更するものではないですが)。
という訳で、私なりの方法で実装したものです。
01-soundcard.zip
/home/pi/plugins/01-soundcardを改変するため、元のファイルはバックアップしておいて下さい。
cd /home/pi/plugins/01-soundcard
cp form.html form.html.org
sndcard.json
[
{"d":"Audiophonics ES9018 DAC","c":"ES9018K2M","k":"i-sabre-k2m"},
{"d":"Allo Boss DAC","c":"Burr Brown PCM5122","k":"allo-boss-dac-pcm512x-audio"},
{"d":"Allo DigiOne","c":"Cirrus Logic WM8805","k":"allo-digione"},
{"d":"Allo MiniBoss DAC","c":"Burr Brown PCM5122","k":"allo-boss-dac-pcm512x-audio"},
{"d":"Allo Piano 2.1 Hi-Fi DAC","c":"Burr Brown PCM5142","k":"allo-piano-dac-plus-pcm512x-audio"},
{"d":"Allo Piano Hi-Fi DAC","c":"Burr Brown PCM5122","k":"allo-piano-dac-pcm512x-audio"},
{"d":"Audiophonics ES9023 DAC","c":"ESS Sabre ES9023","k":"hifiberry-dac"},
{"d":"Audiophonics ES9023 DAC LTE","c":"ESS Sabre ES9023","k":"hifiberry-dac"},
{"d":"Audiophonics ES9023 DAC TXCO","c":"ESS Sabre ES9023","k":"hifiberry-dac"},
{"d":"Audiophonics ES9028 DAC","c":"ESS Sabre ES9028Q2M","k":"rpi-dac"},
{"d":"Audiophonics PCM5102 DAC","c":"Burr Brown PCM5102A","k":"hifiberry-dac"},
{"d":"Audiophonics PCM5122 DAC","c":"Burr Brown PCM5122","k":"hifiberry-dacplus"},
{"d":"Audiophonics TDA1387 DAC","c":"Philips TDA1387","k":"hifiberry-dac"},
{"d":"Buffalo I","c":"ESS Sabre ES9008","k":"rpi-dac"},
{"d":"Buffalo II/IIIse","c":"ESS Sabre ES9018","k":"rpi-dac"},
{"d":"DDDAC1794 NOS","c":"Burr Brown PCM1794","k":"rpi-dac"},
{"d":"DIAL-DAC","c":"Burr Brown PCM1793","k":"rpi-dac"},
{"d":"DIYINHK ES9023 DAC","c":"ESS Sabre ES9023","k":"hifiberry-dac"},
{"d":"Denafrips Pontus R2R DAC (I2S)","c":"Altera MAX II CPLD","k":"rpi-dac"},
{"d":"Dion Audio LOCO","c":"PCM5242 DAC","k":"dionaudio-loco"},
{"d":"Durio Sound PRO","c":"Burr Brown PCM5102A","k":"hifiberry-dac"},
{"d":"G2 Labs BerryNOS","c":"Philips TDA1543","k":"hifiberry-dac"},
{"d":"G2 Labs BerryNOS","c":" RedPhilips TDA1543","k":"hifiberry-dac"},
{"d":"HIFI DAC","c":"Burr Brown PCM5102A","k":"hifiberry-dac"},
{"d":"HIFI DAC+","c":"Burr Brown PCM5122","k":"hifiberry-dacplus"},
{"d":"HIFI Digi","c":"Wolfson WM8804G","k":"hifiberry-digi"},
{"d":"HIFI Digi+","c":"Wolfson WM8804G","k":"hifiberry-digi"},
{"d":"HiFiBerry Amp(Amp+)","c":"Burr Brown TAS5713","k":"hifiberry-amp"},
{"d":"HiFiBerry DAC","c":"Burr Brown PCM5102A","k":"hifiberry-dac"},
{"d":"HiFiBerry DAC+","c":"Burr Brown PCM5122","k":"hifiberry-dacplus"},
{"d":"HiFiBerry DAC+ Light","c":"ESS Sabre ES9023","k":"hifiberry-dac"},
{"d":"HiFiBerry DAC+ Pro","c":"Burr Brown PCM5122","k":"hifiberry-dacplus"},
{"d":"HiFiBerry Digi(Digi+)","c":"Cirrus Logic WM8804","k":"hifiberry-digi"},
{"d":"HiFiBerry Digi+ Pro","c":"Cirrus Logic WM8804","k":"hifiberry-digi-pro"},
{"d":"Hifimediy ES9023","c":"ESS Sabre ES9023","k":"hifiberry-dac"},
{"d":"IQaudIO Pi-AMP+","c":"Burr Brown TPA3118","k":"iqaudio-dacplus"},
{"d":"IQaudIO Pi-DAC","c":"Burr Brown PCM5122","k":"iqaudio-dac"},
{"d":"IQaudIO Pi-DAC PRO","c":"Burr Brown PCM5242","k":"iqaudio-dacplus"},
{"d":"IQaudIO Pi-DAC+","c":"Burr Brown PCM5122","k":"iqaudio-dacplus"},
{"d":"IQaudIO Pi-DACZero","c":"Burr Brown PCM5122","k":"iqaudio-dacplus"},
{"d":"IQaudIO Pi-Digi+","c":"Wolfson WM8804","k":"iqaudio-digi-wm8804-audio"},
{"d":"IQaudIO Pi-DigiAMP+","c":"Burr Brown TAS5756","k":"iqaudio-dacplus"},
{"d":"IanFIFO II","c":"Altera Max II CPLD","k":"hifiberry-dac"},
{"d":"JustBoom AMP HAT(Zero)","c":"Burr Brown TAS5756","k":"justboom-dac"},
{"d":"JustBoom DAC HAT(Zero)","c":"Burr Brown PCM5122 (PCM5121)","k":"justboom-dac"},
{"d":"JustBoom Digi HAT(Zero)","c":"Wolfson WM8804G","k":"justboom-digi"},
{"d":"Lucid Labs Raspberry Pi DAC","c":"Burr Brown PCM5102A","k":"hifiberry-dac"},
{"d":"Mamboberry HiFi DAC+","c":"ESS Sabre ES9032","k":"hifiberry-dac"},
{"d":"Mamboberry LS DAC+","c":"ESS Sabre ES9023p","k":"hifiberry-dac"},
{"d":"Pi2Design 503HTA Hybrid Tube Amp","c":"Burr Brown PCM5102A","k":"hifiberry-dac"},
{"d":"Pimoroni pHAT DAC","c":"Burr Brown PCM5102A","k":"hifiberry-dac"},
{"d":"PlainAMP","c":"Burr Brown TAS5756","k":"iqaudio-dacplus"},
{"d":"PlainDAC","c":"Burr Brown PCM5100","k":"hifiberry-dac"},
{"d":"PlainDAC+","c":"Burr Brown PCM5121","k":"hifiberry-dacplus"},
{"d":"PlainDSP","c":"Burr Brown PCM5121","k":"hifiberry-dacplus"},
{"d":"RPi-DAC","c":"Burr Brown PCM1794A","k":"rpi-dac"},
{"d":"RaspyPlay4","c":"Burr Brown PCM5122","k":"iqaudio-dac"},
{"d":"Red Rocks Audio DigiDAC1","c":"Wolfson WM8742 (DAC) WM8804 (S/PDIF)","k":"rra-digidac1-wm8741-audio"},
{"d":"Sabreberry32","c":"ES9018Q2C","k":"sabreberry32"},
{"d":"SB32+PRO DoP","c":"ESS Sabre ES9218P","k":"hifiberry-dacplus"},
{"d":"Soekris DAM1021/1121 (I2S)","c":"FPGA based","k":"rpi-dac"},
{"d":"Suptronics x400","c":"Burr Brown PCM5122","k":"iqaudio-dacplus"},
{"d":"Terra-BerryDAC 2","c":"AK4490EQ","k":"hifiberry-dac"}
]
対応表をJSON化したものです。dはサウンドカード名、kはdtoverlayを示します(未使用ですがcにサウンドチップを格納しています。)。
将来的に新しいデバイスが増えた、対応カードが見つかった場合はこのファイルを拡張すれば良いわけです。
form.html
<script>
$(function() {
var i2sc;
$.getJSON('/plugins/01-soundcard/sndcard.json' , function(data) {
i2sc = data;
init1();
});
$('input[name="sel"]').change(function() {
if ($(this).val() === "1") {
init1();
} else {
init2();
}
});
function removeArrayDuplicates(ary) {
var ext = {}, res = [];
for (var i = 0, l = ary.length; i < l; i++) {
var tmp = ary[i];
if (!ext[tmp]) {
ext[tmp] = true;
res.push(tmp);
}
}
return res;
}
function init1() {
$("#d").val("");
$("#scard option").remove();
$("#device option").remove();
var ary1 = [], ary2 = [];
for (var i = 0, l = i2sc.length; i < l; i++) {
ary1.push(i2sc[i].k);
}
ary2 = removeArrayDuplicates(ary1);
ary2.sort();
ary1 = null;
for (var i = 0, l = ary2.length; i < l; i++) {
$("#scard").append($("<option>").val(ary2[i]));
}
$("#k").attr("list", "scard");
change();
$("#sep").text("->");
$("#dl").text("(Compat. Card)");
$("#d").keyup(function() {
change();
});
$("#d").focus(function() {
change();
});
$("#k").off("keyup");
$("#k").off("focus");
}
function init2() {
$("#k").val("");
$("#scard option").remove();
$("#device option").remove();
for (var i = 0, l = i2sc.length; i < l; i++) {
$("#device").append($("<option>").val(i2sc[i].d));
}
$("#sep").text("<-");
$("#dl").text("SoundCard");
$("#d").off("keyup");
$("#d").off("focus");
$("#k").keyup(function() {
change2();
});
$("#k").focus(function() {
change2();
});
}
function change() {
$("#device option").remove();
var spl = $("#k").val().split(",");
for (var i = 0, l = i2sc.length; i < l; i++) {
if (spl[0] === i2sc[i].k || $("#k").val === "") {
$("#device").append($("<option>").val(i2sc[i].d));
}
}
$("#d").attr("list", "device");
}
function change2() {
$("#scard option").remove();
for (var i = 0, l = i2sc.length; i < l; i++) {
if ($("#d").val() === i2sc[i].d) {
$("#scard").append($("<option>").val(i2sc[i].k));
$("#k").val(i2sc[i].k);
break;
}
}
$("#k").attr("list", "scard");
}
});
</script>
<datalist id="scard">
</datalist>
<datalist id="device">
</datalist>
<datalist id="format_list">
<option value="S16">
<option value="S32">
</datalist>
<div style="padding:0px 20px 10px 20px;">
<h3>config.txt</h3>
<input type="radio" name="sel" value="1" checked>dtoverlay -> SoundCard (Check)<br/>
<input type="radio" name="sel" value="2">dtoverlay <- Soundard
<table style="width:100%;"><tr><td style="width:48%;">
<label class="control-label">dtoverlay</label>
<input type="text" id="k" class="config" uri="/boot/config.txt" key="dtoverlay" list="scard" />
</td><td id="sep" style="width:4%;text-align:center;vertical-alighn:middle;"><label class="control-label">-></label></td><td style="width:48%;">
<label id="dl" class="control-label">(Compat. Card)</label>
<input type="text" id="d" class="config" list="device">
</td></tr></table>
<h3>environment</h3>
<label class="control-label "><small>DEFAULT_SAMPLE_FORMAT</small></label>
<input type="text" class="config" uri="/etc/environment" key="DEFAULT_SAMPLE_FORMAT" list="format_list" />
<label class="control-label"><small>GPIO_DRIVE_STRENGTH (2~16)</small></label>
<input type="text" class="config" uri="/etc/environment" key="GPIO_DRIVE_STRENGTH" />
<br />
<p>Restart is required after changing the setting.</p>
</div>
使い方
dtoverlayの記載部分のテキストボックスが左右2個あります。
左がdtoverlayをそのまま記載する場所(従来通りここの値が/boot/config.txtに保存されます)、
右が当該dtoverlayが対応するサウンドカード名が表示されるようになっています。
ラジオボタンで機能を切り替えできるように設計しました。
・dtoverlay -> SoundCard (Check)(デフォルトでON)
現在指定されているdtoverlayで対応するサウンドカード名が右のテキストボックスに表示されます。設定があっているかの確認用として使用してみて下さい。
・dtoverlay <- Soundard
このチェックボックスを選択すると、dtoverlayの文字列が消され、右のテキストボックスから
サウンドカード名を選択すると左のテキストボックスに対応するdtoverlayドライバ文字列が表示されます(一回クリックして表示させて下さい)
↑
ちょっとわかりにくいですが、触ってみれば何をしているかお分かりになるかと思います。
なお、「こんな構成ならもっと分かりやすいのでは?」というご提案ありましたら、お教え下さい。