2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Psychopy から 低レイテンシ聴覚刺激のための Psychtoolbox を使う (Audio)

Last updated at Posted at 2020-09-16

神経生理学において視聴覚刺激を行う際の選択肢は大体,

  • Psychtoolbox
  • Psychopy

である(筆者は最近はPsychopy を愛用している).
これらのライブラリは排他的ではなく,Psychopy において聴覚刺激については Psychtoolbox (以下PTB) のバックエンドの使用がレイテンシの面から推奨されている.

PsychoPy currently supports a choice of sound engines: PTB, pyo, sounddevice or pygame. You can select which will be used via the audioLib preference. sound.Sound() will then refer to one of SoundPTB, SoundDevice, SoundPyo or SoundPygame. This preference can be set on a per-experiment basis by importing preferences, and setting the audioLib option to use.
The PTB library has by far the lowest latencies and is strongly recommended (requires 64 bit Python3)

インストール手順は下記の通り (Windows10 + Anaconda).

pip install psychopy
pip install git+https://github.com/Psychtoolbox-3/Psychtoolbox-3

この状態でSound のサンプルコード

import psychtoolbox as ptb
from psychopy import sound

mySound = sound.Sound('A')
now = ptb.GetSecs()
mySound.play(when=now+0.5)  # play in EXACTLY 0.5s

を実行するとおそらくインポートのエラーが発生する.
そこで,

  • libusb-1.0.dll
  • libusb-1.0.dll.a
  • portaudio_x64.dll

をPsychtoolbox のリポジトリから探し,コピーする.
筆者の場合は

C:\Users\username\anaconda3\envs\psypy3\Lib\site-packages\psychtoolbox

にコピーした.

これで上記サンプルコードが動作する.実際に低レイテンシかどうかは,手元では未検証.

追記:
git と VS build tool が必要

2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?