-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a sample non-OL dynamic random experiment
flyvr.exe --config rig.yml -p playlists\audio_daq_paused.yml -e experiments\paired_random_audio_daq.py this starts a python experiment which randomly chooses corresponding pairs (in the order they were written in the playlist) from the audio and daq backend, and plays them simultaenously. note: the rig.yml configuration file should have * the audio_in and audio_out channels defined * you should disable the next signaling with remote_2P_next_disable
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import time | ||
import random | ||
|
||
from flyvr.control.experiment import Experiment | ||
|
||
# this experiment randomly chooses only corresponding playlist items across | ||
# the audio and daq backend. for example, if the daq playlist as items with | ||
# identifiers 'd1', 'd2', 'd3', and 'd4', and the audio playlist has items | ||
# with identifiers 'a1', 'a2', and 'a3', then every SWITCH_SECONDS we random | ||
# choose to play simultaneously only (`d1' and 'a1'), ('d2' and 'a2'), or | ||
# ('d3' and 'a3') | ||
|
||
SWITCH_SECONDS = 5 | ||
|
||
|
||
class _MyExperiment(Experiment): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self._exp_started = False | ||
self._last_switch = None | ||
self._n_common_playlist_items = 0 | ||
|
||
def process_state(self, state): | ||
if self._exp_started: | ||
t = time.time() | ||
if (t - self._last_switch) > SWITCH_SECONDS: | ||
idx = random.randint(0, self._n_common_playlist_items - 1) | ||
|
||
item_daq = self.configured_playlist_items[Experiment.BACKEND_DAQ][idx] | ||
self.play_playlist_item(Experiment.BACKEND_DAQ, item_daq) | ||
item_audio = self.configured_playlist_items[Experiment.BACKEND_AUDIO][idx] | ||
self.play_playlist_item(Experiment.BACKEND_AUDIO, item_audio) | ||
|
||
self.log.info('switched to daq:%s and audio:%s' % (item_daq, item_audio)) | ||
|
||
self._last_switch = t | ||
else: | ||
if self.is_started() and \ | ||
self.is_backend_ready(Experiment.BACKEND_AUDIO) and \ | ||
self.is_backend_ready(Experiment.BACKEND_DAQ): | ||
self._exp_started = True | ||
self._last_switch = time.time() - SWITCH_SECONDS # switch next loop | ||
|
||
self._n_common_playlist_items = min(len(self.configured_playlist_items[Experiment.BACKEND_DAQ]), | ||
len(self.configured_playlist_items[Experiment.BACKEND_AUDIO])) | ||
assert self._n_common_playlist_items > 0 | ||
|
||
|
||
experiment = _MyExperiment() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
playlist: | ||
daq: | ||
- _options: {random_mode: 'none', paused: true} | ||
- sq20hz: {name: 'square', sample_rate: 10000, duration: 1000, pre_silence: 0, post_silence: 500, attenuator: null, frequency: 20, max_value: 10.0, min_value: -10.0, amplitude: 2.0, phase: 0.0} | ||
- sq40hz: {name: 'square', sample_rate: 10000, duration: 1000, pre_silence: 0, post_silence: 500, attenuator: null, frequency: 40, max_value: 10.0, min_value: -10.0, amplitude: 4.0, phase: 0.0} | ||
- sq60hz: {name: 'square', sample_rate: 10000, duration: 1000, pre_silence: 0, post_silence: 500, attenuator: null, frequency: 60, max_value: 10.0, min_value: -10.0, amplitude: 6.0, phase: 0.0} | ||
- sq80hz: {name: 'square', sample_rate: 10000, duration: 1000, pre_silence: 0, post_silence: 500, attenuator: null, frequency: 80, max_value: 10.0, min_value: -10.0, amplitude: 8.0, phase: 0.0} | ||
audio: | ||
- _options: {random_mode: 'none', paused: true} | ||
- sin200hz: {name: 'sin', sample_rate: 44100, duration: 1000, pre_silence: 0, post_silence: 500, attenuator: null, frequency: 200, max_value: 10.0, min_value: -10.0, amplitude: 1.0, phase: 0.0} | ||
- sin400hz: {name: 'sin', sample_rate': 44100, duration: 1000, pre_silence: 0, post_silence: 500, attenuator: null, frequency: 400, max_value: 10.0, min_value: -10.0, amplitude: 1.0, phase: 0.0} | ||
- sin600hz: {name: 'sin', sample_rate: 44100, duration: 1000, pre_silence: 0, post_silence: 500, attenuator: null, frequency: 600, max_value: 10.0, min_value: -10.0, amplitude: 1.0, phase: 0.0} | ||
- sin800hz: {name: 'sin', sample_rate: 44100, duration: 1000, pre_silence: 0, post_silence: 500, attenuator: null, frequency: 800, max_value: 10.0, min_value: -10.0, amplitude: 1.0, phase: 0.0} |