Some bugfixes and useful function additions

This commit is contained in:
Anne de Jong 2022-09-28 09:41:02 +02:00
parent 288e7c8dc5
commit 59085b091f
16 changed files with 805 additions and 195 deletions

View File

@ -1,114 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from lasp import SeriesBiquad\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-03 17:21:46+0200 DebugTrace-cpp 2.0.0a2 (g++ 12.2.0)\n",
"2022-09-03 17:21:46+0200 \n",
"2022-09-03 17:21:46+0200 Enter SeriesBiquad (lasp_biquadbank.cpp: 12)\n",
"2022-09-03 17:21:46+0200 Leave SeriesBiquad (lasp_biquadbank.cpp)\n"
]
}
],
"source": [
"coefs = np.array([1.,0,0,1.,-.9,0])\n",
"bq = SeriesBiquad(coefs)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-03 17:21:47+0200 \n",
"2022-09-03 17:21:47+0200 Enter filter (lasp_biquadbank.cpp: 44)\n",
"2022-09-03 17:21:47+0200 Leave filter (lasp_biquadbank.cpp)\n"
]
}
],
"source": [
"x = np.zeros(10, dtype=float)\n",
"x[0] = 1\n",
"\n",
"x2 = bq.filter(x)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1. ],\n",
" [0.9 ],\n",
" [0.81 ],\n",
" [0.729 ],\n",
" [0.6561 ],\n",
" [0.59049 ],\n",
" [0.531441 ],\n",
" [0.4782969 ],\n",
" [0.43046721],\n",
" [0.38742049]])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

View File

@ -0,0 +1,82 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from lasp import SeriesBiquad\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"coefs = np.array([1.,0,0,1.,-.9,0])\n",
"bq = SeriesBiquad(coefs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x = np.zeros(10, dtype=float)\n",
"x[0] = 1\n",
"\n",
"x2 = bq.filter(x)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"type(x2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

View File

@ -2,6 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "740b4091",
"metadata": {},
"source": [
"# Test DAQ input on a device"
@ -10,6 +11,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ac06df04",
"metadata": {},
"outputs": [],
"source": [
@ -19,6 +21,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ce0dd691",
"metadata": {},
"outputs": [],
"source": [
@ -30,6 +33,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "3cd242a8",
"metadata": {},
"outputs": [],
"source": [
@ -39,18 +43,20 @@
{
"cell_type": "code",
"execution_count": null,
"id": "a5d878e9",
"metadata": {},
"outputs": [],
"source": [
"# Search for a device\n",
"for i, d in enumerate(ds):\n",
" print(f'{i}: ' + d.device_name)\n",
"d = ds[1]"
"d = ds[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a456054e",
"metadata": {},
"outputs": [],
"source": [
@ -61,6 +67,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "6d5b281e",
"metadata": {},
"outputs": [],
"source": [
@ -75,6 +82,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "1ead3995",
"metadata": {},
"outputs": [],
"source": [
@ -85,16 +93,27 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"id": "12db8306",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Start a stream with a configuration\n",
"mgr.startStream(config)"
"mgr.startStream(config)\n",
"\n",
"def cb(data):\n",
" # raise RuntimeError('hh')\n",
" print(data.shape)\n",
"i = lasp.InDataHandler(mgr, cb)\n",
"import time\n",
"#time.sleep(4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4d9f0103",
"metadata": {},
"outputs": [],
"source": [
@ -104,37 +123,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mgr.stopAllStreams()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def cb(data):\n",
" # raise RuntimeError('hh')\n",
" print(data.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"i = lasp.InDataHandler(mgr, cb)\n",
"import time\n",
"#time.sleep(4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "61b7282f",
"metadata": {
"scrolled": true
},
@ -142,13 +131,6 @@
"source": [
"del i"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {

138
examples/test_output.ipynb Normal file
View File

@ -0,0 +1,138 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "740b4091",
"metadata": {},
"source": [
"# Test DAQ output on a device"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ac06df04",
"metadata": {},
"outputs": [],
"source": [
"# !make -j -C ~/wip/mycode/lasp"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ce0dd691",
"metadata": {},
"outputs": [],
"source": [
"import lasp\n",
"# Get handle to stream manager\n",
"mgr = lasp.StreamMgr.getInstance()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3cd242a8",
"metadata": {},
"outputs": [],
"source": [
"ds = mgr.getDeviceInfo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a5d878e9",
"metadata": {},
"outputs": [],
"source": [
"# Search for a device\n",
"for i, d in enumerate(ds):\n",
" print(f'{i}: ' + d.device_name)\n",
"d = ds[1]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6d5b281e",
"metadata": {},
"outputs": [],
"source": [
"# Create a configuration and enable some input channels\n",
"config = lasp.DaqConfiguration(d)\n",
"config.outchannel_config[0].enabled = True\n",
"config.outchannel_config[1].enabled = True\n",
"config.setAllInputEnabled(False)\n",
"# Choose a different number of frames per block\n",
"config.framesPerBlockIndex = 4"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1ead3995",
"metadata": {},
"outputs": [],
"source": [
"print('Out channels:',d.noutchannels)\n",
"print('In channels:',d.ninchannels)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12db8306",
"metadata": {},
"outputs": [],
"source": [
"# Start a stream with a configuration\n",
"mgr.startStream(config)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da5e8b81-bcd6-4587-8f59-74811a263eee",
"metadata": {},
"outputs": [],
"source": [
"siggen = lasp.Sine(1000)\n",
"siggen.setLevel(-20)\n",
"mgr.setSiggen(siggen)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4d9f0103",
"metadata": {},
"outputs": [],
"source": [
"mgr.stopStream(lasp.StreamMgr.StreamType.output)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

506
examples/test_record.ipynb Normal file
View File

@ -0,0 +1,506 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "2406f830",
"metadata": {},
"source": [
"# Test DAQ input on a device"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "e3d3280f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"make: Entering directory '/home/anne/wip/mycode/lasp'\n",
"make[1]: Entering directory '/home/anne/wip/mycode/lasp'\n",
"make[2]: Entering directory '/home/anne/wip/mycode/lasp'\n",
"make[2]: Leaving directory '/home/anne/wip/mycode/lasp'\n",
"[ 42%] Built target lasp_dsp_lib\n",
"make[2]: Entering directory '/home/anne/wip/mycode/lasp'\n",
"make[2]: Leaving directory '/home/anne/wip/mycode/lasp'\n",
"[ 67%] Built target lasp_device_lib\n",
"make[2]: Entering directory '/home/anne/wip/mycode/lasp'\n",
"make[2]: Leaving directory '/home/anne/wip/mycode/lasp'\n",
"[100%] Built target lasp_cpp\n",
"make[1]: Leaving directory '/home/anne/wip/mycode/lasp'\n",
"make: Leaving directory '/home/anne/wip/mycode/lasp'\n"
]
}
],
"source": [
" !make -j -C ~/wip/mycode/lasp"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d12f103c",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-27 22:08:01+0200 DebugTrace-cpp 2.0.0a2 (g++ 12.2.0)\n",
"2022-09-27 22:08:01+0200 \n",
"2022-09-27 22:08:01+0200 Enter getInstance (lasp_streammgr.cpp: 40)\n",
"2022-09-27 22:08:01+0200 | Enter StreamMgr (lasp_streammgr.cpp: 45)\n",
"2022-09-27 22:08:01+0200 | | Enter rescanDAQDevices (lasp_streammgr.cpp: 60)\n",
"2022-09-27 22:08:01+0200 | | | Enter rescanDAQDevices_impl (lasp_streammgr.cpp: 80)\n",
"2022-09-27 22:08:01+0200 | | | | Enter fillRtAudioDeviceInfo (lasp_rtaudiodaq.cpp: 20)\n",
"\n",
"RtApiAlsa::getDeviceInfo: snd_pcm_open error for device (hw:1,0), Device or resource busy.\n",
"\n",
"2022-09-27 22:08:01+0200 | | | | Leave fillRtAudioDeviceInfo (lasp_rtaudiodaq.cpp)\n",
"2022-09-27 22:08:01+0200 | | | Leave rescanDAQDevices_impl (lasp_streammgr.cpp)\n",
"2022-09-27 22:08:01+0200 | | Leave rescanDAQDevices (lasp_streammgr.cpp)\n",
"2022-09-27 22:08:01+0200 | Leave StreamMgr (lasp_streammgr.cpp)\n",
"2022-09-27 22:08:01+0200 Leave getInstance (lasp_streammgr.cpp)\n"
]
}
],
"source": [
"import lasp\n",
"# Get handle to stream manager\n",
"mgr = lasp.StreamMgr.getInstance()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f44b1946",
"metadata": {},
"outputs": [],
"source": [
"ds = mgr.getDeviceInfo()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "db0f3bb7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0: Monitor of Starship/Matisse HD Audio Controller Analog Stereo\n",
"1: Starship/Matisse HD Audio Controller Analog Stereo\n",
"2: GP108 High Definition Audio Controller Digital Stereo (HDMI)\n",
"3: Monitor of GP108 High Definition Audio Controller Digital Stereo (HDMI)\n",
"4: default\n",
"5: hw:HDA NVidia,3\n",
"6: hw:HDA NVidia,7\n",
"7: hw:HDA NVidia,8\n",
"8: hw:HDA NVidia,9\n",
"9: hw:HDA NVidia,10\n",
"10: hw:HD-Audio Generic,0\n",
"11: hw:HD-Audio Generic,1\n",
"12: hw:HD-Audio Generic,2\n"
]
}
],
"source": [
"# Search for a device\n",
"for i, d in enumerate(ds):\n",
" print(f'{i}: ' + d.device_name)\n",
"d = ds[0]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f97c13d5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[512, 1024, 2048, 4096, 8192]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Check the available block sizes\n",
"d.availableFramesPerBlock"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "5c84d454",
"metadata": {},
"outputs": [],
"source": [
"# Create a configuration and enable some input channels\n",
"config = lasp.DaqConfiguration(d)\n",
"config.inchannel_config[0].enabled = True\n",
"config.inchannel_config[1].enabled = True\n",
"# Choose a different number of frames per block\n",
"config.framesPerBlockIndex = 4"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "a020f86f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Out channels: 0\n",
"In channels: 2\n"
]
}
],
"source": [
"print('Out channels:',d.noutchannels)\n",
"print('In channels:',d.ninchannels)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "034b5f5e",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-27 22:08:02+0200 \n",
"2022-09-27 22:08:02+0200 Enter startStream (lasp_streammgr.cpp: 209)\n",
"2022-09-27 22:08:02+0200 | Enter createDaq (lasp_daq.cpp: 18)\n",
"2022-09-27 22:08:02+0200 | | Enter Daq (lasp_daq.cpp: 37)\n",
"2022-09-27 22:08:02+0200 | | Leave Daq (lasp_daq.cpp)\n",
"2022-09-27 22:08:02+0200 | | \n",
"2022-09-27 22:08:02+0200 | | Enter RtAudioDaq (lasp_rtaudiodaq.cpp: 135)\n",
"2022-09-27 22:08:02+0200 | | | Enter samplerate (lasp_daq.cpp: 58)\n",
"2022-09-27 22:08:02+0200 | | | Leave samplerate (lasp_daq.cpp)\n",
"2022-09-27 22:08:02+0200 | | Leave RtAudioDaq (lasp_rtaudiodaq.cpp)\n",
"2022-09-27 22:08:02+0200 | Leave createDaq (lasp_daq.cpp)\n",
"2022-09-27 22:08:02+0200 | isInput = true\n",
"2022-09-27 22:08:02+0200 | isOutput = false\n",
"2022-09-27 22:08:02+0200 | \n",
"2022-09-27 22:08:02+0200 | Enter start (lasp_rtaudiodaq.cpp: 215)\n",
"2022-09-27 22:08:02+0200 | Leave start (lasp_rtaudiodaq.cpp)\n",
"2022-09-27 22:08:02+0200 Leave startStream (lasp_streammgr.cpp)\n"
]
}
],
"source": [
"# Start a stream with a configuration\n",
"mgr.startStream(config)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "59326eda-f249-4a9b-9191-a784b01694b9",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-27 22:08:02+0200 \n",
"2022-09-27 22:08:02+0200 Enter InDataHandler (lasp_streammgr.cpp: 14)\n",
"2022-09-27 22:08:02+0200 Leave InDataHandler (lasp_streammgr.cpp)\n",
"2022-09-27 22:08:02+0200 \n",
"2022-09-27 22:08:02+0200 Enter ThreadedInDataHandler (lasp_threadedindatahandler.cpp: 13)\n",
"2022-09-27 22:08:02+0200 Leave ThreadedInDataHandler (lasp_threadedindatahandler.cpp)\n",
"2022-09-27 22:08:02+0200 \n",
"2022-09-27 22:08:02+0200 Enter PyIndataHandler (lasp_pyindatahandler.cpp: 78)\n",
"2022-09-27 22:08:02+0200 | Enter start (lasp_streammgr.cpp: 16)\n",
"2022-09-27 22:08:02+0200 | Leave start (lasp_streammgr.cpp)\n",
"2022-09-27 22:08:02+0200 Leave PyIndataHandler (lasp_pyindatahandler.cpp)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"."
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-27 22:08:02+0200 \n",
"2022-09-27 22:08:02+0200 Enter samplerate (lasp_daq.cpp: 58)\n",
"2022-09-27 22:08:02+0200 Leave samplerate (lasp_daq.cpp)\n",
"2022-09-27 22:08:02+0200 \n",
"2022-09-27 22:08:02+0200 Enter samplerate (lasp_daq.cpp: 58)\n",
"2022-09-27 22:08:02+0200 Leave samplerate (lasp_daq.cpp)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
".....1....2.....3....4....5.....6....7.....8....9....10"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-27 22:08:12+0200 \n",
"2022-09-27 22:08:12+0200 Enter ~PyIndataHandler (lasp_pyindatahandler.cpp: 87)\n",
"2022-09-27 22:08:12+0200 Leave ~PyIndataHandler (lasp_pyindatahandler.cpp)\n",
"2022-09-27 22:08:12+0200 \n",
"2022-09-27 22:08:12+0200 Enter ~ThreadedInDataHandler (lasp_threadedindatahandler.cpp: 38)\n",
"2022-09-27 22:08:12+0200 Leave ~ThreadedInDataHandler (lasp_threadedindatahandler.cpp)\n",
"2022-09-27 22:08:12+0200 \n",
"2022-09-27 22:08:12+0200 Enter ~InDataHandler (lasp_streammgr.cpp: 27)\n",
"2022-09-27 22:08:12+0200 Leave ~InDataHandler (lasp_streammgr.cpp)\n"
]
}
],
"source": [
"rec = lasp.Recording('test', mgr, 10.0)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "5defa804",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-27 22:08:12+0200 \n",
"2022-09-27 22:08:12+0200 Enter stopStream (lasp_streammgr.cpp: 287)\n",
"2022-09-27 22:08:12+0200 | Enter ~Daq (lasp_daq.cpp: 14)\n",
"2022-09-27 22:08:12+0200 | Leave ~Daq (lasp_daq.cpp)\n",
"2022-09-27 22:08:12+0200 Leave stopStream (lasp_streammgr.cpp)\n"
]
}
],
"source": [
"mgr.stopStream(lasp.StreamMgr.StreamType.input)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "d12f8c4a",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-27 22:08:12+0200 \n",
"2022-09-27 22:08:12+0200 Enter stopAllStreams (lasp_streammgr.cpp: 202)\n",
"2022-09-27 22:08:12+0200 Leave stopAllStreams (lasp_streammgr.cpp)\n"
]
}
],
"source": [
"mgr.stopAllStreams()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "83b1713b",
"metadata": {},
"outputs": [],
"source": [
"def cb(data):\n",
" # raise RuntimeError('hh')\n",
" print(data.shape)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "ff7c1e03",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-27 22:08:12+0200 \n",
"2022-09-27 22:08:12+0200 Enter InDataHandler (lasp_streammgr.cpp: 14)\n",
"2022-09-27 22:08:12+0200 Leave InDataHandler (lasp_streammgr.cpp)\n",
"2022-09-27 22:08:12+0200 \n",
"2022-09-27 22:08:12+0200 Enter ThreadedInDataHandler (lasp_threadedindatahandler.cpp: 13)\n",
"2022-09-27 22:08:12+0200 Leave ThreadedInDataHandler (lasp_threadedindatahandler.cpp)\n",
"2022-09-27 22:08:12+0200 \n",
"2022-09-27 22:08:12+0200 Enter PyIndataHandler (lasp_pyindatahandler.cpp: 78)\n",
"2022-09-27 22:08:12+0200 | Enter start (lasp_streammgr.cpp: 16)\n",
"2022-09-27 22:08:12+0200 | Leave start (lasp_streammgr.cpp)\n",
"2022-09-27 22:08:12+0200 Leave PyIndataHandler (lasp_pyindatahandler.cpp)\n"
]
}
],
"source": [
"i = lasp.InDataHandler(mgr, cb)\n",
"import time\n",
"#time.sleep(4)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "9ba54238",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-27 22:08:12+0200 \n",
"2022-09-27 22:08:12+0200 Enter ~PyIndataHandler (lasp_pyindatahandler.cpp: 87)\n",
"2022-09-27 22:08:12+0200 Leave ~PyIndataHandler (lasp_pyindatahandler.cpp)\n",
"2022-09-27 22:08:12+0200 \n",
"2022-09-27 22:08:12+0200 Enter ~ThreadedInDataHandler (lasp_threadedindatahandler.cpp: 38)\n",
"2022-09-27 22:08:12+0200 Leave ~ThreadedInDataHandler (lasp_threadedindatahandler.cpp)\n",
"2022-09-27 22:08:12+0200 \n",
"2022-09-27 22:08:12+0200 Enter ~InDataHandler (lasp_streammgr.cpp: 27)\n",
"2022-09-27 22:08:12+0200 Leave ~InDataHandler (lasp_streammgr.cpp)\n"
]
}
],
"source": [
"del i"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "0f0edc36",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"numpy.ndarray"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"a = np.array([1,2,3])\n",
"type(a)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "ee546114-a879-4ebe-a6eb-e2354b2247fd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dtype('int64')"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a.dtype"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "5d033d6d-3052-42ce-9441-faa917ece6a9",
"metadata": {},
"outputs": [],
"source": [
"from lasp import DaqChannel"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "bb99ec99-b921-4fb2-bd79-87db8dfcdb03",
"metadata": {},
"outputs": [],
"source": [
"d = DaqChannel()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "ad67d273-45aa-4358-9405-de5924f087a2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d.qty.value"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "53ab5c8f-f904-4f9f-b591-6a5dd1581ddd",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@ -86,6 +86,13 @@ int DaqConfiguration::getLowestOutChannel() const {
}
return -1;
}
vector<DaqChannel> DaqConfiguration::enabledInChannels() const {
vector<DaqChannel> res;
for(auto& ch: inchannel_config) {
if(ch.enabled) { res.push_back(ch);}
}
return res;
}
#include "toml++/toml.h"
#include <sstream>

View File

@ -234,6 +234,14 @@ public:
*/
std::vector<DaqChannel> inchannel_config;
/**
* @brief Return list of enabled input channels
*
* @return That.
*/
std::vector<DaqChannel> enabledInChannels() const;
/**
* @brief Channel configuration for output channels
*/

View File

@ -267,7 +267,7 @@ public:
unsigned int nFrames, double streamTime,
RtAudioStreamStatus status) {
DEBUGTRACE_ENTER;
/* DEBUGTRACE_ENTER; */
using se = StreamStatus::StreamError;

View File

@ -91,9 +91,11 @@ bool StreamMgr::inCallback(const DaqData &data) {
std::scoped_lock<std::mutex> lck(_inDataHandler_mtx);
for (auto &handler : _inDataHandlers) {
bool res = handler->inCallback(data);
if (!res)
return false;
}
return true;
}

View File

@ -32,7 +32,7 @@ class Atomic:
self._lock = Lock()
def checkType(self, val):
if not (type(val) == bool | type(val) == int):
if not (type(val) == bool or type(val) == int):
raise RuntimeError("Invalid type for Atomic")
def __iadd__(self, toadd):

View File

@ -8,6 +8,7 @@ import logging
import os
import time
import h5py
import numpy as np
from .lasp_cpp import InDataHandler, StreamMgr
from .lasp_atomic import Atomic
@ -108,11 +109,14 @@ class Recording:
and make ready for storing data.
"""
daq = self.smgr.getDaq(StreamMgr.StreamType.input)
dtype = daq.dtype()
in_ch = daq.inchannel_config
in_ch = daq.enabledInChannels()
blocksize = daq.framesPerBlock()
self.blocksize = blocksize
# The array data type cannot
# datatype = daq.dataType()
dtype = np.dtype(data.dtype)
f = self.f
# Set the bunch of attributes
@ -129,7 +133,7 @@ class Recording:
nchannels = len(in_ch)
self.ad = f.create_dataset('audio',
(1, blocksize, nchannels),
dtype=data.dtype,
dtype=dtype,
maxshape=(
None, # This means, we can add blocks
# indefinitely
@ -144,7 +148,7 @@ class Recording:
# In V2, we do not store JSON metadata anymore, but just an enumeration
# index to a physical quantity.
f.attrs['qtys_idx'] = [ch.qty for ch in in_ch]
f.attrs['qtys_enum_idx'] = [ch.qty.value for ch in in_ch]
def inCallback(self, adata):
"""
@ -161,7 +165,7 @@ class Recording:
self.firstFrames(adata)
self.__addTimeData(adata)
return True
def setDelete(self, val: bool):
"""
@ -177,17 +181,12 @@ class Recording:
remove the queue from the stream, etc.
"""
assert self.stop() == True
self.stop <<= True
logging.debug('Recording::finish()')
smgr = self.smgr
# Remove indata handler
self.indh = None
# TODO: Fix when video
# if smgr.hasVideo():
# smgr.removeCallback(self.vCallback, AvType.video_input)
# self.f['video_frame_positions'] = self.video_frame_positions
try:
# Close the recording file
self.f.close()
@ -217,7 +216,7 @@ class Recording:
# Stop flag is raised. We stop recording here.
return
curT = self.ablockno*self.blocksize/self.fs
curT = self.ablockno()*self.blocksize/self.fs
# Increase the block counter
self.ablockno += 1
@ -230,9 +229,10 @@ class Recording:
self.startDelay_passed = True
# Reset the audio block counter and the recording time
self.ablockno = 1
self.ablockno = Atomic(1)
curT = 0
ablockno = self.ablockno()
recstatus = RecordStatus(
curT=curT,
done=False)
@ -252,10 +252,10 @@ class Recording:
if self.progressCallback is not None:
recstatus.done = True
self.progressCallback(recstatus)
self.stop << True
self.stop <<= True
return
# Add the data to the file, and resize the audio data blocks
self.ad.resize(self.ablockno, axis=0)
self.ad[self.ablockno-1, :, :] = indata
self.ad.resize(ablockno, axis=0)
self.ad[ablockno-1, :, :] = indata

View File

@ -32,7 +32,7 @@ void init_daq(py::module &m) {
ss.def("errorMsg", &Daq::StreamStatus::errorMsg);
/// Daq
daq.def("neninchannels", &Daq::neninchannels);
daq.def("neninchannels", &Daq::neninchannels, py::arg("include_monitor") = true);
daq.def("nenoutchannels", &Daq::nenoutchannels);
daq.def("samplerate", &Daq::samplerate);
daq.def("dataType", &Daq::dataType);

View File

@ -93,4 +93,5 @@ void init_daqconfiguration(py::module &m) {
&DaqConfiguration::outchannel_config);
daqconfig.def("setAllInputEnabled", &DaqConfiguration::setAllInputEnabled);
daqconfig.def("setAllOutputEnabled", &DaqConfiguration::setAllOutputEnabled);
daqconfig.def("enabledInChannels", &DaqConfiguration::enabledInChannels);
}

View File

@ -48,7 +48,7 @@ template <typename T> py::array_t<T> getPyArray(const DaqData &d) {
return py::array_t<T>(
py::array::ShapeContainer({d.nframes, d.nchannels}), // Shape
py::array::StridesContainer( // Strides
py::array::StridesContainer( // Strides
{sizeof(T),
sizeof(T) * d.nframes}), // Strides (in bytes) for each index
@ -99,37 +99,34 @@ public:
py::gil_scoped_acquire acquire;
try {
py::array binfo;
py::object bool_val;
switch (d.dtype) {
case (DataType::dtype_int8):
binfo = getPyArray<int8_t>(d);
break;
case (DataType::dtype_int16):
binfo = getPyArray<int16_t>(d);
break;
case (DataType::dtype_int32):
binfo = getPyArray<int32_t>(d);
break;
case (DataType::dtype_fl32):
binfo = getPyArray<float>(d);
break;
case (DataType::dtype_fl64):
binfo = getPyArray<double>(d);
break;
case (DataType::dtype_int8): {
bool_val = cb(getPyArray<int8_t>(d));
} break;
case (DataType::dtype_int16): {
bool_val = cb(getPyArray<int16_t>(d));
} break;
case (DataType::dtype_int32): {
bool_val = cb(getPyArray<int32_t>(d));
} break;
case (DataType::dtype_fl32): {
bool_val = cb(getPyArray<float>(d));
} break;
case (DataType::dtype_fl64): {
bool_val = cb(getPyArray<double>(d));
} break;
default:
throw std::runtime_error("BUG");
} // End of switch
py::object bool_val = cb(binfo);
bool res = bool_val.cast<bool>();
if (!res)
return false;
} catch (py::error_already_set &e) {
cerr << "ERROR: Python raised exception from callback function: ";
cerr << e.what() << endl;
return false;
} catch (py::cast_error &e) {
cerr << e.what() << endl;
cerr << "ERROR: Python callback does not return boolean value." << endl;

View File

@ -30,4 +30,5 @@ void init_streammgr(py::module &m) {
smgr.def("getStreamStatus", &StreamMgr::getStreamStatus);
smgr.def("isStreamRunningOK", &StreamMgr::isStreamRunningOK);
smgr.def("isStreamRunning", &StreamMgr::isStreamRunning);
smgr.def("getDaq", &StreamMgr::getDaq, py::return_value_policy::reference);
}