|
| 1 | +========== |
| 2 | +Converters |
| 3 | +========== |
| 4 | + |
| 5 | +The SigMF Python library includes converters to import data from various RF recording formats into SigMF. |
| 6 | +Converters can create standard SigMF file pairs or Non-Conforming Datasets (NCDs) that reference the original files. |
| 7 | + |
| 8 | +Overview |
| 9 | +-------- |
| 10 | + |
| 11 | +Conversion is available for: |
| 12 | + |
| 13 | +* **BLUE files** - MIDAS Blue and Platinum BLUE RF recordings (usually ``.cdif``) |
| 14 | +* **WAV files** - Audio recordings (``.wav``) |
| 15 | + |
| 16 | +All converters return a :class:`~sigmf.SigMFFile` object with converted metadata. |
| 17 | + |
| 18 | + |
| 19 | +Fromfile Auto-Detection |
| 20 | +~~~~~~~~~~~~~~~~~~~~~~~ |
| 21 | + |
| 22 | +The :func:`~sigmf.sigmffile.fromfile` function automatically detects input file |
| 23 | +formats and reads without writing any output files: |
| 24 | + |
| 25 | +.. code-block:: python |
| 26 | +
|
| 27 | + import sigmf |
| 28 | +
|
| 29 | + # auto-detect and create NCD for any supported format |
| 30 | + meta = sigmf.fromfile("recording.cdif") # BLUE file |
| 31 | + meta = sigmf.fromfile("recording.wav") # WAV file |
| 32 | + meta = sigmf.fromfile("recording.sigmf") # SigMF archive |
| 33 | +
|
| 34 | + all_samples = meta.read_samples() |
| 35 | + sample_rate = meta.sample_rate |
| 36 | +
|
| 37 | +
|
| 38 | +Python API |
| 39 | +~~~~~~~~~~~ |
| 40 | + |
| 41 | +For programmatic access, use the individual converter functions directly: |
| 42 | + |
| 43 | +.. code-block:: python |
| 44 | +
|
| 45 | + from sigmf.convert.wav import wav_to_sigmf |
| 46 | + from sigmf.convert.blue import blue_to_sigmf |
| 47 | +
|
| 48 | + # convert WAV to SigMF archive |
| 49 | + _ = wav_to_sigmf(wav_path="recording.wav", out_path="recording", create_archive=True) |
| 50 | +
|
| 51 | + # convert BLUE to SigMF pair and return metadata for new files |
| 52 | + meta = blue_to_sigmf(blue_path="recording.cdif", out_path="recording") |
| 53 | +
|
| 54 | +
|
| 55 | +Command Line Usage |
| 56 | +~~~~~~~~~~~~~~~~~~ |
| 57 | + |
| 58 | +Converters are accessed through a unified command-line interface that automatically detects file formats: |
| 59 | + |
| 60 | +.. code-block:: bash |
| 61 | +
|
| 62 | + # unified converter |
| 63 | + sigmf_convert input_file output_file |
| 64 | +
|
| 65 | + # examples |
| 66 | + sigmf_convert recording.cdif recording.sigmf |
| 67 | + sigmf_convert recording.wav recording.sigmf |
| 68 | +
|
| 69 | +The converter uses magic byte detection to automatically identify BLUE and WAV file formats. |
| 70 | +No need to remember format-specific commands! |
| 71 | + |
| 72 | + |
| 73 | +Output Options |
| 74 | +~~~~~~~~~~~~~~ |
| 75 | + |
| 76 | +The unified converter supports multiple output modes: |
| 77 | + |
| 78 | +.. code-block:: bash |
| 79 | +
|
| 80 | + # standard conversion (creates out.sigmf-data and out.sigmf-meta files) |
| 81 | + sigmf_convert in.wav out |
| 82 | +
|
| 83 | + # archive mode (creates single out.sigmf archive) |
| 84 | + sigmf_convert in.wav out --archive |
| 85 | +
|
| 86 | + # non-conforming dataset (creates out.sigmf-meta only, references original file) |
| 87 | + sigmf_convert in.wav out --ncd |
| 88 | +
|
| 89 | + # extra verbose output |
| 90 | + sigmf_convert in.wav out -vv |
| 91 | +
|
| 92 | +**Important**: When using ``--ncd``, the input and output files must be in the same directory. |
| 93 | +This ensures proper relative path references in the metadata. |
| 94 | + |
| 95 | + |
| 96 | +BLUE Converter |
| 97 | +-------------- |
| 98 | + |
| 99 | +The BLUE converter handles CDIF (.cdif) recordings while placing BLUE header information into the following global fields: |
| 100 | + |
| 101 | +* ``blue:fixed`` - Fixed header information (at start of file). |
| 102 | +* ``blue:adjunct`` - Adjunct header information (after fixed header). |
| 103 | +* ``blue:extended`` - Extended header information (at end of file). Note any duplicate fields will have a suffix like ``_1``, ``_2``, etc appended. |
| 104 | + |
| 105 | +.. autofunction:: sigmf.convert.blue.blue_to_sigmf |
| 106 | + |
| 107 | +Examples |
| 108 | +~~~~~~~~ |
| 109 | + |
| 110 | +.. code-block:: python |
| 111 | +
|
| 112 | + from sigmf.convert.blue import blue_to_sigmf |
| 113 | +
|
| 114 | + # standard conversion |
| 115 | + meta = blue_to_sigmf(blue_path="recording.cdif", out_path="recording") |
| 116 | +
|
| 117 | + # create NCD automatically (metadata-only, references original file) but don't save any output file |
| 118 | + meta = blue_to_sigmf(blue_path="recording.cdif") |
| 119 | +
|
| 120 | + # access standard SigMF data & metadata |
| 121 | + all_samples = meta.read_samples() |
| 122 | + sample_rate = meta.sample_rate |
| 123 | +
|
| 124 | + # access BLUE-specific metadata |
| 125 | + blue_type = meta.get_global_field("blue:fixed")["type"] # e.g., 1000 |
| 126 | + blue_version = meta.get_global_field("blue:fixed")["keywords"]["IO"] # e.g., "X-Midas" |
| 127 | +
|
| 128 | +Tested Formats |
| 129 | +~~~~~~~~~~~~~~ |
| 130 | + |
| 131 | +BLUE files use a 2-digit format code where the first is the sample type (row) and the second is the sample size (column). |
| 132 | +For example ``SB`` contains real values with 8 bits per sample and ``CF`` contains complex values with 32 bits per component (64 bits per sample). |
| 133 | + |
| 134 | +The following table summarizes tested BLUE formats and their compatibility with the converter: |
| 135 | + |
| 136 | +.. csv-table:: |
| 137 | + :header-rows: 1 |
| 138 | + :stub-columns: 1 |
| 139 | + |
| 140 | + "Code", ":abbr:`B (int8)`", ":abbr:`I (int16)`", ":abbr:`L (int32)`", ":abbr:`X (int64)`", ":abbr:`F (float32)`", ":abbr:`D (float64)`", ":abbr:`P (packed)`", ":abbr:`N (int4)`" |
| 141 | + ":abbr:`S (scalar)`", "✅", "✅", "✅", "✅", "✅", "✅", "❌", "❌" |
| 142 | + ":abbr:`C (complex)`", "✅", "✅", "✅", "✅", "✅", ""✅", "❌", "❌" |
| 143 | + |
| 144 | +**Legend:** |
| 145 | + * ✅ = Tested and known working |
| 146 | + * ❌ = Unsupported |
| 147 | + |
| 148 | + |
| 149 | +WAV Converter |
| 150 | +------------- |
| 151 | + |
| 152 | +Converts WAV audio recordings to SigMF format. |
| 153 | + |
| 154 | +.. autofunction:: sigmf.convert.wav.wav_to_sigmf |
| 155 | + |
| 156 | +Examples |
| 157 | +~~~~~~~~ |
| 158 | + |
| 159 | +.. code-block:: python |
| 160 | +
|
| 161 | + from sigmf.convert.wav import wav_to_sigmf |
| 162 | +
|
| 163 | + # standard conversion |
| 164 | + meta = wav_to_sigmf(wav_path="recording.wav", out_path="recording") |
| 165 | +
|
| 166 | + # create NCD automatically (metadata-only, references original file) |
| 167 | + meta = wav_to_sigmf(wav_path="recording.wav") |
| 168 | +
|
| 169 | + # access standard SigMF data & metadata |
| 170 | + all_samples = meta.read_samples() |
| 171 | + sample_rate_hz = meta.sample_rate |
0 commit comments