From 2f367b6b8b70ebb4dcdf4984222fee581c2a4da4 Mon Sep 17 00:00:00 2001 From: ChiWai Chan <chiwai.chan@ligo.org> Date: Mon, 4 Mar 2019 23:57:42 -0800 Subject: [PATCH] pipeio.array_from_audio_sample(): - require numpy 1.7 and simplify --- gstlal/python/pipeio.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/gstlal/python/pipeio.py b/gstlal/python/pipeio.py index de71b432d8..833ebc7eac 100644 --- a/gstlal/python/pipeio.py +++ b/gstlal/python/pipeio.py @@ -151,16 +151,18 @@ def caps_from_array(arr, rate = None): def array_from_audio_sample(sample): caps = sample.get_caps() - bufmap = sample.get_buffer().map(Gst.MapFlags.READ)[1] - (success, channels) = caps.get_structure(0).get_int("channels") - # FIXME: conditional is work-around for broken handling of - # zero-length buffers in numpy < 1.7. remove and use frombuffer() - # unconditionally when we can rely on numpy >= 1.7 - if bufmap.size > 0: - a = numpy.frombuffer(bufmap.data, dtype = numpy_dtype_from_caps(caps)) - else: - a = numpy.array((), dtype = numpy_dtype_from_caps(caps)) - return numpy.reshape(a, (len(a) // channels, channels)) + success, channels = caps.get_structure(0).get_int("channels") + assert success + + buf = sample.get_buffer() + success, mapinfo = buf.map(Gst.MapFlags.READ) + assert success + + a = numpy.frombuffer(mapinfo.data, dtype = numpy_dtype_from_caps(caps)) + buf.unmap(mapinfo) + a.shape = len(a) // channels, channels + + return a def audio_buffer_from_array(arr, timestamp, offset, rate): -- GitLab