Bläddra i källkod

updates to SIT -PR

asobolev 1 år sedan
förälder
incheckning
88517366f7
4 ändrade filer med 135 tillägg och 93 borttagningar
  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",

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 28 - 45
SIT.ipynb


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 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)