Quellcode durchsuchen

fixes to sound controllers

Andrey Sobolev vor 1 Jahr
Ursprung
Commit
562e801e81
1 geänderte Dateien mit 55 neuen und 6 gelöschten Zeilen
  1. 55 6
      controllers/sound.ipynb

+ 55 - 6
controllers/sound.ipynb

@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": 16,
    "metadata": {},
    "outputs": [
     {
@@ -165,6 +165,7 @@
     "                time.sleep(0.05)\n",
     "                \n",
     "        stream.stop()\n",
+    "        stream.close()\n",
     "        print('Sound stopped')\n",
     "\n",
     "        \n",
@@ -207,6 +208,7 @@
     "            self.stream.write(self.data[start_idx:end_idx])\n",
     "            \n",
     "        self.stream.stop()\n",
+    "        self.stream.close()\n",
     "        \n",
     "        \n",
     "class SoundControllerPR:\n",
@@ -305,7 +307,8 @@
     "    def stop(self):\n",
     "        for t in self.timers:\n",
     "            t.cancel()\n",
-    "        self.stream.stop()"
+    "        self.stream.stop()\n",
+    "        self.stream.close()"
    ]
   },
   {
@@ -376,16 +379,62 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": 6,
    "metadata": {},
    "outputs": [],
    "source": [
-    "sc = SoundControllerPR(1, SoundControllerPR.default_cfg)"
+    "sound_cfg = {\n",
+    "    \"device\": [1, 24],\n",
+    "    \"n_channels\": 14,\n",
+    "    \"sounds\": {\n",
+    "        \"noise\": {\"amp\": 0.3, \"duration\": 5.0, \"channels\": [9]},\n",
+    "        \"target\": {\"freq\": 660, \"amp\": 0.3, \"duration\": 0.015, \"window\": 0.005, \"iti\": 0.1, \"number\": 10, \"channels\": [5]}\n",
+    "    },\n",
+    "    \"sample_rate\": 44100,\n",
+    "    \"volume\": 0.1,\n",
+    "    \"file_path\": \"sounds.csv\"\n",
+    "}"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 12,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "True"
+      ]
+     },
+     "execution_count": 12,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "sc.stream.stopped"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 14,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "sc = SoundControllerPR(1, sound_cfg)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -394,7 +443,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": 5,
    "metadata": {},
    "outputs": [],
    "source": [