Skip to content

Commit

Permalink
psycho: use pygame audiolib by default on Mac OS
Browse files Browse the repository at this point in the history
  • Loading branch information
smathot committed Apr 19, 2023
1 parent 674b07c commit 8c8140f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libopensesame/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def reset(self):
self.var.sound_channels = 2
self.var.sound_buf_size = 1024
# Default backend
self.var.canvas_backend = u'xpyriment'
self.var.canvas_backend = u'psycho'
# Display parameters
self.var.width = 1024
self.var.height = 768
Expand Down
8 changes: 6 additions & 2 deletions openexp/_sampler/psycho.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
DEFAULT_SOUND_FREQ = 48000
DEFAULT_BLOCK_SIZE = 256
NEEDS_BLOCK_SIZE = 'sounddevice', 'PTB'
# Due to issues with sounddevice/ portaudio on Mac OS, we fall back to
# pygame on that platform
DEFAULT_AUDIOLIB = 'pygame' if sys.platform == 'darwin' else 'sounddevice'
# Will be intialized during init_sound()
Sound = None
PLAYING = None



class Psycho(Sampler):
"""This is a sampler backend built on top of PsychoPy. For function
specifications and docstrings, see `openexp._sampler.sampler`.
Expand All @@ -43,7 +47,7 @@ class Psycho(Sampler):
'psycho_audiolib': {
'name': 'Sound library',
'description': 'Can be sounddevice, pyo, pygame, or PTB',
'default': 'pygame' if sys.platform == 'darwin' else 'sounddevice'},
'default': DEFAULT_AUDIOLIB},
'sound_freq': {
'name': 'Sampling frequency for synth',
'description': 'Determines the sampling rate of synthesized sounds',
Expand Down Expand Up @@ -194,7 +198,7 @@ def init_sound(experiment):

from psychopy import prefs
prefs.hardware['audioLib'] = [
experiment.var.get('psycho_audiolib', 'sounddevice')]
experiment.var.get('psycho_audiolib', DEFAULT_AUDIOLIB)]
from psychopy import constants
PLAYING = constants.PLAYING
# Fixes a regression in psychopy introduced in
Expand Down

0 comments on commit 8c8140f

Please sign in to comment.