8import sounddevice
as sd
10from .lasp_atomic
import Atomic
11from threading
import Thread, Condition
17 Play back a single channel from a
20 def __init__(self, fn1, channel=0, video=False, verbose=True):
22 Initialize a Playback class for playing back audio
25 fn1: Filename of the measurement file
26 channel: channel index to play back
27 video: if True and video is available in the measurement file,
28 video will also be shown
29 verbose: print out status messages to stdout
37 print(
'Filename: ', fn)
48 with h5py.File(fn,
'r')
as f:
56 print(
'Recording time: ', self.
nblocks
63 except AttributeError:
64 print(
'No video available in measurement file.'
72 the lenght of the measurement in seconds
74 return self._nblocks*self._blocksize/self._samplerate
80 with h5py.File(self.
_fn,
'r')
as f:
82 dtype = self.
_ad.dtype
83 dtype_str = str(dtype)
84 stream = sd.OutputStream(samplerate=self.
samplerate,
101 except KeyboardInterrupt:
102 print(
'Keyboard interrupt. Quit playback')
113 outdata[:, 0] = self.
_ad[aframectr, :, self.
channel]
122 nframes = self.
_vd.shape[0]
124 assert video_frame_positions.shape[0] == nframes
126 while self.
_running and frame_ctr < nframes:
127 frame = self.
_vd[frame_ctr]
130 corsp_aframe = video_frame_positions[frame_ctr]
133 print(
'Sleep video...')
136 cv.imshow(
"Video output. Press 'q' to quit", frame)
137 if cv.waitKey(1) & 0xFF == ord(
'q'):
141 print(
'Ending video playback thread')
142 cv.destroyAllWindows()
Implementation of atomic operations on integers and booleans.
Play back a single channel from a.
__init__(self, fn1, channel=0, video=False, verbose=True)
Initialize a Playback class for playing back audio.
start(self)
Start the playback.
T(self)
Returns the lenght of the measurement in seconds.
audio_callback(self, outdata, frames, time, status)