見出し画像

Mac OS CatalinaでProcessingのSoundの入力値が0の時の対処法

(2021/9/9追記) Processing 4では、この記事の方法は必要ありません。こちらの記事をご覧ください! 

--------

今年の頭にVideoについての記事を書きましたが、同様の問題がSoundでも起きていたようで、対処法を調べてみました!

検証環境

・Mac OS Catalina (10.15.6)
・Processing 3.5.4
・Sound Library (2.2.2)

問題

こちらの講義資料を参考に以下のコードを実行してみると、コンソールに 0 が並んでしまって、音量が正しく取得できません。

// マイクの音を扱うためのライブラリをインポート
import processing.sound.*;
// マイク
AudioIn in;
// 音量を取得してくれるもの
Amplitude amp;
void setup() {
 size(600, 600);
 strokeWeight(2);
 fill(255, 200, 100);
 // マイクを初期化(おまじない。現時点で深い意味は考えなくてOK)
 in = new AudioIn(this);
 in.start();
 // 音量の取得を開始
 amp = new Amplitude(this);
 amp.input(in);
}
void draw() {
 background(255);
 // マイクの音量を取得して、
 // 結果を変数 a に入れる
 float a = amp.analyze();
 // 音量の数値をコンソールに出力してみる
 println(a);
}

スクリーンショット 2020-10-07 11.03.06

ビデオのとき同様システム環境設定の「セキュリティとプライバシー」を開き、「マイク」の項目を見ると、やはりProcessingがここにありません。

スクリーンショット 2020-10-07 11.03.47

最近のMac OSでおなじみのこんなセキュリティの許可をしたい。

画像5

解決方法

本家のこちらのissueに暫定的な解決方法が書かれていました。

Open the Processing 3 app through Terminal by typing:
/Applications/Processing.app/Contents/MacOS/Processing;
Then open a sketch that requires use of the mic/camera in the Processing PDE (this doesn't work if you're using Sublime etc as an editor). Then you will get the pop-up that asks if you want to allow Processing to access the mic/camera.
Once you've done it once, the privacy setting seems to stay 'allowed' and you don't need to open Processing through the Terminal again. You can check by looking at your 'security & privacy' settings under 'system preferences'.

1. Processingを一度終了し、ターミナル経由で起動します。

$ /Applications/Processing.app/Contents/MacOS/Processing;

2. 起動したら、先程のサンプルコードを実行してみましょう。

3. マイクの使用許可を求めるダイアログが出るので「OK」

4. マイクの入力値が取れました!

スクリーンショット 2020-10-07 11.06.29

5. セキュリティとプライバシー内にProcessingが追加されました!

スクリーンショット 2020-10-07 10.50.04


手軽さが売りのProcessingですが最近はボランティアプロジェクトゆえに、メンテナンスが間に合っていないようです。学生のみなさんにはご不便おかけします 🥺

まだリリースされていませんが、Processing 4のalpha 3版では解決予定とのこと!!開発チームに感謝です。

Hi all, sorry that this has been broken for so long. The video and sound libraries were moved out of the core because 1) they were very large, and 2) so that others could maintain them. Unfortunately there's nobody doing that maintenance at the moment, so once again it falls to me. We're all volunteers, making this available for free, and have very limited time (none, in the midst of a pandemic) to work on it.

I've made the necessary changes so that the prompt will show up on in the next 4.0 release (alpha 3), or you can build that code and run it yourself from that repo: https://github.com/processing/processing4

====
2020/9/24
https://github.com/processing/processing-sound/issues/51#issuecomment-697818548

===

Processing 4については以前調べた際のこちらの記事をどうぞ。



この記事が気に入ったらサポートをしてみませんか?