2019-12-18 09:02:20 +00:00
|
|
|
#!/usr/bin/python3
|
2018-07-31 11:09:42 +00:00
|
|
|
import argparse
|
2019-12-18 09:02:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-31 11:09:42 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='Acquire data and store a measurement file'
|
|
|
|
)
|
|
|
|
parser.add_argument('filename', type=str,
|
|
|
|
help='File name to record to.'
|
|
|
|
' Extension is automatically added.')
|
|
|
|
parser.add_argument('--duration', '-d', type=float,
|
|
|
|
help='The recording duration in [s]')
|
2018-09-13 11:56:05 +00:00
|
|
|
|
|
|
|
device_help = 'DAQ Device to record from'
|
2018-12-28 12:55:09 +00:00
|
|
|
parser.add_argument('--input-daq', '-i', help=device_help, type=str,
|
2019-12-18 09:02:20 +00:00
|
|
|
default='Default')
|
2018-09-13 11:56:05 +00:00
|
|
|
|
2018-07-31 11:09:42 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2019-10-27 13:19:26 +00:00
|
|
|
|
2019-12-18 09:02:20 +00:00
|
|
|
from lasp.lasp_avstream import AvStream
|
|
|
|
from lasp.lasp_record import Recording
|
|
|
|
from lasp.device import DAQConfiguration, RtAudio
|
2019-10-27 13:19:26 +00:00
|
|
|
|
2019-12-18 09:02:20 +00:00
|
|
|
config = DAQConfiguration.loadConfigs()[args.input_daq]
|
2019-10-27 13:19:26 +00:00
|
|
|
|
2019-12-18 09:02:20 +00:00
|
|
|
print(config)
|
|
|
|
rtaudio = RtAudio()
|
|
|
|
count = rtaudio.getDeviceCount()
|
|
|
|
devices = [rtaudio.getDeviceInfo(i) for i in range(count)]
|
|
|
|
|
|
|
|
input_devices = {}
|
|
|
|
for device in devices:
|
|
|
|
if device.inputchannels >= 0:
|
|
|
|
input_devices[device.name] = device
|
|
|
|
|
|
|
|
try:
|
|
|
|
input_device = input_devices[config.input_device_name]
|
|
|
|
except KeyError:
|
|
|
|
raise RuntimeError(f'Input device {config.input_device_name} not available')
|
2019-10-27 13:19:26 +00:00
|
|
|
|
2019-12-18 09:02:20 +00:00
|
|
|
print(input_device)
|
|
|
|
|
|
|
|
stream = AvStream(rtaudio,
|
|
|
|
None, # No output device
|
|
|
|
input_device,
|
|
|
|
config)
|
2018-09-13 11:56:05 +00:00
|
|
|
|
2018-07-31 11:09:42 +00:00
|
|
|
rec = Recording(args.filename, stream, args.duration)
|
|
|
|
rec.start()
|
2019-12-18 09:02:20 +00:00
|
|
|
|
|
|
|
print('Stopping stream...')
|
2018-07-31 11:09:42 +00:00
|
|
|
stream.stop()
|
2019-12-18 09:02:20 +00:00
|
|
|
|
|
|
|
print('Stream stopped')
|
|
|
|
print('Closing stream...')
|
|
|
|
stream.close()
|
|
|
|
print('Stream closed')
|