Skip to content

Commit

Permalink
Add .cu8 .cs8 format alias (#612)
Browse files Browse the repository at this point in the history
* Add .cu8 .cs8 format alias

* Add .cu8 and .cs8 as Save File format options
  • Loading branch information
zuckschwerdt authored and jopohl committed Jan 19, 2019
1 parent 6831028 commit 357f48b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/urh/signalprocessing/Signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def __init__(self, filename: str, name: str, modulation: str = None, sample_rate
self.filename = ""

def __load_complex_file(self, filename: str):
if filename.endswith(".complex16u"):
if filename.endswith(".complex16u") or filename.endswith(".cu8"):
# two 8 bit unsigned integers
raw = np.fromfile(filename, dtype=[('r', np.uint8), ('i', np.uint8)])
self._fulldata = np.empty(raw.shape[0], dtype=np.complex64)
self._fulldata.real = (raw['r'] / 127.5) - 1.0
self._fulldata.imag = (raw['i'] / 127.5) - 1.0
elif filename.endswith(".complex16s"):
elif filename.endswith(".complex16s") or filename.endswith(".cs8"):
# two 8 bit signed integers
raw = np.fromfile(filename, dtype=[('r', np.int8), ('i', np.int8)])
self._fulldata = np.empty(raw.shape[0], dtype=np.complex64)
Expand Down
10 changes: 5 additions & 5 deletions src/urh/util/FileOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def get_open_dialog(directory_mode=False, parent=None, name_filter="full") -> QF
dialog.setWindowTitle("Open Files")
if name_filter == "full":
name_filter = "All files (*);;Complex (*.complex);;" \
"Complex16 unsigned (*.complex16u);;" \
"Complex16 signed (*.complex16s);;" \
"Complex16 unsigned (*.complex16u *.cu8);;" \
"Complex16 signed (*.complex16s *.cs8);;" \
"Wave (*.wav);;" \
"Protocols (*.proto.xml *.proto);;" \
"Binary Protocols (*.bin);;" \
Expand Down Expand Up @@ -99,7 +99,7 @@ def get_save_file_name(initial_name: str, wav_only=False, caption="Save signal")
global RECENT_PATH
if caption == "Save signal":
name_filter = "Complex files (*.complex);;Complex16 files (2 unsigned int8) " \
"(*.complex16u);;Complex16 files (2 signed int8) (*.complex16s);;" \
"(*.complex16u *.cu8);;Complex16 files (2 signed int8) (*.complex16s *.cs8);;" \
"Compressed complex files (*.coco);;wav files (*.wav);;all files (*)"
if wav_only:
name_filter = "wav files (*.wav);;all files (*)"
Expand Down Expand Up @@ -181,9 +181,9 @@ def save_data(data, filename: str, sample_rate=1e6, num_channels=2):
def convert_data_to_format(data: np.ndarray, filename: str):
if filename.endswith(".wav"):
return (data.view(np.float32) * 32767).astype(np.int16)
elif filename.endswith(".complex16u"):
elif filename.endswith(".complex16u") or filename.endswith(".cu8"):
return (127.5 * (data.view(np.float32) + 1.0)).astype(np.uint8)
elif filename.endswith(".complex16s"):
elif filename.endswith(".complex16s") or filename.endswith(".cs8"):
return (127.5 * ((data.view(np.float32)) - 0.5 / 127.5)).astype(np.int8)
else:
return data
Expand Down

0 comments on commit 357f48b

Please sign in to comment.