Merge branch 'develop' into channel_metadata
This commit is contained in:
commit
3e2e8c8953
@ -71,7 +71,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
|||||||
link_directories(C:\\mingw\\lib)
|
link_directories(C:\\mingw\\lib)
|
||||||
link_directories(C:\\mingw\\bin)
|
link_directories(C:\\mingw\\bin)
|
||||||
link_directories(..\\rtaudio)
|
link_directories(..\\rtaudio)
|
||||||
link_directories(C:\\Users\\librewin7\\Miniconda3)
|
link_directories(C:\\Users\\User\\Miniconda3)
|
||||||
else()
|
else()
|
||||||
set(win32 false)
|
set(win32 false)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -std=c11 \
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -std=c11 \
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
Description: Read data from image stream and record sound at the same time
|
Description: Read data from image stream and record sound at the same time
|
||||||
"""
|
"""
|
||||||
import cv2 as cv
|
#import cv2 as cv
|
||||||
from .lasp_atomic import Atomic
|
from .lasp_atomic import Atomic
|
||||||
from threading import Thread, Condition, Lock
|
from threading import Thread, Condition, Lock
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -73,7 +73,7 @@ class AvStream:
|
|||||||
rtaudio_inputparams = None
|
rtaudio_inputparams = None
|
||||||
rtaudio_outputparams = None
|
rtaudio_outputparams = None
|
||||||
|
|
||||||
self.nframes_per_block = 512
|
self.nframes_per_block = 1024
|
||||||
|
|
||||||
if self.duplex_mode or avtype == AvType.audio_output:
|
if self.duplex_mode or avtype == AvType.audio_output:
|
||||||
rtaudio_outputparams = {'deviceid': device.index,
|
rtaudio_outputparams = {'deviceid': device.index,
|
||||||
|
@ -489,6 +489,8 @@ class Measurement:
|
|||||||
firstcoltime: If true, the first column is the treated as the
|
firstcoltime: If true, the first column is the treated as the
|
||||||
sample time.
|
sample time.
|
||||||
"""
|
"""
|
||||||
|
if os.path.splitext(mfn)[1] != '.h5':
|
||||||
|
mfn += '.h5'
|
||||||
if os.path.exists(mfn):
|
if os.path.exists(mfn):
|
||||||
raise ValueError(f'File {mfn} already exist.')
|
raise ValueError(f'File {mfn} already exist.')
|
||||||
if timestamp is None:
|
if timestamp is None:
|
||||||
@ -497,6 +499,13 @@ class Measurement:
|
|||||||
if data.ndim != 2:
|
if data.ndim != 2:
|
||||||
data = data[:, np.newaxis]
|
data = data[:, np.newaxis]
|
||||||
|
|
||||||
|
try:
|
||||||
|
len(sensitivity)
|
||||||
|
except:
|
||||||
|
raise ValueError('Sensitivity should be given as array-like data type')
|
||||||
|
sensitivity = np.asarray(sensitivity)
|
||||||
|
|
||||||
|
|
||||||
nchannels = data.shape[1]
|
nchannels = data.shape[1]
|
||||||
if nchannels != sensitivity.shape[0]:
|
if nchannels != sensitivity.shape[0]:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
@ -514,3 +523,45 @@ class Measurement:
|
|||||||
compression='gzip')
|
compression='gzip')
|
||||||
ad[0] = data
|
ad[0] = data
|
||||||
return Measurement(mfn)
|
return Measurement(mfn)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def fromWaveFile(fn, newfn=None, force=False, timestamp=None):
|
||||||
|
"""Convert a measurement file to a wave file, and return the
|
||||||
|
measurement handle."""
|
||||||
|
if timestamp is None:
|
||||||
|
timestamp = int(time.time())
|
||||||
|
|
||||||
|
base_fn = os.path.splitext(fn)[0]
|
||||||
|
if newfn is None:
|
||||||
|
newfn = base_fn + '.h5'
|
||||||
|
if os.path.exists(newfn) and not force:
|
||||||
|
raise RuntimeError(f'Measurement file name {newfn} already exists in path, set "force" to true to overwrite')
|
||||||
|
|
||||||
|
with wave.open(fn, 'r') as wf:
|
||||||
|
nchannels = wf.getnchannels()
|
||||||
|
samplerate = wf.getframerate()
|
||||||
|
sensitivity = np.ones(nchannels)
|
||||||
|
sampwidth = wf.getsampwidth()
|
||||||
|
nframes = wf.getnframes()
|
||||||
|
if sampwidth == 2:
|
||||||
|
dtype = np.int16
|
||||||
|
elif sampwidth == 1:
|
||||||
|
dtype = np.int8
|
||||||
|
elif sampwidth == 4:
|
||||||
|
dtype = np.int32
|
||||||
|
|
||||||
|
with h5.File(newfn, 'w') as hf:
|
||||||
|
hf.attrs['samplerate'] = samplerate
|
||||||
|
hf.attrs['nchannels'] = nchannels
|
||||||
|
hf.attrs['time'] = timestamp
|
||||||
|
hf.attrs['blocksize'] = 1
|
||||||
|
hf.attrs['sensitivity'] = sensitivity
|
||||||
|
data = np.frombuffer(
|
||||||
|
wf.readframes(nframes), dtype=dtype).reshape(nframes, nchannels)
|
||||||
|
ad = hf.create_dataset('audio', (1, data.shape[0], data.shape[1]),
|
||||||
|
dtype=dtype,
|
||||||
|
maxshape=(1, data.shape[0], data.shape[1]),
|
||||||
|
compression='gzip')
|
||||||
|
ad[0] = data
|
||||||
|
|
||||||
|
return Measurement(newfn)
|
||||||
|
Loading…
Reference in New Issue
Block a user