lasp/examples/test_record.ipynb

507 lines
14 KiB
Plaintext

{
"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
}