Skip to content
Snippets Groups Projects
Commit f8dd71be authored by ChiWai Chan's avatar ChiWai Chan
Browse files

pipeio.format_string_from_numpy_dtype numpy_dtype_from_caps

- add support for single and double precision complex floating point formats
parent 2f367b6b
No related branches found
No related tags found
No related merge requests found
...@@ -126,23 +126,36 @@ def numpy_dtype_from_caps(caps): ...@@ -126,23 +126,36 @@ def numpy_dtype_from_caps(caps):
GstAudio.AudioFormat.S32: numpy.dtype("int32"), GstAudio.AudioFormat.S32: numpy.dtype("int32"),
GstAudio.AudioFormat.U32: numpy.dtype("uint32") GstAudio.AudioFormat.U32: numpy.dtype("uint32")
} }
custom_formats_dict = {
"Z64LE" : numpy.dtype("complex64"),
"Z128LE": numpy.dtype("complex128")
}
info = GstAudio.AudioInfo() info = GstAudio.AudioInfo()
info.from_caps(caps) info.from_caps(caps)
return formats_dict[info.finfo.format]
def format_string_from_numpy_dtype(dtype): if info.finfo.format in formats_dict:
formats_dict = { return formats_dict[info.finfo.format]
numpy.dtype("float32"): GstAudio.AudioFormat.F32, elif caps.get_structure(0).get_string("format") in custom_formats_dict:
numpy.dtype("float64"): GstAudio.AudioFormat.F64, return custom_formats_dict[caps.get_structure(0).get_string("format")]
numpy.dtype("int8"): GstAudio.AudioFormat.S8, else:
numpy.dtype("uint8"): GstAudio.AudioFormat.U8, raise ValueError("unknown GstAudioFormat : %s" % caps.get_structure(0).get_string("format"))
numpy.dtype("int16"): GstAudio.AudioFormat.S16,
numpy.dtype("uint16"): GstAudio.AudioFormat.U16,
numpy.dtype("int32"): GstAudio.AudioFormat.S32, def format_string_from_numpy_dtype(dtype, formats_dict = {
numpy.dtype("uint32"): GstAudio.AudioFormat.U32 numpy.dtype("float32"): GstAudio.AudioFormat.to_string(GstAudio.AudioFormat.F32),
} numpy.dtype("float64"): GstAudio.AudioFormat.to_string(GstAudio.AudioFormat.F64),
return GstAudio.AudioFormat.to_string(formats_dict[dtype]) numpy.dtype("int8"): GstAudio.AudioFormat.to_string(GstAudio.AudioFormat.S8),
numpy.dtype("uint8"): GstAudio.AudioFormat.to_string(GstAudio.AudioFormat.U8),
numpy.dtype("int16"): GstAudio.AudioFormat.to_string(GstAudio.AudioFormat.S16),
numpy.dtype("uint16"): GstAudio.AudioFormat.to_string(GstAudio.AudioFormat.U16),
numpy.dtype("int32"): GstAudio.AudioFormat.to_string(GstAudio.AudioFormat.S32),
numpy.dtype("uint32"): GstAudio.AudioFormat.to_string(GstAudio.AudioFormat.U32),
numpy.dtype("complex64") : "Z64LE",
numpy.dtype("complex128") : "Z128LE"
}):
return formats_dict[dtype]
def caps_from_array(arr, rate = None): def caps_from_array(arr, rate = None):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment