소스 검색

updates to SIT -PR

asobolev 1 년 전
부모
커밋
88517366f7
4개의 변경된 파일135개의 추가작업 그리고 93개의 파일을 삭제
  1. 6 27
      SIT-PR.ipynb
  2. 28 45
      SIT.ipynb
  3. 76 11
      controllers/sound.ipynb
  4. 25 10
      controllers/sound.py

+ 6 - 27
SIT-PR.ipynb

@@ -57,7 +57,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "cfg_filename = os.path.join('profiles', 'default_PR.json')"
+    "cfg_filename = os.path.join('profiles', 'valentin_PR_experiment.json')"
    ]
   },
   {
@@ -205,17 +205,14 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": null,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "Webcam stream 1024.0:768.0 at 30.00 FPS started\n",
-      "Position tracker stopped\n",
-      "Video writer stopped\n",
-      "Camera released\n"
+      "Webcam stream 1024.0:768.0 at 30.00 FPS started\n"
      ]
     }
    ],
@@ -482,7 +479,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 11,
+   "execution_count": null,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -493,27 +490,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 12,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "ename": "SystemExit",
-     "evalue": "Nothing recorded. No sense to continue.",
-     "output_type": "error",
-     "traceback": [
-      "An exception has occurred, use %tb to see the full traceback.\n",
-      "\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m Nothing recorded. No sense to continue.\n"
-     ]
-    },
-    {
-     "name": "stderr",
-     "output_type": "stream",
-     "text": [
-      "C:\\Users\\inhibition\\.conda\\envs\\runsit\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3445: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n",
-      "  warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "if not trial > 0:\n",
     "    raise SystemExit('Nothing recorded. No sense to continue.')\n",

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 28 - 45
SIT.ipynb


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 76 - 11
controllers/sound.ipynb


+ 25 - 10
controllers/sound.py

@@ -5,7 +5,7 @@ from functools import reduce
 
 import os
 import threading
-
+import random
 
 class SoundController:
     # https://python-sounddevice.readthedocs.io/en/0.3.15/api/streams.html#sounddevice.OutputStream
@@ -230,23 +230,38 @@ class SoundControllerPR:
         noise = noise.astype(np.float32)
 
         # target (not assigned to channels)
-        snd = cfg['sounds']['target']
-        target = SoundController.get_pure_tone(snd['freq'], snd['duration'], cfg['sample_rate']) * cfg['volume']
-        target = target * SoundController.get_cos_window(target, 0.01, cfg['sample_rate'])  # onset / offset
-        target = target * snd['amp']  # amplitude
+        sample_rate = cfg['sample_rate']
+        target_cfg = cfg['sounds']['target']
+
+        tone = SoundController.get_pure_tone(target_cfg['freq'], target_cfg['duration'], sample_rate=cfg['sample_rate'])
+        tone = tone * SoundController.get_cos_window(tone, target_cfg['window'], sample_rate=cfg['sample_rate'])
+
+        if target_cfg['number'] > 1:
+            silence = np.zeros( int(target_cfg['iti'] * cfg['sample_rate']) )
+            tone_with_iti = np.concatenate([tone, silence])
+            target = np.concatenate([tone_with_iti for i in range(target_cfg['number'] - 1)])
+            target = np.concatenate([target, tone])
+        else:
+            target = tone
+            
+        target = target * target_cfg['amp']  # amplitude
+       
+        #snd = cfg['sounds']['target']
+        #target = SoundController.get_pure_tone(snd['freq'], snd['duration'], cfg['sample_rate']) * cfg['volume']
+        #target = target * SoundController.get_cos_window(target, 0.01, cfg['sample_rate'])  # onset / offset
+        #target = target * snd['amp']  # amplitude
         
         self.sounds = {'noise': noise, 'target': target}
         
     def target(self, hd_angle):
-        # TODO define which speakers should play
-        speaker1, speaker2 = 1, 8
         to_play = np.zeros((len(self.sounds['target']), self.cfg['n_channels']), dtype='float32')
-        for ch in (speaker1, speaker2):
-            to_play[:, ch-1] = self.sounds['target']
+        channel = random.choice(self.cfg['sounds']['target']['channels'])  # random speaker!
+        
+        to_play[:, channel-1] = self.sounds['target']
             
         t0 = time.time()
         with open(self.cfg['file_path'], 'a') as f:
-            f.write(",".join([str(x) for x in (t0, 2, speaker1, speaker2)]) + "\n")
+            f.write(",".join([str(x) for x in (t0, 2, channel)]) + "\n")
         
         self.stream.write(to_play)