Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
From @cxrodgers 👍 This is a PR for issue #94 This implements multi-channel (e.g., stereo) sound. Some major changes: * The sound classes in autopilot.stim.sound accept a `channel` argument. (Right now, only Noise does this.) If this is `None` (the default), a mono (1-dimensional) sound is produced, exactly as before. If this is 0, a Noise burst only in the first channel is produced. If 1, a Noise burst only in the second channel is produced. * Multi-channel sounds are properly padded to the correct chunk length in Jack_Sound.chunk (implemented here: https://github.com/cxrodgers/autopilot/blob/4dfe9e77687a8a9083ee7903136f99cc7e63671f/autopilot/stim/sound/sounds.py#L223) * The preference OUTCHANNELS is now interpreted differently. If empty string, then plays in mono mode (same sound to all speakers). If a list, connect channels to physical speakers in that order. If an int, treat as a list of length one. (implemented here: https://github.com/cxrodgers/autopilot/blob/4dfe9e77687a8a9083ee7903136f99cc7e63671f/autopilot/stim/sound/jackclient.py#L160) * I removed padding code in the process() function because 1) this should already be done by Jack_Sound.chunk; 2) process probably doesn't have time to do this kind of thing; 3) the padding code was causing errors on multi-channel sounds, would need to be reimplemented as in Jack_Sound.chunk, but see reason number 1. * OUTCHANNELS default in prefs.py changes to empty string (mono mode, no changes to Task code needed). The old default of [1] suggested 1-based indexing and in any case produced essentially mono results. * NCHANNELS deprecated in prefs.py Error are raised if: * The length of OUTCHANNELS is longer than the number of available ports * OUTCHANNELS indicates mono mode, but multi-channel audio is provided * OUTCHANNELS is length N, but M-channel audio is provided, where N != M. However, 1-dimensional (mono) audio can be provided, and this will play to all N speakers. jonny had suggested using None as the OUTCHANNELS flag for "connect no speakers", but [] works for this more naturally. Also, None cannot easily be put into the json. Known issues: * Presently only Noise can produce multi-channel output. Others can only produce mono output, as before. Should be an easy improvement. * Only works for Jack, not pyo! Not tested! * pyo is not tested! * AUDIOSERVER = 'docs' is not tested! * continuous mode is not tested! Tested on: * jackd from APT and (less thoroughly) jackd built from source I know this is a big change, please lmk if changes are requested/needed! * first pass at stereo * doc; remove extra whitespace; reorganize order of imports * doc Noise * doc and reorganize the way Noise is generated * fix typo * intify channel if possible * remove duplicate outports code * typo * handle stereo or mono output * new way of init outports * remove empty lines and comments * doc * move soudn writing code to its own method * cherry pick a commit to init stereo_output, which required a merge on init_logger * fix chunking and padding for multi-channel sound * removing debug statements * reimplement mono sound * fix typo; error messages; use empty string instead of None as mono flag * remove comment * change default of OUTCHANNELS to empty string (mono) * deprecate NCHANNELS * adding test_sound.py * catch ModuleNotFoundError * server_type is not accessible via self * trace out FS; finish test_init_noise * put various durations into test function * flesh out mono and stereo tests * comments * change calling functions to pytest parameterizations * deprecation for prefs * replace SOUND_LIST with autopilot.get, make placeholder Stim metaclass to make it work when audio server is undefined * fix registry with plugin present * warn if jackd server sampling rate doesn't match prefs Co-authored-by: sneakers-the-rat <JLSaunders987@gmail.com>
- Loading branch information