mirror of
https://github.com/pelgraine/Meck.git
synced 2026-05-15 13:55:52 +02:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 926736016e | |||
| ef62b7145c | |||
| f6cc939c4d | |||
| cd2c8ae5b3 | |||
| 2907cc64f3 | |||
| 1e589b3eb9 | |||
| b0ad1c4901 | |||
| ceb29ba662 | |||
| 18b9ab6c4d | |||
| 661157e368 | |||
| 5cca0e8e50 | |||
| 3596ad558d | |||
| 6de664ea37 | |||
| 708b96e0e8 | |||
| 4b734f1bac | |||
| 20310018d3 | |||
| 8afe71510e | |||
| 7adc0283b2 | |||
| e72e498db9 | |||
| 468a5ad324 | |||
| 44353fcf9e |
@@ -0,0 +1,4 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: pelgraine
|
||||||
|
|
||||||
@@ -29,6 +29,11 @@ A fork created specifically to focus on enabling BLE & WiFi companion firmware f
|
|||||||
- [Sending a Direct Message](#sending-a-direct-message)
|
- [Sending a Direct Message](#sending-a-direct-message)
|
||||||
- [Roomservers](#roomservers)
|
- [Roomservers](#roomservers)
|
||||||
- [Repeater Admin Screen](#repeater-admin-screen)
|
- [Repeater Admin Screen](#repeater-admin-screen)
|
||||||
|
- [Trace Route Screen (v1.9+)](#trace-route-screen-v19)
|
||||||
|
- [Delete Message History (v1.10+)](#delete-message-history-v110)
|
||||||
|
- [Per-Channel Notification Preferences (v1.10+)](#per-channel-notification-preferences-v110)
|
||||||
|
- [Custom Notification Tones (v1.10+)](#custom-notification-tones-v110)
|
||||||
|
- [Games (v1.10+)](#games-v110)
|
||||||
- [Settings Screen](#settings-screen)
|
- [Settings Screen](#settings-screen)
|
||||||
- [Font Styles](#font-styles)
|
- [Font Styles](#font-styles)
|
||||||
- [Compose Mode](#compose-mode)
|
- [Compose Mode](#compose-mode)
|
||||||
@@ -243,6 +248,8 @@ The T-Deck Pro firmware includes full keyboard support for standalone messaging
|
|||||||
| K | Open alarm clock (audio variant only) |
|
| K | Open alarm clock (audio variant only) |
|
||||||
| F | Open node discovery (search for nearby repeaters/nodes) |
|
| F | Open node discovery (search for nearby repeaters/nodes) |
|
||||||
| H | Open last heard list (passive advert history) |
|
| H | Open last heard list (passive advert history) |
|
||||||
|
| R | Open trace route screen (v1.9+) -- see [Trace Route Screen](#trace-route-screen-v19) |
|
||||||
|
| J | Open games menu (v1.10+) -- see [Games](#games-v110) |
|
||||||
| G | Open map screen (shows contacts with GPS positions) |
|
| G | Open map screen (shows contacts with GPS positions) |
|
||||||
| Mic | Open voice messages (audio variant only) |
|
| Mic | Open voice messages (audio variant only) |
|
||||||
| Q | Back to home screen |
|
| Q | Back to home screen |
|
||||||
@@ -310,9 +317,12 @@ Pressing **A** or **D** on the channel messages screen opens the channel picker.
|
|||||||
|-----|--------|
|
|-----|--------|
|
||||||
| W / S | Navigate up / down |
|
| W / S | Navigate up / down |
|
||||||
| Enter | Switch to selected channel |
|
| Enter | Switch to selected channel |
|
||||||
|
| X | Delete message history for highlighted channel (v1.10+) |
|
||||||
| Q | Back to home screen |
|
| Q | Back to home screen |
|
||||||
|
|
||||||
On the T5S3, swiping left or right on the channel messages screen also opens the channel picker, which displays a **vertical bubble list** matching the Meck P4 aesthetic.
|
Pressing **X** on any highlighted channel brings up a confirmation overlay. Press **Enter** to confirm deletion or **Q** to cancel. This clears all stored messages for that channel from the circular buffer and saves to SD. The channel itself is not removed -- only its message history.
|
||||||
|
|
||||||
|
On the T5S3, swiping left or right on the channel messages screen also opens the channel picker, which displays a **vertical bubble list** matching the Meck P4 aesthetic. Long-press a channel to bring up the delete history confirmation.
|
||||||
|
|
||||||
### Contacts Screen
|
### Contacts Screen
|
||||||
|
|
||||||
@@ -430,6 +440,115 @@ After a successful login, you'll see a menu with the following remote administra
|
|||||||
|
|
||||||
Command responses are displayed in a scrollable view. Use **W / S** to scroll long responses and **Q** to return to the menu.
|
Command responses are displayed in a scrollable view. Use **W / S** to scroll long responses and **Q** to return to the menu.
|
||||||
|
|
||||||
|
### Trace Route Screen (v1.9+)
|
||||||
|
|
||||||
|
The trace route screen lets you build a chain of repeaters and run a trace through them — the same feature available in the MeshCore companion app, but on-device. Each repeater in the chain that recognises its hash appends its receive SNR before forwarding the packet, giving you per-hop signal quality data for the whole route.
|
||||||
|
|
||||||
|
Press **R** from the home screen to open the trace screen. T5S3 users with a CardKB attached can use **R** as well.
|
||||||
|
|
||||||
|
**Building the path**
|
||||||
|
|
||||||
|
There are two ways to add hops to the path:
|
||||||
|
|
||||||
|
- **+ Add repeater** — opens a picker showing all known Repeater contacts. Press W/S to scroll, Enter to append the highlighted repeater to the path. The contact picker uses the repeater's stored public key bytes directly, so the hash is always correct regardless of mode.
|
||||||
|
- **Type Path** — opens an inline text editor for comma-separated decimal hash values, matching the format the companion app uses (e.g. `3601,2198,1244,2198,3601`). Useful when the repeater isn't in your contacts but you know its hash from the app or a community listing.
|
||||||
|
|
||||||
|
The path is shown as a numbered list below the menu. Individual hops can be edited or removed, and the whole path can be cleared if you need to start over.
|
||||||
|
|
||||||
|
**Hash mode**
|
||||||
|
|
||||||
|
Meck supports both 1-byte and 2-byte hash modes. The screen defaults to your device's `path.hash.mode` setting but can be toggled on the fly:
|
||||||
|
|
||||||
|
- 1-byte mode (`Mode: 1-byte`) — older networks, more collision-prone but smaller packets
|
||||||
|
- 2-byte mode (`Mode: 2-byte`) — current MeshCore default in most regions, fewer hash collisions
|
||||||
|
|
||||||
|
Use **A / D** on the mode row to toggle, or Enter to cycle.
|
||||||
|
|
||||||
|
**Running a trace**
|
||||||
|
|
||||||
|
Once at least one hop is in the path, scroll to **Run Trace** and press Enter. Meck creates a `PAYLOAD_TYPE_TRACE` packet and sends it direct-routed through the chain. The screen switches to a "Tracing..." state with an elapsed-time counter while waiting for the response.
|
||||||
|
|
||||||
|
When the trace completes, the screen shows:
|
||||||
|
|
||||||
|
- Each hop in order with its receive SNR (in dB)
|
||||||
|
- The final SNR of the response packet arriving back at your device
|
||||||
|
- Total round-trip time in milliseconds
|
||||||
|
|
||||||
|
If 30 seconds pass without a response, the trace times out and the screen returns to the build view so you can adjust the path and try again.
|
||||||
|
|
||||||
|
**Symmetric paths and direct visibility**
|
||||||
|
|
||||||
|
For a round-trip trace, the path needs to be symmetric. To trace through repeaters A → B → C and back, type `A,B,C,B,A`. The trace packet travels out through A→B→C, and the response comes back C→B→A.
|
||||||
|
|
||||||
|
You also need to be able to **hear the last repeater in the chain directly** — that's the one that sends the response back to your device. If the last hop is too far away to hear, the trace will time out even though the outbound leg succeeded.
|
||||||
|
|
||||||
|
| Key | Action |
|
||||||
|
|-----|--------|
|
||||||
|
| W / S | Navigate menu items |
|
||||||
|
| A / D | Toggle hash mode (1-byte / 2-byte) on the mode row |
|
||||||
|
| Enter | Select / confirm / open editor |
|
||||||
|
| 0–9 , | Path values (when the inline text editor is open) |
|
||||||
|
| Q | Cancel edit / back to home screen |
|
||||||
|
|
||||||
|
The screen supports up to **16 hops** per trace.
|
||||||
|
|
||||||
|
### Delete Message History (v1.10+)
|
||||||
|
|
||||||
|
You can clear all stored messages for any individual channel or the DM inbox without removing the channel itself.
|
||||||
|
|
||||||
|
From the home screen, press **M** to open the channel messages screen, then **A** or **D** to open the channel picker. Navigate to the channel you want to clear and press **X**. A confirmation overlay appears asking "Delete message history?" -- press **Enter** to confirm or **Q** to cancel.
|
||||||
|
|
||||||
|
On the T5S3, long-press the channel in the channel picker to bring up the same confirmation. Tap to confirm or press the Boot button to cancel.
|
||||||
|
|
||||||
|
Messages are invalidated in the circular buffer and the change is saved to SD immediately. The unread counter is also reset. New messages will continue to appear as they arrive.
|
||||||
|
|
||||||
|
### Per-Channel Notification Preferences (v1.10+)
|
||||||
|
|
||||||
|
Each channel (and the DM inbox) can be individually set to one of three notification levels:
|
||||||
|
|
||||||
|
- **All** -- notify on every message (default)
|
||||||
|
- **@ (Mentions)** -- only notify when someone tags you with @YourNodeName or @[YourNodeName]
|
||||||
|
- **Off** -- completely muted (no buzzer, no keyboard flash, no screen wake, no toast)
|
||||||
|
|
||||||
|
Messages are always stored in history regardless of the notification setting -- only the alerts and unread badges are suppressed.
|
||||||
|
|
||||||
|
To change a channel's notification preference: from the home screen, press **S** to open settings, scroll down to the **Channels >>** section and open it. Navigate to the channel you want to configure, and press **N** to cycle through the three modes. The current setting is shown in the channel row hint as `N:All`, `N:@`, or `N:Off`.
|
||||||
|
|
||||||
|
### Custom Notification Tones (v1.10+)
|
||||||
|
|
||||||
|
Each channel can have its own notification tone instead of the default buzzer sound. When a message arrives on a channel with a custom tone assigned, that tone plays through the speaker instead of the RTTTL buzzer.
|
||||||
|
|
||||||
|
To assign a tone: from the home screen, press **S** to open settings, scroll down to the **Channels >>** section and open it. Navigate to the channel you want, and press **T**. The tone picker appears with a list of available sounds. Use **W/S** to browse, **Enter** to select, or **Q** to cancel. Select "Default (silent)" to remove a custom tone and revert to the standard buzzer.
|
||||||
|
|
||||||
|
**Audio variant (PCM5102A DAC):** A selection of bundled tones are copied to the `/alarms/` folder on the SD card on first boot. You can also add your own MP3 files to that folder -- they'll appear in the tone picker alongside the bundled options. This gives you complete flexibility to use any short MP3 as a notification sound.
|
||||||
|
|
||||||
|
**4G variant (A7682E modem):** Seven bundled notification tones are embedded in the firmware as 8kHz mono WAV files and transferred to the modem's internal filesystem on boot. Playback goes through the modem's own speaker amplifier via AT+CCMXPLAY. Custom user-supplied tones are not supported on the 4G variant -- only the bundled set is available.
|
||||||
|
|
||||||
|
**Available bundled tones:** Bell, Ding, High Trill, Low Soft Ding (x2), Mid Trill, and Soft Notif. All are short, 1-2 second alert sounds.
|
||||||
|
|
||||||
|
### Games (v1.10+)
|
||||||
|
|
||||||
|
Press **J** from the home screen to open the games menu. Two classic games are included:
|
||||||
|
|
||||||
|
**Snake** -- the Nokia classic. Guide the snake around the screen to eat food and grow longer without crashing into the walls or your own tail. The game runs on the e-ink display at a pace suited to the refresh rate.
|
||||||
|
|
||||||
|
| Key | Action |
|
||||||
|
|-----|--------|
|
||||||
|
| W | Turn up |
|
||||||
|
| A | Turn left |
|
||||||
|
| S | Turn down |
|
||||||
|
| D | Turn right |
|
||||||
|
| Q | Quit to games menu |
|
||||||
|
|
||||||
|
**Minesweeper** -- clear the board without hitting a mine. Numbers reveal how many adjacent cells contain mines. Flag cells you suspect are mines to keep track.
|
||||||
|
|
||||||
|
| Key | Action |
|
||||||
|
|-----|--------|
|
||||||
|
| W / A / S / D | Move cursor |
|
||||||
|
| Enter | Reveal cell |
|
||||||
|
| F | Toggle flag on cell |
|
||||||
|
| Q | Quit to games menu |
|
||||||
|
|
||||||
### Settings Screen
|
### Settings Screen
|
||||||
|
|
||||||
Press **S** from the home screen to open settings. On first boot (when the device name is still the default hex ID), the settings screen launches automatically as an onboarding wizard to set your device name and radio preset.
|
Press **S** from the home screen to open settings. On first boot (when the device name is still the default hex ID), the settings screen launches automatically as an onboarding wizard to set your device name and radio preset.
|
||||||
@@ -478,7 +597,15 @@ Press **S** from the home screen to open settings. On first boot (when the devic
|
|||||||
|
|
||||||
Press Q to return to the top-level settings list.
|
Press Q to return to the top-level settings list.
|
||||||
|
|
||||||
**Channels sub-screen** — press Enter on the `Channels >>` row to open. Lists all current channels with their region scope tags (e.g. `[au-nsw]` or `[*]` for device default). Press Enter on a channel to edit its region scope. Press X to delete non-primary channels. Press Q to return to the top-level settings list.
|
**Channels sub-screen** -- press Enter on the `Channels >>` row to open. Lists all current channels with their region scope tags (e.g. `[au-nsw]` or `[*]` for device default). The hint line for each channel shows its current notification preference (`N:All`, `N:@`, or `N:Off`) and available actions.
|
||||||
|
|
||||||
|
| Key | Action |
|
||||||
|
|-----|--------|
|
||||||
|
| Enter | Edit channel region scope |
|
||||||
|
| N | Cycle notification preference (All / Mentions / Off) -- see [Per-Channel Notification Preferences](#per-channel-notification-preferences-v110) |
|
||||||
|
| T | Open notification tone picker (audio and 4G variants) -- see [Custom Notification Tones](#custom-notification-tones-v110) |
|
||||||
|
| X | Delete channel (non-primary channels only) |
|
||||||
|
| Q | Back to top-level settings |
|
||||||
|
|
||||||
The top-level settings screen also displays your node ID and firmware version. On the 4G variant, IMEI, carrier name, and APN details are shown here as well.
|
The top-level settings screen also displays your node ID and firmware version. On the 4G variant, IMEI, carrier name, and APN details are shown here as well.
|
||||||
|
|
||||||
@@ -1085,11 +1212,17 @@ There are a number of fairly major features in the pipeline, with no particular
|
|||||||
- [X] Page scroll (Shift+W/S) on all list screens
|
- [X] Page scroll (Shift+W/S) on all list screens
|
||||||
- [X] True power off (deep sleep, no wake sources)
|
- [X] True power off (deep sleep, no wake sources)
|
||||||
- [X] BLE 2M PHY, DLE, and faster write interval
|
- [X] BLE 2M PHY, DLE, and faster write interval
|
||||||
|
- [X] Trace route screen with contact picker and typed-path entry (v1.9)
|
||||||
|
- [X] DM message persistence across reboots (v1.9)
|
||||||
|
- [X] Per-channel message history deletion (v1.10)
|
||||||
|
- [X] Per-channel notification preferences with @mention support (v1.10)
|
||||||
|
- [X] Custom notification tones per channel -- audio variant (MP3) and 4G variant (WAV via modem) (v1.10)
|
||||||
|
- [X] Games menu with Snake and Minesweeper (v1.10)
|
||||||
|
- [X] MAX_GROUP_CHANNELS expanded to 40 for all builds (v1.10)
|
||||||
- [ ] Fix M4B rendering to enable chaptered audiobook playback
|
- [ ] Fix M4B rendering to enable chaptered audiobook playback
|
||||||
- [ ] Better JPEG and PNG decoding
|
- [ ] Better JPEG and PNG decoding
|
||||||
- [ ] Improve EPUB rendering and EPUB format handling
|
- [ ] Improve EPUB rendering and EPUB format handling
|
||||||
- [ ] Figure out a way to silence the ringtone
|
- [ ] Incoming call ringer silence (hardware limitation -- A7682E drives speaker autonomously on RING, no software mute path available)
|
||||||
- [ ] Figure out a way to customise the ringtone
|
|
||||||
|
|
||||||
**T5S3 E-Paper Pro:**
|
**T5S3 E-Paper Pro:**
|
||||||
- [X] Core port: display, touch input, LoRa, battery, RTC
|
- [X] Core port: display, touch input, LoRa, battery, RTC
|
||||||
@@ -1119,6 +1252,7 @@ There are a number of fairly major features in the pipeline, with no particular
|
|||||||
- [X] Selectable font styles (Classic, Noto Sans, Montserrat)
|
- [X] Selectable font styles (Classic, Noto Sans, Montserrat)
|
||||||
- [X] Virtual keyboard emoji grid with scrollable pages
|
- [X] Virtual keyboard emoji grid with scrollable pages
|
||||||
- [X] Accented character / diacritics support (Czech, Polish, French, German, Latin Extended)
|
- [X] Accented character / diacritics support (Czech, Polish, French, German, Latin Extended)
|
||||||
|
- [X] DM message persistence across reboots (v1.9)
|
||||||
- [ ] Improve EPUB rendering and EPUB format handling
|
- [ ] Improve EPUB rendering and EPUB format handling
|
||||||
|
|
||||||
**Heltec V4:**
|
**Heltec V4:**
|
||||||
|
|||||||
@@ -5,47 +5,29 @@
|
|||||||
},
|
},
|
||||||
"core": "nRF5",
|
"core": "nRF5",
|
||||||
"cpu": "cortex-m4",
|
"cpu": "cortex-m4",
|
||||||
"extra_flags": [
|
"extra_flags": "-DNRF52840_XXAA",
|
||||||
"-DARDUINO_NRF52840_TECHO_CARD",
|
|
||||||
"-DNRF52840_XXAA",
|
|
||||||
"-DNRF52_SERIES",
|
|
||||||
|
|
||||||
"-DUSE_LFXO",
|
|
||||||
|
|
||||||
"-DLED_BUILTIN=39",
|
|
||||||
"-DLED_BLUE=39",
|
|
||||||
"-DLED_RED=39",
|
|
||||||
"-DLED_STATE_ON=1",
|
|
||||||
|
|
||||||
"-DPIN_WIRE_SDA=36",
|
|
||||||
"-DPIN_WIRE_SCL=34",
|
|
||||||
"-DWIRE_INTERFACES_COUNT=1",
|
|
||||||
|
|
||||||
"-DPIN_SPI_MISO=17",
|
|
||||||
"-DPIN_SPI_SCK=13",
|
|
||||||
"-DPIN_SPI_MOSI=15",
|
|
||||||
"-DSPI_INTERFACES_COUNT=1",
|
|
||||||
|
|
||||||
"-DPIN_SERIAL1_RX=21",
|
|
||||||
"-DPIN_SERIAL1_TX=19",
|
|
||||||
|
|
||||||
"-DPIN_A0=2"
|
|
||||||
],
|
|
||||||
"f_cpu": "64000000L",
|
"f_cpu": "64000000L",
|
||||||
"hwids": [["0x239A", "0x8029"]],
|
"hwids": [
|
||||||
|
["0x239A", "0x8029"]
|
||||||
|
],
|
||||||
|
"usb_product": "T-Echo Card",
|
||||||
"mcu": "nrf52840",
|
"mcu": "nrf52840",
|
||||||
"variant": "lilygo_techo_card",
|
"variant": "lilygo_techo_card",
|
||||||
|
"variants_dir": "variants_bsp",
|
||||||
"bsp": {
|
"bsp": {
|
||||||
"name": "adafruit"
|
"name": "adafruit"
|
||||||
},
|
},
|
||||||
"softdevice": {
|
"softdevice": {
|
||||||
|
"sd_flags": "-DS140",
|
||||||
"sd_name": "s140",
|
"sd_name": "s140",
|
||||||
"sd_version": "6.1.1",
|
"sd_version": "6.1.1",
|
||||||
"sd_fwid": "0x00B6"
|
"sd_fwid": "0x00B6"
|
||||||
},
|
},
|
||||||
"usb_product": "T-Echo Card"
|
"bootloader": {
|
||||||
|
"settings_addr": "0xFF000"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"connectivity": ["bluetooth", "lora"],
|
"connectivity": ["bluetooth"],
|
||||||
"debug": {
|
"debug": {
|
||||||
"jlink_device": "nRF52840_xxAA",
|
"jlink_device": "nRF52840_xxAA",
|
||||||
"openocd_target": "nrf52840"
|
"openocd_target": "nrf52840"
|
||||||
@@ -53,15 +35,14 @@
|
|||||||
"frameworks": ["arduino"],
|
"frameworks": ["arduino"],
|
||||||
"name": "LilyGo T-Echo Card (nRF52840, SX1262, 4MB Flash)",
|
"name": "LilyGo T-Echo Card (nRF52840, SX1262, 4MB Flash)",
|
||||||
"upload": {
|
"upload": {
|
||||||
"flash_size": "796KB",
|
|
||||||
"maximum_ram_size": 248832,
|
"maximum_ram_size": 248832,
|
||||||
"maximum_size": 815104,
|
"maximum_size": 815104,
|
||||||
"native_usb": true,
|
"speed": 115200,
|
||||||
"protocol": "nrfutil",
|
"protocol": "nrfutil",
|
||||||
"protocols": ["nrfutil", "jlink", "cmsis-dap"],
|
"protocols": ["nrfutil", "jlink", "cmsis-dap"],
|
||||||
"require_upload_port": true,
|
"native_usb": true,
|
||||||
"speed": 115200,
|
|
||||||
"use_1200bps_touch": true,
|
"use_1200bps_touch": true,
|
||||||
|
"require_upload_port": true,
|
||||||
"wait_for_upload_port": true
|
"wait_for_upload_port": true
|
||||||
},
|
},
|
||||||
"url": "https://github.com/Xinyuan-LilyGO/T-Echo-Card",
|
"url": "https://github.com/Xinyuan-LilyGO/T-Echo-Card",
|
||||||
|
|||||||
@@ -57,4 +57,8 @@ public:
|
|||||||
virtual void onAdminLoginResult(bool success, uint8_t permissions, uint32_t server_time) {}
|
virtual void onAdminLoginResult(bool success, uint8_t permissions, uint32_t server_time) {}
|
||||||
virtual void onAdminCliResponse(const char* from_name, const char* text) {}
|
virtual void onAdminCliResponse(const char* from_name, const char* text) {}
|
||||||
virtual void onAdminTelemetryResult(const uint8_t* data, uint8_t len) {}
|
virtual void onAdminTelemetryResult(const uint8_t* data, uint8_t len) {}
|
||||||
|
|
||||||
|
// Trace path callback (from MyMesh::onTraceRecv)
|
||||||
|
virtual void onTraceResult(uint32_t tag, uint8_t flags, const uint8_t* path_snrs,
|
||||||
|
const uint8_t* path_hashes, uint8_t path_len, int8_t final_snr) {}
|
||||||
};
|
};
|
||||||
@@ -280,14 +280,31 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
|
|||||||
if (file.read((uint8_t *)&_prefs.rx_fail_reboot_threshold, sizeof(_prefs.rx_fail_reboot_threshold)) != sizeof(_prefs.rx_fail_reboot_threshold)) {
|
if (file.read((uint8_t *)&_prefs.rx_fail_reboot_threshold, sizeof(_prefs.rx_fail_reboot_threshold)) != sizeof(_prefs.rx_fail_reboot_threshold)) {
|
||||||
_prefs.rx_fail_reboot_threshold = 3; // default: 3
|
_prefs.rx_fail_reboot_threshold = 3; // default: 3
|
||||||
}
|
}
|
||||||
|
if (file.read((uint8_t *)&_prefs.ui_font_style, sizeof(_prefs.ui_font_style)) != sizeof(_prefs.ui_font_style)) {
|
||||||
|
_prefs.ui_font_style = 0; // default: Classic (FreeSans)
|
||||||
|
}
|
||||||
|
if (file.read((uint8_t *)_prefs.default_scope_name, sizeof(_prefs.default_scope_name)) != sizeof(_prefs.default_scope_name)) {
|
||||||
|
memset(_prefs.default_scope_name, 0, sizeof(_prefs.default_scope_name));
|
||||||
|
}
|
||||||
|
if (file.read((uint8_t *)_prefs.default_scope_key, sizeof(_prefs.default_scope_key)) != sizeof(_prefs.default_scope_key)) {
|
||||||
|
memset(_prefs.default_scope_key, 0, sizeof(_prefs.default_scope_key));
|
||||||
|
}
|
||||||
|
if (file.read((uint8_t *)_prefs.channel_notif, sizeof(_prefs.channel_notif)) != sizeof(_prefs.channel_notif)) {
|
||||||
|
memset(_prefs.channel_notif, 0, sizeof(_prefs.channel_notif)); // default: NOTIF_ALL
|
||||||
|
}
|
||||||
|
|
||||||
// Clamp to valid ranges
|
// Clamp to valid ranges
|
||||||
if (_prefs.dark_mode > 1) _prefs.dark_mode = 0;
|
if (_prefs.dark_mode > 1) _prefs.dark_mode = 0;
|
||||||
if (_prefs.portrait_mode > 1) _prefs.portrait_mode = 0;
|
if (_prefs.portrait_mode > 1) _prefs.portrait_mode = 0;
|
||||||
if (_prefs.hint_shown > 1) _prefs.hint_shown = 0;
|
if (_prefs.hint_shown > 1) _prefs.hint_shown = 0;
|
||||||
if (_prefs.large_font > 1) _prefs.large_font = 0;
|
if (_prefs.large_font > 1) _prefs.large_font = 0;
|
||||||
|
if (_prefs.ui_font_style > 2) _prefs.ui_font_style = 0;
|
||||||
if (_prefs.tx_fail_reset_threshold > 10) _prefs.tx_fail_reset_threshold = 3;
|
if (_prefs.tx_fail_reset_threshold > 10) _prefs.tx_fail_reset_threshold = 3;
|
||||||
if (_prefs.rx_fail_reboot_threshold > 10) _prefs.rx_fail_reboot_threshold = 3;
|
if (_prefs.rx_fail_reboot_threshold > 10) _prefs.rx_fail_reboot_threshold = 3;
|
||||||
|
// Clamp channel notification preferences to valid range
|
||||||
|
for (int i = 0; i < (int)sizeof(_prefs.channel_notif); i++) {
|
||||||
|
if (_prefs.channel_notif[i] > 2) _prefs.channel_notif[i] = 0;
|
||||||
|
}
|
||||||
// auto_lock_minutes: only accept known options (0, 2, 5, 10, 15, 30)
|
// auto_lock_minutes: only accept known options (0, 2, 5, 10, 15, 30)
|
||||||
{
|
{
|
||||||
uint8_t alm = _prefs.auto_lock_minutes;
|
uint8_t alm = _prefs.auto_lock_minutes;
|
||||||
@@ -344,6 +361,10 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
|
|||||||
file.write((uint8_t *)&_prefs.large_font, sizeof(_prefs.large_font)); // 102
|
file.write((uint8_t *)&_prefs.large_font, sizeof(_prefs.large_font)); // 102
|
||||||
file.write((uint8_t *)&_prefs.tx_fail_reset_threshold, sizeof(_prefs.tx_fail_reset_threshold)); // 103
|
file.write((uint8_t *)&_prefs.tx_fail_reset_threshold, sizeof(_prefs.tx_fail_reset_threshold)); // 103
|
||||||
file.write((uint8_t *)&_prefs.rx_fail_reboot_threshold, sizeof(_prefs.rx_fail_reboot_threshold)); // 104
|
file.write((uint8_t *)&_prefs.rx_fail_reboot_threshold, sizeof(_prefs.rx_fail_reboot_threshold)); // 104
|
||||||
|
file.write((uint8_t *)&_prefs.ui_font_style, sizeof(_prefs.ui_font_style)); // 105
|
||||||
|
file.write((uint8_t *)_prefs.default_scope_name, sizeof(_prefs.default_scope_name)); // 106
|
||||||
|
file.write((uint8_t *)_prefs.default_scope_key, sizeof(_prefs.default_scope_key)); // 137
|
||||||
|
file.write((uint8_t *)_prefs.channel_notif, sizeof(_prefs.channel_notif)); // 153
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1290,6 +1290,14 @@ void MyMesh::onTraceRecv(mesh::Packet *packet, uint32_t tag, uint32_t auth_code,
|
|||||||
} else {
|
} else {
|
||||||
MESH_DEBUG_PRINTLN("onTraceRecv(), data received while app offline");
|
MESH_DEBUG_PRINTLN("onTraceRecv(), data received while app offline");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Route trace result to standalone UI (TraceScreen)
|
||||||
|
#ifdef DISPLAY_CLASS
|
||||||
|
if (_ui) {
|
||||||
|
_ui->onTraceResult(tag, flags, path_snrs, path_hashes, path_len,
|
||||||
|
(int8_t)(packet->getSNR() * 4));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t MyMesh::calcFloodTimeoutMillisFor(uint32_t pkt_airtime_millis) const {
|
uint32_t MyMesh::calcFloodTimeoutMillisFor(uint32_t pkt_airtime_millis) const {
|
||||||
@@ -2173,6 +2181,9 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
memcpy(&auth, &cmd_frame[5], 4);
|
memcpy(&auth, &cmd_frame[5], 4);
|
||||||
auto pkt = createTrace(tag, auth, flags);
|
auto pkt = createTrace(tag, auth, flags);
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
|
Serial.printf("[BLE Trace] flags=%d, path_len=%d, path hex:", flags, path_len);
|
||||||
|
for (int pi = 0; pi < path_len; pi++) Serial.printf(" %02X", cmd_frame[10 + pi]);
|
||||||
|
Serial.println();
|
||||||
sendDirect(pkt, &cmd_frame[10], path_len);
|
sendDirect(pkt, &cmd_frame[10], path_len);
|
||||||
|
|
||||||
uint32_t t = _radio->getEstAirtimeFor(pkt->payload_len + pkt->path_len + 2);
|
uint32_t t = _radio->getEstAirtimeFor(pkt->payload_len + pkt->path_len + 2);
|
||||||
|
|||||||
@@ -8,11 +8,11 @@
|
|||||||
#define FIRMWARE_VER_CODE 11
|
#define FIRMWARE_VER_CODE 11
|
||||||
|
|
||||||
#ifndef FIRMWARE_BUILD_DATE
|
#ifndef FIRMWARE_BUILD_DATE
|
||||||
#define FIRMWARE_BUILD_DATE "3 May 2026"
|
#define FIRMWARE_BUILD_DATE "15 May 2026"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FIRMWARE_VERSION
|
#ifndef FIRMWARE_VERSION
|
||||||
#define FIRMWARE_VERSION "Meck v1.8"
|
#define FIRMWARE_VERSION "Meck v1.10"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||||
@@ -322,7 +322,9 @@ private:
|
|||||||
AckTableEntry expected_ack_table[EXPECTED_ACK_TABLE_SIZE]; // circular table
|
AckTableEntry expected_ack_table[EXPECTED_ACK_TABLE_SIZE]; // circular table
|
||||||
int next_ack_idx;
|
int next_ack_idx;
|
||||||
|
|
||||||
#define ADVERT_PATH_TABLE_SIZE 1000
|
#ifndef ADVERT_PATH_TABLE_SIZE
|
||||||
|
#define ADVERT_PATH_TABLE_SIZE 1000
|
||||||
|
#endif
|
||||||
AdvertPath* advert_paths; // PSRAM-allocated in begin(), size = ADVERT_PATH_TABLE_SIZE
|
AdvertPath* advert_paths; // PSRAM-allocated in begin(), size = ADVERT_PATH_TABLE_SIZE
|
||||||
|
|
||||||
// Sent message repeat tracking
|
// Sent message repeat tracking
|
||||||
|
|||||||
@@ -8,6 +8,11 @@
|
|||||||
#define ADVERT_LOC_NONE 0
|
#define ADVERT_LOC_NONE 0
|
||||||
#define ADVERT_LOC_SHARE 1
|
#define ADVERT_LOC_SHARE 1
|
||||||
|
|
||||||
|
// Per-channel notification preferences (stored in channel_notif[])
|
||||||
|
#define NOTIF_ALL 0 // Notify on all messages (default)
|
||||||
|
#define NOTIF_MENTIONS 1 // Notify only when @nodename appears in message
|
||||||
|
#define NOTIF_NONE 2 // No notifications (muted)
|
||||||
|
|
||||||
struct NodePrefs { // persisted to file
|
struct NodePrefs { // persisted to file
|
||||||
float airtime_factor;
|
float airtime_factor;
|
||||||
char node_name[32];
|
char node_name[32];
|
||||||
@@ -53,6 +58,12 @@ struct NodePrefs { // persisted to file
|
|||||||
char default_scope_name[31]; // e.g. "au-nsw", empty = unscoped
|
char default_scope_name[31]; // e.g. "au-nsw", empty = unscoped
|
||||||
uint8_t default_scope_key[16]; // TransportKey derived from "#" + name
|
uint8_t default_scope_key[16]; // TransportKey derived from "#" + name
|
||||||
|
|
||||||
|
// --- Per-channel notification preferences ---
|
||||||
|
// Index 0..MAX_GROUP_CHANNELS-1 for group channels, index MAX_GROUP_CHANNELS for DMs.
|
||||||
|
// Values: NOTIF_ALL (0), NOTIF_MENTIONS (1), NOTIF_NONE (2).
|
||||||
|
// Defaults to NOTIF_ALL for all channels.
|
||||||
|
uint8_t channel_notif[21]; // 20 group channels + 1 DM slot
|
||||||
|
|
||||||
// --- Font helpers (inline, no overhead) ---
|
// --- Font helpers (inline, no overhead) ---
|
||||||
// Returns the DisplayDriver text-size index for "small/body" text.
|
// Returns the DisplayDriver text-size index for "small/body" text.
|
||||||
// T-Deck Pro: 0 = built-in 6×8 (or 7pt with custom fonts), 1 = 9pt.
|
// T-Deck Pro: 0 = built-in 6×8 (or 7pt with custom fonts), 1 = 9pt.
|
||||||
|
|||||||
@@ -28,6 +28,10 @@
|
|||||||
#include "DiscoveryScreen.h"
|
#include "DiscoveryScreen.h"
|
||||||
#include "LastHeardScreen.h"
|
#include "LastHeardScreen.h"
|
||||||
#include "PathEditorScreen.h"
|
#include "PathEditorScreen.h"
|
||||||
|
#include "Tracescreen.h"
|
||||||
|
#include "GamesMenuScreen.h"
|
||||||
|
#include "SnakeScreen.h"
|
||||||
|
#include "MinesweeperScreen.h"
|
||||||
#ifdef MECK_WEB_READER
|
#ifdef MECK_WEB_READER
|
||||||
#include "WebReaderScreen.h"
|
#include "WebReaderScreen.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -83,6 +87,11 @@
|
|||||||
#endif
|
#endif
|
||||||
#ifdef MECK_AUDIO_VARIANT
|
#ifdef MECK_AUDIO_VARIANT
|
||||||
#include "VoiceMessageScreen.h"
|
#include "VoiceMessageScreen.h"
|
||||||
|
#include "BundledSounds.h"
|
||||||
|
#endif
|
||||||
|
#if defined(MECK_AUDIO_VARIANT) || defined(HAS_4G_MODEM)
|
||||||
|
#include "NotifSounds.h"
|
||||||
|
NotifSounds notifSounds; // Global singleton for per-channel notification tones
|
||||||
#endif
|
#endif
|
||||||
static bool audiobookMode = false;
|
static bool audiobookMode = false;
|
||||||
static bool voiceMode = false;
|
static bool voiceMode = false;
|
||||||
@@ -695,6 +704,10 @@
|
|||||||
#include "DiscoveryScreen.h"
|
#include "DiscoveryScreen.h"
|
||||||
#include "LastHeardScreen.h"
|
#include "LastHeardScreen.h"
|
||||||
#include "PathEditorScreen.h"
|
#include "PathEditorScreen.h"
|
||||||
|
#include "Tracescreen.h"
|
||||||
|
#include "GamesMenuScreen.h"
|
||||||
|
#include "SnakeScreen.h"
|
||||||
|
#include "MinesweeperScreen.h"
|
||||||
|
|
||||||
static TouchDrvGT911 gt911Touch;
|
static TouchDrvGT911 gt911Touch;
|
||||||
static bool gt911Ready = false;
|
static bool gt911Ready = false;
|
||||||
@@ -894,7 +907,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// --- T-Echo Lite: CardKB keyboard, GxEPD2 e-ink, no touch ---
|
// --- T-Echo Lite: CardKB keyboard, GxEPD2 e-ink, no touch ---
|
||||||
#if defined(LILYGO_TECHO_LITE)
|
#if defined(LILYGO_TECHO_LITE) || defined(LILYGO_TECHO_CARD)
|
||||||
#include "ContactsScreen.h"
|
#include "ContactsScreen.h"
|
||||||
#include "ChannelScreen.h"
|
#include "ChannelScreen.h"
|
||||||
#include "ChannelPickerScreen.h"
|
#include "ChannelPickerScreen.h"
|
||||||
@@ -904,6 +917,12 @@
|
|||||||
#include "LastHeardScreen.h"
|
#include "LastHeardScreen.h"
|
||||||
#include "PathEditorScreen.h"
|
#include "PathEditorScreen.h"
|
||||||
|
|
||||||
|
#ifdef LILYGO_TECHO_CARD
|
||||||
|
#include "TechoCardHomeScreen.h"
|
||||||
|
static TechoCardHomeScreen* _techoHome = nullptr;
|
||||||
|
static int _techoC2Debug = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MECK_CARDKB
|
#ifdef MECK_CARDKB
|
||||||
#include "CardKBKeyboard.h"
|
#include "CardKBKeyboard.h"
|
||||||
static CardKBKeyboard cardkb;
|
static CardKBKeyboard cardkb;
|
||||||
@@ -1027,8 +1046,8 @@ static uint32_t _atoi(const char* sp) {
|
|||||||
/* GLOBAL OBJECTS */
|
/* GLOBAL OBJECTS */
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
#include "UITask.h"
|
#include "UITask.h"
|
||||||
#if HAS_GPS
|
#if HAS_GPS && !defined(LILYGO_TECHO_CARD)
|
||||||
#include "MapScreen.h" // After BLE — PNGdec headers conflict with BLE if included earlier
|
#include "MapScreen.h" // After BLE -- PNGdec headers conflict with BLE if included earlier
|
||||||
#endif
|
#endif
|
||||||
UITask ui_task(&board, &serial_interface);
|
UITask ui_task(&board, &serial_interface);
|
||||||
#endif
|
#endif
|
||||||
@@ -1199,20 +1218,40 @@ static void lastHeardToggleContact() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Games menu: tap to select game entry
|
||||||
|
if (ui_task.isOnGamesMenu()) {
|
||||||
|
GamesMenuScreen* gm = (GamesMenuScreen*)ui_task.getGamesMenuScreen();
|
||||||
|
if (gm) {
|
||||||
|
int result = gm->selectRowAtVY(vy);
|
||||||
|
if (result == 2) return '\r'; // Tapped current selection -- launch
|
||||||
|
}
|
||||||
|
return 0; // Cursor moved or miss -- just refresh
|
||||||
|
}
|
||||||
|
|
||||||
|
// Snake screen: tap = Enter (start / restart)
|
||||||
|
if (ui_task.isOnSnakeScreen()) {
|
||||||
|
return '\r';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Minesweeper screen: tap = Enter (reveal cell / start / restart)
|
||||||
|
if (ui_task.isOnMinesweeperScreen()) {
|
||||||
|
return '\r';
|
||||||
|
}
|
||||||
|
|
||||||
// Home screen FIRST page: tile taps (virtual coordinate hit test)
|
// Home screen FIRST page: tile taps (virtual coordinate hit test)
|
||||||
if (ui_task.isOnHomeScreen() && ui_task.isHomeShowingTiles()) {
|
if (ui_task.isOnHomeScreen() && ui_task.isHomeShowingTiles()) {
|
||||||
const int tileW = 40, tileH = 28, gapX = 1, gapY = 1;
|
const int tileW = 40, tileH = 22, gapX = 1, gapY = 1;
|
||||||
const int gridW = tileW * 3 + gapX * 2;
|
const int gridW = tileW * 3 + gapX * 2;
|
||||||
const int gridX = (128 - gridW) / 2; // =3
|
const int gridX = (128 - gridW) / 2; // =3
|
||||||
int gridY = ui_task.getTileGridVY();
|
int gridY = ui_task.getTileGridVY();
|
||||||
|
|
||||||
// Check if tap is within the tile grid area
|
// Check if tap is within the tile grid area
|
||||||
if (vx >= gridX && vx < gridX + gridW &&
|
if (vx >= gridX && vx < gridX + gridW &&
|
||||||
vy >= gridY && vy < gridY + 2 * (tileH + gapY)) {
|
vy >= gridY && vy < gridY + 3 * (tileH + gapY)) {
|
||||||
int col = (vx - gridX) / (tileW + gapX);
|
int col = (vx - gridX) / (tileW + gapX);
|
||||||
if (col > 2) col = 2;
|
if (col > 2) col = 2;
|
||||||
int row = (vy - gridY) / (tileH + gapY);
|
int row = (vy - gridY) / (tileH + gapY);
|
||||||
if (row > 1) row = 1;
|
if (row > 2) row = 2;
|
||||||
|
|
||||||
if (row == 0 && col == 0) { ui_task.gotoChannelPickerScreen(); return 0; }
|
if (row == 0 && col == 0) { ui_task.gotoChannelPickerScreen(); return 0; }
|
||||||
if (row == 0 && col == 1) { ui_task.gotoContactsScreen(); return 0; }
|
if (row == 0 && col == 1) { ui_task.gotoContactsScreen(); return 0; }
|
||||||
@@ -1224,6 +1263,9 @@ static void lastHeardToggleContact() {
|
|||||||
#else
|
#else
|
||||||
if (row == 1 && col == 2) { ui_task.gotoDiscoveryScreen(); return 0; }
|
if (row == 1 && col == 2) { ui_task.gotoDiscoveryScreen(); return 0; }
|
||||||
#endif
|
#endif
|
||||||
|
// Third row: Trace (col 0) + Games (col 1)
|
||||||
|
if (row == 2 && col == 0) { ui_task.gotoTraceScreen(); return 0; }
|
||||||
|
if (row == 2 && col == 1) { ui_task.gotoGamesMenu(); return 0; }
|
||||||
}
|
}
|
||||||
// Tap outside tiles — left half backward, right half forward
|
// Tap outside tiles — left half backward, right half forward
|
||||||
return (vx < 64) ? (char)KEY_PREV : (char)KEY_NEXT;
|
return (vx < 64) ? (char)KEY_PREV : (char)KEY_NEXT;
|
||||||
@@ -1460,6 +1502,32 @@ static void lastHeardToggleContact() {
|
|||||||
if (ui_task.isOnSMSScreen()) return 0;
|
if (ui_task.isOnSMSScreen()) return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Snake screen: swipes control direction
|
||||||
|
if (ui_task.isOnSnakeScreen()) {
|
||||||
|
if (horizontal) {
|
||||||
|
return (dx < 0) ? 'a' : 'd';
|
||||||
|
} else {
|
||||||
|
return (dy < 0) ? 'w' : 's';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Minesweeper screen: swipes move cursor
|
||||||
|
if (ui_task.isOnMinesweeperScreen()) {
|
||||||
|
if (horizontal) {
|
||||||
|
return (dx < 0) ? 'a' : 'd';
|
||||||
|
} else {
|
||||||
|
return (dy < 0) ? 'w' : 's';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Games menu: vertical swipe scrolls list
|
||||||
|
if (ui_task.isOnGamesMenu()) {
|
||||||
|
if (!horizontal) {
|
||||||
|
return (dy > 0) ? 's' : 'w';
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Reader (reading mode): swipe left/right for page turn
|
// Reader (reading mode): swipe left/right for page turn
|
||||||
if (ui_task.isOnTextReader()) {
|
if (ui_task.isOnTextReader()) {
|
||||||
TextReaderScreen* reader = (TextReaderScreen*)ui_task.getTextReaderScreen();
|
TextReaderScreen* reader = (TextReaderScreen*)ui_task.getTextReaderScreen();
|
||||||
@@ -1495,7 +1563,11 @@ static void lastHeardToggleContact() {
|
|||||||
if (horizontal) {
|
if (horizontal) {
|
||||||
return (dx < 0) ? (char)KEY_NEXT : (char)KEY_PREV;
|
return (dx < 0) ? (char)KEY_NEXT : (char)KEY_PREV;
|
||||||
}
|
}
|
||||||
return (char)KEY_NEXT; // vertical swipe = next (default)
|
// Shutdown page: vertical swipe toggles hibernate/power off
|
||||||
|
if (ui_task.isHomeOnShutdownPage()) {
|
||||||
|
return 'w'; // toggle (direction doesn't matter)
|
||||||
|
}
|
||||||
|
return (char)KEY_NEXT; // vertical swipe = next page (default)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Settings: horizontal swipe → a/d for picker/number editing
|
// Settings: horizontal swipe → a/d for picker/number editing
|
||||||
@@ -1528,6 +1600,21 @@ static void lastHeardToggleContact() {
|
|||||||
if (ui_task.isOnSMSScreen()) return 0;
|
if (ui_task.isOnSMSScreen()) return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Snake screen: long press exits to games menu
|
||||||
|
if (ui_task.isOnSnakeScreen()) {
|
||||||
|
return 'q';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Minesweeper screen: long press toggles flag on cursor cell
|
||||||
|
if (ui_task.isOnMinesweeperScreen()) {
|
||||||
|
return 'f';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Games menu: long press exits to home
|
||||||
|
if (ui_task.isOnGamesMenu()) {
|
||||||
|
return 'q';
|
||||||
|
}
|
||||||
|
|
||||||
// Home screen: long press = activate current page action
|
// Home screen: long press = activate current page action
|
||||||
// (BLE toggle, send advert, hibernate, GPS toggle, etc.)
|
// (BLE toggle, send advert, hibernate, GPS toggle, etc.)
|
||||||
if (ui_task.isOnHomeScreen()) {
|
if (ui_task.isOnHomeScreen()) {
|
||||||
@@ -1683,6 +1770,21 @@ static void lastHeardToggleContact() {
|
|||||||
return KEY_ENTER;
|
return KEY_ENTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trace screen: long press = Enter on most rows; on T5S3 the Type Path row
|
||||||
|
// opens the virtual keyboard instead so users can enter a comma-separated
|
||||||
|
// hash list without a physical keyboard.
|
||||||
|
if (ui_task.isOnTraceScreen()) {
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
TraceScreen* ts = (TraceScreen*)ui_task.getTraceScreen();
|
||||||
|
if (ts && ts->isOnTypePathRow()) {
|
||||||
|
const char* current = ts->getCurrentPathAsText();
|
||||||
|
ui_task.showVirtualKeyboard(VKB_TRACE_PATH, "Type Path", current, 79);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return KEY_ENTER;
|
||||||
|
}
|
||||||
|
|
||||||
// Repeater admin: long press → open keyboard for password or CLI
|
// Repeater admin: long press → open keyboard for password or CLI
|
||||||
if (ui_task.isOnRepeaterAdmin()) {
|
if (ui_task.isOnRepeaterAdmin()) {
|
||||||
RepeaterAdminScreen* admin = (RepeaterAdminScreen*)ui_task.getRepeaterAdminScreen();
|
RepeaterAdminScreen* admin = (RepeaterAdminScreen*)ui_task.getRepeaterAdminScreen();
|
||||||
@@ -1722,6 +1824,11 @@ static void lastHeardToggleContact() {
|
|||||||
return KEY_ENTER; // Not editing: toggle/edit selected row
|
return KEY_ENTER; // Not editing: toggle/edit selected row
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Channel picker: long press = delete message history for highlighted channel
|
||||||
|
if (ui_task.isOnChannelPickerScreen()) {
|
||||||
|
return 'x';
|
||||||
|
}
|
||||||
|
|
||||||
// Default: enter/select
|
// Default: enter/select
|
||||||
return KEY_ENTER;
|
return KEY_ENTER;
|
||||||
}
|
}
|
||||||
@@ -2000,6 +2107,21 @@ void setup() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Copy bundled notification sounds to SD card (audio variant only).
|
||||||
|
// Skips files that already exist so user customisations are preserved.
|
||||||
|
#ifdef MECK_AUDIO_VARIANT
|
||||||
|
if (sdCardReady) {
|
||||||
|
copyBundledSoundsToSD();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Initialise per-channel notification sound config (audio + 4G variants).
|
||||||
|
#if defined(MECK_AUDIO_VARIANT) || defined(HAS_4G_MODEM)
|
||||||
|
if (sdCardReady) {
|
||||||
|
notifSounds.begin();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
MESH_DEBUG_PRINTLN("setup() - about to call store.begin()");
|
MESH_DEBUG_PRINTLN("setup() - about to call store.begin()");
|
||||||
store.begin();
|
store.begin();
|
||||||
MESH_DEBUG_PRINTLN("setup() - store.begin() done");
|
MESH_DEBUG_PRINTLN("setup() - store.begin() done");
|
||||||
@@ -2097,6 +2219,16 @@ void setup() {
|
|||||||
MESH_DEBUG_PRINTLN("setup() - about to call ui_task.begin()");
|
MESH_DEBUG_PRINTLN("setup() - about to call ui_task.begin()");
|
||||||
ui_task.begin(disp, &sensors, the_mesh.getNodePrefs());
|
ui_task.begin(disp, &sensors, the_mesh.getNodePrefs());
|
||||||
MESH_DEBUG_PRINTLN("setup() - ui_task.begin() done");
|
MESH_DEBUG_PRINTLN("setup() - ui_task.begin() done");
|
||||||
|
|
||||||
|
// T-Echo Card: replace the generic HomeScreen with the 72x40 OLED home screen
|
||||||
|
#ifdef LILYGO_TECHO_CARD
|
||||||
|
{
|
||||||
|
_techoHome = new TechoCardHomeScreen(&ui_task, &rtc_clock,
|
||||||
|
the_mesh.getNodePrefs());
|
||||||
|
ui_task.setHomeScreen(_techoHome);
|
||||||
|
MESH_DEBUG_PRINTLN("setup() - TechoCardHomeScreen installed");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -2383,6 +2515,12 @@ void setup() {
|
|||||||
Serial.printf("setup() complete - free heap: %d, largest block: %d\n",
|
Serial.printf("setup() complete - free heap: %d, largest block: %d\n",
|
||||||
ESP.getFreeHeap(), ESP.getMaxAllocHeap());
|
ESP.getFreeHeap(), ESP.getMaxAllocHeap());
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
void* p25 = malloc(25000); void* p10 = malloc(10000); void* p4 = malloc(4000);
|
||||||
|
Serial.printf("setup() heap probe: 25K=%s 10K=%s 4K=%s\n",
|
||||||
|
p25?"yes":"no", p10?"yes":"no", p4?"yes":"no");
|
||||||
|
if (p4) free(p4); if (p10) free(p10); if (p25) free(p25);
|
||||||
|
}
|
||||||
MESH_DEBUG_PRINTLN("=== setup() - COMPLETE ===");
|
MESH_DEBUG_PRINTLN("=== setup() - COMPLETE ===");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2410,10 +2548,49 @@ void otaResumeRadio() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
// T-Echo Card: lazy Codec2 init from shallow stack context.
|
||||||
|
// codec2_create needs ~3KB stack for FFT/trig init. The loop task
|
||||||
|
// has only 4KB total. Calling from render() (deep call chain) overflows.
|
||||||
|
// Calling from here (top of loop) works because stack depth is minimal.
|
||||||
|
#ifdef LILYGO_TECHO_CARD
|
||||||
|
if (_techoHome && _techoHome->needsCodec2()) {
|
||||||
|
void* probe = malloc(25000);
|
||||||
|
Serial.printf("Voice: heap probe 25K=%s, creating codec2...\n", probe?"yes":"no");
|
||||||
|
if (probe) free(probe);
|
||||||
|
Serial.flush();
|
||||||
|
|
||||||
|
struct CODEC2* c2 = codec2_create(VC_C2_MODE);
|
||||||
|
Serial.printf("Voice: codec2_create returned %p\n", c2);
|
||||||
|
Serial.flush();
|
||||||
|
|
||||||
|
if (c2) {
|
||||||
|
_techoHome->setCodec2Instance(c2);
|
||||||
|
void* postProbe = malloc(1000);
|
||||||
|
Serial.printf("Voice: set OK, post-probe=%s\n", postProbe?"yes":"no");
|
||||||
|
if (postProbe) free(postProbe);
|
||||||
|
Serial.flush();
|
||||||
|
_techoC2Debug = 99999; // Keep printing to test if yields prevent crash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MECK_OTA_UPDATE
|
#ifdef MECK_OTA_UPDATE
|
||||||
if (!otaRadioPaused) {
|
if (!otaRadioPaused) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LILYGO_TECHO_CARD
|
||||||
|
if (_techoC2Debug > 0) {
|
||||||
|
Serial.print("[pre-mesh]"); Serial.flush();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
the_mesh.loop();
|
the_mesh.loop();
|
||||||
|
|
||||||
|
#ifdef LILYGO_TECHO_CARD
|
||||||
|
if (_techoC2Debug > 0) {
|
||||||
|
Serial.print("[post-mesh]"); Serial.flush();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef MECK_OTA_UPDATE
|
#ifdef MECK_OTA_UPDATE
|
||||||
} else {
|
} else {
|
||||||
// OTA/File Manager active — poll the web server from the main loop for fast response.
|
// OTA/File Manager active — poll the web server from the main loop for fast response.
|
||||||
@@ -2453,7 +2630,7 @@ void loop() {
|
|||||||
|
|
||||||
// Map screen: periodically update own GPS position and contact markers
|
// Map screen: periodically update own GPS position and contact markers
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
#if HAS_GPS
|
#if HAS_GPS && !defined(LILYGO_TECHO_CARD)
|
||||||
if (ui_task.isOnMapScreen()) {
|
if (ui_task.isOnMapScreen()) {
|
||||||
static unsigned long lastMapUpdate = 0;
|
static unsigned long lastMapUpdate = 0;
|
||||||
if (millis() - lastMapUpdate > 30000) { // Every 30 seconds
|
if (millis() - lastMapUpdate > 30000) { // Every 30 seconds
|
||||||
@@ -2574,6 +2751,137 @@ void loop() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Notification tone: play custom MP3 for per-channel notification sounds.
|
||||||
|
// Polls the notifSounds pending request, lazy-inits Audio*, plays the file,
|
||||||
|
// and disables DAC when playback finishes.
|
||||||
|
#if defined(LilyGo_TDeck_Pro) && defined(MECK_AUDIO_VARIANT)
|
||||||
|
{
|
||||||
|
static bool notifTonePlaying = false;
|
||||||
|
static bool notifFadingOut = false;
|
||||||
|
static bool notifMuted = false;
|
||||||
|
static uint32_t notifStartMs = 0;
|
||||||
|
static uint32_t notifDurationMs = 0;
|
||||||
|
|
||||||
|
// Service audio decode while notification tone is playing
|
||||||
|
if (notifTonePlaying && audio) {
|
||||||
|
audio->loop();
|
||||||
|
|
||||||
|
// Fade-out: ramp volume down near the end of the file.
|
||||||
|
// Window scales with duration -- 15% of estimated length, capped at 400ms.
|
||||||
|
// Prevents short tones from losing too much audio to the fade.
|
||||||
|
if (!notifFadingOut && notifDurationMs > 0) {
|
||||||
|
uint32_t elapsed = millis() - notifStartMs;
|
||||||
|
uint32_t fadeWindow = notifDurationMs * 15 / 100; // 15% of duration
|
||||||
|
if (fadeWindow > 400) fadeWindow = 400;
|
||||||
|
if (fadeWindow < 80) fadeWindow = 80;
|
||||||
|
uint32_t fadePoint = notifDurationMs - fadeWindow;
|
||||||
|
if (elapsed >= fadePoint) {
|
||||||
|
notifFadingOut = true;
|
||||||
|
audio->setVolume(3);
|
||||||
|
Serial.printf("NotifTone: Fade at %lums (window %lums)\n", elapsed, fadeWindow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mute completely at 40% through the fade window
|
||||||
|
if (notifFadingOut && !notifMuted && notifDurationMs > 0) {
|
||||||
|
uint32_t elapsed = millis() - notifStartMs;
|
||||||
|
uint32_t muteWindow = notifDurationMs * 6 / 100; // 6% of duration
|
||||||
|
if (muteWindow > 150) muteWindow = 150;
|
||||||
|
if (muteWindow < 30) muteWindow = 30;
|
||||||
|
uint32_t mutePoint = notifDurationMs - muteWindow;
|
||||||
|
if (elapsed >= mutePoint) {
|
||||||
|
notifMuted = true;
|
||||||
|
audio->setVolume(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!audio->isRunning()) {
|
||||||
|
audio->setVolume(0);
|
||||||
|
audio->stopSong();
|
||||||
|
delay(50);
|
||||||
|
digitalWrite(41, LOW);
|
||||||
|
notifTonePlaying = false;
|
||||||
|
notifFadingOut = false;
|
||||||
|
notifMuted = false;
|
||||||
|
notifDurationMs = 0;
|
||||||
|
Serial.println("NotifTone: Playback finished");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for new play request
|
||||||
|
if (notifSounds.hasPendingPlay()) {
|
||||||
|
const char* file = notifSounds.getPendingFile();
|
||||||
|
|
||||||
|
// Don't interrupt alarm or active audiobook
|
||||||
|
AlarmScreen* alarmScr = (AlarmScreen*)ui_task.getAlarmScreen();
|
||||||
|
AudiobookPlayerScreen* abPlayer =
|
||||||
|
(AudiobookPlayerScreen*)ui_task.getAudiobookScreen();
|
||||||
|
bool audioBusy = (alarmScr && alarmScr->isRinging()) ||
|
||||||
|
(alarmScr && alarmScr->isAlarmAudioActive()) ||
|
||||||
|
(abPlayer && abPlayer->isAudioActive());
|
||||||
|
|
||||||
|
if (!audioBusy && file[0] != '\0') {
|
||||||
|
// Lazy-init Audio object
|
||||||
|
if (!audio) audio = new Audio();
|
||||||
|
|
||||||
|
// Read file size to estimate duration for fade-out timing.
|
||||||
|
// Estimate assumes 256kbps CBR: durationMs = fileBytes / 32.
|
||||||
|
// Slightly overestimates for lower bitrates (fade triggers early
|
||||||
|
// rather than late — better than hiss at end).
|
||||||
|
uint32_t estimatedMs = 0;
|
||||||
|
{
|
||||||
|
File f = SD.open(file, "r");
|
||||||
|
if (f) {
|
||||||
|
uint32_t sz = f.size();
|
||||||
|
estimatedMs = sz / 32; // 256kbps: bytes * 8 / 256000 * 1000
|
||||||
|
Serial.printf("NotifTone: File %lu bytes, est %lums\n", sz, estimatedMs);
|
||||||
|
f.close();
|
||||||
|
digitalWrite(SDCARD_CS, HIGH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop any stale playback before touching DAC
|
||||||
|
audio->stopSong();
|
||||||
|
|
||||||
|
// Configure I2S pins first (before DAC power)
|
||||||
|
bool ok = audio->setPinout(BOARD_I2S_BCLK, BOARD_I2S_LRC, BOARD_I2S_DOUT, 0);
|
||||||
|
if (!ok) ok = audio->setPinout(BOARD_I2S_BCLK, BOARD_I2S_LRC, BOARD_I2S_DOUT);
|
||||||
|
|
||||||
|
// Start playback at volume 0 (silence into DAC during power-on)
|
||||||
|
audio->setVolume(0);
|
||||||
|
audio->connecttoFS(SD, file);
|
||||||
|
|
||||||
|
// Enable DAC amplifier and let it stabilise with silence flowing
|
||||||
|
pinMode(41, OUTPUT);
|
||||||
|
digitalWrite(41, HIGH);
|
||||||
|
delay(80);
|
||||||
|
|
||||||
|
// Fill audio buffer with silence at volume 0 (prevents power-on pop)
|
||||||
|
for (int i = 0; i < 30; i++) {
|
||||||
|
audio->loop();
|
||||||
|
delay(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ramp volume up to max
|
||||||
|
audio->setVolume(21);
|
||||||
|
notifTonePlaying = true;
|
||||||
|
notifFadingOut = false;
|
||||||
|
notifMuted = false;
|
||||||
|
notifStartMs = millis();
|
||||||
|
// Subtract ~140ms of pre-decode (80ms DAC warmup + 60ms buffer fill)
|
||||||
|
// that elapsed between connecttoFS and now — the file is already
|
||||||
|
// that far into decoding when we start timing.
|
||||||
|
notifDurationMs = (estimatedMs > 140) ? (estimatedMs - 140) : estimatedMs;
|
||||||
|
|
||||||
|
Serial.printf("NotifTone: Playing '%s'\n", file);
|
||||||
|
} else if (audioBusy) {
|
||||||
|
Serial.println("NotifTone: Skipped -- audio busy");
|
||||||
|
}
|
||||||
|
notifSounds.clearPending();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Voice message: service mic DMA capture + playback audio decode
|
// Voice message: service mic DMA capture + playback audio decode
|
||||||
#if defined(LilyGo_TDeck_Pro) && defined(MECK_AUDIO_VARIANT)
|
#if defined(LilyGo_TDeck_Pro) && defined(MECK_AUDIO_VARIANT)
|
||||||
{
|
{
|
||||||
@@ -2923,7 +3231,13 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
#ifdef LILYGO_TECHO_CARD
|
||||||
|
if (_techoC2Debug > 0) { Serial.print("[pre-ui]"); Serial.flush(); }
|
||||||
|
#endif
|
||||||
ui_task.loop();
|
ui_task.loop();
|
||||||
|
#ifdef LILYGO_TECHO_CARD
|
||||||
|
if (_techoC2Debug > 0) { Serial.print("[post-ui]"); Serial.flush(); _techoC2Debug--; }
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
rtc_clock.tick();
|
rtc_clock.tick();
|
||||||
@@ -3133,6 +3447,40 @@ void loop() {
|
|||||||
ui_task.gotoContactsScreen();
|
ui_task.gotoContactsScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Trace screen: check if Exit was triggered
|
||||||
|
if (ui_task.isOnTraceScreen()) {
|
||||||
|
TraceScreen* ts = (TraceScreen*)ui_task.getTraceScreen();
|
||||||
|
if (ts && ts->wantsExit()) {
|
||||||
|
ui_task.gotoHomeScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Snake screen: check if Exit was triggered
|
||||||
|
if (ui_task.isOnSnakeScreen()) {
|
||||||
|
SnakeScreen* ss = (SnakeScreen*)ui_task.getSnakeScreen();
|
||||||
|
if (ss && ss->wantsExit()) {
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Minesweeper screen: check if Exit was triggered
|
||||||
|
if (ui_task.isOnMinesweeperScreen()) {
|
||||||
|
MinesweeperScreen* ms = (MinesweeperScreen*)ui_task.getMinesweeperScreen();
|
||||||
|
if (ms && ms->wantsExit()) {
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Games menu: check if game launch was triggered
|
||||||
|
if (ui_task.isOnGamesMenu()) {
|
||||||
|
GamesMenuScreen* gm = (GamesMenuScreen*)ui_task.getGamesMenuScreen();
|
||||||
|
if (gm && gm->wantsLaunch()) {
|
||||||
|
GameID sel = gm->selectedGame();
|
||||||
|
gm->clearFlags();
|
||||||
|
switch (sel) {
|
||||||
|
case GAME_SNAKE: ui_task.gotoSnakeScreen(); break;
|
||||||
|
case GAME_MINESWEEPER: ui_task.gotoMinesweeperScreen(); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Channel picker: check if long-press Enter was handled (wantsExit)
|
// Channel picker: check if long-press Enter was handled (wantsExit)
|
||||||
if (ui_task.isOnChannelPickerScreen()) {
|
if (ui_task.isOnChannelPickerScreen()) {
|
||||||
ChannelPickerScreen* pick = (ChannelPickerScreen*)ui_task.getChannelPickerScreen();
|
ChannelPickerScreen* pick = (ChannelPickerScreen*)ui_task.getChannelPickerScreen();
|
||||||
@@ -3159,6 +3507,40 @@ void loop() {
|
|||||||
ui_task.gotoContactsScreen();
|
ui_task.gotoContactsScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Trace screen: check if Exit was triggered
|
||||||
|
if (ui_task.isOnTraceScreen()) {
|
||||||
|
TraceScreen* ts = (TraceScreen*)ui_task.getTraceScreen();
|
||||||
|
if (ts && ts->wantsExit()) {
|
||||||
|
ui_task.gotoHomeScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Snake screen: check if Exit was triggered
|
||||||
|
if (ui_task.isOnSnakeScreen()) {
|
||||||
|
SnakeScreen* ss = (SnakeScreen*)ui_task.getSnakeScreen();
|
||||||
|
if (ss && ss->wantsExit()) {
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Minesweeper screen: check if Exit was triggered
|
||||||
|
if (ui_task.isOnMinesweeperScreen()) {
|
||||||
|
MinesweeperScreen* ms = (MinesweeperScreen*)ui_task.getMinesweeperScreen();
|
||||||
|
if (ms && ms->wantsExit()) {
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Games menu: check if game launch was triggered
|
||||||
|
if (ui_task.isOnGamesMenu()) {
|
||||||
|
GamesMenuScreen* gm = (GamesMenuScreen*)ui_task.getGamesMenuScreen();
|
||||||
|
if (gm && gm->wantsLaunch()) {
|
||||||
|
GameID sel = gm->selectedGame();
|
||||||
|
gm->clearFlags();
|
||||||
|
switch (sel) {
|
||||||
|
case GAME_SNAKE: ui_task.gotoSnakeScreen(); break;
|
||||||
|
case GAME_MINESWEEPER: ui_task.gotoMinesweeperScreen(); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Channel picker: check if Enter/Q was handled (wantsExit)
|
// Channel picker: check if Enter/Q was handled (wantsExit)
|
||||||
if (ui_task.isOnChannelPickerScreen()) {
|
if (ui_task.isOnChannelPickerScreen()) {
|
||||||
ChannelPickerScreen* pick = (ChannelPickerScreen*)ui_task.getChannelPickerScreen();
|
ChannelPickerScreen* pick = (ChannelPickerScreen*)ui_task.getChannelPickerScreen();
|
||||||
@@ -3301,6 +3683,8 @@ void loop() {
|
|||||||
break;
|
break;
|
||||||
case 'f': ui_task.gotoDiscoveryScreen(); break;
|
case 'f': ui_task.gotoDiscoveryScreen(); break;
|
||||||
case 'h': ui_task.gotoLastHeardScreen(); break;
|
case 'h': ui_task.gotoLastHeardScreen(); break;
|
||||||
|
case 'r': ui_task.gotoTraceScreen(); break;
|
||||||
|
case 'j': ui_task.gotoGamesMenu(); break;
|
||||||
case (char)0xF3: ui_task.injectKey(KEY_LEFT); break; // Left arrow → prev page
|
case (char)0xF3: ui_task.injectKey(KEY_LEFT); break; // Left arrow → prev page
|
||||||
case (char)0xF4: ui_task.injectKey(KEY_RIGHT); break; // Right arrow → next page
|
case (char)0xF4: ui_task.injectKey(KEY_RIGHT); break; // Right arrow → next page
|
||||||
#ifdef MECK_WEB_READER
|
#ifdef MECK_WEB_READER
|
||||||
@@ -3351,7 +3735,21 @@ void loop() {
|
|||||||
if (!handled) {
|
if (!handled) {
|
||||||
// ESC or Q → back navigation
|
// ESC or Q → back navigation
|
||||||
if (ckb == 0x1B || ckb == 'q') {
|
if (ckb == 0x1B || ckb == 'q') {
|
||||||
if (ui_task.isOnChannelPickerScreen()) {
|
if (ui_task.isOnSnakeScreen()) {
|
||||||
|
ui_task.injectKey('q');
|
||||||
|
SnakeScreen* ss = (SnakeScreen*)ui_task.getSnakeScreen();
|
||||||
|
if (ss && ss->wantsExit()) {
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
|
} else if (ui_task.isOnMinesweeperScreen()) {
|
||||||
|
ui_task.injectKey('q');
|
||||||
|
MinesweeperScreen* ms = (MinesweeperScreen*)ui_task.getMinesweeperScreen();
|
||||||
|
if (ms && ms->wantsExit()) {
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
|
} else if (ui_task.isOnGamesMenu()) {
|
||||||
|
ui_task.gotoHomeScreen();
|
||||||
|
} else if (ui_task.isOnChannelPickerScreen()) {
|
||||||
ui_task.gotoHomeScreen();
|
ui_task.gotoHomeScreen();
|
||||||
} else if (ui_task.isOnChannelScreen()) {
|
} else if (ui_task.isOnChannelScreen()) {
|
||||||
ChannelScreen* chScr = (ChannelScreen*)ui_task.getChannelScreen();
|
ChannelScreen* chScr = (ChannelScreen*)ui_task.getChannelScreen();
|
||||||
@@ -3499,6 +3897,40 @@ void loop() {
|
|||||||
if (pe && pe->wantsExit()) {
|
if (pe && pe->wantsExit()) {
|
||||||
ui_task.gotoContactsScreen();
|
ui_task.gotoContactsScreen();
|
||||||
}
|
}
|
||||||
|
} else if (ui_task.isOnTraceScreen()) {
|
||||||
|
// Trace screen handles Enter internally
|
||||||
|
ui_task.injectKey('\r');
|
||||||
|
TraceScreen* ts = (TraceScreen*)ui_task.getTraceScreen();
|
||||||
|
if (ts && ts->wantsExit()) {
|
||||||
|
ui_task.gotoHomeScreen();
|
||||||
|
}
|
||||||
|
} else if (ui_task.isOnGamesMenu()) {
|
||||||
|
// Games menu: Enter launches selected game
|
||||||
|
ui_task.injectKey('\r');
|
||||||
|
GamesMenuScreen* gm = (GamesMenuScreen*)ui_task.getGamesMenuScreen();
|
||||||
|
if (gm && gm->wantsLaunch()) {
|
||||||
|
GameID sel = gm->selectedGame();
|
||||||
|
gm->clearFlags();
|
||||||
|
switch (sel) {
|
||||||
|
case GAME_SNAKE: ui_task.gotoSnakeScreen(); break;
|
||||||
|
case GAME_MINESWEEPER: ui_task.gotoMinesweeperScreen(); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (ui_task.isOnSnakeScreen()) {
|
||||||
|
// Snake: Enter starts/restarts game
|
||||||
|
ui_task.injectKey('\r');
|
||||||
|
SnakeScreen* ss = (SnakeScreen*)ui_task.getSnakeScreen();
|
||||||
|
if (ss && ss->wantsExit()) {
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
|
} else if (ui_task.isOnMinesweeperScreen()) {
|
||||||
|
// Minesweeper: Enter reveals cell or starts/restarts
|
||||||
|
ui_task.injectKey('\r');
|
||||||
|
MinesweeperScreen* ms = (MinesweeperScreen*)ui_task.getMinesweeperScreen();
|
||||||
|
if (ms && ms->wantsExit()) {
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
} else if (ui_task.isOnChannelPickerScreen()) {
|
} else if (ui_task.isOnChannelPickerScreen()) {
|
||||||
// Channel picker: Enter selects channel
|
// Channel picker: Enter selects channel
|
||||||
ui_task.injectKey('\r');
|
ui_task.injectKey('\r');
|
||||||
@@ -3597,7 +4029,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Low-power loop throttle — yield CPU when lock screen is active.
|
// Low-power loop throttle -- yield CPU when lock screen is active.
|
||||||
// The RTOS idle task executes WFI (wait-for-interrupt) during delay(),
|
// The RTOS idle task executes WFI (wait-for-interrupt) during delay(),
|
||||||
// dramatically reducing CPU power draw. 50 ms gives 20 loop cycles/sec
|
// dramatically reducing CPU power draw. 50 ms gives 20 loop cycles/sec
|
||||||
// which is ample for LoRa packet reception (radio has hardware FIFO).
|
// which is ample for LoRa packet reception (radio has hardware FIFO).
|
||||||
@@ -4604,6 +5036,8 @@ void handleKeyboardInput() {
|
|||||||
if (ui_task.isOnChannelScreen() || ui_task.isOnContactsScreen() || ui_task.isOnRepeaterAdmin()
|
if (ui_task.isOnChannelScreen() || ui_task.isOnContactsScreen() || ui_task.isOnRepeaterAdmin()
|
||||||
|| ui_task.isOnDiscoveryScreen() || ui_task.isOnLastHeardScreen()
|
|| ui_task.isOnDiscoveryScreen() || ui_task.isOnLastHeardScreen()
|
||||||
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
||||||
|
|| ui_task.isOnTraceScreen()
|
||||||
|
|| ui_task.isOnGamesMenu() || ui_task.isOnSnakeScreen() || ui_task.isOnMinesweeperScreen()
|
||||||
#ifdef MECK_WEB_READER
|
#ifdef MECK_WEB_READER
|
||||||
|| ui_task.isOnWebReader()
|
|| ui_task.isOnWebReader()
|
||||||
#endif
|
#endif
|
||||||
@@ -4621,6 +5055,8 @@ void handleKeyboardInput() {
|
|||||||
if (ui_task.isOnChannelScreen() || ui_task.isOnContactsScreen() || ui_task.isOnRepeaterAdmin()
|
if (ui_task.isOnChannelScreen() || ui_task.isOnContactsScreen() || ui_task.isOnRepeaterAdmin()
|
||||||
|| ui_task.isOnDiscoveryScreen() || ui_task.isOnLastHeardScreen()
|
|| ui_task.isOnDiscoveryScreen() || ui_task.isOnLastHeardScreen()
|
||||||
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
||||||
|
|| ui_task.isOnTraceScreen()
|
||||||
|
|| ui_task.isOnGamesMenu() || ui_task.isOnSnakeScreen() || ui_task.isOnMinesweeperScreen()
|
||||||
#ifdef MECK_WEB_READER
|
#ifdef MECK_WEB_READER
|
||||||
|| ui_task.isOnWebReader()
|
|| ui_task.isOnWebReader()
|
||||||
#endif
|
#endif
|
||||||
@@ -4642,6 +5078,8 @@ void handleKeyboardInput() {
|
|||||||
if (ui_task.isOnChannelScreen() || ui_task.isOnContactsScreen() || ui_task.isOnRepeaterAdmin()
|
if (ui_task.isOnChannelScreen() || ui_task.isOnContactsScreen() || ui_task.isOnRepeaterAdmin()
|
||||||
|| ui_task.isOnDiscoveryScreen() || ui_task.isOnLastHeardScreen()
|
|| ui_task.isOnDiscoveryScreen() || ui_task.isOnLastHeardScreen()
|
||||||
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
||||||
|
|| ui_task.isOnTraceScreen()
|
||||||
|
|| ui_task.isOnGamesMenu() || ui_task.isOnSnakeScreen() || ui_task.isOnMinesweeperScreen()
|
||||||
#ifdef MECK_WEB_READER
|
#ifdef MECK_WEB_READER
|
||||||
|| ui_task.isOnWebReader()
|
|| ui_task.isOnWebReader()
|
||||||
#endif
|
#endif
|
||||||
@@ -4659,6 +5097,8 @@ void handleKeyboardInput() {
|
|||||||
if (ui_task.isOnChannelScreen() || ui_task.isOnContactsScreen() || ui_task.isOnRepeaterAdmin()
|
if (ui_task.isOnChannelScreen() || ui_task.isOnContactsScreen() || ui_task.isOnRepeaterAdmin()
|
||||||
|| ui_task.isOnDiscoveryScreen() || ui_task.isOnLastHeardScreen()
|
|| ui_task.isOnDiscoveryScreen() || ui_task.isOnLastHeardScreen()
|
||||||
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
||||||
|
|| ui_task.isOnTraceScreen()
|
||||||
|
|| ui_task.isOnGamesMenu() || ui_task.isOnSnakeScreen() || ui_task.isOnMinesweeperScreen()
|
||||||
#ifdef MECK_WEB_READER
|
#ifdef MECK_WEB_READER
|
||||||
|| ui_task.isOnWebReader()
|
|| ui_task.isOnWebReader()
|
||||||
#endif
|
#endif
|
||||||
@@ -4680,6 +5120,8 @@ void handleKeyboardInput() {
|
|||||||
ui_task.gotoChannelPickerScreen();
|
ui_task.gotoChannelPickerScreen();
|
||||||
} else if (ui_task.isOnContactsScreen() || ui_task.isOnMapScreen()
|
} else if (ui_task.isOnContactsScreen() || ui_task.isOnMapScreen()
|
||||||
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
||||||
|
|| ui_task.isOnTraceScreen()
|
||||||
|
|| ui_task.isOnSnakeScreen() || ui_task.isOnMinesweeperScreen()
|
||||||
#ifdef MECK_AUDIO_VARIANT
|
#ifdef MECK_AUDIO_VARIANT
|
||||||
|| ui_task.isOnAlarmScreen()
|
|| ui_task.isOnAlarmScreen()
|
||||||
#endif
|
#endif
|
||||||
@@ -4697,6 +5139,8 @@ void handleKeyboardInput() {
|
|||||||
ui_task.gotoChannelPickerScreen();
|
ui_task.gotoChannelPickerScreen();
|
||||||
} else if (ui_task.isOnContactsScreen() || ui_task.isOnMapScreen()
|
} else if (ui_task.isOnContactsScreen() || ui_task.isOnMapScreen()
|
||||||
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
|| ui_task.isOnPathEditor() || ui_task.isOnChannelPickerScreen()
|
||||||
|
|| ui_task.isOnTraceScreen()
|
||||||
|
|| ui_task.isOnSnakeScreen() || ui_task.isOnMinesweeperScreen()
|
||||||
#ifdef MECK_AUDIO_VARIANT
|
#ifdef MECK_AUDIO_VARIANT
|
||||||
|| ui_task.isOnAlarmScreen()
|
|| ui_task.isOnAlarmScreen()
|
||||||
#endif
|
#endif
|
||||||
@@ -4715,9 +5159,41 @@ void handleKeyboardInput() {
|
|||||||
// Check if Save & Exit was selected
|
// Check if Save & Exit was selected
|
||||||
PathEditorScreen* pe = (PathEditorScreen*)ui_task.getPathEditorScreen();
|
PathEditorScreen* pe = (PathEditorScreen*)ui_task.getPathEditorScreen();
|
||||||
if (pe && pe->wantsExit()) {
|
if (pe && pe->wantsExit()) {
|
||||||
Serial.println("PathEditor: Save & Exit — returning to contacts");
|
Serial.println("PathEditor: Save & Exit -- returning to contacts");
|
||||||
ui_task.gotoContactsScreen();
|
ui_task.gotoContactsScreen();
|
||||||
}
|
}
|
||||||
|
} else if (ui_task.isOnTraceScreen()) {
|
||||||
|
ui_task.injectKey('\r');
|
||||||
|
TraceScreen* ts = (TraceScreen*)ui_task.getTraceScreen();
|
||||||
|
if (ts && ts->wantsExit()) {
|
||||||
|
Serial.println("TraceScreen: Exit -- returning to home");
|
||||||
|
ui_task.gotoHomeScreen();
|
||||||
|
}
|
||||||
|
} else if (ui_task.isOnGamesMenu()) {
|
||||||
|
ui_task.injectKey('\r');
|
||||||
|
GamesMenuScreen* gm = (GamesMenuScreen*)ui_task.getGamesMenuScreen();
|
||||||
|
if (gm && gm->wantsLaunch()) {
|
||||||
|
GameID sel = gm->selectedGame();
|
||||||
|
gm->clearFlags();
|
||||||
|
switch (sel) {
|
||||||
|
case GAME_SNAKE: ui_task.gotoSnakeScreen(); break;
|
||||||
|
case GAME_MINESWEEPER: ui_task.gotoMinesweeperScreen(); break;
|
||||||
|
// case GAME_2048: ui_task.goto2048Screen(); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (ui_task.isOnSnakeScreen()) {
|
||||||
|
ui_task.injectKey('\r');
|
||||||
|
SnakeScreen* ss = (SnakeScreen*)ui_task.getSnakeScreen();
|
||||||
|
if (ss && ss->wantsExit()) {
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
|
} else if (ui_task.isOnMinesweeperScreen()) {
|
||||||
|
ui_task.injectKey('\r');
|
||||||
|
MinesweeperScreen* ms = (MinesweeperScreen*)ui_task.getMinesweeperScreen();
|
||||||
|
if (ms && ms->wantsExit()) {
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
} else if (ui_task.isOnChannelPickerScreen()) {
|
} else if (ui_task.isOnChannelPickerScreen()) {
|
||||||
ui_task.injectKey('\r'); // Picker handles Enter: selects channel + sets wantsExit
|
ui_task.injectKey('\r'); // Picker handles Enter: selects channel + sets wantsExit
|
||||||
ChannelPickerScreen* pick = (ChannelPickerScreen*)ui_task.getChannelPickerScreen();
|
ChannelPickerScreen* pick = (ChannelPickerScreen*)ui_task.getChannelPickerScreen();
|
||||||
@@ -4865,15 +5341,17 @@ void handleKeyboardInput() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
// Reply select mode (channel screen) or import contacts (contacts screen)
|
// Reply select (channel), import contacts, trace screen passthrough, or open trace (home)
|
||||||
if (ui_task.isOnChannelScreen()) {
|
if (ui_task.isOnChannelScreen()) {
|
||||||
ui_task.injectKey('r');
|
ui_task.injectKey('r');
|
||||||
|
} else if (ui_task.isOnTraceScreen()) {
|
||||||
|
ui_task.injectKey('r'); // Pass to trace screen (for edit mode)
|
||||||
} else if (ui_task.isOnContactsScreen()) {
|
} else if (ui_task.isOnContactsScreen()) {
|
||||||
// Try JSON first, fall back to binary
|
// Try JSON first, fall back to binary
|
||||||
Serial.println("Contacts: Importing from SD...");
|
Serial.println("Contacts: Importing from SD...");
|
||||||
int added = importContactsJSON();
|
int added = importContactsJSON();
|
||||||
if (added == -1) {
|
if (added == -1) {
|
||||||
// No JSON file — try legacy binary
|
// No JSON file -- try legacy binary
|
||||||
added = importContactsFromSD();
|
added = importContactsFromSD();
|
||||||
}
|
}
|
||||||
if (added > 0) {
|
if (added > 0) {
|
||||||
@@ -4888,12 +5366,19 @@ void handleKeyboardInput() {
|
|||||||
} else {
|
} else {
|
||||||
ui_task.showAlert("Import failed (no file?)", 2000);
|
ui_task.showAlert("Import failed (no file?)", 2000);
|
||||||
}
|
}
|
||||||
|
} else if (ui_task.isOnHomeScreen()) {
|
||||||
|
Serial.println("Opening trace path");
|
||||||
|
ui_task.gotoTraceScreen();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
|
// Minesweeper: F toggles flag on cursor cell
|
||||||
|
if (ui_task.isOnMinesweeperScreen()) {
|
||||||
|
ui_task.injectKey('f');
|
||||||
|
}
|
||||||
// Start discovery scan from home/contacts screen, or rescan on discovery screen
|
// Start discovery scan from home/contacts screen, or rescan on discovery screen
|
||||||
if (ui_task.isOnContactsScreen() || ui_task.isOnHomeScreen()) {
|
else if (ui_task.isOnContactsScreen() || ui_task.isOnHomeScreen()) {
|
||||||
Serial.println("Starting discovery scan...");
|
Serial.println("Starting discovery scan...");
|
||||||
the_mesh.startDiscovery();
|
the_mesh.startDiscovery();
|
||||||
ui_task.gotoDiscoveryScreen();
|
ui_task.gotoDiscoveryScreen();
|
||||||
@@ -4910,6 +5395,14 @@ void handleKeyboardInput() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'j':
|
||||||
|
// Open games menu from home screen
|
||||||
|
if (ui_task.isOnHomeScreen()) {
|
||||||
|
Serial.println("Opening games menu");
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
// L = Login/Admin — from DM conversation, open repeater admin with auto-login
|
// L = Login/Admin — from DM conversation, open repeater admin with auto-login
|
||||||
if (ui_task.isOnChannelScreen()) {
|
if (ui_task.isOnChannelScreen()) {
|
||||||
@@ -4979,6 +5472,42 @@ void handleKeyboardInput() {
|
|||||||
ui_task.gotoContactsScreen();
|
ui_task.gotoContactsScreen();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// Trace screen: Q/wantsExit goes home
|
||||||
|
if (ui_task.isOnTraceScreen()) {
|
||||||
|
ui_task.injectKey('q');
|
||||||
|
TraceScreen* ts = (TraceScreen*)ui_task.getTraceScreen();
|
||||||
|
if (ts && ts->wantsExit()) {
|
||||||
|
Serial.println("Nav: Trace -> Home");
|
||||||
|
ui_task.gotoHomeScreen();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Snake screen: Q goes back to games menu
|
||||||
|
if (ui_task.isOnSnakeScreen()) {
|
||||||
|
ui_task.injectKey('q');
|
||||||
|
SnakeScreen* ss = (SnakeScreen*)ui_task.getSnakeScreen();
|
||||||
|
if (ss && ss->wantsExit()) {
|
||||||
|
Serial.println("Nav: Snake -> Games Menu");
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Minesweeper screen: Q goes back to games menu
|
||||||
|
if (ui_task.isOnMinesweeperScreen()) {
|
||||||
|
ui_task.injectKey('q');
|
||||||
|
MinesweeperScreen* ms = (MinesweeperScreen*)ui_task.getMinesweeperScreen();
|
||||||
|
if (ms && ms->wantsExit()) {
|
||||||
|
Serial.println("Nav: Minesweeper -> Games Menu");
|
||||||
|
ui_task.gotoGamesMenu();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Games menu: Q goes back to home
|
||||||
|
if (ui_task.isOnGamesMenu()) {
|
||||||
|
Serial.println("Nav: Games Menu -> Home");
|
||||||
|
ui_task.gotoHomeScreen();
|
||||||
|
break;
|
||||||
|
}
|
||||||
// Alarm screen: Q/backspace routing depends on sub-mode
|
// Alarm screen: Q/backspace routing depends on sub-mode
|
||||||
#ifdef MECK_AUDIO_VARIANT
|
#ifdef MECK_AUDIO_VARIANT
|
||||||
if (ui_task.isOnAlarmScreen()) {
|
if (ui_task.isOnAlarmScreen()) {
|
||||||
@@ -5052,6 +5581,11 @@ void handleKeyboardInput() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
// Pass unhandled keys to trace screen (digits, comma for path entry)
|
||||||
|
if (ui_task.isOnTraceScreen()) {
|
||||||
|
ui_task.injectKey(key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
Serial.printf("Unhandled key in normal mode: '%c' (0x%02X)\n", key, key);
|
Serial.printf("Unhandled key in normal mode: '%c' (0x%02X)\n", key, key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -29,7 +29,7 @@
|
|||||||
// On-disk format for message persistence (SD card)
|
// On-disk format for message persistence (SD card)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
#define MSG_FILE_MAGIC 0x4D434853 // "MCHS" - MeshCore History Store
|
#define MSG_FILE_MAGIC 0x4D434853 // "MCHS" - MeshCore History Store
|
||||||
#define MSG_FILE_VERSION 3 // v3: MSG_PATH_MAX=20, reserved→snr field
|
#define MSG_FILE_VERSION 4 // v4: added dm_peer_hash for DM persistence
|
||||||
#define MSG_FILE_PATH "/meshcore/messages.bin"
|
#define MSG_FILE_PATH "/meshcore/messages.bin"
|
||||||
|
|
||||||
struct __attribute__((packed)) MsgFileHeader {
|
struct __attribute__((packed)) MsgFileHeader {
|
||||||
@@ -46,10 +46,11 @@ struct __attribute__((packed)) MsgFileRecord {
|
|||||||
uint8_t path_len;
|
uint8_t path_len;
|
||||||
uint8_t channel_idx;
|
uint8_t channel_idx;
|
||||||
uint8_t valid;
|
uint8_t valid;
|
||||||
int8_t snr; // Receive SNR × 4 (was reserved; 0 = unknown)
|
int8_t snr; // Receive SNR x 4 (was reserved; 0 = unknown)
|
||||||
|
uint32_t dm_peer_hash; // DM peer name hash (v4+, for conversation filtering)
|
||||||
uint8_t path[MSG_PATH_MAX]; // Repeater hop hashes (first byte of pub key)
|
uint8_t path[MSG_PATH_MAX]; // Repeater hop hashes (first byte of pub key)
|
||||||
char text[CHANNEL_MSG_TEXT_LEN];
|
char text[CHANNEL_MSG_TEXT_LEN];
|
||||||
// 188 bytes total
|
// 192 bytes total
|
||||||
};
|
};
|
||||||
|
|
||||||
class UITask; // Forward declaration
|
class UITask; // Forward declaration
|
||||||
@@ -147,8 +148,10 @@ public:
|
|||||||
|
|
||||||
// Add a new message to the history
|
// Add a new message to the history
|
||||||
// peer_name: for DMs, the contact this message belongs to (sender for received, recipient for sent)
|
// peer_name: for DMs, the contact this message belongs to (sender for received, recipient for sent)
|
||||||
|
// suppressUnread: if true, do not increment the unread counter for this message
|
||||||
void addMessage(uint8_t channel_idx, uint8_t path_len, const char* sender, const char* text,
|
void addMessage(uint8_t channel_idx, uint8_t path_len, const char* sender, const char* text,
|
||||||
const uint8_t* path_bytes = nullptr, int8_t snr = 0, const char* peer_name = nullptr) {
|
const uint8_t* path_bytes = nullptr, int8_t snr = 0, const char* peer_name = nullptr,
|
||||||
|
bool suppressUnread = false) {
|
||||||
// Move to next slot in circular buffer
|
// Move to next slot in circular buffer
|
||||||
_newestIdx = (_newestIdx + 1) % CHANNEL_MSG_HISTORY_SIZE;
|
_newestIdx = (_newestIdx + 1) % CHANNEL_MSG_HISTORY_SIZE;
|
||||||
|
|
||||||
@@ -190,8 +193,9 @@ public:
|
|||||||
_replySelectPos = -1;
|
_replySelectPos = -1;
|
||||||
|
|
||||||
// Track unread count for this channel (only for received messages, not sent)
|
// Track unread count for this channel (only for received messages, not sent)
|
||||||
// path_len == 0 means locally sent
|
// path_len == 0 means locally sent.
|
||||||
if (path_len != 0) {
|
// suppressUnread: per-channel notification preference says not to count this message.
|
||||||
|
if (path_len != 0 && !suppressUnread) {
|
||||||
int unreadSlot = (channel_idx == 0xFF) ? MAX_GROUP_CHANNELS : channel_idx;
|
int unreadSlot = (channel_idx == 0xFF) ? MAX_GROUP_CHANNELS : channel_idx;
|
||||||
if (unreadSlot >= 0 && unreadSlot <= MAX_GROUP_CHANNELS) {
|
if (unreadSlot >= 0 && unreadSlot <= MAX_GROUP_CHANNELS) {
|
||||||
_unread[unreadSlot]++;
|
_unread[unreadSlot]++;
|
||||||
@@ -396,6 +400,42 @@ public:
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
// Per-channel history deletion
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Clear all stored messages for a specific channel (or all DMs if 0xFF).
|
||||||
|
// Invalidates matching slots in the circular buffer and persists to SD.
|
||||||
|
// Does NOT alter _newestIdx -- gaps are naturally overwritten as new
|
||||||
|
// messages arrive.
|
||||||
|
int clearHistoryForChannel(uint8_t channel_idx) {
|
||||||
|
int cleared = 0;
|
||||||
|
for (int i = 0; i < CHANNEL_MSG_HISTORY_SIZE; i++) {
|
||||||
|
if (_messages[i].valid && _messages[i].channel_idx == channel_idx) {
|
||||||
|
_messages[i].valid = false;
|
||||||
|
cleared++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cleared > 0) {
|
||||||
|
// Reset unread counter for the cleared channel
|
||||||
|
markChannelRead(channel_idx);
|
||||||
|
// Reset scroll if we're viewing the cleared channel
|
||||||
|
if (_viewChannelIdx == channel_idx) {
|
||||||
|
_scrollPos = 0;
|
||||||
|
}
|
||||||
|
// Reset DM inbox state if clearing DMs
|
||||||
|
if (channel_idx == 0xFF) {
|
||||||
|
_dmInboxScroll = 0;
|
||||||
|
_dmFilterName[0] = '\0';
|
||||||
|
_dmInboxMode = true;
|
||||||
|
}
|
||||||
|
saveToSD();
|
||||||
|
Serial.printf("ChannelScreen: Cleared %d messages for channel %d\n",
|
||||||
|
cleared, (int)channel_idx);
|
||||||
|
}
|
||||||
|
return cleared;
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// SD card persistence
|
// SD card persistence
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -434,6 +474,7 @@ public:
|
|||||||
rec.channel_idx = _messages[i].channel_idx;
|
rec.channel_idx = _messages[i].channel_idx;
|
||||||
rec.valid = _messages[i].valid ? 1 : 0;
|
rec.valid = _messages[i].valid ? 1 : 0;
|
||||||
rec.snr = _messages[i].snr;
|
rec.snr = _messages[i].snr;
|
||||||
|
rec.dm_peer_hash = _messages[i].dm_peer_hash;
|
||||||
memcpy(rec.path, _messages[i].path, MSG_PATH_MAX);
|
memcpy(rec.path, _messages[i].path, MSG_PATH_MAX);
|
||||||
memcpy(rec.text, _messages[i].text, CHANNEL_MSG_TEXT_LEN);
|
memcpy(rec.text, _messages[i].text, CHANNEL_MSG_TEXT_LEN);
|
||||||
f.write((uint8_t*)&rec, sizeof(rec));
|
f.write((uint8_t*)&rec, sizeof(rec));
|
||||||
@@ -501,6 +542,7 @@ public:
|
|||||||
_messages[i].channel_idx = rec.channel_idx;
|
_messages[i].channel_idx = rec.channel_idx;
|
||||||
_messages[i].valid = (rec.valid != 0);
|
_messages[i].valid = (rec.valid != 0);
|
||||||
_messages[i].snr = rec.snr;
|
_messages[i].snr = rec.snr;
|
||||||
|
_messages[i].dm_peer_hash = rec.dm_peer_hash;
|
||||||
memcpy(_messages[i].path, rec.path, MSG_PATH_MAX);
|
memcpy(_messages[i].path, rec.path, MSG_PATH_MAX);
|
||||||
memcpy(_messages[i].text, rec.text, CHANNEL_MSG_TEXT_LEN);
|
memcpy(_messages[i].text, rec.text, CHANNEL_MSG_TEXT_LEN);
|
||||||
if (_messages[i].valid) loaded++;
|
if (_messages[i].valid) loaded++;
|
||||||
|
|||||||
@@ -32,7 +32,13 @@ extern MyMesh the_mesh;
|
|||||||
// T-Deck Pro / MAX : vertical list with "> " cursor, unread badge, right-
|
// T-Deck Pro / MAX : vertical list with "> " cursor, unread badge, right-
|
||||||
// aligned. Same highlight/tap convention as Contacts.
|
// aligned. Same highlight/tap convention as Contacts.
|
||||||
//
|
//
|
||||||
// Navigation signals use a wantsExit() flag (same pattern as PathEditor) —
|
// Delete history:
|
||||||
|
// Press X on a highlighted channel to enter delete confirmation mode.
|
||||||
|
// Confirmation overlay asks the user to press Enter to confirm or Q to
|
||||||
|
// cancel. On confirm, all messages for that channel are invalidated in
|
||||||
|
// the circular buffer and persisted to SD.
|
||||||
|
//
|
||||||
|
// Navigation signals use a wantsExit() flag (same pattern as PathEditor) --
|
||||||
// UITask is only forward-declared, so the picker cannot call UITask methods
|
// UITask is only forward-declared, so the picker cannot call UITask methods
|
||||||
// directly. main.cpp / UITask.cpp check the flag after injectKey().
|
// directly. main.cpp / UITask.cpp check the flag after injectKey().
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -50,12 +56,15 @@ class ChannelPickerScreen : public UIScreen {
|
|||||||
int _cursor;
|
int _cursor;
|
||||||
int _scrollTop; // Scroll offset (T-Deck Pro list only)
|
int _scrollTop; // Scroll offset (T-Deck Pro list only)
|
||||||
|
|
||||||
// Grid layout cache (T5S3) — set in render(), consumed by touch hit test
|
// Grid layout cache (T5S3) -- set in render(), consumed by touch hit test
|
||||||
int _cellW;
|
int _cellW;
|
||||||
int _cellH;
|
int _cellH;
|
||||||
int _gridTop;
|
int _gridTop;
|
||||||
int _gridCols;
|
int _gridCols;
|
||||||
|
|
||||||
|
// Delete confirmation sub-menu
|
||||||
|
bool _confirmDelete; // True when showing "Delete history?" overlay
|
||||||
|
|
||||||
// Rebuild the items list from MyMesh. O(20), safe every render.
|
// Rebuild the items list from MyMesh. O(20), safe every render.
|
||||||
void rebuildItems() {
|
void rebuildItems() {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
@@ -100,13 +109,14 @@ public:
|
|||||||
: _task(task), _channelScreen(nullptr),
|
: _task(task), _channelScreen(nullptr),
|
||||||
_itemCount(0), _cursor(0), _scrollTop(0),
|
_itemCount(0), _cursor(0), _scrollTop(0),
|
||||||
_cellW(40), _cellH(12), _gridTop(14), _gridCols(3),
|
_cellW(40), _cellH(12), _gridTop(14), _gridCols(3),
|
||||||
|
_confirmDelete(false),
|
||||||
_wantExit(false) {
|
_wantExit(false) {
|
||||||
_items[0] = 0xFF;
|
_items[0] = 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setChannelScreen(ChannelScreen* cs) { _channelScreen = cs; }
|
void setChannelScreen(ChannelScreen* cs) { _channelScreen = cs; }
|
||||||
|
|
||||||
// --- wantsExit flag — checked by main.cpp / UITask after injectKey() ---
|
// --- wantsExit flag -- checked by main.cpp / UITask after injectKey() ---
|
||||||
bool _wantExit;
|
bool _wantExit;
|
||||||
bool wantsExit() const { return _wantExit; }
|
bool wantsExit() const { return _wantExit; }
|
||||||
|
|
||||||
@@ -118,6 +128,7 @@ public:
|
|||||||
if (_items[i] == currentChannelIdx) { _cursor = i; break; }
|
if (_items[i] == currentChannelIdx) { _cursor = i; break; }
|
||||||
}
|
}
|
||||||
_scrollTop = 0;
|
_scrollTop = 0;
|
||||||
|
_confirmDelete = false;
|
||||||
_wantExit = false;
|
_wantExit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +182,7 @@ public:
|
|||||||
_cellW = bubbleW;
|
_cellW = bubbleW;
|
||||||
_cellH = bubbleH + gap;
|
_cellH = bubbleH + gap;
|
||||||
_gridTop = headerH;
|
_gridTop = headerH;
|
||||||
_gridCols = 1; // Single column — list mode
|
_gridCols = 1; // Single column -- list mode
|
||||||
|
|
||||||
// Centre scroll window on cursor
|
// Centre scroll window on cursor
|
||||||
_scrollTop = max(0, min(_cursor - maxVisible / 2, _itemCount - maxVisible));
|
_scrollTop = max(0, min(_cursor - maxVisible / 2, _itemCount - maxVisible));
|
||||||
@@ -200,7 +211,7 @@ public:
|
|||||||
display.drawRect(x + 1, y + 1, w - 2, h - 2);
|
display.drawRect(x + 1, y + 1, w - 2, h - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Channel name — left-aligned with inner padding
|
// Channel name -- left-aligned with inner padding
|
||||||
char name[32];
|
char name[32];
|
||||||
getItemName(i, name, sizeof(name));
|
getItemName(i, name, sizeof(name));
|
||||||
char filtered[32];
|
char filtered[32];
|
||||||
@@ -229,7 +240,7 @@ public:
|
|||||||
display.drawTextEllipsized(textX, textY, nameMaxW, filtered);
|
display.drawTextEllipsized(textX, textY, nameMaxW, filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unread badge — right-aligned inside bubble
|
// Unread badge -- right-aligned inside bubble
|
||||||
if (unread > 0) {
|
if (unread > 0) {
|
||||||
int bx = x + w - badgeW;
|
int bx = x + w - badgeW;
|
||||||
display.setCursor(bx, textY);
|
display.setCursor(bx, textY);
|
||||||
@@ -329,6 +340,47 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// =================================================================
|
||||||
|
// Delete confirmation overlay
|
||||||
|
// Drawn on top of the list when _confirmDelete is active.
|
||||||
|
// =================================================================
|
||||||
|
if (_confirmDelete) {
|
||||||
|
// Clear a centred box and draw a border
|
||||||
|
int boxW = display.width() - 16;
|
||||||
|
int boxH = 42;
|
||||||
|
int boxX = 8;
|
||||||
|
int boxY = (display.height() - boxH) / 2;
|
||||||
|
|
||||||
|
// Clear the box area
|
||||||
|
display.setColor(DisplayDriver::DARK);
|
||||||
|
display.fillRect(boxX, boxY, boxW, boxH);
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(boxX, boxY, boxW, boxH);
|
||||||
|
display.drawRect(boxX + 1, boxY + 1, boxW - 2, boxH - 2);
|
||||||
|
|
||||||
|
// Channel name
|
||||||
|
display.setTextSize(1);
|
||||||
|
char name[32];
|
||||||
|
getItemName(_cursor, name, sizeof(name));
|
||||||
|
char filtered[32];
|
||||||
|
display.translateUTF8ToBlocks(filtered, name, sizeof(filtered));
|
||||||
|
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
display.drawTextEllipsized(boxX + 4, boxY + 5, boxW - 8, filtered);
|
||||||
|
|
||||||
|
// "Delete history?" prompt
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
const char* prompt = "Delete message history?";
|
||||||
|
display.setCursor(boxX + 4, boxY + 17);
|
||||||
|
display.print(prompt);
|
||||||
|
|
||||||
|
// Key hints
|
||||||
|
display.setColor(DisplayDriver::YELLOW);
|
||||||
|
const char* hints = "Enter:Yes Q:Cancel";
|
||||||
|
display.setCursor(boxX + 4, boxY + 29);
|
||||||
|
display.print(hints);
|
||||||
|
}
|
||||||
|
|
||||||
// === Footer ===
|
// === Footer ===
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
int footerY = display.height() - 12;
|
int footerY = display.height() - 12;
|
||||||
@@ -337,20 +389,31 @@ public:
|
|||||||
display.setCursor(0, footerY);
|
display.setCursor(0, footerY);
|
||||||
|
|
||||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
display.print("Tap:Open");
|
if (_confirmDelete) {
|
||||||
const char* rt = "Boot:Back";
|
display.print("Tap:Yes");
|
||||||
display.setCursor(display.width() - display.getTextWidth(rt) - 2, footerY);
|
const char* rt = "Boot:Cancel";
|
||||||
display.print(rt);
|
display.setCursor(display.width() - display.getTextWidth(rt) - 2, footerY);
|
||||||
|
display.print(rt);
|
||||||
|
} else {
|
||||||
|
display.print("Tap:Open");
|
||||||
|
const char* rt = "Hold:Del Boot:Back";
|
||||||
|
display.setCursor(display.width() - display.getTextWidth(rt) - 2, footerY);
|
||||||
|
display.print(rt);
|
||||||
|
}
|
||||||
#elif defined(LILYGO_TECHO_LITE)
|
#elif defined(LILYGO_TECHO_LITE)
|
||||||
display.print("Q:Bk");
|
display.print("Q:Bk");
|
||||||
const char* rt = "Ent:Open";
|
const char* rt = "Ent:Open";
|
||||||
display.setCursor(display.width() - display.getTextWidth(rt) - 2, footerY);
|
display.setCursor(display.width() - display.getTextWidth(rt) - 2, footerY);
|
||||||
display.print(rt);
|
display.print(rt);
|
||||||
#else
|
#else
|
||||||
display.print("W/S:Nav Q:Back");
|
if (_confirmDelete) {
|
||||||
const char* rt = "Ent:Open";
|
display.print("Enter:Yes Q:Cancel");
|
||||||
display.setCursor(display.width() - display.getTextWidth(rt) - 2, footerY);
|
} else {
|
||||||
display.print(rt);
|
display.print("W/S:Nav Q:Back");
|
||||||
|
const char* rt = "Ent:Open";
|
||||||
|
display.setCursor(display.width() - display.getTextWidth(rt) - 2, footerY);
|
||||||
|
display.print(rt);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_EINK
|
#ifdef USE_EINK
|
||||||
@@ -364,6 +427,30 @@ public:
|
|||||||
// Input
|
// Input
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
bool handleInput(char c) override {
|
bool handleInput(char c) override {
|
||||||
|
// --- Delete confirmation mode ---
|
||||||
|
if (_confirmDelete) {
|
||||||
|
// Enter -- confirm deletion
|
||||||
|
if (c == '\r' || c == 13 || c == KEY_ENTER || c == KEY_SELECT) {
|
||||||
|
if (_channelScreen && _cursor >= 0 && _cursor < _itemCount) {
|
||||||
|
int cleared = _channelScreen->clearHistoryForChannel(_items[_cursor]);
|
||||||
|
char name[32];
|
||||||
|
getItemName(_cursor, name, sizeof(name));
|
||||||
|
Serial.printf("ChannelPicker: Deleted %d messages for '%s'\n", cleared, name);
|
||||||
|
}
|
||||||
|
_confirmDelete = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Q / backspace -- cancel
|
||||||
|
if (c == 'q' || c == 'Q' || c == '\b' || c == KEY_CANCEL) {
|
||||||
|
_confirmDelete = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Consume all other keys while confirmation is showing
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Normal picker mode ---
|
||||||
|
|
||||||
// W / UP
|
// W / UP
|
||||||
if (c == 'w' || c == 'W' || c == 0xF2 || c == KEY_UP) {
|
if (c == 'w' || c == 'W' || c == 0xF2 || c == KEY_UP) {
|
||||||
if (_cursor > 0) { _cursor--; return true; }
|
if (_cursor > 0) { _cursor--; return true; }
|
||||||
@@ -376,7 +463,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A / D — consumed (no channel cycling from picker)
|
// A / D -- consumed (no channel cycling from picker)
|
||||||
if (c == 'a' || c == 'A' || c == KEY_LEFT) {
|
if (c == 'a' || c == 'A' || c == KEY_LEFT) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -384,16 +471,24 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enter — select the highlighted channel and signal exit
|
// X -- delete message history for highlighted channel
|
||||||
|
if (c == 'x' || c == 'X') {
|
||||||
|
if (_cursor >= 0 && _cursor < _itemCount) {
|
||||||
|
_confirmDelete = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enter -- select the highlighted channel and signal exit
|
||||||
if (c == '\r' || c == 13 || c == KEY_ENTER || c == KEY_SELECT) {
|
if (c == '\r' || c == 13 || c == KEY_ENTER || c == KEY_SELECT) {
|
||||||
if (_channelScreen && _cursor >= 0 && _cursor < _itemCount) {
|
if (_channelScreen && _cursor >= 0 && _cursor < _itemCount) {
|
||||||
_channelScreen->setViewChannelIdx(_items[_cursor]);
|
_channelScreen->setViewChannelIdx(_items[_cursor]);
|
||||||
}
|
}
|
||||||
_wantExit = true;
|
_wantExit = true;
|
||||||
return true; // Consumed — caller checks wantsExit() and navigates
|
return true; // Consumed -- caller checks wantsExit() and navigates
|
||||||
}
|
}
|
||||||
|
|
||||||
// Q / backspace — cancel without changing channel, signal exit
|
// Q / backspace -- cancel without changing channel, signal exit
|
||||||
if (c == 'q' || c == 'Q' || c == '\b' || c == KEY_CANCEL) {
|
if (c == 'q' || c == 'Q' || c == '\b' || c == KEY_CANCEL) {
|
||||||
_wantExit = true;
|
_wantExit = true;
|
||||||
return true;
|
return true;
|
||||||
@@ -405,10 +500,22 @@ public:
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// Touch hit test (virtual coordinates)
|
// Touch hit test (virtual coordinates)
|
||||||
// Returns: 0=miss, 1=cursor moved, 2=activate.
|
// Returns: 0=miss, 1=cursor moved, 2=activate.
|
||||||
// T5S3 bubbles: any tap on a bubble → 2 (direct open).
|
// T5S3 bubbles: any tap on a bubble -> 2 (direct open).
|
||||||
// T-Deck Pro list: 1st tap → 1 (highlight), 2nd tap same row → 2.
|
// T-Deck Pro list: 1st tap -> 1 (highlight), 2nd tap same row -> 2.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int selectAtVxVy(int vx, int vy) {
|
int selectAtVxVy(int vx, int vy) {
|
||||||
|
// If delete confirmation is showing:
|
||||||
|
// T5S3: tap = confirm (return 2 → KEY_ENTER → handleInput confirms)
|
||||||
|
// T-Deck Pro: tap = cancel (dismiss overlay, stay on picker)
|
||||||
|
if (_confirmDelete) {
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
return 2; // Confirm — maps to KEY_ENTER in mapTouchTap
|
||||||
|
#else
|
||||||
|
_confirmDelete = false;
|
||||||
|
return 1; // Cancel — redraw without activating
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
// Vertical bubble list hit test
|
// Vertical bubble list hit test
|
||||||
if (vy < _gridTop || _cellH == 0) return 0;
|
if (vy < _gridTop || _cellH == 0) return 0;
|
||||||
@@ -420,7 +527,7 @@ public:
|
|||||||
_cursor = idx;
|
_cursor = idx;
|
||||||
return 2; // Direct open on tap
|
return 2; // Direct open on tap
|
||||||
#else
|
#else
|
||||||
// T-Deck Pro / MAX list hit test — uses NodePrefs for large_font compatibility
|
// T-Deck Pro / MAX list hit test -- uses NodePrefs for large_font compatibility
|
||||||
NodePrefs* prefs = the_mesh.getNodePrefs();
|
NodePrefs* prefs = the_mesh.getNodePrefs();
|
||||||
int lineH = prefs->smallLineH();
|
int lineH = prefs->smallLineH();
|
||||||
const int headerH = 14;
|
const int headerH = 14;
|
||||||
|
|||||||
@@ -0,0 +1,171 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// GamesMenuScreen -- Game launcher menu for Meck
|
||||||
|
//
|
||||||
|
// Lists available games. W/S to navigate, Enter to launch, Q to exit.
|
||||||
|
// Uses wantsExit() and wantsLaunch() flags for navigation -- same pattern
|
||||||
|
// as ChannelPickerScreen.
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
#include <helpers/ui/UIScreen.h>
|
||||||
|
#include <helpers/ui/DisplayDriver.h>
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
class UITask;
|
||||||
|
|
||||||
|
// Game identifiers -- add new entries here as games are added
|
||||||
|
enum GameID {
|
||||||
|
GAME_NONE = 0,
|
||||||
|
GAME_SNAKE,
|
||||||
|
GAME_MINESWEEPER,
|
||||||
|
// GAME_2048,
|
||||||
|
GAME_COUNT // Must be last -- used for array sizing
|
||||||
|
};
|
||||||
|
|
||||||
|
class GamesMenuScreen : public UIScreen {
|
||||||
|
private:
|
||||||
|
UITask* _task;
|
||||||
|
bool _wantsExit;
|
||||||
|
bool _wantsLaunch;
|
||||||
|
int _cursor;
|
||||||
|
GameID _selectedGame;
|
||||||
|
|
||||||
|
// Game registry -- add new games here
|
||||||
|
struct GameEntry {
|
||||||
|
GameID id;
|
||||||
|
const char* name;
|
||||||
|
const char* description;
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr int NUM_GAMES = 2; // Increment as games are added
|
||||||
|
|
||||||
|
static const GameEntry* getGames() {
|
||||||
|
static const GameEntry games[NUM_GAMES] = {
|
||||||
|
{ GAME_SNAKE, "Snake", "Classic Nokia-style" },
|
||||||
|
{ GAME_MINESWEEPER, "Minesweeper", "Find the mines" },
|
||||||
|
// { GAME_2048, "2048", "Slide and merge" },
|
||||||
|
};
|
||||||
|
return games;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
GamesMenuScreen(UITask* task)
|
||||||
|
: _task(task), _wantsExit(false), _wantsLaunch(false),
|
||||||
|
_cursor(0), _selectedGame(GAME_NONE) {}
|
||||||
|
|
||||||
|
bool wantsExit() const { return _wantsExit; }
|
||||||
|
bool wantsLaunch() const { return _wantsLaunch; }
|
||||||
|
GameID selectedGame() const { return _selectedGame; }
|
||||||
|
|
||||||
|
void enter() {
|
||||||
|
_wantsExit = false;
|
||||||
|
_wantsLaunch = false;
|
||||||
|
_selectedGame = GAME_NONE;
|
||||||
|
// Preserve cursor position so returning from a game stays on the same entry
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearFlags() {
|
||||||
|
_wantsExit = false;
|
||||||
|
_wantsLaunch = false;
|
||||||
|
_selectedGame = GAME_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------- Input -------
|
||||||
|
bool handleInput(char c) override {
|
||||||
|
switch (c) {
|
||||||
|
case 'w': case 'W':
|
||||||
|
if (_cursor > 0) _cursor--;
|
||||||
|
return true;
|
||||||
|
case 's': case 'S':
|
||||||
|
if (_cursor < NUM_GAMES - 1) _cursor++;
|
||||||
|
return true;
|
||||||
|
case '\r':
|
||||||
|
_selectedGame = getGames()[_cursor].id;
|
||||||
|
_wantsLaunch = true;
|
||||||
|
return true;
|
||||||
|
case 'q': case 'Q':
|
||||||
|
_wantsExit = true;
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------- Render -------
|
||||||
|
int render(DisplayDriver& display) override {
|
||||||
|
display.startFrame();
|
||||||
|
display.setTextSize(1);
|
||||||
|
|
||||||
|
// --- Header ---
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.drawTextCentered(display.width() / 2, 2, "Games");
|
||||||
|
#else
|
||||||
|
display.setCursor(2, 2);
|
||||||
|
display.print("Games");
|
||||||
|
#endif
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(0, 12, display.width(), 1);
|
||||||
|
|
||||||
|
// --- Game list ---
|
||||||
|
int y = 18;
|
||||||
|
int lineH = 16;
|
||||||
|
|
||||||
|
for (int i = 0; i < NUM_GAMES; i++) {
|
||||||
|
bool selected = (i == _cursor);
|
||||||
|
|
||||||
|
if (selected) {
|
||||||
|
// Highlight bar
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.fillRect(0, y - 1, display.width(), lineH);
|
||||||
|
display.setColor(DisplayDriver::DARK);
|
||||||
|
} else {
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.drawTextCentered(display.width() / 2, y + 2, getGames()[i].name);
|
||||||
|
#else
|
||||||
|
display.setCursor(6, y + 2);
|
||||||
|
display.print(getGames()[i].name);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
y += lineH;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Footer ---
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.setTextSize(0);
|
||||||
|
display.drawTextCentered(display.width() / 2, display.height() - 8, "Tap to select");
|
||||||
|
display.setTextSize(1);
|
||||||
|
#else
|
||||||
|
display.setTextSize(1);
|
||||||
|
int fy = display.height() - 12;
|
||||||
|
display.drawRect(0, fy - 2, display.width(), 1);
|
||||||
|
display.setCursor(2, fy);
|
||||||
|
display.print("Enter:Play Q:Back");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 5000; // Static menu -- slow refresh
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- T5S3 touch: tap to select game entry ---
|
||||||
|
int selectRowAtVY(int vy) {
|
||||||
|
int y = 18;
|
||||||
|
int lineH = 16;
|
||||||
|
if (vy < y) return 0; // Above list
|
||||||
|
int row = (vy - y) / lineH;
|
||||||
|
if (row >= NUM_GAMES) return 0; // Below list
|
||||||
|
|
||||||
|
if (row == _cursor) {
|
||||||
|
// Tapped current selection -- launch
|
||||||
|
_selectedGame = getGames()[_cursor].id;
|
||||||
|
_wantsLaunch = true;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
_cursor = row;
|
||||||
|
return 1; // Moved cursor
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,466 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// MinesweeperScreen -- Classic Minesweeper for Meck e-ink devices
|
||||||
|
//
|
||||||
|
// 9x9 grid, 10 mines (classic Beginner difficulty).
|
||||||
|
// First reveal is always safe -- mines are placed after the first click.
|
||||||
|
// Fully turn-based: no tick timer, renders only on input. Perfect for e-ink.
|
||||||
|
//
|
||||||
|
// T-Deck Pro: 14x14 pixel cells (126x126 grid area on 240x320 display)
|
||||||
|
// T5S3: 8x8 pixel cells (72x72 grid area on 128x128 virtual display)
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
#include <helpers/ui/UIScreen.h>
|
||||||
|
#include <helpers/ui/DisplayDriver.h>
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
class UITask;
|
||||||
|
|
||||||
|
// -- Grid parameters --
|
||||||
|
#define MINE_GRID_W 9
|
||||||
|
#define MINE_GRID_H 9
|
||||||
|
#define MINE_COUNT 10
|
||||||
|
#define MINE_TOTAL (MINE_GRID_W * MINE_GRID_H)
|
||||||
|
|
||||||
|
// -- Cell sizes per platform --
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
#define MINE_CELL 8
|
||||||
|
#define MINE_HDR 14
|
||||||
|
#define MINE_FTR 10
|
||||||
|
#else
|
||||||
|
#define MINE_CELL 14
|
||||||
|
#define MINE_HDR 14
|
||||||
|
#define MINE_FTR 14
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MINE_VALUE 9 // Content value indicating a mine
|
||||||
|
|
||||||
|
class MinesweeperScreen : public UIScreen {
|
||||||
|
public:
|
||||||
|
enum GameState { READY, PLAYING, WON, LOST };
|
||||||
|
enum CellState : uint8_t { CELL_HIDDEN, CELL_REVEALED, CELL_FLAGGED };
|
||||||
|
|
||||||
|
private:
|
||||||
|
UITask* _task;
|
||||||
|
bool _wantsExit;
|
||||||
|
|
||||||
|
// Grid
|
||||||
|
uint8_t _content[MINE_TOTAL]; // 0-8 = adjacent mine count, MINE_VALUE = mine
|
||||||
|
CellState _cellState[MINE_TOTAL]; // Hidden, revealed, or flagged
|
||||||
|
|
||||||
|
// Game state
|
||||||
|
GameState _state;
|
||||||
|
bool _minesPlaced; // False until first reveal (first-click safety)
|
||||||
|
int _cursorX, _cursorY;
|
||||||
|
int _flagCount;
|
||||||
|
int _revealedCount;
|
||||||
|
|
||||||
|
// Display layout (recomputed each render based on game state)
|
||||||
|
int _offsetX, _offsetY;
|
||||||
|
bool _cursorBlink; // Toggles each render for slow blink cursor
|
||||||
|
|
||||||
|
// Simple xorshift PRNG
|
||||||
|
uint16_t _rngState;
|
||||||
|
|
||||||
|
uint16_t rng() {
|
||||||
|
_rngState ^= _rngState << 7;
|
||||||
|
_rngState ^= _rngState >> 9;
|
||||||
|
_rngState ^= _rngState << 8;
|
||||||
|
return _rngState;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Grid helpers --
|
||||||
|
|
||||||
|
int idx(int x, int y) const { return y * MINE_GRID_W + x; }
|
||||||
|
bool inBounds(int x, int y) const { return x >= 0 && x < MINE_GRID_W && y >= 0 && y < MINE_GRID_H; }
|
||||||
|
|
||||||
|
void resetGrid() {
|
||||||
|
memset(_content, 0, sizeof(_content));
|
||||||
|
for (int i = 0; i < MINE_TOTAL; i++) _cellState[i] = CELL_HIDDEN;
|
||||||
|
_minesPlaced = false;
|
||||||
|
_flagCount = 0;
|
||||||
|
_revealedCount = 0;
|
||||||
|
_cursorX = MINE_GRID_W / 2;
|
||||||
|
_cursorY = MINE_GRID_H / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Place mines randomly, excluding the first-clicked cell and its neighbours
|
||||||
|
void placeMines(int safeX, int safeY) {
|
||||||
|
_rngState = (uint16_t)(millis() ^ 0xC0DE);
|
||||||
|
int placed = 0;
|
||||||
|
while (placed < MINE_COUNT) {
|
||||||
|
int x = rng() % MINE_GRID_W;
|
||||||
|
int y = rng() % MINE_GRID_H;
|
||||||
|
// Skip safe zone (first click + 8 neighbours)
|
||||||
|
if (abs(x - safeX) <= 1 && abs(y - safeY) <= 1) continue;
|
||||||
|
// Skip if already a mine
|
||||||
|
if (_content[idx(x, y)] == MINE_VALUE) continue;
|
||||||
|
_content[idx(x, y)] = MINE_VALUE;
|
||||||
|
placed++;
|
||||||
|
}
|
||||||
|
// Compute adjacency counts
|
||||||
|
for (int cy = 0; cy < MINE_GRID_H; cy++) {
|
||||||
|
for (int cx = 0; cx < MINE_GRID_W; cx++) {
|
||||||
|
if (_content[idx(cx, cy)] == MINE_VALUE) continue;
|
||||||
|
int count = 0;
|
||||||
|
for (int dy = -1; dy <= 1; dy++) {
|
||||||
|
for (int dx = -1; dx <= 1; dx++) {
|
||||||
|
if (dx == 0 && dy == 0) continue;
|
||||||
|
int nx = cx + dx, ny = cy + dy;
|
||||||
|
if (inBounds(nx, ny) && _content[idx(nx, ny)] == MINE_VALUE) count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_content[idx(cx, cy)] = count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_minesPlaced = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flood-fill reveal from (x,y). Reveals empty cells and their numbered borders.
|
||||||
|
void floodReveal(int x, int y) {
|
||||||
|
if (!inBounds(x, y)) return;
|
||||||
|
int i = idx(x, y);
|
||||||
|
if (_cellState[i] != CELL_HIDDEN) return;
|
||||||
|
if (_content[i] == MINE_VALUE) return;
|
||||||
|
|
||||||
|
_cellState[i] = CELL_REVEALED;
|
||||||
|
_revealedCount++;
|
||||||
|
|
||||||
|
// If this cell is 0 (no adjacent mines), reveal all neighbours
|
||||||
|
if (_content[i] == 0) {
|
||||||
|
for (int dy = -1; dy <= 1; dy++) {
|
||||||
|
for (int dx = -1; dx <= 1; dx++) {
|
||||||
|
if (dx == 0 && dy == 0) continue;
|
||||||
|
floodReveal(x + dx, y + dy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reveal a cell. Returns false if mine was hit.
|
||||||
|
bool revealCell(int x, int y) {
|
||||||
|
int i = idx(x, y);
|
||||||
|
if (_cellState[i] != CELL_HIDDEN) return true; // Already revealed or flagged
|
||||||
|
|
||||||
|
// First click: place mines safely
|
||||||
|
if (!_minesPlaced) {
|
||||||
|
placeMines(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_content[i] == MINE_VALUE) {
|
||||||
|
// Hit a mine -- game over
|
||||||
|
_cellState[i] = CELL_REVEALED;
|
||||||
|
_state = LOST;
|
||||||
|
revealAllMines();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
floodReveal(x, y);
|
||||||
|
checkWin();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggleFlag(int x, int y) {
|
||||||
|
int i = idx(x, y);
|
||||||
|
if (_cellState[i] == CELL_HIDDEN) {
|
||||||
|
_cellState[i] = CELL_FLAGGED;
|
||||||
|
_flagCount++;
|
||||||
|
} else if (_cellState[i] == CELL_FLAGGED) {
|
||||||
|
_cellState[i] = CELL_HIDDEN;
|
||||||
|
_flagCount--;
|
||||||
|
}
|
||||||
|
// Can't flag revealed cells
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkWin() {
|
||||||
|
// Win when all non-mine cells are revealed
|
||||||
|
if (_revealedCount == MINE_TOTAL - MINE_COUNT) {
|
||||||
|
_state = WON;
|
||||||
|
// Auto-flag remaining mines
|
||||||
|
for (int i = 0; i < MINE_TOTAL; i++) {
|
||||||
|
if (_content[i] == MINE_VALUE && _cellState[i] == CELL_HIDDEN) {
|
||||||
|
_cellState[i] = CELL_FLAGGED;
|
||||||
|
_flagCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void revealAllMines() {
|
||||||
|
for (int i = 0; i < MINE_TOTAL; i++) {
|
||||||
|
if (_content[i] == MINE_VALUE) {
|
||||||
|
_cellState[i] = CELL_REVEALED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Drawing helpers --
|
||||||
|
|
||||||
|
void drawCell(DisplayDriver& display, int gx, int gy) const {
|
||||||
|
int px = _offsetX + gx * MINE_CELL;
|
||||||
|
int py = _offsetY + gy * MINE_CELL;
|
||||||
|
int i = idx(gx, gy);
|
||||||
|
bool isCursor = (gx == _cursorX && gy == _cursorY && _state == PLAYING);
|
||||||
|
|
||||||
|
if (_cellState[i] == CELL_HIDDEN) {
|
||||||
|
if (isCursor && !_cursorBlink) {
|
||||||
|
// Cursor blink OFF phase: outline only (visible gap in the solid grid)
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(px, py, MINE_CELL, MINE_CELL);
|
||||||
|
display.drawRect(px + 1, py + 1, MINE_CELL - 2, MINE_CELL - 2);
|
||||||
|
} else {
|
||||||
|
// Solid filled with 1px inset (preserves grid lines between cells)
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.fillRect(px + 1, py + 1, MINE_CELL - 2, MINE_CELL - 2);
|
||||||
|
}
|
||||||
|
} else if (_cellState[i] == CELL_FLAGGED) {
|
||||||
|
if (isCursor && !_cursorBlink) {
|
||||||
|
// Cursor blink OFF phase: outline with F
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(px, py, MINE_CELL, MINE_CELL);
|
||||||
|
display.drawRect(px + 1, py + 1, MINE_CELL - 2, MINE_CELL - 2);
|
||||||
|
} else {
|
||||||
|
// Solid fill with 1px inset
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.fillRect(px + 1, py + 1, MINE_CELL - 2, MINE_CELL - 2);
|
||||||
|
}
|
||||||
|
// F overlay
|
||||||
|
display.setColor((isCursor && !_cursorBlink) ? DisplayDriver::LIGHT : DisplayDriver::DARK);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.setTextSize(0);
|
||||||
|
display.drawTextCentered(px + MINE_CELL / 2, py + 1, "F");
|
||||||
|
#else
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.drawTextCentered(px + MINE_CELL / 2, py + 3, "F");
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
// Revealed cell: thin border
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(px, py, MINE_CELL, MINE_CELL);
|
||||||
|
|
||||||
|
if (_content[i] == MINE_VALUE) {
|
||||||
|
// Mine: solid dot in centre
|
||||||
|
int dotR = MINE_CELL / 4;
|
||||||
|
if (dotR < 2) dotR = 2;
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.fillRect(px + MINE_CELL/2 - dotR, py + MINE_CELL/2 - dotR, dotR*2, dotR*2);
|
||||||
|
} else if (_content[i] > 0) {
|
||||||
|
// Number 1-8
|
||||||
|
char num[2] = { (char)('0' + _content[i]), '\0' };
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.setTextSize(0);
|
||||||
|
display.drawTextCentered(px + MINE_CELL / 2, py + 1, num);
|
||||||
|
#else
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.drawTextCentered(px + MINE_CELL / 2, py + 3, num);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
// Revealed 0: just the border (already drawn)
|
||||||
|
|
||||||
|
// Cursor on revealed cell: green double border
|
||||||
|
if (isCursor) {
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
display.drawRect(px, py, MINE_CELL, MINE_CELL);
|
||||||
|
display.drawRect(px + 1, py + 1, MINE_CELL - 2, MINE_CELL - 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
MinesweeperScreen(UITask* task)
|
||||||
|
: _task(task), _wantsExit(false), _state(READY), _minesPlaced(false),
|
||||||
|
_cursorX(MINE_GRID_W / 2), _cursorY(MINE_GRID_H / 2),
|
||||||
|
_flagCount(0), _revealedCount(0),
|
||||||
|
_offsetX(0), _offsetY(0), _cursorBlink(false), _rngState(0xBEEF) {
|
||||||
|
memset(_content, 0, sizeof(_content));
|
||||||
|
for (int i = 0; i < MINE_TOTAL; i++) _cellState[i] = CELL_HIDDEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wantsExit() const { return _wantsExit; }
|
||||||
|
void clearExit() { _wantsExit = false; }
|
||||||
|
GameState getState() const { return _state; }
|
||||||
|
|
||||||
|
void enter() {
|
||||||
|
_wantsExit = false;
|
||||||
|
// If game was PLAYING, resume where we left off
|
||||||
|
// If READY, WON, or LOST, show that state as-is
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------- Input -------
|
||||||
|
bool handleInput(char c) override {
|
||||||
|
switch (_state) {
|
||||||
|
case READY:
|
||||||
|
if (c == '\r') {
|
||||||
|
resetGrid();
|
||||||
|
_state = PLAYING;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c == 'q' || c == 'Q') { _wantsExit = true; return true; }
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case PLAYING:
|
||||||
|
switch (c) {
|
||||||
|
case 'w': case 'W': if (_cursorY > 0) _cursorY--; return true;
|
||||||
|
case 's': case 'S': if (_cursorY < MINE_GRID_H - 1) _cursorY++; return true;
|
||||||
|
case 'a': case 'A': if (_cursorX > 0) _cursorX--; return true;
|
||||||
|
case 'd': case 'D': if (_cursorX < MINE_GRID_W - 1) _cursorX++; return true;
|
||||||
|
case '\r':
|
||||||
|
revealCell(_cursorX, _cursorY);
|
||||||
|
return true;
|
||||||
|
case 'f': case 'F':
|
||||||
|
toggleFlag(_cursorX, _cursorY);
|
||||||
|
return true;
|
||||||
|
case 'q': case 'Q':
|
||||||
|
_wantsExit = true;
|
||||||
|
return true;
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
case WON:
|
||||||
|
case LOST:
|
||||||
|
if (c == '\r') {
|
||||||
|
resetGrid();
|
||||||
|
_state = PLAYING;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c == 'q' || c == 'Q') { _wantsExit = true; return true; }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------- Render -------
|
||||||
|
int render(DisplayDriver& display) override {
|
||||||
|
// Compute grid offset based on state
|
||||||
|
// PLAYING: full screen (no header/footer) for clean grid
|
||||||
|
// Other states: header + footer visible
|
||||||
|
int gridPixW = MINE_GRID_W * MINE_CELL;
|
||||||
|
int gridPixH = MINE_GRID_H * MINE_CELL;
|
||||||
|
if (_state == PLAYING) {
|
||||||
|
_offsetX = (display.width() - gridPixW) / 2;
|
||||||
|
_offsetY = (display.height() - gridPixH) / 2;
|
||||||
|
} else {
|
||||||
|
int usableH = display.height() - MINE_HDR - MINE_FTR;
|
||||||
|
_offsetX = (display.width() - gridPixW) / 2;
|
||||||
|
_offsetY = MINE_HDR + (usableH - gridPixH) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle cursor blink each render cycle
|
||||||
|
if (_state == PLAYING) _cursorBlink = !_cursorBlink;
|
||||||
|
|
||||||
|
display.startFrame();
|
||||||
|
display.setTextSize(1);
|
||||||
|
|
||||||
|
if (_state == READY) {
|
||||||
|
// --- READY: header + instructions + footer ---
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.drawTextCentered(display.width() / 2, 2, "Minesweeper");
|
||||||
|
#else
|
||||||
|
display.setCursor(2, 2);
|
||||||
|
display.print("Minesweeper");
|
||||||
|
#endif
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(0, MINE_HDR - 2, display.width(), 1);
|
||||||
|
|
||||||
|
int cx = display.width() / 2;
|
||||||
|
int y = MINE_HDR + 10;
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawTextCentered(cx, y, "Minesweeper");
|
||||||
|
y += 16;
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.drawTextCentered(cx, y, "Swipe to move cursor");
|
||||||
|
y += 11;
|
||||||
|
display.drawTextCentered(cx, y, "Tap to reveal");
|
||||||
|
y += 11;
|
||||||
|
display.drawTextCentered(cx, y, "Long press to flag");
|
||||||
|
#else
|
||||||
|
display.drawTextCentered(cx, y, "W/S/A/D to move cursor");
|
||||||
|
y += 11;
|
||||||
|
display.drawTextCentered(cx, y, "Enter to reveal a cell");
|
||||||
|
y += 11;
|
||||||
|
display.drawTextCentered(cx, y, "F to flag a mine");
|
||||||
|
#endif
|
||||||
|
y += 16;
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
char info[32];
|
||||||
|
snprintf(info, sizeof(info), "%dx%d grid, %d mines", MINE_GRID_W, MINE_GRID_H, MINE_COUNT);
|
||||||
|
display.drawTextCentered(cx, y, info);
|
||||||
|
y += 16;
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.drawTextCentered(cx, y, "Tap to start");
|
||||||
|
#else
|
||||||
|
display.drawTextCentered(cx, y, "Press Enter to start");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Footer
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
#if !defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
int fy = display.height() - 12;
|
||||||
|
display.drawRect(0, fy - 2, display.width(), 1);
|
||||||
|
display.setCursor(2, fy);
|
||||||
|
display.print("Enter:Start Q:Back");
|
||||||
|
#endif
|
||||||
|
return 5000;
|
||||||
|
|
||||||
|
} else if (_state == PLAYING) {
|
||||||
|
// --- PLAYING: full screen grid, no header/footer ---
|
||||||
|
|
||||||
|
// Draw grid border
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(_offsetX - 1, _offsetY - 1, gridPixW + 2, gridPixH + 2);
|
||||||
|
|
||||||
|
// Draw all cells
|
||||||
|
for (int gy = 0; gy < MINE_GRID_H; gy++) {
|
||||||
|
for (int gx = 0; gx < MINE_GRID_W; gx++) {
|
||||||
|
drawCell(display, gx, gy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 100; // Blink cycle -- clamped to 800ms by render floor
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// --- WON / LOST: grid + overlay ---
|
||||||
|
|
||||||
|
// Draw grid border
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(_offsetX - 1, _offsetY - 1, gridPixW + 2, gridPixH + 2);
|
||||||
|
|
||||||
|
// Draw all cells (no cursor blink in end state)
|
||||||
|
for (int gy = 0; gy < MINE_GRID_H; gy++) {
|
||||||
|
for (int gx = 0; gx < MINE_GRID_W; gx++) {
|
||||||
|
drawCell(display, gx, gy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overlay
|
||||||
|
int cx = display.width() / 2;
|
||||||
|
int cy = display.height() / 2;
|
||||||
|
int boxW = display.width() * 3 / 4;
|
||||||
|
int boxH = 50;
|
||||||
|
int boxX = cx - boxW / 2;
|
||||||
|
int boxY = cy - boxH / 2;
|
||||||
|
|
||||||
|
display.setColor(DisplayDriver::DARK);
|
||||||
|
display.fillRect(boxX, boxY, boxW, boxH);
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(boxX, boxY, boxW, boxH);
|
||||||
|
|
||||||
|
int ty = boxY + 10;
|
||||||
|
if (_state == WON) {
|
||||||
|
display.setColor(DisplayDriver::YELLOW);
|
||||||
|
display.drawTextCentered(cx, ty, "Cleared!");
|
||||||
|
} else {
|
||||||
|
display.drawTextCentered(cx, ty, "Boom!");
|
||||||
|
}
|
||||||
|
ty += 16;
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
display.drawTextCentered(cx, ty, "Enter:Retry Q:Back");
|
||||||
|
|
||||||
|
return 5000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -37,6 +37,10 @@ void ModemManager::begin() {
|
|||||||
_ringing = false;
|
_ringing = false;
|
||||||
_nextRingTone = 0;
|
_nextRingTone = 0;
|
||||||
_toneActive = false;
|
_toneActive = false;
|
||||||
|
_pendingToneIdx = -1;
|
||||||
|
_tonesTransferred = false;
|
||||||
|
_notifTonePlaying = false;
|
||||||
|
_notifToneStartTime = 0;
|
||||||
_urcPos = 0;
|
_urcPos = 0;
|
||||||
_imei[0] = '\0';
|
_imei[0] = '\0';
|
||||||
_imsi[0] = '\0';
|
_imsi[0] = '\0';
|
||||||
@@ -67,6 +71,12 @@ void ModemManager::shutdown() {
|
|||||||
|
|
||||||
MESH_DEBUG_PRINTLN("[Modem] shutdown()");
|
MESH_DEBUG_PRINTLN("[Modem] shutdown()");
|
||||||
|
|
||||||
|
// Stop any playing notification tone
|
||||||
|
if (_notifTonePlaying) {
|
||||||
|
// Best-effort stop -- task is about to be deleted
|
||||||
|
_pendingToneIdx = -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Hang up any active call first
|
// Hang up any active call first
|
||||||
if (isCallActive()) {
|
if (isCallActive()) {
|
||||||
CallCommand cmd;
|
CallCommand cmd;
|
||||||
@@ -171,6 +181,38 @@ bool ModemManager::pollCallEvent(CallEvent& out) {
|
|||||||
return xQueueReceive(_callEvtQueue, &out, 0) == pdTRUE;
|
return xQueueReceive(_callEvtQueue, &out, 0) == pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Public API - Notification Tones
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void ModemManager::requestNotifTone(int8_t toneIdx) {
|
||||||
|
if (toneIdx < 0 || toneIdx >= MODEM_BUNDLED_TONE_COUNT) return;
|
||||||
|
if (!_tonesTransferred) return; // Not ready yet
|
||||||
|
if (isCallActive()) return; // Don't interrupt voice calls
|
||||||
|
_pendingToneIdx = toneIdx;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t ModemManager::findToneByName(const char* name) {
|
||||||
|
if (!name || !name[0]) return -1;
|
||||||
|
|
||||||
|
for (int i = 0; i < MODEM_BUNDLED_TONE_COUNT; i++) {
|
||||||
|
// Match against filename (with or without .wav extension)
|
||||||
|
const char* fn = modemBundledTones[i].filename;
|
||||||
|
if (strcasecmp(name, fn) == 0) return i;
|
||||||
|
|
||||||
|
// Try matching without extension
|
||||||
|
const char* dot = strrchr(fn, '.');
|
||||||
|
if (dot) {
|
||||||
|
int baseLen = dot - fn;
|
||||||
|
if ((int)strlen(name) == baseLen && strncasecmp(name, fn, baseLen) == 0) return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also match against label
|
||||||
|
if (strcasecmp(name, modemBundledTones[i].label) == 0) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// State helpers
|
// State helpers
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -262,11 +304,11 @@ void ModemManager::saveAPNConfig(const char* apn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// APN Resolution — called during init after network registration
|
// APN Resolution -- called during init after network registration
|
||||||
//
|
//
|
||||||
// Priority:
|
// Priority:
|
||||||
// 1. User-configured APN (from /sms/apn.cfg)
|
// 1. User-configured APN (from /sms/apn.cfg)
|
||||||
// 2. Network-provisioned APN (AT+CGDCONT? — modem already has one)
|
// 2. Network-provisioned APN (AT+CGDCONT? -- modem already has one)
|
||||||
// 3. Auto-detected from IMSI via embedded ApnDatabase
|
// 3. Auto-detected from IMSI via embedded ApnDatabase
|
||||||
// 4. Blank (some carriers work with empty APN)
|
// 4. Blank (some carriers work with empty APN)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -327,7 +369,7 @@ void ModemManager::resolveAPN() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. No APN found — leave blank
|
// 4. No APN found -- leave blank
|
||||||
_apn[0] = '\0';
|
_apn[0] = '\0';
|
||||||
strcpy(_apnSource, "none");
|
strcpy(_apnSource, "none");
|
||||||
MESH_DEBUG_PRINTLN("[Modem] APN: none detected (IMSI=%s)", _imsi[0] ? _imsi : "unknown");
|
MESH_DEBUG_PRINTLN("[Modem] APN: none detected (IMSI=%s)", _imsi[0] ? _imsi : "unknown");
|
||||||
@@ -337,12 +379,13 @@ void ModemManager::resolveAPN() {
|
|||||||
// URC (Unsolicited Result Code) Handling
|
// URC (Unsolicited Result Code) Handling
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// The modem can send unsolicited messages at any time:
|
// The modem can send unsolicited messages at any time:
|
||||||
// RING — incoming call ringing
|
// RING -- incoming call ringing
|
||||||
// +CLIP: "+1234...",145,... — caller ID (after AT+CLIP=1)
|
// +CLIP: "+1234...",145,... -- caller ID (after AT+CLIP=1)
|
||||||
// NO CARRIER — call ended by remote
|
// NO CARRIER -- call ended by remote
|
||||||
// BUSY — outgoing call busy
|
// BUSY -- outgoing call busy
|
||||||
// NO ANSWER — outgoing call no answer
|
// NO ANSWER -- outgoing call no answer
|
||||||
// +CMTI: "SM",<idx> — new SMS arrived
|
// +CMTI: "SM",<idx> -- new SMS arrived
|
||||||
|
// +AUDIOSTATE: audio play stop -- notification tone finished
|
||||||
//
|
//
|
||||||
// drainURCs() accumulates bytes into a line buffer and calls
|
// drainURCs() accumulates bytes into a line buffer and calls
|
||||||
// processURCLine() for each complete line.
|
// processURCLine() for each complete line.
|
||||||
@@ -354,7 +397,7 @@ void ModemManager::drainURCs() {
|
|||||||
|
|
||||||
// Accumulate into line buffer
|
// Accumulate into line buffer
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
// End of line — process if non-empty
|
// End of line -- process if non-empty
|
||||||
if (_urcPos > 0) {
|
if (_urcPos > 0) {
|
||||||
// Trim trailing \r
|
// Trim trailing \r
|
||||||
while (_urcPos > 0 && _urcBuf[_urcPos - 1] == '\r') _urcPos--;
|
while (_urcPos > 0 && _urcBuf[_urcPos - 1] == '\r') _urcPos--;
|
||||||
@@ -418,7 +461,7 @@ void ModemManager::processURCLine(const char* line) {
|
|||||||
if (strcmp(line, "NO CARRIER") == 0) {
|
if (strcmp(line, "NO CARRIER") == 0) {
|
||||||
MESH_DEBUG_PRINTLN("[Modem] URC: NO CARRIER");
|
MESH_DEBUG_PRINTLN("[Modem] URC: NO CARRIER");
|
||||||
if (_state == ModemState::RINGING_IN) {
|
if (_state == ModemState::RINGING_IN) {
|
||||||
// Incoming call ended before we answered — missed call
|
// Incoming call ended before we answered -- missed call
|
||||||
queueCallEvent(CallEventType::MISSED, _callPhone);
|
queueCallEvent(CallEventType::MISSED, _callPhone);
|
||||||
} else if (_state == ModemState::DIALING || _state == ModemState::IN_CALL) {
|
} else if (_state == ModemState::DIALING || _state == ModemState::IN_CALL) {
|
||||||
uint32_t duration = 0;
|
uint32_t duration = 0;
|
||||||
@@ -465,7 +508,7 @@ void ModemManager::processURCLine(const char* line) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- VOICE CALL: BEGIN — A76xx-specific: audio path established ---
|
// --- VOICE CALL: BEGIN -- A76xx-specific: audio path established ---
|
||||||
if (strncmp(line, "VOICE CALL: BEGIN", 17) == 0) {
|
if (strncmp(line, "VOICE CALL: BEGIN", 17) == 0) {
|
||||||
MESH_DEBUG_PRINTLN("[Modem] URC: VOICE CALL: BEGIN");
|
MESH_DEBUG_PRINTLN("[Modem] URC: VOICE CALL: BEGIN");
|
||||||
if (_state == ModemState::DIALING) {
|
if (_state == ModemState::DIALING) {
|
||||||
@@ -477,7 +520,7 @@ void ModemManager::processURCLine(const char* line) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- VOICE CALL: END — A76xx-specific: audio path closed ---
|
// --- VOICE CALL: END -- A76xx-specific: audio path closed ---
|
||||||
// Format: "VOICE CALL: END: <duration>"
|
// Format: "VOICE CALL: END: <duration>"
|
||||||
if (strncmp(line, "VOICE CALL: END", 15) == 0) {
|
if (strncmp(line, "VOICE CALL: END", 15) == 0) {
|
||||||
MESH_DEBUG_PRINTLN("[Modem] URC: %s", line);
|
MESH_DEBUG_PRINTLN("[Modem] URC: %s", line);
|
||||||
@@ -502,6 +545,20 @@ void ModemManager::processURCLine(const char* line) {
|
|||||||
_callStartTime = 0;
|
_callStartTime = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- +AUDIOSTATE: notification tone playback status ---
|
||||||
|
// +AUDIOSTATE: audio play -- playback started
|
||||||
|
// +AUDIOSTATE: audio play stop -- playback finished
|
||||||
|
if (strncmp(line, "+AUDIOSTATE:", 12) == 0) {
|
||||||
|
if (strstr(line, "play stop") || strstr(line, "PLAY STOP")) {
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] URC: AUDIOSTATE play stop");
|
||||||
|
_notifTonePlaying = false;
|
||||||
|
} else if (strstr(line, "play") || strstr(line, "PLAY")) {
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] URC: AUDIOSTATE play");
|
||||||
|
// Playback confirmed started -- _notifTonePlaying already set
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModemManager::queueCallEvent(CallEventType type, const char* phone, uint32_t duration) {
|
void ModemManager::queueCallEvent(CallEventType type, const char* phone, uint32_t duration) {
|
||||||
@@ -526,7 +583,7 @@ bool ModemManager::doDialCall(const char* phone) {
|
|||||||
_callPhone[SMS_PHONE_LEN - 1] = '\0';
|
_callPhone[SMS_PHONE_LEN - 1] = '\0';
|
||||||
_state = ModemState::DIALING;
|
_state = ModemState::DIALING;
|
||||||
|
|
||||||
// ATD<number>; — the semicolon makes it a voice call (not data)
|
// ATD<number>; -- the semicolon makes it a voice call (not data)
|
||||||
char cmd[32];
|
char cmd[32];
|
||||||
snprintf(cmd, sizeof(cmd), "ATD%s;", phone);
|
snprintf(cmd, sizeof(cmd), "ATD%s;", phone);
|
||||||
|
|
||||||
@@ -538,11 +595,11 @@ bool ModemManager::doDialCall(const char* phone) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ATD returned OK — call is being set up.
|
// ATD returned OK -- call is being set up.
|
||||||
// Connection/failure will come as URCs (NO CARRIER, BUSY, etc.)
|
// Connection/failure will come as URCs (NO CARRIER, BUSY, etc.)
|
||||||
// or we detect active call via AT+CLCC polling.
|
// or we detect active call via AT+CLCC polling.
|
||||||
// For now, assume we're dialing and wait for URCs.
|
// For now, assume we're dialing and wait for URCs.
|
||||||
MESH_DEBUG_PRINTLN("[Modem] ATD OK — dialing...");
|
MESH_DEBUG_PRINTLN("[Modem] ATD OK -- dialing...");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,8 +667,8 @@ bool ModemManager::doSetVolume(uint8_t level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Incoming call ringtone — tone bursts via AT+SIMTONE on modem speaker
|
// Incoming call ringtone -- tone bursts via AT+SIMTONE on modem speaker
|
||||||
// Pattern: 400ms tone → 1200ms silence → repeat
|
// Pattern: 400ms tone -> 1200ms silence -> repeat
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
void ModemManager::handleRingtone() {
|
void ModemManager::handleRingtone() {
|
||||||
@@ -643,12 +700,192 @@ void ModemManager::handleRingtone() {
|
|||||||
_toneActive = true;
|
_toneActive = true;
|
||||||
_nextRingTone = now + 400; // Tone plays for 400ms
|
_nextRingTone = now + 400; // Tone plays for 400ms
|
||||||
} else {
|
} else {
|
||||||
// Tone just finished — gap before next burst
|
// Tone just finished -- gap before next burst
|
||||||
_toneActive = false;
|
_toneActive = false;
|
||||||
_nextRingTone = now + 1200; // 1.2s silence (classic ring cadence)
|
_nextRingTone = now + 1200; // 1.2s silence (classic ring cadence)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Notification Tone Transfer and Playback
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Transfers embedded WAV files from PROGMEM to the modem's internal
|
||||||
|
// filesystem using AT+CFTRANRX (confirmed via probe), then plays them
|
||||||
|
// on demand via AT+CCMXPLAY through the modem's speaker amplifier.
|
||||||
|
//
|
||||||
|
// Confirmed working commands on A7682E:
|
||||||
|
// AT+FSMEM -- filesystem space query
|
||||||
|
// AT+FSDEL="C:/file" -- delete file
|
||||||
|
// AT+CFTRANRX="C:/file",size -- write file (modem responds CONNECT)
|
||||||
|
// AT+CCMXPLAY="C:/file",0,0 -- play audio
|
||||||
|
// AT+CCMXSTOP -- stop audio
|
||||||
|
// AT+CRSL=n -- ringer volume (0-20)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool ModemManager::transferTonesToModem() {
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] Transferring %d notification tones to modem...", MODEM_BUNDLED_TONE_COUNT);
|
||||||
|
|
||||||
|
// Verify filesystem is accessible
|
||||||
|
if (sendAT("AT+FSMEM", "OK", 3000)) {
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] Filesystem: %s", _atBuf);
|
||||||
|
} else {
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] FSMEM failed -- modem filesystem not accessible");
|
||||||
|
_tonesTransferred = true; // Don't retry every boot
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int successCount = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < MODEM_BUNDLED_TONE_COUNT; i++) {
|
||||||
|
const ModemToneEntry& tone = modemBundledTones[i];
|
||||||
|
|
||||||
|
// Build modem filesystem path
|
||||||
|
char modemPath[48];
|
||||||
|
snprintf(modemPath, sizeof(modemPath), "C:/%s", tone.filename);
|
||||||
|
|
||||||
|
// Delete any existing file first (AT+FSDEL, ignore errors if not found)
|
||||||
|
char delCmd[64];
|
||||||
|
snprintf(delCmd, sizeof(delCmd), "AT+FSDEL=\"%s\"", modemPath);
|
||||||
|
sendAT(delCmd, "OK", 2000);
|
||||||
|
|
||||||
|
// Small gap to let modem settle between delete and write
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
|
||||||
|
// Drain any stale UART data before transfer
|
||||||
|
while (MODEM_SERIAL.available()) MODEM_SERIAL.read();
|
||||||
|
|
||||||
|
// Transfer file via AT+CFTRANRX="path",<size>
|
||||||
|
// Modem responds with CONNECT, then expects <size> bytes of binary data,
|
||||||
|
// then responds with OK.
|
||||||
|
char txCmd[80];
|
||||||
|
snprintf(txCmd, sizeof(txCmd), "AT+CFTRANRX=\"%s\",%d", modemPath, (int)tone.size);
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] Tone %d/%d: %s (%d bytes) -- sending...",
|
||||||
|
i + 1, MODEM_BUNDLED_TONE_COUNT, tone.filename, (int)tone.size);
|
||||||
|
|
||||||
|
Serial.printf("[Modem] TX: %s\n", txCmd);
|
||||||
|
MODEM_SERIAL.println(txCmd);
|
||||||
|
|
||||||
|
// Wait for CONNECT prompt (case-insensitive, also check for ">")
|
||||||
|
unsigned long start = millis();
|
||||||
|
bool gotPrompt = false;
|
||||||
|
bool gotError = false;
|
||||||
|
char promptBuf[128];
|
||||||
|
int ppos = 0;
|
||||||
|
while (millis() - start < 8000) {
|
||||||
|
while (MODEM_SERIAL.available()) {
|
||||||
|
char c = MODEM_SERIAL.read();
|
||||||
|
if (ppos < 127) { promptBuf[ppos++] = c; promptBuf[ppos] = '\0'; }
|
||||||
|
// Check for any known data-ready prompts
|
||||||
|
if (strstr(promptBuf, "CONNECT") || strstr(promptBuf, "connect") ||
|
||||||
|
c == '>') {
|
||||||
|
gotPrompt = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (strstr(promptBuf, "ERROR")) { gotError = true; break; }
|
||||||
|
}
|
||||||
|
if (gotPrompt || gotError) break;
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gotPrompt) {
|
||||||
|
// Log whatever we DID receive for debugging
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] Tone %d: no CONNECT/> prompt (got: [%s])",
|
||||||
|
i + 1, ppos > 0 ? promptBuf : "TIMEOUT");
|
||||||
|
// Drain UART and recover
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
while (MODEM_SERIAL.available()) MODEM_SERIAL.read();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] Tone %d: got prompt, sending %d bytes...", i + 1, (int)tone.size);
|
||||||
|
|
||||||
|
// Send the binary WAV data from PROGMEM in chunks
|
||||||
|
const uint8_t* src = tone.data;
|
||||||
|
size_t remaining = tone.size;
|
||||||
|
const size_t CHUNK_SIZE = 256;
|
||||||
|
|
||||||
|
while (remaining > 0) {
|
||||||
|
size_t chunk = (remaining > CHUNK_SIZE) ? CHUNK_SIZE : remaining;
|
||||||
|
uint8_t buf[CHUNK_SIZE];
|
||||||
|
memcpy_P(buf, src, chunk);
|
||||||
|
MODEM_SERIAL.write(buf, chunk);
|
||||||
|
src += chunk;
|
||||||
|
remaining -= chunk;
|
||||||
|
// Brief yield to avoid starving other tasks during large transfers
|
||||||
|
if (remaining > 0) vTaskDelay(pdMS_TO_TICKS(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for OK response after transfer completes
|
||||||
|
if (waitResponse("OK", 15000, _atBuf, AT_BUF_SIZE)) {
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] Tone %d: %s transferred OK", i + 1, tone.filename);
|
||||||
|
successCount++;
|
||||||
|
} else {
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] Tone %d: %s transfer FAILED: %s", i + 1, tone.filename, _atBuf);
|
||||||
|
// Drain UART to recover modem state
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
while (MODEM_SERIAL.available()) MODEM_SERIAL.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delay between transfers to let modem flush to storage
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(200));
|
||||||
|
}
|
||||||
|
|
||||||
|
_tonesTransferred = (successCount > 0);
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] Notification tones: %d/%d transferred", successCount, MODEM_BUNDLED_TONE_COUNT);
|
||||||
|
return (successCount == MODEM_BUNDLED_TONE_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ModemManager::playModemTone(const char* filename) {
|
||||||
|
// AT+CCMXPLAY="C:/filename.wav",0,0
|
||||||
|
// param 1: 0 = local speaker output
|
||||||
|
// param 2: 0 = no repeat
|
||||||
|
char cmd[64];
|
||||||
|
snprintf(cmd, sizeof(cmd), "AT+CCMXPLAY=\"C:/%s\",0,0", filename);
|
||||||
|
bool ok = sendAT(cmd, "OK", 2000);
|
||||||
|
if (ok) {
|
||||||
|
_notifTonePlaying = true;
|
||||||
|
_notifToneStartTime = millis();
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] Playing tone: %s", filename);
|
||||||
|
} else {
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] CCMXPLAY failed: %s", filename);
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ModemManager::stopModemTone() {
|
||||||
|
if (!_notifTonePlaying) return true;
|
||||||
|
bool ok = sendAT("AT+CCMXSTOP", "OK", 1000);
|
||||||
|
_notifTonePlaying = false;
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] Tone stop %s", ok ? "OK" : "FAIL");
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModemManager::handleNotifTone() {
|
||||||
|
// Auto-stop if playback has been running too long (safety net)
|
||||||
|
if (_notifTonePlaying &&
|
||||||
|
(millis() - _notifToneStartTime) > NOTIF_TONE_TIMEOUT_MS) {
|
||||||
|
MESH_DEBUG_PRINTLN("[Modem] Tone playback timeout -- stopping");
|
||||||
|
stopModemTone();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for pending tone request from main loop
|
||||||
|
int8_t idx = _pendingToneIdx;
|
||||||
|
if (idx < 0) return;
|
||||||
|
_pendingToneIdx = -1; // Consume the request
|
||||||
|
|
||||||
|
if (idx >= MODEM_BUNDLED_TONE_COUNT) return;
|
||||||
|
|
||||||
|
// Stop any currently playing tone before starting new one
|
||||||
|
if (_notifTonePlaying) {
|
||||||
|
stopModemTone();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't play during active calls
|
||||||
|
if (isCallActive()) return;
|
||||||
|
|
||||||
|
playModemTone(modemBundledTones[idx].filename);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// FreeRTOS Task
|
// FreeRTOS Task
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -683,7 +920,7 @@ restart:
|
|||||||
vTaskDelay(pdMS_TO_TICKS(500));
|
vTaskDelay(pdMS_TO_TICKS(500));
|
||||||
}
|
}
|
||||||
if (!atOk) {
|
if (!atOk) {
|
||||||
MESH_DEBUG_PRINTLN("[Modem] AT check failed — retry from power-on in 30s");
|
MESH_DEBUG_PRINTLN("[Modem] AT check failed -- retry from power-on in 30s");
|
||||||
_state = ModemState::ERROR;
|
_state = ModemState::ERROR;
|
||||||
vTaskDelay(pdMS_TO_TICKS(30000));
|
vTaskDelay(pdMS_TO_TICKS(30000));
|
||||||
goto restart;
|
goto restart;
|
||||||
@@ -705,7 +942,7 @@ restart:
|
|||||||
MESH_DEBUG_PRINTLN("[Modem] IMEI: %s", _imei);
|
MESH_DEBUG_PRINTLN("[Modem] IMEI: %s", _imei);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IMSI (International Mobile Subscriber Identity) — for APN auto-detection
|
// IMSI (International Mobile Subscriber Identity) -- for APN auto-detection
|
||||||
if (sendAT("AT+CIMI", "OK", 3000)) {
|
if (sendAT("AT+CIMI", "OK", 3000)) {
|
||||||
char* p = _atBuf;
|
char* p = _atBuf;
|
||||||
while (*p && !isdigit(*p)) p++;
|
while (*p && !isdigit(*p)) p++;
|
||||||
@@ -732,7 +969,7 @@ restart:
|
|||||||
sendAT("AT+CLIP=1", "OK");
|
sendAT("AT+CLIP=1", "OK");
|
||||||
|
|
||||||
// Set audio output to loudspeaker mode (device speaker)
|
// Set audio output to loudspeaker mode (device speaker)
|
||||||
// 1=earpiece, 3=loudspeaker — use loudspeaker for T-Deck Pro
|
// 1=earpiece, 3=loudspeaker -- use loudspeaker for T-Deck Pro
|
||||||
sendAT("AT+CSDVC=3", "OK", 1000);
|
sendAT("AT+CSDVC=3", "OK", 1000);
|
||||||
|
|
||||||
// Set initial call volume (mid-level)
|
// Set initial call volume (mid-level)
|
||||||
@@ -805,7 +1042,7 @@ restart:
|
|||||||
// Initial signal query
|
// Initial signal query
|
||||||
pollCSQ();
|
pollCSQ();
|
||||||
|
|
||||||
// Resolve APN (user config → network provisioned → IMSI auto-detect)
|
// Resolve APN (user config -> network provisioned -> IMSI auto-detect)
|
||||||
resolveAPN();
|
resolveAPN();
|
||||||
|
|
||||||
// Sync ESP32 system clock from modem network time
|
// Sync ESP32 system clock from modem network time
|
||||||
@@ -857,6 +1094,11 @@ restart:
|
|||||||
MESH_DEBUG_PRINTLN("[Modem] READY (CSQ=%d, operator=%s, APN=%s [%s], IMEI=%s)",
|
MESH_DEBUG_PRINTLN("[Modem] READY (CSQ=%d, operator=%s, APN=%s [%s], IMEI=%s)",
|
||||||
_csq, _operator, _apn[0] ? _apn : "(none)", _apnSource, _imei);
|
_csq, _operator, _apn[0] ? _apn : "(none)", _apnSource, _imei);
|
||||||
|
|
||||||
|
// ---- Phase 3b: Transfer notification tones to modem filesystem ----
|
||||||
|
// Done after READY so modem is fully initialised. Non-blocking for the
|
||||||
|
// mesh -- runs on Core 0 modem task. Uses AT+FSDEL + AT+CFTRANRX.
|
||||||
|
transferTonesToModem();
|
||||||
|
|
||||||
// ---- Phase 4: Main loop ----
|
// ---- Phase 4: Main loop ----
|
||||||
unsigned long lastCSQPoll = 0;
|
unsigned long lastCSQPoll = 0;
|
||||||
unsigned long lastSMSPoll = 0;
|
unsigned long lastSMSPoll = 0;
|
||||||
@@ -867,17 +1109,22 @@ restart:
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// ================================================================
|
// ================================================================
|
||||||
// Step 1: Drain URCs — catch RING, NO CARRIER, +CLIP, etc.
|
// Step 1: Drain URCs -- catch RING, NO CARRIER, +CLIP, +AUDIOSTATE
|
||||||
// This must run every iteration to avoid missing time-sensitive
|
// This must run every iteration to avoid missing time-sensitive
|
||||||
// events like incoming calls or call-ended notifications.
|
// events like incoming calls or call-ended notifications.
|
||||||
// ================================================================
|
// ================================================================
|
||||||
drainURCs();
|
drainURCs();
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
// Step 1b: Ringtone — play tone bursts while incoming call rings
|
// Step 1b: Ringtone -- play tone bursts while incoming call rings
|
||||||
// ================================================================
|
// ================================================================
|
||||||
handleRingtone();
|
handleRingtone();
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// Step 1c: Notification tone -- play/stop requested tones
|
||||||
|
// ================================================================
|
||||||
|
handleNotifTone();
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
// Step 2: Process call commands from main loop
|
// Step 2: Process call commands from main loop
|
||||||
// ================================================================
|
// ================================================================
|
||||||
@@ -888,7 +1135,7 @@ restart:
|
|||||||
if (_state == ModemState::READY) {
|
if (_state == ModemState::READY) {
|
||||||
doDialCall(callCmd.phone);
|
doDialCall(callCmd.phone);
|
||||||
} else {
|
} else {
|
||||||
MESH_DEBUG_PRINTLN("[Modem] Can't dial — state=%d", (int)_state);
|
MESH_DEBUG_PRINTLN("[Modem] Can't dial -- state=%d", (int)_state);
|
||||||
queueCallEvent(CallEventType::DIAL_FAILED, callCmd.phone);
|
queueCallEvent(CallEventType::DIAL_FAILED, callCmd.phone);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -928,7 +1175,7 @@ restart:
|
|||||||
_state == ModemState::DIALING &&
|
_state == ModemState::DIALING &&
|
||||||
millis() - lastCLCCPoll > CLCC_POLL_INTERVAL) {
|
millis() - lastCLCCPoll > CLCC_POLL_INTERVAL) {
|
||||||
if (sendAT("AT+CLCC", "OK", 2000)) {
|
if (sendAT("AT+CLCC", "OK", 2000)) {
|
||||||
// +CLCC: 1,0,0,0,0,"number",129 — stat field:
|
// +CLCC: 1,0,0,0,0,"number",129 -- stat field:
|
||||||
// 0=active, 1=held, 2=dialing, 3=alerting, 4=incoming, 5=waiting
|
// 0=active, 1=held, 2=dialing, 3=alerting, 4=incoming, 5=waiting
|
||||||
char* p = strstr(_atBuf, "+CLCC:");
|
char* p = strstr(_atBuf, "+CLCC:");
|
||||||
if (p) {
|
if (p) {
|
||||||
@@ -936,16 +1183,16 @@ restart:
|
|||||||
if (sscanf(p, "+CLCC: %d,%d,%d,%d,%d", &idx, &dir, &stat, &mode, &mpty) >= 3) {
|
if (sscanf(p, "+CLCC: %d,%d,%d,%d,%d", &idx, &dir, &stat, &mode, &mpty) >= 3) {
|
||||||
MESH_DEBUG_PRINTLN("[Modem] CLCC: stat=%d", stat);
|
MESH_DEBUG_PRINTLN("[Modem] CLCC: stat=%d", stat);
|
||||||
if (stat == 0) {
|
if (stat == 0) {
|
||||||
// Call is active — remote answered
|
// Call is active -- remote answered
|
||||||
_state = ModemState::IN_CALL;
|
_state = ModemState::IN_CALL;
|
||||||
_callStartTime = millis();
|
_callStartTime = millis();
|
||||||
queueCallEvent(CallEventType::CONNECTED, _callPhone);
|
queueCallEvent(CallEventType::CONNECTED, _callPhone);
|
||||||
MESH_DEBUG_PRINTLN("[Modem] Call connected (detected via CLCC)");
|
MESH_DEBUG_PRINTLN("[Modem] Call connected (detected via CLCC)");
|
||||||
}
|
}
|
||||||
// stat 2=dialing, 3=alerting — still setting up, keep polling
|
// stat 2=dialing, 3=alerting -- still setting up, keep polling
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No +CLCC line in response — no active calls
|
// No +CLCC line in response -- no active calls
|
||||||
// This shouldn't happen during DIALING unless the call ended
|
// This shouldn't happen during DIALING unless the call ended
|
||||||
// and we missed the URC. Check state and clean up.
|
// and we missed the URC. Check state and clean up.
|
||||||
// (NO CARRIER URC should have been caught by drainURCs)
|
// (NO CARRIER URC should have been caught by drainURCs)
|
||||||
@@ -988,9 +1235,9 @@ restart:
|
|||||||
|
|
||||||
// Shorter delay during active call states for responsive URC handling
|
// Shorter delay during active call states for responsive URC handling
|
||||||
if (isCallActive()) {
|
if (isCallActive()) {
|
||||||
vTaskDelay(pdMS_TO_TICKS(100)); // 100ms — responsive to URCs
|
vTaskDelay(pdMS_TO_TICKS(100)); // 100ms -- responsive to URCs
|
||||||
} else {
|
} else {
|
||||||
vTaskDelay(pdMS_TO_TICKS(500)); // 500ms — normal idle
|
vTaskDelay(pdMS_TO_TICKS(500)); // 500ms -- normal idle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1108,7 +1355,7 @@ bool ModemManager::waitResponse(const char* expect, uint32_t timeout_ms,
|
|||||||
vTaskDelay(pdMS_TO_TICKS(10));
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timeout — check one more time
|
// Timeout -- check one more time
|
||||||
if (buf && expect && strstr(buf, expect)) return true;
|
if (buf && expect && strstr(buf, expect)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
// Runs AT commands on a dedicated FreeRTOS task (Core 0, priority 1) to never
|
// Runs AT commands on a dedicated FreeRTOS task (Core 0, priority 1) to never
|
||||||
// block the mesh radio loop. Communicates with main loop via lock-free queues.
|
// block the mesh radio loop. Communicates with main loop via lock-free queues.
|
||||||
//
|
//
|
||||||
// Supports: SMS send/receive, voice call dial/answer/hangup/DTMF
|
// Supports: SMS send/receive, voice call dial/answer/hangup/DTMF,
|
||||||
|
// notification tone playback via AT+CCMXPLAY
|
||||||
//
|
//
|
||||||
// Guard: HAS_4G_MODEM (defined only for the 4G build environment)
|
// Guard: HAS_4G_MODEM (defined only for the 4G build environment)
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
#include <freertos/semphr.h>
|
#include <freertos/semphr.h>
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
#include "ApnDatabase.h"
|
#include "ApnDatabase.h"
|
||||||
|
#include "ModemBundledSounds.h"
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Modem pins (from variant.h, always defined for reference)
|
// Modem pins (from variant.h, always defined for reference)
|
||||||
@@ -50,6 +52,10 @@
|
|||||||
#define MODEM_CALL_CMD_QUEUE_SIZE 4
|
#define MODEM_CALL_CMD_QUEUE_SIZE 4
|
||||||
#define MODEM_CALL_EVT_QUEUE_SIZE 4
|
#define MODEM_CALL_EVT_QUEUE_SIZE 4
|
||||||
|
|
||||||
|
// Notification tone auto-stop timeout (ms) -- stop playback after this
|
||||||
|
// even if no +AUDIOSTATE URC received, to avoid stuck audio
|
||||||
|
#define NOTIF_TONE_TIMEOUT_MS 4000
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Modem state machine
|
// Modem state machine
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -88,7 +94,7 @@ struct SMSIncoming {
|
|||||||
// Voice call structures
|
// Voice call structures
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Commands from main loop → modem task
|
// Commands from main loop -> modem task
|
||||||
enum class CallCmd : uint8_t {
|
enum class CallCmd : uint8_t {
|
||||||
DIAL, // Initiate outgoing call
|
DIAL, // Initiate outgoing call
|
||||||
ANSWER, // Answer incoming call
|
ANSWER, // Answer incoming call
|
||||||
@@ -104,7 +110,7 @@ struct CallCommand {
|
|||||||
uint8_t volume; // Used by SET_VOLUME (0-5)
|
uint8_t volume; // Used by SET_VOLUME (0-5)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Events from modem task → main loop
|
// Events from modem task -> main loop
|
||||||
enum class CallEventType : uint8_t {
|
enum class CallEventType : uint8_t {
|
||||||
INCOMING, // Incoming call ringing (+CLIP parsed)
|
INCOMING, // Incoming call ringing (+CLIP parsed)
|
||||||
CONNECTED, // Call answered / outgoing connected
|
CONNECTED, // Call answered / outgoing connected
|
||||||
@@ -142,10 +148,24 @@ public:
|
|||||||
bool setCallVolume(uint8_t level); // Set volume 0-5
|
bool setCallVolume(uint8_t level); // Set volume 0-5
|
||||||
bool pollCallEvent(CallEvent& out); // Poll from main loop
|
bool pollCallEvent(CallEvent& out); // Poll from main loop
|
||||||
|
|
||||||
// Ringtone control — called from main loop
|
// Ringtone control -- called from main loop
|
||||||
void setRingtoneEnabled(bool en) { _ringtoneEnabled = en; }
|
void setRingtoneEnabled(bool en) { _ringtoneEnabled = en; }
|
||||||
bool isRingtoneEnabled() const { return _ringtoneEnabled; }
|
bool isRingtoneEnabled() const { return _ringtoneEnabled; }
|
||||||
|
|
||||||
|
// --- Notification tone API ---
|
||||||
|
// Request playback of a bundled notification tone by index (0-based).
|
||||||
|
// Called from main loop (Core 1); playback happens on modem task (Core 0).
|
||||||
|
// Pass -1 or out-of-range to be ignored.
|
||||||
|
void requestNotifTone(int8_t toneIdx);
|
||||||
|
|
||||||
|
// Check if bundled tones have been transferred to modem filesystem
|
||||||
|
bool areTonesReady() const { return _tonesTransferred; }
|
||||||
|
|
||||||
|
// Look up a modem tone index by base filename (e.g. "Bell-01").
|
||||||
|
// Returns index into modemBundledTones[] or -1 if not found.
|
||||||
|
// Matches with or without .wav extension.
|
||||||
|
static int8_t findToneByName(const char* name);
|
||||||
|
|
||||||
// --- State queries (lock-free reads) ---
|
// --- State queries (lock-free reads) ---
|
||||||
ModemState getState() const { return _state; }
|
ModemState getState() const { return _state; }
|
||||||
int getSignalBars() const; // 0-5
|
int getSignalBars() const; // 0-5
|
||||||
@@ -177,7 +197,7 @@ public:
|
|||||||
// Save user-configured APN to SD card.
|
// Save user-configured APN to SD card.
|
||||||
static void saveAPNConfig(const char* apn);
|
static void saveAPNConfig(const char* apn);
|
||||||
|
|
||||||
// Pause/resume polling — used by web reader to avoid Core 0 contention
|
// Pause/resume polling -- used by web reader to avoid Core 0 contention
|
||||||
// during WiFi TLS handshakes. While paused, the task skips AT commands
|
// during WiFi TLS handshakes. While paused, the task skips AT commands
|
||||||
// (SMS poll, CSQ poll) but still drains URCs and handles call commands
|
// (SMS poll, CSQ poll) but still drains URCs and handles call commands
|
||||||
// so incoming calls aren't missed.
|
// so incoming calls aren't missed.
|
||||||
@@ -213,6 +233,12 @@ private:
|
|||||||
unsigned long _nextRingTone = 0; // Next tone burst timestamp (modem task)
|
unsigned long _nextRingTone = 0; // Next tone burst timestamp (modem task)
|
||||||
bool _toneActive = false; // Is a tone currently sounding
|
bool _toneActive = false; // Is a tone currently sounding
|
||||||
|
|
||||||
|
// Notification tone state
|
||||||
|
volatile int8_t _pendingToneIdx = -1; // Set by main loop, consumed by modem task
|
||||||
|
volatile bool _tonesTransferred = false; // True after all tones written to modem C:/
|
||||||
|
bool _notifTonePlaying = false; // Modem is currently playing a notif tone
|
||||||
|
unsigned long _notifToneStartTime = 0; // millis() when playback started (for timeout)
|
||||||
|
|
||||||
TaskHandle_t _taskHandle = nullptr;
|
TaskHandle_t _taskHandle = nullptr;
|
||||||
|
|
||||||
// SMS queues
|
// SMS queues
|
||||||
@@ -220,8 +246,8 @@ private:
|
|||||||
QueueHandle_t _recvQueue = nullptr;
|
QueueHandle_t _recvQueue = nullptr;
|
||||||
|
|
||||||
// Call queues
|
// Call queues
|
||||||
QueueHandle_t _callCmdQueue = nullptr; // main loop → modem task
|
QueueHandle_t _callCmdQueue = nullptr; // main loop -> modem task
|
||||||
QueueHandle_t _callEvtQueue = nullptr; // modem task → main loop
|
QueueHandle_t _callEvtQueue = nullptr; // modem task -> main loop
|
||||||
|
|
||||||
SemaphoreHandle_t _uartMutex = nullptr;
|
SemaphoreHandle_t _uartMutex = nullptr;
|
||||||
|
|
||||||
@@ -254,6 +280,12 @@ private:
|
|||||||
void queueCallEvent(CallEventType type, const char* phone = nullptr, uint32_t duration = 0);
|
void queueCallEvent(CallEventType type, const char* phone = nullptr, uint32_t duration = 0);
|
||||||
void handleRingtone(); // Play tone bursts while incoming call rings
|
void handleRingtone(); // Play tone bursts while incoming call rings
|
||||||
|
|
||||||
|
// Notification tone transfer and playback (called from modem task)
|
||||||
|
bool transferTonesToModem(); // Transfer embedded WAVs to modem C:/ filesystem
|
||||||
|
bool playModemTone(const char* filename); // AT+CCMXPLAY
|
||||||
|
bool stopModemTone(); // AT+CCMXSTOP
|
||||||
|
void handleNotifTone(); // Poll _pendingToneIdx, play/stop as needed
|
||||||
|
|
||||||
// FreeRTOS task
|
// FreeRTOS task
|
||||||
static void taskEntry(void* param);
|
static void taskEntry(void* param);
|
||||||
void taskLoop();
|
void taskLoop();
|
||||||
|
|||||||
@@ -0,0 +1,260 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// NotifSounds.h -- Per-channel notification sound configuration
|
||||||
|
//
|
||||||
|
// Stores a custom sound filename per channel for notification tones.
|
||||||
|
// Config persisted to /meshcore/notif_sounds.cfg on SD card.
|
||||||
|
//
|
||||||
|
// Audio variant: Sound files are MP3s in /alarms/ (shared with alarm clock).
|
||||||
|
// Playback is request-based: UITask calls requestPlay() when a message
|
||||||
|
// arrives on a channel with a custom tone. main.cpp loop() polls
|
||||||
|
// hasPendingPlay() and drives the Audio* object.
|
||||||
|
//
|
||||||
|
// 4G variant: Sound files are 8kHz mono WAVs embedded in firmware
|
||||||
|
// (ModemBundledSounds.h) and transferred to modem C:/ filesystem on boot.
|
||||||
|
// UITask calls modemManager.requestNotifTone() directly.
|
||||||
|
//
|
||||||
|
// Guard: MECK_AUDIO_VARIANT || HAS_4G_MODEM
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
#if defined(MECK_AUDIO_VARIANT) || defined(HAS_4G_MODEM)
|
||||||
|
|
||||||
|
#ifndef NOTIF_SOUNDS_H
|
||||||
|
#define NOTIF_SOUNDS_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <SD.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include "variant.h"
|
||||||
|
|
||||||
|
#ifdef HAS_4G_MODEM
|
||||||
|
#include "ModemBundledSounds.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX_GROUP_CHANNELS
|
||||||
|
#define MAX_GROUP_CHANNELS 20
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NOTIF_SOUND_NAME_MAX 32
|
||||||
|
#define NOTIF_SOUND_SLOTS (MAX_GROUP_CHANNELS + 1) // +1 for DMs
|
||||||
|
#define NOTIF_SOUND_CONFIG_PATH "/meshcore/notif_sounds.cfg"
|
||||||
|
#define NOTIF_SOUND_MAGIC 0x4E534E44 // "NSND"
|
||||||
|
#define NOTIF_SOUND_VERSION 1
|
||||||
|
#ifndef ALARMS_FOLDER
|
||||||
|
#define ALARMS_FOLDER "/alarms"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct __attribute__((packed)) NotifSoundCfgHeader {
|
||||||
|
uint32_t magic;
|
||||||
|
uint8_t version;
|
||||||
|
uint8_t count; // Number of slots stored
|
||||||
|
uint8_t reserved[2];
|
||||||
|
// Followed by count * NOTIF_SOUND_NAME_MAX bytes
|
||||||
|
};
|
||||||
|
|
||||||
|
class NotifSounds {
|
||||||
|
public:
|
||||||
|
NotifSounds() {
|
||||||
|
memset(_sounds, 0, sizeof(_sounds));
|
||||||
|
#ifdef MECK_AUDIO_VARIANT
|
||||||
|
_pendingPlay = false;
|
||||||
|
_pendingFile[0] = '\0';
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
loadConfig();
|
||||||
|
Serial.println("NotifSounds: Config loaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Config accessors ---
|
||||||
|
|
||||||
|
const char* getSoundForChannel(uint8_t channel_idx) const {
|
||||||
|
int slot = (channel_idx == 0xFF) ? MAX_GROUP_CHANNELS : (int)channel_idx;
|
||||||
|
if (slot < 0 || slot >= NOTIF_SOUND_SLOTS) return "";
|
||||||
|
return _sounds[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasSoundForChannel(uint8_t channel_idx) const {
|
||||||
|
const char* s = getSoundForChannel(channel_idx);
|
||||||
|
return s && s[0] != '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
void setSoundForChannel(uint8_t channel_idx, const char* filename) {
|
||||||
|
int slot = (channel_idx == 0xFF) ? MAX_GROUP_CHANNELS : (int)channel_idx;
|
||||||
|
if (slot < 0 || slot >= NOTIF_SOUND_SLOTS) return;
|
||||||
|
if (filename) {
|
||||||
|
strncpy(_sounds[slot], filename, NOTIF_SOUND_NAME_MAX - 1);
|
||||||
|
_sounds[slot][NOTIF_SOUND_NAME_MAX - 1] = '\0';
|
||||||
|
} else {
|
||||||
|
_sounds[slot][0] = '\0';
|
||||||
|
}
|
||||||
|
saveConfig();
|
||||||
|
Serial.printf("NotifSounds: Channel %d -> '%s'\n", (int)channel_idx,
|
||||||
|
_sounds[slot][0] ? _sounds[slot] : "(default)");
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearSoundForChannel(uint8_t channel_idx) {
|
||||||
|
setSoundForChannel(channel_idx, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Sound file scanning ---
|
||||||
|
|
||||||
|
void scanSoundFiles() {
|
||||||
|
_soundFiles.clear();
|
||||||
|
|
||||||
|
#ifdef HAS_4G_MODEM
|
||||||
|
// 4G variant: available tones are embedded in firmware
|
||||||
|
for (int i = 0; i < MODEM_BUNDLED_TONE_COUNT; i++) {
|
||||||
|
_soundFiles.push_back(String(modemBundledTones[i].filename));
|
||||||
|
}
|
||||||
|
Serial.printf("NotifSounds: %d modem tones available\n", (int)_soundFiles.size());
|
||||||
|
|
||||||
|
#else // MECK_AUDIO_VARIANT
|
||||||
|
// Audio variant: scan SD card /alarms/ folder for MP3 files
|
||||||
|
if (!SD.exists(ALARMS_FOLDER)) {
|
||||||
|
SD.mkdir(ALARMS_FOLDER);
|
||||||
|
}
|
||||||
|
File root = SD.open(ALARMS_FOLDER);
|
||||||
|
if (!root || !root.isDirectory()) {
|
||||||
|
digitalWrite(SDCARD_CS, HIGH);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File entry = root.openNextFile();
|
||||||
|
while (entry) {
|
||||||
|
if (!entry.isDirectory()) {
|
||||||
|
String name = entry.name();
|
||||||
|
if (name.length() > 0 && name.charAt(0) != '.') {
|
||||||
|
String lower = name;
|
||||||
|
lower.toLowerCase();
|
||||||
|
if (lower.endsWith(".mp3")) {
|
||||||
|
_soundFiles.push_back(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entry = root.openNextFile();
|
||||||
|
}
|
||||||
|
root.close();
|
||||||
|
digitalWrite(SDCARD_CS, HIGH);
|
||||||
|
std::sort(_soundFiles.begin(), _soundFiles.end());
|
||||||
|
Serial.printf("NotifSounds: Found %d sound files\n", (int)_soundFiles.size());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int getSoundFileCount() const { return (int)_soundFiles.size(); }
|
||||||
|
const String& getSoundFile(int idx) const { return _soundFiles[idx]; }
|
||||||
|
const std::vector<String>& getSoundFiles() const { return _soundFiles; }
|
||||||
|
|
||||||
|
#ifdef HAS_4G_MODEM
|
||||||
|
// Get the display label for a tone file (4G variant only).
|
||||||
|
// Returns the human-readable label from ModemBundledSounds.
|
||||||
|
const char* getToneLabel(int idx) const {
|
||||||
|
if (idx < 0 || idx >= MODEM_BUNDLED_TONE_COUNT) return "";
|
||||||
|
return modemBundledTones[idx].label;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// --- Pending playback request (audio variant only) ---
|
||||||
|
// The 4G variant calls modemManager.requestNotifTone() directly
|
||||||
|
// from UITask; no pending mechanism needed.
|
||||||
|
|
||||||
|
#ifdef MECK_AUDIO_VARIANT
|
||||||
|
void requestPlay(const char* fullPath) {
|
||||||
|
strncpy(_pendingFile, fullPath, sizeof(_pendingFile) - 1);
|
||||||
|
_pendingFile[sizeof(_pendingFile) - 1] = '\0';
|
||||||
|
_pendingPlay = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasPendingPlay() const { return _pendingPlay; }
|
||||||
|
|
||||||
|
const char* getPendingFile() const { return _pendingFile; }
|
||||||
|
|
||||||
|
void clearPending() {
|
||||||
|
_pendingPlay = false;
|
||||||
|
_pendingFile[0] = '\0';
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
char _sounds[NOTIF_SOUND_SLOTS][NOTIF_SOUND_NAME_MAX];
|
||||||
|
std::vector<String> _soundFiles;
|
||||||
|
|
||||||
|
#ifdef MECK_AUDIO_VARIANT
|
||||||
|
bool _pendingPlay;
|
||||||
|
char _pendingFile[48];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void loadConfig() {
|
||||||
|
memset(_sounds, 0, sizeof(_sounds));
|
||||||
|
|
||||||
|
if (!SD.exists(NOTIF_SOUND_CONFIG_PATH)) {
|
||||||
|
Serial.println("NotifSounds: No config file, using defaults");
|
||||||
|
digitalWrite(SDCARD_CS, HIGH);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File f = SD.open(NOTIF_SOUND_CONFIG_PATH, "r");
|
||||||
|
if (!f) {
|
||||||
|
Serial.println("NotifSounds: Failed to open config");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NotifSoundCfgHeader hdr;
|
||||||
|
if (f.read((uint8_t*)&hdr, sizeof(hdr)) != sizeof(hdr) ||
|
||||||
|
hdr.magic != NOTIF_SOUND_MAGIC || hdr.version != NOTIF_SOUND_VERSION) {
|
||||||
|
Serial.println("NotifSounds: Config invalid or wrong version");
|
||||||
|
f.close();
|
||||||
|
digitalWrite(SDCARD_CS, HIGH);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int slotsToRead = hdr.count;
|
||||||
|
if (slotsToRead > NOTIF_SOUND_SLOTS) slotsToRead = NOTIF_SOUND_SLOTS;
|
||||||
|
|
||||||
|
for (int i = 0; i < slotsToRead; i++) {
|
||||||
|
if (f.read((uint8_t*)_sounds[i], NOTIF_SOUND_NAME_MAX) != NOTIF_SOUND_NAME_MAX) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_sounds[i][NOTIF_SOUND_NAME_MAX - 1] = '\0'; // Safety null-terminate
|
||||||
|
}
|
||||||
|
|
||||||
|
f.close();
|
||||||
|
digitalWrite(SDCARD_CS, HIGH);
|
||||||
|
Serial.printf("NotifSounds: Loaded %d slots from config\n", slotsToRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveConfig() {
|
||||||
|
if (!SD.exists("/meshcore")) {
|
||||||
|
SD.mkdir("/meshcore");
|
||||||
|
}
|
||||||
|
|
||||||
|
File f = SD.open(NOTIF_SOUND_CONFIG_PATH, FILE_WRITE);
|
||||||
|
if (!f) {
|
||||||
|
Serial.println("NotifSounds: Failed to save config");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NotifSoundCfgHeader hdr;
|
||||||
|
hdr.magic = NOTIF_SOUND_MAGIC;
|
||||||
|
hdr.version = NOTIF_SOUND_VERSION;
|
||||||
|
hdr.count = NOTIF_SOUND_SLOTS;
|
||||||
|
hdr.reserved[0] = 0;
|
||||||
|
hdr.reserved[1] = 0;
|
||||||
|
f.write((uint8_t*)&hdr, sizeof(hdr));
|
||||||
|
|
||||||
|
for (int i = 0; i < NOTIF_SOUND_SLOTS; i++) {
|
||||||
|
f.write((uint8_t*)_sounds[i], NOTIF_SOUND_NAME_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
f.close();
|
||||||
|
digitalWrite(SDCARD_CS, HIGH);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Global singleton
|
||||||
|
extern NotifSounds notifSounds;
|
||||||
|
|
||||||
|
#endif // NOTIF_SOUNDS_H
|
||||||
|
#endif // MECK_AUDIO_VARIANT || HAS_4G_MODEM
|
||||||
@@ -7,6 +7,9 @@
|
|||||||
#include <MeshCore.h>
|
#include <MeshCore.h>
|
||||||
#include "../NodePrefs.h"
|
#include "../NodePrefs.h"
|
||||||
#include "MeckFonts.h"
|
#include "MeckFonts.h"
|
||||||
|
#if defined(MECK_AUDIO_VARIANT) || defined(HAS_4G_MODEM)
|
||||||
|
#include "NotifSounds.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Inline edit hint shown next to values being adjusted
|
// Inline edit hint shown next to values being adjusted
|
||||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
@@ -170,6 +173,7 @@ enum EditMode : uint8_t {
|
|||||||
EDIT_PICKER, // A/D cycles options (radio preset, contact mode)
|
EDIT_PICKER, // A/D cycles options (radio preset, contact mode)
|
||||||
EDIT_NUMBER, // W/S adjusts value (freq, BW, SF, CR, TX, UTC)
|
EDIT_NUMBER, // W/S adjusts value (freq, BW, SF, CR, TX, UTC)
|
||||||
EDIT_CONFIRM, // Confirmation dialog (delete channel, apply radio)
|
EDIT_CONFIRM, // Confirmation dialog (delete channel, apply radio)
|
||||||
|
EDIT_NOTIF_SOUND, // Sound picker for per-channel notification tone
|
||||||
#ifdef MECK_WIFI_COMPANION
|
#ifdef MECK_WIFI_COMPANION
|
||||||
EDIT_WIFI, // WiFi scan/select/password flow
|
EDIT_WIFI, // WiFi scan/select/password flow
|
||||||
#endif
|
#endif
|
||||||
@@ -252,6 +256,13 @@ private:
|
|||||||
uint8_t _fontPickerOriginal; // font style before edit (for cancel revert)
|
uint8_t _fontPickerOriginal; // font style before edit (for cancel revert)
|
||||||
int _confirmAction; // 0=none, 1=delete channel, 2=apply radio
|
int _confirmAction; // 0=none, 1=delete channel, 2=apply radio
|
||||||
|
|
||||||
|
// Notification sound picker state
|
||||||
|
#if defined(MECK_AUDIO_VARIANT) || defined(HAS_4G_MODEM)
|
||||||
|
int _notifSoundSelected; // Cursor in sound picker (0=default/silent, 1+=files)
|
||||||
|
int _notifSoundScroll; // Scroll offset in picker list
|
||||||
|
uint8_t _notifSoundChannel; // Channel index being edited
|
||||||
|
#endif
|
||||||
|
|
||||||
// Onboarding mode
|
// Onboarding mode
|
||||||
bool _onboarding;
|
bool _onboarding;
|
||||||
|
|
||||||
@@ -595,6 +606,11 @@ public:
|
|||||||
_fmError = nullptr;
|
_fmError = nullptr;
|
||||||
_dnsServer = nullptr;
|
_dnsServer = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(MECK_AUDIO_VARIANT) || defined(HAS_4G_MODEM)
|
||||||
|
_notifSoundSelected = 0;
|
||||||
|
_notifSoundScroll = 0;
|
||||||
|
_notifSoundChannel = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void enter() {
|
void enter() {
|
||||||
@@ -1930,15 +1946,33 @@ public:
|
|||||||
snprintf(tmp, sizeof(tmp), " %s [*]", ch.name);
|
snprintf(tmp, sizeof(tmp), " %s [*]", ch.name);
|
||||||
}
|
}
|
||||||
if (selected) {
|
if (selected) {
|
||||||
// Show edit/delete hints on right
|
// Build hint with notification state + actions
|
||||||
|
uint8_t nPref = _prefs->channel_notif[chIdx];
|
||||||
|
const char* nTag = (nPref == NOTIF_NONE) ? "Off" :
|
||||||
|
(nPref == NOTIF_MENTIONS) ? "@" : "All";
|
||||||
|
char hintBuf[40];
|
||||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
const char* hint = chIdx > 0 ? "Ent:Region Hold:Del" : "Ent:Region";
|
if (chIdx > 0) {
|
||||||
|
snprintf(hintBuf, sizeof(hintBuf), "Notif:%s Ent:Region Hold:Del", nTag);
|
||||||
|
} else {
|
||||||
|
snprintf(hintBuf, sizeof(hintBuf), "Notif:%s Ent:Region", nTag);
|
||||||
|
}
|
||||||
|
#elif defined(MECK_AUDIO_VARIANT) || defined(HAS_4G_MODEM)
|
||||||
|
if (chIdx > 0) {
|
||||||
|
snprintf(hintBuf, sizeof(hintBuf), "N:%s T:Tone X:Del", nTag);
|
||||||
|
} else {
|
||||||
|
snprintf(hintBuf, sizeof(hintBuf), "N:%s T:Tone Ent:Region", nTag);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
const char* hint = chIdx > 0 ? "Ent:Region X:Del" : "Ent:Region";
|
if (chIdx > 0) {
|
||||||
|
snprintf(hintBuf, sizeof(hintBuf), "N:%s Ent:Region X:Del", nTag);
|
||||||
|
} else {
|
||||||
|
snprintf(hintBuf, sizeof(hintBuf), "N:%s Ent:Region", nTag);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
int hintW = display.getTextWidth(hint);
|
int hintW = display.getTextWidth(hintBuf);
|
||||||
display.setCursor(display.width() - hintW - 2, y);
|
display.setCursor(display.width() - hintW - 2, y);
|
||||||
display.print(hint);
|
display.print(hintBuf);
|
||||||
display.setCursor(0, y);
|
display.setCursor(0, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2075,6 +2109,92 @@ public:
|
|||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === Notification sound picker overlay ===
|
||||||
|
#if defined(MECK_AUDIO_VARIANT) || defined(HAS_4G_MODEM)
|
||||||
|
if (_editMode == EDIT_NOTIF_SOUND) {
|
||||||
|
int bx = 2, by = 14, bw = display.width() - 4;
|
||||||
|
int bh = display.height() - 28;
|
||||||
|
display.setColor(DisplayDriver::DARK);
|
||||||
|
display.fillRect(bx, by, bw, bh);
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(bx, by, bw, bh);
|
||||||
|
|
||||||
|
display.setTextSize(_prefs->smallTextSize());
|
||||||
|
int lineH = _prefs->smallLineH();
|
||||||
|
|
||||||
|
// Header
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
display.setCursor(bx + 4, by + 3);
|
||||||
|
display.print("Notification Tone");
|
||||||
|
|
||||||
|
int listTop = by + 14;
|
||||||
|
int listBot = by + bh - 14;
|
||||||
|
int maxVisible = (listBot - listTop) / lineH;
|
||||||
|
if (maxVisible < 3) maxVisible = 3;
|
||||||
|
|
||||||
|
// Total items: 1 ("Default") + sound file count
|
||||||
|
const auto& files = notifSounds.getSoundFiles();
|
||||||
|
int totalItems = 1 + (int)files.size();
|
||||||
|
|
||||||
|
// Centre scroll on selection
|
||||||
|
_notifSoundScroll = max(0, min(_notifSoundSelected - maxVisible / 2,
|
||||||
|
totalItems - maxVisible));
|
||||||
|
if (_notifSoundScroll < 0) _notifSoundScroll = 0;
|
||||||
|
int endIdx = min(totalItems, _notifSoundScroll + maxVisible);
|
||||||
|
|
||||||
|
int sy = listTop;
|
||||||
|
for (int i = _notifSoundScroll; i < endIdx && sy + lineH <= listBot; i++) {
|
||||||
|
bool isSel = (i == _notifSoundSelected);
|
||||||
|
|
||||||
|
if (isSel) {
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.fillRect(bx + 2, sy + _prefs->smallHighlightOff(), bw - 4, lineH);
|
||||||
|
display.setColor(DisplayDriver::DARK);
|
||||||
|
} else {
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
display.setCursor(bx + 6, sy);
|
||||||
|
if (i == 0) {
|
||||||
|
display.print("Default (silent)");
|
||||||
|
} else {
|
||||||
|
// Show filename without extension
|
||||||
|
String displayName = files[i - 1];
|
||||||
|
int dot = displayName.lastIndexOf('.');
|
||||||
|
if (dot > 0) displayName = displayName.substring(0, dot);
|
||||||
|
if (displayName.length() > 28) displayName = displayName.substring(0, 28);
|
||||||
|
display.print(displayName.c_str());
|
||||||
|
}
|
||||||
|
sy += lineH;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Footer
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setColor(DisplayDriver::YELLOW);
|
||||||
|
int fy = by + bh - 11;
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.setCursor(bx + 4, fy);
|
||||||
|
display.print("Tap:Pick Boot:Back");
|
||||||
|
#else
|
||||||
|
display.setCursor(bx + 4, fy);
|
||||||
|
display.print("Enter:Pick Q:Back");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Scroll indicator
|
||||||
|
if (totalItems > maxVisible) {
|
||||||
|
int sbX = bx + bw - 4;
|
||||||
|
int sbH = listBot - listTop;
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(sbX, listTop, 3, sbH);
|
||||||
|
int thumbH = max(4, (maxVisible * sbH) / totalItems);
|
||||||
|
int maxScroll = totalItems - maxVisible;
|
||||||
|
if (maxScroll < 1) maxScroll = 1;
|
||||||
|
int thumbY = listTop + (_notifSoundScroll * (sbH - thumbH)) / maxScroll;
|
||||||
|
display.fillRect(sbX + 1, thumbY + 1, 1, thumbH - 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MECK_WIFI_COMPANION
|
#ifdef MECK_WIFI_COMPANION
|
||||||
// === WiFi setup overlay ===
|
// === WiFi setup overlay ===
|
||||||
if (_editMode == EDIT_WIFI) {
|
if (_editMode == EDIT_WIFI) {
|
||||||
@@ -2536,6 +2656,41 @@ public:
|
|||||||
return true; // consume all keys in confirm mode
|
return true; // consume all keys in confirm mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Notification sound picker ---
|
||||||
|
#if defined(MECK_AUDIO_VARIANT) || defined(HAS_4G_MODEM)
|
||||||
|
if (_editMode == EDIT_NOTIF_SOUND) {
|
||||||
|
const auto& files = notifSounds.getSoundFiles();
|
||||||
|
int totalItems = 1 + (int)files.size(); // 0=Default, rest=files
|
||||||
|
|
||||||
|
if (c == 'w' || c == 'W' || c == 0xF2 || c == KEY_UP) {
|
||||||
|
if (_notifSoundSelected > 0) _notifSoundSelected--;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c == 's' || c == 'S' || c == 0xF1 || c == KEY_DOWN) {
|
||||||
|
if (_notifSoundSelected < totalItems - 1) _notifSoundSelected++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c == '\r' || c == 13) {
|
||||||
|
// Select: 0 = clear (default silent), 1+ = file
|
||||||
|
if (_notifSoundSelected == 0) {
|
||||||
|
notifSounds.clearSoundForChannel(_notifSoundChannel);
|
||||||
|
} else {
|
||||||
|
int fileIdx = _notifSoundSelected - 1;
|
||||||
|
if (fileIdx >= 0 && fileIdx < (int)files.size()) {
|
||||||
|
notifSounds.setSoundForChannel(_notifSoundChannel, files[fileIdx].c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_editMode = EDIT_NONE;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c == 'q' || c == 'Q' || c == '\b') {
|
||||||
|
_editMode = EDIT_NONE;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true; // consume all keys in picker mode
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MECK_OTA_UPDATE
|
#ifdef MECK_OTA_UPDATE
|
||||||
// --- OTA update flow ---
|
// --- OTA update flow ---
|
||||||
if (_editMode == EDIT_OTA) {
|
if (_editMode == EDIT_OTA) {
|
||||||
@@ -2814,9 +2969,11 @@ public:
|
|||||||
} else if (type == ROW_GPS_BAUD) {
|
} else if (type == ROW_GPS_BAUD) {
|
||||||
_editPickerIdx--;
|
_editPickerIdx--;
|
||||||
if (_editPickerIdx < 0) _editPickerIdx = GPS_BAUD_OPTION_COUNT - 1;
|
if (_editPickerIdx < 0) _editPickerIdx = GPS_BAUD_OPTION_COUNT - 1;
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro) || defined(LilyGo_TDeck_Pro)
|
||||||
} else if (type == ROW_AUTO_LOCK) {
|
} else if (type == ROW_AUTO_LOCK) {
|
||||||
_editPickerIdx--;
|
_editPickerIdx--;
|
||||||
if (_editPickerIdx < 0) _editPickerIdx = AUTO_LOCK_OPTION_COUNT - 1;
|
if (_editPickerIdx < 0) _editPickerIdx = AUTO_LOCK_OPTION_COUNT - 1;
|
||||||
|
#endif
|
||||||
} else if (type == ROW_FONT_STYLE) {
|
} else if (type == ROW_FONT_STYLE) {
|
||||||
_editPickerIdx--;
|
_editPickerIdx--;
|
||||||
if (_editPickerIdx < 0) _editPickerIdx = MECK_FONT_STYLE_COUNT - 1;
|
if (_editPickerIdx < 0) _editPickerIdx = MECK_FONT_STYLE_COUNT - 1;
|
||||||
@@ -2835,9 +2992,11 @@ public:
|
|||||||
} else if (type == ROW_GPS_BAUD) {
|
} else if (type == ROW_GPS_BAUD) {
|
||||||
_editPickerIdx++;
|
_editPickerIdx++;
|
||||||
if (_editPickerIdx >= GPS_BAUD_OPTION_COUNT) _editPickerIdx = 0;
|
if (_editPickerIdx >= GPS_BAUD_OPTION_COUNT) _editPickerIdx = 0;
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro) || defined(LilyGo_TDeck_Pro)
|
||||||
} else if (type == ROW_AUTO_LOCK) {
|
} else if (type == ROW_AUTO_LOCK) {
|
||||||
_editPickerIdx++;
|
_editPickerIdx++;
|
||||||
if (_editPickerIdx >= AUTO_LOCK_OPTION_COUNT) _editPickerIdx = 0;
|
if (_editPickerIdx >= AUTO_LOCK_OPTION_COUNT) _editPickerIdx = 0;
|
||||||
|
#endif
|
||||||
} else if (type == ROW_FONT_STYLE) {
|
} else if (type == ROW_FONT_STYLE) {
|
||||||
_editPickerIdx++;
|
_editPickerIdx++;
|
||||||
if (_editPickerIdx >= MECK_FONT_STYLE_COUNT) _editPickerIdx = 0;
|
if (_editPickerIdx >= MECK_FONT_STYLE_COUNT) _editPickerIdx = 0;
|
||||||
@@ -2859,12 +3018,14 @@ public:
|
|||||||
_editMode = EDIT_NONE;
|
_editMode = EDIT_NONE;
|
||||||
Serial.printf("Settings: GPS baud set to %lu (reboot to apply)\n",
|
Serial.printf("Settings: GPS baud set to %lu (reboot to apply)\n",
|
||||||
(unsigned long)_prefs->gps_baudrate);
|
(unsigned long)_prefs->gps_baudrate);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro) || defined(LilyGo_TDeck_Pro)
|
||||||
} else if (type == ROW_AUTO_LOCK) {
|
} else if (type == ROW_AUTO_LOCK) {
|
||||||
_prefs->auto_lock_minutes = AUTO_LOCK_OPTIONS[_editPickerIdx];
|
_prefs->auto_lock_minutes = AUTO_LOCK_OPTIONS[_editPickerIdx];
|
||||||
the_mesh.savePrefs();
|
the_mesh.savePrefs();
|
||||||
_editMode = EDIT_NONE;
|
_editMode = EDIT_NONE;
|
||||||
Serial.printf("Settings: Auto lock = %s\n",
|
Serial.printf("Settings: Auto lock = %s\n",
|
||||||
autoLockLabel(_prefs->auto_lock_minutes));
|
autoLockLabel(_prefs->auto_lock_minutes));
|
||||||
|
#endif
|
||||||
} else if (type == ROW_FONT_STYLE) {
|
} else if (type == ROW_FONT_STYLE) {
|
||||||
_prefs->ui_font_style = _editPickerIdx;
|
_prefs->ui_font_style = _editPickerIdx;
|
||||||
the_mesh.savePrefs();
|
the_mesh.savePrefs();
|
||||||
@@ -3280,6 +3441,45 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// N: cycle notification preference (All -> Mentions -> None -> All)
|
||||||
|
if (c == 'n' || c == 'N') {
|
||||||
|
if (_rows[_cursor].type == ROW_CHANNEL) {
|
||||||
|
uint8_t chIdx = _rows[_cursor].param;
|
||||||
|
uint8_t cur = _prefs->channel_notif[chIdx];
|
||||||
|
_prefs->channel_notif[chIdx] = (cur + 1) % 3;
|
||||||
|
the_mesh.savePrefs();
|
||||||
|
const char* labels[] = {"All", "Mentions", "Off"};
|
||||||
|
Serial.printf("Settings: Channel %d notif -> %s\n",
|
||||||
|
chIdx, labels[_prefs->channel_notif[chIdx]]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// T: open notification tone picker
|
||||||
|
#if defined(MECK_AUDIO_VARIANT) || defined(HAS_4G_MODEM)
|
||||||
|
if (c == 't' || c == 'T') {
|
||||||
|
if (_rows[_cursor].type == ROW_CHANNEL) {
|
||||||
|
_notifSoundChannel = _rows[_cursor].param;
|
||||||
|
notifSounds.scanSoundFiles();
|
||||||
|
_notifSoundSelected = 0; // 0 = "Default (silent)"
|
||||||
|
_notifSoundScroll = 0;
|
||||||
|
// Pre-select current assignment
|
||||||
|
const char* current = notifSounds.getSoundForChannel(_notifSoundChannel);
|
||||||
|
if (current && current[0] != '\0') {
|
||||||
|
const auto& files = notifSounds.getSoundFiles();
|
||||||
|
for (int i = 0; i < (int)files.size(); i++) {
|
||||||
|
if (files[i] == String(current)) {
|
||||||
|
_notifSoundSelected = i + 1; // +1 because 0 is "Default"
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_editMode = EDIT_NOTIF_SOUND;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Q: back -- if in sub-screen, return to top level; else exit settings
|
// Q: back -- if in sub-screen, return to top level; else exit settings
|
||||||
if (c == 'q' || c == 'Q') {
|
if (c == 'q' || c == 'Q') {
|
||||||
if (_subScreen != SUB_NONE) {
|
if (_subScreen != SUB_NONE) {
|
||||||
|
|||||||
@@ -0,0 +1,489 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// SnakeScreen -- Classic Nokia-style Snake for Meck e-ink devices
|
||||||
|
//
|
||||||
|
// T-Deck Pro: 8x8 pixel cells on 240x320 display
|
||||||
|
// T5S3: 4x4 pixel cells on 128x128 virtual display
|
||||||
|
//
|
||||||
|
// The 800ms partial refresh floor naturally produces Nokia-era tick speed.
|
||||||
|
// Snake body stored as circular buffer -- ~1KB, no PSRAM needed.
|
||||||
|
// Game state persists when switching screens (auto-pause on exit).
|
||||||
|
//
|
||||||
|
// High scores: top 10 scores with dates stored to /games/snake_hi.dat on SD.
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
#include <helpers/ui/UIScreen.h>
|
||||||
|
#include <helpers/ui/DisplayDriver.h>
|
||||||
|
#include <SD.h>
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
class UITask;
|
||||||
|
|
||||||
|
// -- Grid sizing per platform --
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
#define SNAKE_CELL 4
|
||||||
|
#define SNAKE_HDR 14
|
||||||
|
#define SNAKE_FTR 10
|
||||||
|
#else
|
||||||
|
#define SNAKE_CELL 8
|
||||||
|
#define SNAKE_HDR 14
|
||||||
|
#define SNAKE_FTR 14
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SNAKE_MAX_LEN 512
|
||||||
|
#define SNAKE_HI_COUNT 10
|
||||||
|
#define SNAKE_HI_PATH "/games/snake_hi.dat"
|
||||||
|
#define SNAKE_HI_VERSION 1
|
||||||
|
|
||||||
|
class SnakeScreen : public UIScreen {
|
||||||
|
public:
|
||||||
|
enum GameState { READY, PLAYING, GAME_OVER };
|
||||||
|
enum Direction { UP, DOWN, LEFT, RIGHT };
|
||||||
|
|
||||||
|
struct HiScoreEntry {
|
||||||
|
uint16_t score;
|
||||||
|
uint32_t timestamp; // Unix epoch from RTC
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
UITask* _task;
|
||||||
|
mesh::RTCClock* _rtc;
|
||||||
|
bool _wantsExit;
|
||||||
|
|
||||||
|
// Grid dimensions (computed once from display size on first render)
|
||||||
|
int _gridW, _gridH;
|
||||||
|
int _offsetX, _offsetY;
|
||||||
|
|
||||||
|
// Snake body circular buffer
|
||||||
|
struct Cell { uint8_t x, y; };
|
||||||
|
Cell _body[SNAKE_MAX_LEN];
|
||||||
|
int _headIdx;
|
||||||
|
int _length;
|
||||||
|
|
||||||
|
// Game state
|
||||||
|
GameState _state;
|
||||||
|
Direction _dir;
|
||||||
|
Direction _pendingDir;
|
||||||
|
Cell _food;
|
||||||
|
int _score;
|
||||||
|
unsigned long _lastTick;
|
||||||
|
unsigned long _tickInterval;
|
||||||
|
|
||||||
|
// High scores
|
||||||
|
HiScoreEntry _hiScores[SNAKE_HI_COUNT];
|
||||||
|
int _hiCount;
|
||||||
|
bool _newHiScore;
|
||||||
|
int _newHiRank; // 0-based rank of newly inserted score (-1 if none)
|
||||||
|
|
||||||
|
// Simple xorshift PRNG
|
||||||
|
uint16_t _rngState;
|
||||||
|
|
||||||
|
uint16_t rng() {
|
||||||
|
_rngState ^= _rngState << 7;
|
||||||
|
_rngState ^= _rngState >> 9;
|
||||||
|
_rngState ^= _rngState << 8;
|
||||||
|
return _rngState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spawnFood() {
|
||||||
|
for (int attempt = 0; attempt < 50; attempt++) {
|
||||||
|
int fx = rng() % _gridW;
|
||||||
|
int fy = rng() % _gridH;
|
||||||
|
if (!isSnakeAt(fx, fy)) {
|
||||||
|
_food.x = fx;
|
||||||
|
_food.y = fy;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int gy = 0; gy < _gridH; gy++) {
|
||||||
|
for (int gx = 0; gx < _gridW; gx++) {
|
||||||
|
if (!isSnakeAt(gx, gy)) {
|
||||||
|
_food.x = gx;
|
||||||
|
_food.y = gy;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSnakeAt(int x, int y) const {
|
||||||
|
for (int i = 0; i < _length; i++) {
|
||||||
|
int idx = (_headIdx - i + SNAKE_MAX_LEN) % SNAKE_MAX_LEN;
|
||||||
|
if (_body[idx].x == x && _body[idx].y == y) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cell getHead() const { return _body[_headIdx]; }
|
||||||
|
|
||||||
|
void resetGame() {
|
||||||
|
int cx = _gridW / 2;
|
||||||
|
int cy = _gridH / 2;
|
||||||
|
_length = 3;
|
||||||
|
_headIdx = 2;
|
||||||
|
_body[0] = { (uint8_t)(cx - 2), (uint8_t)cy };
|
||||||
|
_body[1] = { (uint8_t)(cx - 1), (uint8_t)cy };
|
||||||
|
_body[2] = { (uint8_t)cx, (uint8_t)cy };
|
||||||
|
_dir = RIGHT;
|
||||||
|
_pendingDir = RIGHT;
|
||||||
|
_score = 0;
|
||||||
|
_tickInterval = 500;
|
||||||
|
_newHiScore = false;
|
||||||
|
_newHiRank = -1;
|
||||||
|
_rngState = (uint16_t)(millis() ^ 0xA5A5);
|
||||||
|
spawnFood();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tick() {
|
||||||
|
_dir = _pendingDir;
|
||||||
|
Cell head = getHead();
|
||||||
|
int nx = head.x;
|
||||||
|
int ny = head.y;
|
||||||
|
switch (_dir) {
|
||||||
|
case UP: ny--; break;
|
||||||
|
case DOWN: ny++; break;
|
||||||
|
case LEFT: nx--; break;
|
||||||
|
case RIGHT: nx++; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nx < 0 || nx >= _gridW || ny < 0 || ny >= _gridH) {
|
||||||
|
onDeath();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool eating = (nx == _food.x && ny == _food.y);
|
||||||
|
int checkLen = eating ? _length : (_length - 1);
|
||||||
|
for (int i = 0; i < checkLen; i++) {
|
||||||
|
int idx = (_headIdx - i + SNAKE_MAX_LEN) % SNAKE_MAX_LEN;
|
||||||
|
if (_body[idx].x == nx && _body[idx].y == ny) {
|
||||||
|
onDeath();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_headIdx = (_headIdx + 1) % SNAKE_MAX_LEN;
|
||||||
|
_body[_headIdx] = { (uint8_t)nx, (uint8_t)ny };
|
||||||
|
|
||||||
|
if (eating) {
|
||||||
|
_length++;
|
||||||
|
if (_length >= SNAKE_MAX_LEN) _length = SNAKE_MAX_LEN;
|
||||||
|
_score += 10;
|
||||||
|
spawnFood();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void onDeath() {
|
||||||
|
_state = GAME_OVER;
|
||||||
|
if (_score > 0) {
|
||||||
|
_newHiRank = insertHiScore(_score);
|
||||||
|
_newHiScore = (_newHiRank >= 0);
|
||||||
|
if (_newHiScore) saveHiScores();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawCellFilled(DisplayDriver& display, int gx, int gy) const {
|
||||||
|
int px = _offsetX + gx * SNAKE_CELL;
|
||||||
|
int py = _offsetY + gy * SNAKE_CELL;
|
||||||
|
display.fillRect(px, py, SNAKE_CELL, SNAKE_CELL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawCellOutline(DisplayDriver& display, int gx, int gy) const {
|
||||||
|
int px = _offsetX + gx * SNAKE_CELL;
|
||||||
|
int py = _offsetY + gy * SNAKE_CELL;
|
||||||
|
display.drawRect(px, py, SNAKE_CELL, SNAKE_CELL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- High score persistence ---
|
||||||
|
|
||||||
|
void loadHiScores() {
|
||||||
|
_hiCount = 0;
|
||||||
|
memset(_hiScores, 0, sizeof(_hiScores));
|
||||||
|
if (!SD.exists(SNAKE_HI_PATH)) return;
|
||||||
|
|
||||||
|
File f = SD.open(SNAKE_HI_PATH, FILE_READ);
|
||||||
|
if (!f) return;
|
||||||
|
|
||||||
|
uint8_t ver = 0;
|
||||||
|
if (f.read(&ver, 1) != 1 || ver != SNAKE_HI_VERSION) { f.close(); return; }
|
||||||
|
|
||||||
|
uint8_t count = 0;
|
||||||
|
if (f.read(&count, 1) != 1) { f.close(); return; }
|
||||||
|
if (count > SNAKE_HI_COUNT) count = SNAKE_HI_COUNT;
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
uint8_t buf[6];
|
||||||
|
if (f.read(buf, 6) != 6) break;
|
||||||
|
_hiScores[i].score = (uint16_t)buf[0] | ((uint16_t)buf[1] << 8);
|
||||||
|
_hiScores[i].timestamp = (uint32_t)buf[2] | ((uint32_t)buf[3] << 8)
|
||||||
|
| ((uint32_t)buf[4] << 16) | ((uint32_t)buf[5] << 24);
|
||||||
|
_hiCount++;
|
||||||
|
}
|
||||||
|
f.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveHiScores() {
|
||||||
|
if (!SD.exists("/games")) SD.mkdir("/games");
|
||||||
|
if (SD.exists(SNAKE_HI_PATH)) SD.remove(SNAKE_HI_PATH);
|
||||||
|
|
||||||
|
File f = SD.open(SNAKE_HI_PATH, FILE_WRITE);
|
||||||
|
if (!f) return;
|
||||||
|
|
||||||
|
uint8_t ver = SNAKE_HI_VERSION;
|
||||||
|
f.write(&ver, 1);
|
||||||
|
uint8_t count = (uint8_t)_hiCount;
|
||||||
|
f.write(&count, 1);
|
||||||
|
|
||||||
|
for (int i = 0; i < _hiCount; i++) {
|
||||||
|
uint8_t buf[6];
|
||||||
|
buf[0] = _hiScores[i].score & 0xFF;
|
||||||
|
buf[1] = (_hiScores[i].score >> 8) & 0xFF;
|
||||||
|
buf[2] = _hiScores[i].timestamp & 0xFF;
|
||||||
|
buf[3] = (_hiScores[i].timestamp >> 8) & 0xFF;
|
||||||
|
buf[4] = (_hiScores[i].timestamp >> 16) & 0xFF;
|
||||||
|
buf[5] = (_hiScores[i].timestamp >> 24) & 0xFF;
|
||||||
|
f.write(buf, 6);
|
||||||
|
}
|
||||||
|
f.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
int insertHiScore(int score) {
|
||||||
|
uint32_t now = (_rtc != nullptr) ? _rtc->getCurrentTime() : 0;
|
||||||
|
int pos = _hiCount;
|
||||||
|
for (int i = 0; i < _hiCount; i++) {
|
||||||
|
if ((uint16_t)score > _hiScores[i].score) { pos = i; break; }
|
||||||
|
}
|
||||||
|
if (pos >= SNAKE_HI_COUNT) return -1;
|
||||||
|
|
||||||
|
int newCount = _hiCount + 1;
|
||||||
|
if (newCount > SNAKE_HI_COUNT) newCount = SNAKE_HI_COUNT;
|
||||||
|
for (int i = newCount - 1; i > pos; i--) _hiScores[i] = _hiScores[i - 1];
|
||||||
|
|
||||||
|
_hiScores[pos].score = (uint16_t)score;
|
||||||
|
_hiScores[pos].timestamp = now;
|
||||||
|
_hiCount = newCount;
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void formatDate(uint32_t ts, char* buf, int bufLen) {
|
||||||
|
if (ts == 0) { snprintf(buf, bufLen, "--"); return; }
|
||||||
|
uint32_t days = ts / 86400;
|
||||||
|
int year = 1970;
|
||||||
|
while (true) {
|
||||||
|
int diy = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? 366 : 365;
|
||||||
|
if (days < (uint32_t)diy) break;
|
||||||
|
days -= diy;
|
||||||
|
year++;
|
||||||
|
}
|
||||||
|
static const int dim[] = {31,28,31,30,31,30,31,31,30,31,30,31};
|
||||||
|
static const char* mn[] = {"Jan","Feb","Mar","Apr","May","Jun",
|
||||||
|
"Jul","Aug","Sep","Oct","Nov","Dec"};
|
||||||
|
bool leap = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
|
||||||
|
int month = 0;
|
||||||
|
for (month = 0; month < 12; month++) {
|
||||||
|
int d = dim[month];
|
||||||
|
if (month == 1 && leap) d = 29;
|
||||||
|
if (days < (uint32_t)d) break;
|
||||||
|
days -= d;
|
||||||
|
}
|
||||||
|
if (month > 11) month = 11;
|
||||||
|
snprintf(buf, bufLen, "%d %s %d", (int)(days + 1), mn[month], year);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
SnakeScreen(UITask* task, mesh::RTCClock* rtc)
|
||||||
|
: _task(task), _rtc(rtc), _wantsExit(false), _gridW(0), _gridH(0),
|
||||||
|
_offsetX(0), _offsetY(0), _headIdx(0), _length(0),
|
||||||
|
_state(READY), _dir(RIGHT), _pendingDir(RIGHT),
|
||||||
|
_score(0), _lastTick(0), _tickInterval(500), _rngState(0xBEEF),
|
||||||
|
_hiCount(0), _newHiScore(false), _newHiRank(-1) {
|
||||||
|
_food = {0, 0};
|
||||||
|
memset(_body, 0, sizeof(_body));
|
||||||
|
memset(_hiScores, 0, sizeof(_hiScores));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wantsExit() const { return _wantsExit; }
|
||||||
|
void clearExit() { _wantsExit = false; }
|
||||||
|
GameState getState() const { return _state; }
|
||||||
|
|
||||||
|
void enter() {
|
||||||
|
_wantsExit = false;
|
||||||
|
loadHiScores();
|
||||||
|
_lastTick = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool handleInput(char c) override {
|
||||||
|
switch (_state) {
|
||||||
|
case READY:
|
||||||
|
if (c == '\r') { _state = PLAYING; _lastTick = millis(); return true; }
|
||||||
|
if (c == 'q' || c == 'Q') { _wantsExit = true; return true; }
|
||||||
|
return false;
|
||||||
|
case PLAYING:
|
||||||
|
switch (c) {
|
||||||
|
case 'w': case 'W': if (_dir != DOWN) _pendingDir = UP; return true;
|
||||||
|
case 's': case 'S': if (_dir != UP) _pendingDir = DOWN; return true;
|
||||||
|
case 'a': case 'A': if (_dir != RIGHT) _pendingDir = LEFT; return true;
|
||||||
|
case 'd': case 'D': if (_dir != LEFT) _pendingDir = RIGHT; return true;
|
||||||
|
case 'q': case 'Q': _wantsExit = true; return true;
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
case GAME_OVER:
|
||||||
|
if (c == '\r') { resetGame(); _state = PLAYING; _lastTick = millis(); return true; }
|
||||||
|
if (c == 'q' || c == 'Q') { _wantsExit = true; return true; }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int render(DisplayDriver& display) override {
|
||||||
|
if (_gridW == 0) {
|
||||||
|
int usableW = display.width();
|
||||||
|
int usableH = display.height() - SNAKE_HDR - SNAKE_FTR;
|
||||||
|
_gridW = usableW / SNAKE_CELL;
|
||||||
|
_gridH = usableH / SNAKE_CELL;
|
||||||
|
_offsetX = (usableW - _gridW * SNAKE_CELL) / 2;
|
||||||
|
_offsetY = SNAKE_HDR + (usableH - _gridH * SNAKE_CELL) / 2;
|
||||||
|
resetGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
display.startFrame();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.drawTextCentered(display.width() / 2, 2, "Snake");
|
||||||
|
#else
|
||||||
|
display.setCursor(2, 2);
|
||||||
|
display.print("Snake");
|
||||||
|
char scoreBuf[16];
|
||||||
|
snprintf(scoreBuf, sizeof(scoreBuf), "Score: %d", _score);
|
||||||
|
int sw = display.getTextWidth(scoreBuf);
|
||||||
|
display.setCursor(display.width() - sw - 2, 2);
|
||||||
|
display.print(scoreBuf);
|
||||||
|
#endif
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(0, SNAKE_HDR - 2, display.width(), 1);
|
||||||
|
|
||||||
|
if (_state == READY) {
|
||||||
|
int cx = display.width() / 2;
|
||||||
|
int y = SNAKE_HDR + 6;
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawTextCentered(cx, y, "Classic Snake");
|
||||||
|
y += 14;
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.drawTextCentered(cx, y, "Swipe to steer");
|
||||||
|
#else
|
||||||
|
display.drawTextCentered(cx, y, "W/S/A/D to steer");
|
||||||
|
#endif
|
||||||
|
y += 11;
|
||||||
|
display.drawTextCentered(cx, y, "Eat food to grow");
|
||||||
|
y += 11;
|
||||||
|
display.drawTextCentered(cx, y, "Steer clear of walls");
|
||||||
|
y += 16;
|
||||||
|
|
||||||
|
if (_hiCount > 0) {
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawTextCentered(cx, y, "-- High Scores --");
|
||||||
|
y += 12;
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
int showCount = (_hiCount < 5) ? _hiCount : 5;
|
||||||
|
#else
|
||||||
|
int showCount = (_hiCount < 10) ? _hiCount : 10;
|
||||||
|
#endif
|
||||||
|
for (int i = 0; i < showCount; i++) {
|
||||||
|
char dateBuf[16];
|
||||||
|
formatDate(_hiScores[i].timestamp, dateBuf, sizeof(dateBuf));
|
||||||
|
char line[48];
|
||||||
|
snprintf(line, sizeof(line), "%d. %d %s", i + 1, _hiScores[i].score, dateBuf);
|
||||||
|
display.drawTextCentered(cx, y, line);
|
||||||
|
y += 10;
|
||||||
|
}
|
||||||
|
y += 4;
|
||||||
|
} else {
|
||||||
|
y += 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.drawTextCentered(cx, y, "Tap to start");
|
||||||
|
#else
|
||||||
|
display.drawTextCentered(cx, y, "Press Enter to start");
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
if (_state == PLAYING) {
|
||||||
|
unsigned long now = millis();
|
||||||
|
if (now - _lastTick >= _tickInterval) { tick(); _lastTick = now; }
|
||||||
|
}
|
||||||
|
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(_offsetX - 1, _offsetY - 1,
|
||||||
|
_gridW * SNAKE_CELL + 2, _gridH * SNAKE_CELL + 2);
|
||||||
|
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
drawCellFilled(display, _food.x, _food.y);
|
||||||
|
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
for (int i = 0; i < _length; i++) {
|
||||||
|
int idx = (_headIdx - i + SNAKE_MAX_LEN) % SNAKE_MAX_LEN;
|
||||||
|
if (i == 0) drawCellFilled(display, _body[idx].x, _body[idx].y);
|
||||||
|
else drawCellOutline(display, _body[idx].x, _body[idx].y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_state == GAME_OVER) {
|
||||||
|
int cx = display.width() / 2;
|
||||||
|
int cy = display.height() / 2;
|
||||||
|
int boxW = display.width() * 3 / 4;
|
||||||
|
int boxH = _newHiScore ? 60 : 50;
|
||||||
|
int boxX = cx - boxW / 2;
|
||||||
|
int boxY = cy - boxH / 2;
|
||||||
|
|
||||||
|
display.setColor(DisplayDriver::DARK);
|
||||||
|
display.fillRect(boxX, boxY, boxW, boxH);
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(boxX, boxY, boxW, boxH);
|
||||||
|
|
||||||
|
int ty = boxY + 8;
|
||||||
|
display.drawTextCentered(cx, ty, "Game Over");
|
||||||
|
ty += 14;
|
||||||
|
char finalScore[24];
|
||||||
|
snprintf(finalScore, sizeof(finalScore), "Score: %d", _score);
|
||||||
|
display.drawTextCentered(cx, ty, finalScore);
|
||||||
|
ty += 12;
|
||||||
|
if (_newHiScore) {
|
||||||
|
display.setColor(DisplayDriver::YELLOW);
|
||||||
|
char rankBuf[32];
|
||||||
|
snprintf(rankBuf, sizeof(rankBuf), "New #%d High Score!", _newHiRank + 1);
|
||||||
|
display.drawTextCentered(cx, ty, rankBuf);
|
||||||
|
ty += 12;
|
||||||
|
}
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
display.drawTextCentered(cx, ty, "Enter:Retry Q:Back");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
char footBuf[32];
|
||||||
|
snprintf(footBuf, sizeof(footBuf), "Score: %d", _score);
|
||||||
|
display.setTextSize(0);
|
||||||
|
display.drawTextCentered(display.width() / 2, display.height() - 8, footBuf);
|
||||||
|
display.setTextSize(1);
|
||||||
|
#else
|
||||||
|
display.setTextSize(1);
|
||||||
|
int fy = display.height() - 12;
|
||||||
|
display.drawRect(0, fy - 2, display.width(), 1);
|
||||||
|
if (_state == PLAYING) {
|
||||||
|
display.setCursor(2, fy);
|
||||||
|
display.print("Q:Back");
|
||||||
|
} else if (_state == READY) {
|
||||||
|
display.setCursor(2, fy);
|
||||||
|
display.print("Enter:Start Q:Back");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (_state == PLAYING) return 100;
|
||||||
|
return 5000;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,988 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <helpers/ui/UIScreen.h>
|
||||||
|
#include <helpers/ui/DisplayDriver.h>
|
||||||
|
#include <MeshCore.h>
|
||||||
|
#include <Packet.h>
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
class UITask;
|
||||||
|
class MyMesh;
|
||||||
|
extern MyMesh the_mesh;
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// TraceScreen
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Standalone trace path tool for the T-Deck Pro. The user builds a repeater
|
||||||
|
// chain from the contacts list or by typing comma-separated hash values, sends
|
||||||
|
// a PAYLOAD_TYPE_TRACE packet direct-routed through the chain, and views
|
||||||
|
// per-hop SNR results.
|
||||||
|
//
|
||||||
|
// Path size (1-byte or 2-byte hashes) follows the device's path_hash_mode
|
||||||
|
// setting but can be toggled on this screen.
|
||||||
|
//
|
||||||
|
// The trace packet is created via Mesh::createTrace() and sent via
|
||||||
|
// Mesh::sendDirect(). Each repeater in the chain checks if its pub_key
|
||||||
|
// prefix matches the next hash in the payload; if so, it appends its receive
|
||||||
|
// SNR*4 to the packet's path field and forwards. When the packet reaches
|
||||||
|
// the end of its given path, onTraceRecv() fires on the receiving node.
|
||||||
|
//
|
||||||
|
// For round-trip traces the user should build a symmetric path
|
||||||
|
// (e.g. A,B,C,B,A) and must be able to hear the last repeater directly.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define TRACE_MAX_HOPS 16
|
||||||
|
#define TRACE_TIMEOUT_MS 30000 // 30 second timeout
|
||||||
|
#define TRACE_EDIT_BUF 80 // Max chars for typed path
|
||||||
|
|
||||||
|
class TraceScreen : public UIScreen {
|
||||||
|
public:
|
||||||
|
enum ScreenState {
|
||||||
|
STATE_BUILD, // Building the path
|
||||||
|
STATE_PICK_HOP, // Picking a repeater from contacts
|
||||||
|
STATE_RUNNING, // Trace sent, waiting for response
|
||||||
|
STATE_RESULTS // Showing results
|
||||||
|
};
|
||||||
|
|
||||||
|
// Trace result data (filled by onTraceResult callback)
|
||||||
|
struct TraceResult {
|
||||||
|
uint8_t hashes[TRACE_MAX_HOPS * 2]; // Hash bytes (1 or 2 per hop)
|
||||||
|
int8_t snrs[TRACE_MAX_HOPS]; // SNR*4 per hop
|
||||||
|
int8_t final_snr; // SNR of the response arriving back
|
||||||
|
int hopCount; // Number of hops that responded
|
||||||
|
int totalHops; // Total hops in the path
|
||||||
|
uint32_t duration_ms; // Round-trip time
|
||||||
|
bool valid;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
UITask* _task;
|
||||||
|
mesh::RTCClock* _rtc;
|
||||||
|
|
||||||
|
ScreenState _state;
|
||||||
|
|
||||||
|
// Path being built
|
||||||
|
uint8_t _pathBuf[TRACE_MAX_HOPS * 2]; // Hash bytes (max 2 bytes per hop)
|
||||||
|
int _hopCount;
|
||||||
|
int _bytesPerHop; // 1 or 2
|
||||||
|
|
||||||
|
// Menu navigation (STATE_BUILD)
|
||||||
|
int _menuSel;
|
||||||
|
|
||||||
|
// Inline text editor (for Type Path)
|
||||||
|
bool _editing;
|
||||||
|
char _editBuf[TRACE_EDIT_BUF];
|
||||||
|
int _editPos;
|
||||||
|
|
||||||
|
// Repeater picker (STATE_PICK_HOP)
|
||||||
|
static const int MAX_REPEATERS = 200;
|
||||||
|
uint16_t* _repIdx; // Indices into contact table (PSRAM)
|
||||||
|
int _repCount;
|
||||||
|
int _repSel;
|
||||||
|
int _repScroll;
|
||||||
|
|
||||||
|
// Trace state (STATE_RUNNING / STATE_RESULTS)
|
||||||
|
uint32_t _traceTag;
|
||||||
|
uint32_t _traceAuth;
|
||||||
|
unsigned long _traceSentAt;
|
||||||
|
TraceResult _result;
|
||||||
|
|
||||||
|
// Results scroll
|
||||||
|
int _resultScroll;
|
||||||
|
|
||||||
|
bool _wantExit;
|
||||||
|
|
||||||
|
// --- Menu helpers (STATE_BUILD) ---
|
||||||
|
// Menu layout:
|
||||||
|
// 0: Mode selector (1-byte / 2-byte)
|
||||||
|
// 1: Type Path (inline text editor)
|
||||||
|
// 2..hopCount+1: each hop
|
||||||
|
// next: + Add repeater (if < TRACE_MAX_HOPS)
|
||||||
|
// next: Remove last (if hopCount > 0)
|
||||||
|
// next: Run Trace (if hopCount > 0)
|
||||||
|
// last: Exit
|
||||||
|
enum MenuItem {
|
||||||
|
MENU_PATH_SIZE = 0,
|
||||||
|
MENU_TYPE_PATH = 1,
|
||||||
|
MENU_HOP_BASE = 2,
|
||||||
|
MENU_ADD_HOP = 200,
|
||||||
|
MENU_REMOVE_LAST,
|
||||||
|
MENU_RUN_TRACE,
|
||||||
|
MENU_EXIT
|
||||||
|
};
|
||||||
|
|
||||||
|
int buildMenuCount() const {
|
||||||
|
int count = 2; // Mode + Type Path
|
||||||
|
count += _hopCount;
|
||||||
|
if (_hopCount < TRACE_MAX_HOPS) count++; // Add hop
|
||||||
|
if (_hopCount > 0) count++; // Remove last
|
||||||
|
if (_hopCount > 0) count++; // Run Trace
|
||||||
|
count++; // Exit
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuItem menuItemAt(int idx) const {
|
||||||
|
if (idx == 0) return MENU_PATH_SIZE;
|
||||||
|
if (idx == 1) return MENU_TYPE_PATH;
|
||||||
|
int pos = 2;
|
||||||
|
for (int h = 0; h < _hopCount; h++) {
|
||||||
|
if (idx == pos) return (MenuItem)(MENU_HOP_BASE + h);
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
if (_hopCount < TRACE_MAX_HOPS) {
|
||||||
|
if (idx == pos) return MENU_ADD_HOP;
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
if (_hopCount > 0) {
|
||||||
|
if (idx == pos) return MENU_REMOVE_LAST;
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
if (_hopCount > 0) {
|
||||||
|
if (idx == pos) return MENU_RUN_TRACE;
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
return MENU_EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build repeater list from contacts
|
||||||
|
void buildRepeaterList() {
|
||||||
|
_repCount = 0;
|
||||||
|
uint32_t numContacts = the_mesh.getNumContacts();
|
||||||
|
ContactInfo c;
|
||||||
|
for (uint32_t i = 0; i < numContacts && _repCount < MAX_REPEATERS; i++) {
|
||||||
|
if (the_mesh.getContactByIdx(i, c)) {
|
||||||
|
if (c.type == ADV_TYPE_REPEATER) {
|
||||||
|
_repIdx[_repCount++] = (uint16_t)i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look up contact name from hash prefix
|
||||||
|
bool findNameForHash(const uint8_t* hash, int hashLen, char* name, size_t nameLen) const {
|
||||||
|
uint32_t numContacts = the_mesh.getNumContacts();
|
||||||
|
ContactInfo c;
|
||||||
|
// First pass: repeaters only
|
||||||
|
for (uint32_t i = 0; i < numContacts; i++) {
|
||||||
|
if (the_mesh.getContactByIdx(i, c) && c.type == ADV_TYPE_REPEATER) {
|
||||||
|
if (memcmp(c.id.pub_key, hash, hashLen) == 0) {
|
||||||
|
strncpy(name, c.name, nameLen);
|
||||||
|
name[nameLen - 1] = '\0';
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Second pass: any contact
|
||||||
|
for (uint32_t i = 0; i < numContacts; i++) {
|
||||||
|
if (the_mesh.getContactByIdx(i, c)) {
|
||||||
|
if (memcmp(c.id.pub_key, hash, hashLen) == 0) {
|
||||||
|
strncpy(name, c.name, nameLen);
|
||||||
|
name[nameLen - 1] = '\0';
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse comma-separated decimal values from edit buffer into path
|
||||||
|
// Returns number of hops parsed, or -1 on error
|
||||||
|
int parseTypedPath() {
|
||||||
|
if (_editBuf[0] == '\0') return 0;
|
||||||
|
|
||||||
|
uint8_t tmpPath[TRACE_MAX_HOPS * 2];
|
||||||
|
int hops = 0;
|
||||||
|
const char* p = _editBuf;
|
||||||
|
|
||||||
|
while (*p && hops < TRACE_MAX_HOPS) {
|
||||||
|
// Skip whitespace/commas
|
||||||
|
while (*p == ',' || *p == ' ') p++;
|
||||||
|
if (*p == '\0') break;
|
||||||
|
|
||||||
|
// Parse hex number (companion app uses hex hash values)
|
||||||
|
char* end;
|
||||||
|
long val = strtol(p, &end, 16);
|
||||||
|
if (end == p) return -1; // No digits found
|
||||||
|
p = end;
|
||||||
|
|
||||||
|
if (_bytesPerHop == 1) {
|
||||||
|
if (val < 0 || val > 255) return -1;
|
||||||
|
tmpPath[hops] = (uint8_t)val;
|
||||||
|
} else {
|
||||||
|
if (val < 0 || val > 65535) return -1;
|
||||||
|
// Big-endian storage: hash display = (pub_key[0] << 8) | pub_key[1]
|
||||||
|
// So val >> 8 is pub_key[0], val & 0xFF is pub_key[1]
|
||||||
|
tmpPath[hops * 2] = (uint8_t)((val >> 8) & 0xFF);
|
||||||
|
tmpPath[hops * 2 + 1] = (uint8_t)(val & 0xFF);
|
||||||
|
}
|
||||||
|
hops++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hops > 0) {
|
||||||
|
memcpy(_pathBuf, tmpPath, hops * _bytesPerHop);
|
||||||
|
_hopCount = hops;
|
||||||
|
}
|
||||||
|
return hops;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build display string from current path (for showing in edit field)
|
||||||
|
void pathToEditBuf() {
|
||||||
|
_editBuf[0] = '\0';
|
||||||
|
_editPos = 0;
|
||||||
|
for (int i = 0; i < _hopCount; i++) {
|
||||||
|
char tmp[8];
|
||||||
|
if (_bytesPerHop == 1) {
|
||||||
|
snprintf(tmp, sizeof(tmp), "%02X", _pathBuf[i]);
|
||||||
|
} else {
|
||||||
|
uint16_t val = ((uint16_t)_pathBuf[i * 2] << 8) | _pathBuf[i * 2 + 1];
|
||||||
|
snprintf(tmp, sizeof(tmp), "%04X", val);
|
||||||
|
}
|
||||||
|
if (i > 0) {
|
||||||
|
if (_editPos < TRACE_EDIT_BUF - 1) _editBuf[_editPos++] = ',';
|
||||||
|
}
|
||||||
|
int tlen = strlen(tmp);
|
||||||
|
if (_editPos + tlen < TRACE_EDIT_BUF - 1) {
|
||||||
|
memcpy(&_editBuf[_editPos], tmp, tlen);
|
||||||
|
_editPos += tlen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_editBuf[_editPos] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Truncate long names to maxLen chars + "..." for display
|
||||||
|
static void truncateName(char* name, int maxLen = 10) {
|
||||||
|
if ((int)strlen(name) > maxLen) {
|
||||||
|
name[maxLen] = '\0';
|
||||||
|
// Remove trailing space before ellipsis
|
||||||
|
while (maxLen > 0 && name[maxLen - 1] == ' ') {
|
||||||
|
name[--maxLen] = '\0';
|
||||||
|
}
|
||||||
|
strcat(name, "...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw signal bars (3 bars) based on SNR
|
||||||
|
void drawSignalBars(DisplayDriver& display, int x, int y, int8_t snr4) {
|
||||||
|
float snr = snr4 / 4.0f;
|
||||||
|
// 3 bars: low >= -5, mid >= 3, high >= 8
|
||||||
|
int bars = 0;
|
||||||
|
if (snr >= -5.0f) bars = 1;
|
||||||
|
if (snr >= 3.0f) bars = 2;
|
||||||
|
if (snr >= 8.0f) bars = 3;
|
||||||
|
|
||||||
|
int barW = 3;
|
||||||
|
int gap = 1;
|
||||||
|
int heights[] = { 4, 7, 10 };
|
||||||
|
for (int b = 0; b < 3; b++) {
|
||||||
|
int bx = x + b * (barW + gap);
|
||||||
|
int by = y + 10 - heights[b];
|
||||||
|
if (b < bars) {
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
} else {
|
||||||
|
display.setColor(DisplayDriver::DARK);
|
||||||
|
}
|
||||||
|
display.fillRect(bx, by, barW, heights[b]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
TraceScreen(UITask* task, mesh::RTCClock* rtc)
|
||||||
|
: _task(task), _rtc(rtc), _state(STATE_BUILD),
|
||||||
|
_hopCount(0), _bytesPerHop(2),
|
||||||
|
_menuSel(0), _editing(false), _editPos(0),
|
||||||
|
_repCount(0), _repSel(0), _repScroll(0),
|
||||||
|
_traceTag(0), _traceAuth(0), _traceSentAt(0),
|
||||||
|
_resultScroll(0), _wantExit(false) {
|
||||||
|
memset(_pathBuf, 0, sizeof(_pathBuf));
|
||||||
|
memset(_editBuf, 0, sizeof(_editBuf));
|
||||||
|
memset(&_result, 0, sizeof(_result));
|
||||||
|
#if defined(ESP32) && defined(BOARD_HAS_PSRAM)
|
||||||
|
_repIdx = (uint16_t*)ps_calloc(MAX_REPEATERS, sizeof(uint16_t));
|
||||||
|
#else
|
||||||
|
_repIdx = new uint16_t[MAX_REPEATERS]();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wantsExit() const { return _wantExit; }
|
||||||
|
bool isEditing() const { return _editing; }
|
||||||
|
|
||||||
|
// --- Public helpers for T5S3 long-press → virtual keyboard integration ---
|
||||||
|
|
||||||
|
// True if the highlighted menu row is the Type Path entry (STATE_BUILD only).
|
||||||
|
bool isOnTypePathRow() const {
|
||||||
|
return _state == STATE_BUILD && menuItemAt(_menuSel) == MENU_TYPE_PATH;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the current path formatted as a comma-separated string, suitable
|
||||||
|
// for pre-populating an external text editor (e.g. the T5S3 virtual keyboard).
|
||||||
|
// The returned pointer references an internal buffer and is valid until the
|
||||||
|
// next call to this method or to setTypedPath()/parseTypedPath().
|
||||||
|
const char* getCurrentPathAsText() {
|
||||||
|
pathToEditBuf();
|
||||||
|
return _editBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply a path typed externally (via virtual keyboard submission).
|
||||||
|
// Replaces the working path buffer with whatever parses out of `text`
|
||||||
|
// and ensures the inline editor flag is cleared so the menu redraws cleanly.
|
||||||
|
void setTypedPath(const char* text) {
|
||||||
|
if (!text) return;
|
||||||
|
strncpy(_editBuf, text, sizeof(_editBuf) - 1);
|
||||||
|
_editBuf[sizeof(_editBuf) - 1] = '\0';
|
||||||
|
parseTypedPath();
|
||||||
|
_editing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void enter(int pathHashMode) {
|
||||||
|
_state = STATE_BUILD;
|
||||||
|
_hopCount = 0;
|
||||||
|
_menuSel = 0;
|
||||||
|
_editing = false;
|
||||||
|
_editPos = 0;
|
||||||
|
memset(_editBuf, 0, sizeof(_editBuf));
|
||||||
|
_repSel = 0;
|
||||||
|
_repScroll = 0;
|
||||||
|
_wantExit = false;
|
||||||
|
_resultScroll = 0;
|
||||||
|
memset(_pathBuf, 0, sizeof(_pathBuf));
|
||||||
|
memset(&_result, 0, sizeof(_result));
|
||||||
|
|
||||||
|
// Default to device path hash mode (clamped to 1 or 2 for trace)
|
||||||
|
_bytesPerHop = (pathHashMode >= 1) ? 2 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called by MyMesh::onTraceRecv() via UITask
|
||||||
|
void onTraceResult(uint32_t tag, uint8_t flags,
|
||||||
|
const uint8_t* path_snrs, const uint8_t* path_hashes,
|
||||||
|
uint8_t path_byte_len, int8_t final_snr) {
|
||||||
|
if (_state != STATE_RUNNING) return;
|
||||||
|
if (tag != _traceTag) return; // Not our trace
|
||||||
|
|
||||||
|
uint8_t pathSz = flags & 0x03;
|
||||||
|
int numHops = (pathSz > 0) ? (path_byte_len >> pathSz) : path_byte_len;
|
||||||
|
|
||||||
|
_result.valid = true;
|
||||||
|
_result.totalHops = numHops;
|
||||||
|
_result.final_snr = final_snr;
|
||||||
|
_result.duration_ms = millis() - _traceSentAt;
|
||||||
|
|
||||||
|
// Copy hash data
|
||||||
|
int copyBytes = path_byte_len;
|
||||||
|
if (copyBytes > (int)sizeof(_result.hashes)) copyBytes = sizeof(_result.hashes);
|
||||||
|
memcpy(_result.hashes, path_hashes, copyBytes);
|
||||||
|
|
||||||
|
// Count SNR entries (= number of hops that actually forwarded)
|
||||||
|
int snrCount = numHops;
|
||||||
|
if (snrCount > TRACE_MAX_HOPS) snrCount = TRACE_MAX_HOPS;
|
||||||
|
_result.hopCount = snrCount;
|
||||||
|
for (int i = 0; i < snrCount; i++) {
|
||||||
|
_result.snrs[i] = (int8_t)path_snrs[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
_state = STATE_RESULTS;
|
||||||
|
_resultScroll = 0;
|
||||||
|
Serial.printf("[Trace] Result received: %d hops, %dms\n", numHops, _result.duration_ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Render ---
|
||||||
|
int render(DisplayDriver& display) override {
|
||||||
|
// Header
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
display.print("Trace Path");
|
||||||
|
display.drawRect(0, 11, display.width(), 1);
|
||||||
|
|
||||||
|
if (_state == STATE_BUILD) {
|
||||||
|
return renderBuild(display);
|
||||||
|
} else if (_state == STATE_PICK_HOP) {
|
||||||
|
return renderPicker(display);
|
||||||
|
} else if (_state == STATE_RUNNING) {
|
||||||
|
return renderRunning(display);
|
||||||
|
} else {
|
||||||
|
return renderResults(display);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int renderBuild(DisplayDriver& display) {
|
||||||
|
char tmp[TRACE_EDIT_BUF + 16];
|
||||||
|
int y = 14;
|
||||||
|
int lineH = 11;
|
||||||
|
int menuCount = buildMenuCount();
|
||||||
|
int maxVisible = (display.height() - y - 14) / lineH;
|
||||||
|
if (maxVisible < 1) maxVisible = 1;
|
||||||
|
|
||||||
|
// Scroll window
|
||||||
|
int scrollTop = 0;
|
||||||
|
if (_menuSel >= scrollTop + maxVisible) scrollTop = _menuSel - maxVisible + 1;
|
||||||
|
if (_menuSel < scrollTop) scrollTop = _menuSel;
|
||||||
|
|
||||||
|
for (int vi = 0; vi < maxVisible && (scrollTop + vi) < menuCount; vi++) {
|
||||||
|
int idx = scrollTop + vi;
|
||||||
|
MenuItem item = menuItemAt(idx);
|
||||||
|
char prefix = (idx == _menuSel) ? '>' : ' ';
|
||||||
|
|
||||||
|
display.setCursor(0, y);
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
|
||||||
|
switch (item) {
|
||||||
|
case MENU_PATH_SIZE:
|
||||||
|
snprintf(tmp, sizeof(tmp), "%c Mode: %d-byte", prefix, _bytesPerHop);
|
||||||
|
display.print(tmp);
|
||||||
|
if (idx == _menuSel) {
|
||||||
|
const char* hint = "(A/D)";
|
||||||
|
display.setCursor(display.width() - display.getTextWidth(hint) - 4, y);
|
||||||
|
display.print(hint);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MENU_TYPE_PATH:
|
||||||
|
if (_editing) {
|
||||||
|
// Active text editor with cursor
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
snprintf(tmp, sizeof(tmp), " Path: %s_", _editBuf);
|
||||||
|
display.print(tmp);
|
||||||
|
} else if (_hopCount > 0) {
|
||||||
|
// Show current path as decimal values
|
||||||
|
char pathStr[TRACE_EDIT_BUF];
|
||||||
|
pathStr[0] = '\0';
|
||||||
|
int pos = 0;
|
||||||
|
for (int i = 0; i < _hopCount && pos < (int)sizeof(pathStr) - 8; i++) {
|
||||||
|
if (i > 0) pathStr[pos++] = ',';
|
||||||
|
if (_bytesPerHop == 1) {
|
||||||
|
pos += snprintf(&pathStr[pos], sizeof(pathStr) - pos, "%02X", _pathBuf[i]);
|
||||||
|
} else {
|
||||||
|
uint16_t val = ((uint16_t)_pathBuf[i * 2] << 8) | _pathBuf[i * 2 + 1];
|
||||||
|
pos += snprintf(&pathStr[pos], sizeof(pathStr) - pos, "%04X", val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
snprintf(tmp, sizeof(tmp), "%c Path: %s", prefix, pathStr);
|
||||||
|
display.print(tmp);
|
||||||
|
} else {
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
snprintf(tmp, sizeof(tmp), "%c Type Path: [Long press]", prefix);
|
||||||
|
#else
|
||||||
|
snprintf(tmp, sizeof(tmp), "%c Type Path: [Press Enter]", prefix);
|
||||||
|
#endif
|
||||||
|
display.print(tmp);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MENU_ADD_HOP:
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
snprintf(tmp, sizeof(tmp), "%c + Add repeater...", prefix);
|
||||||
|
display.print(tmp);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MENU_REMOVE_LAST:
|
||||||
|
snprintf(tmp, sizeof(tmp), "%c - Remove last", prefix);
|
||||||
|
display.print(tmp);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MENU_RUN_TRACE:
|
||||||
|
display.setColor(DisplayDriver::YELLOW);
|
||||||
|
snprintf(tmp, sizeof(tmp), "%c Run Trace", prefix);
|
||||||
|
display.print(tmp);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MENU_EXIT:
|
||||||
|
snprintf(tmp, sizeof(tmp), "%c Exit", prefix);
|
||||||
|
display.print(tmp);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Hop line
|
||||||
|
if (item >= MENU_HOP_BASE && item < MENU_HOP_BASE + TRACE_MAX_HOPS) {
|
||||||
|
int hopIdx = item - MENU_HOP_BASE;
|
||||||
|
int offset = hopIdx * _bytesPerHop;
|
||||||
|
char hopName[24];
|
||||||
|
uint16_t hashVal;
|
||||||
|
if (_bytesPerHop == 1) {
|
||||||
|
hashVal = _pathBuf[offset];
|
||||||
|
} else {
|
||||||
|
hashVal = ((uint16_t)_pathBuf[offset] << 8) | _pathBuf[offset + 1];
|
||||||
|
}
|
||||||
|
if (findNameForHash(&_pathBuf[offset], _bytesPerHop, hopName, sizeof(hopName))) {
|
||||||
|
truncateName(hopName);
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
snprintf(tmp, sizeof(tmp), "%c%d: %s (%X)", prefix, hopIdx + 1,
|
||||||
|
hopName, hashVal);
|
||||||
|
} else {
|
||||||
|
snprintf(tmp, sizeof(tmp), "%c%d: (%X)", prefix, hopIdx + 1, hashVal);
|
||||||
|
}
|
||||||
|
display.print(tmp);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
y += lineH;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Footer
|
||||||
|
int footerY = display.height() - 12;
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.drawRect(0, footerY - 2, display.width(), 1);
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.setCursor(0, footerY);
|
||||||
|
if (_editing) {
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.print("Boot:Cancel Tap:Apply");
|
||||||
|
#else
|
||||||
|
display.print("Q:Cancel Enter:Apply");
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.print("Boot:Exit Tap:Sel");
|
||||||
|
#else
|
||||||
|
display.print("Q:Exit W/S:Nav Ent:Sel");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
int renderPicker(DisplayDriver& display) {
|
||||||
|
char tmp[48];
|
||||||
|
int y = 14;
|
||||||
|
int lineH = 11;
|
||||||
|
int maxVisible = (display.height() - y - 14) / lineH;
|
||||||
|
if (maxVisible < 1) maxVisible = 1;
|
||||||
|
|
||||||
|
if (_repCount == 0) {
|
||||||
|
display.setCursor(0, y);
|
||||||
|
display.setColor(DisplayDriver::RED);
|
||||||
|
display.print("No repeaters in contacts");
|
||||||
|
y += lineH;
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.print("Press Q to go back");
|
||||||
|
} else {
|
||||||
|
// Clamp scroll
|
||||||
|
if (_repSel >= _repCount) _repSel = _repCount - 1;
|
||||||
|
if (_repSel < 0) _repSel = 0;
|
||||||
|
if (_repSel < _repScroll) _repScroll = _repSel;
|
||||||
|
if (_repSel >= _repScroll + maxVisible) _repScroll = _repSel - maxVisible + 1;
|
||||||
|
|
||||||
|
for (int vi = 0; vi < maxVisible && (_repScroll + vi) < _repCount; vi++) {
|
||||||
|
int idx = _repScroll + vi;
|
||||||
|
uint16_t contactIdx = _repIdx[idx];
|
||||||
|
ContactInfo c;
|
||||||
|
if (!the_mesh.getContactByIdx(contactIdx, c)) continue;
|
||||||
|
|
||||||
|
char prefix = (idx == _repSel) ? '>' : ' ';
|
||||||
|
display.setCursor(0, y);
|
||||||
|
|
||||||
|
// Show name + decimal hash value
|
||||||
|
char filteredName[24];
|
||||||
|
display.translateUTF8ToBlocks(filteredName, c.name, sizeof(filteredName));
|
||||||
|
truncateName(filteredName, 14); // Picker has more room
|
||||||
|
uint16_t hashVal;
|
||||||
|
if (_bytesPerHop == 1) {
|
||||||
|
hashVal = c.id.pub_key[0];
|
||||||
|
} else {
|
||||||
|
hashVal = ((uint16_t)c.id.pub_key[0] << 8) | c.id.pub_key[1];
|
||||||
|
}
|
||||||
|
snprintf(tmp, sizeof(tmp), "%c %s (%X)", prefix, filteredName, hashVal);
|
||||||
|
display.setColor((idx == _repSel) ? DisplayDriver::GREEN : DisplayDriver::LIGHT);
|
||||||
|
display.print(tmp);
|
||||||
|
y += lineH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Footer
|
||||||
|
int footerY = display.height() - 12;
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.drawRect(0, footerY - 2, display.width(), 1);
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.setCursor(0, footerY);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.print("Boot:Back Tap:Add");
|
||||||
|
#else
|
||||||
|
display.print("Q:Back W/S:Scroll Ent:Add");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
int renderRunning(DisplayDriver& display) {
|
||||||
|
int y = 14;
|
||||||
|
display.setColor(DisplayDriver::YELLOW);
|
||||||
|
display.setCursor(0, y);
|
||||||
|
display.print("Tracing...");
|
||||||
|
y += 14;
|
||||||
|
|
||||||
|
// Show path summary
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
char tmp[48];
|
||||||
|
snprintf(tmp, sizeof(tmp), "%d hops, %d-byte mode", _hopCount, _bytesPerHop);
|
||||||
|
display.setCursor(0, y);
|
||||||
|
display.print(tmp);
|
||||||
|
y += 14;
|
||||||
|
|
||||||
|
// Elapsed time
|
||||||
|
unsigned long elapsed = millis() - _traceSentAt;
|
||||||
|
snprintf(tmp, sizeof(tmp), "Elapsed: %lu ms", elapsed);
|
||||||
|
display.setCursor(0, y);
|
||||||
|
display.print(tmp);
|
||||||
|
y += 14;
|
||||||
|
|
||||||
|
// Timeout bar
|
||||||
|
int barW = display.width() - 20;
|
||||||
|
int barH = 4;
|
||||||
|
int barX = 10;
|
||||||
|
display.setColor(DisplayDriver::DARK);
|
||||||
|
display.drawRect(barX, y, barW, barH);
|
||||||
|
int fill = (int)((unsigned long)barW * elapsed / TRACE_TIMEOUT_MS);
|
||||||
|
if (fill > barW) fill = barW;
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
display.fillRect(barX, y, fill, barH);
|
||||||
|
|
||||||
|
// Check timeout
|
||||||
|
if (elapsed >= TRACE_TIMEOUT_MS) {
|
||||||
|
_state = STATE_RESULTS;
|
||||||
|
_result.valid = false;
|
||||||
|
_result.duration_ms = TRACE_TIMEOUT_MS;
|
||||||
|
Serial.println("[Trace] Timeout");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Footer
|
||||||
|
int footerY = display.height() - 12;
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.drawRect(0, footerY - 2, display.width(), 1);
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.setCursor(0, footerY);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.print("Boot:Cancel");
|
||||||
|
#else
|
||||||
|
display.print("Q:Cancel");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 500; // Fast refresh for elapsed timer
|
||||||
|
}
|
||||||
|
|
||||||
|
int renderResults(DisplayDriver& display) {
|
||||||
|
char tmp[48];
|
||||||
|
int y = 14;
|
||||||
|
int lineH = 12;
|
||||||
|
|
||||||
|
if (!_result.valid) {
|
||||||
|
display.setColor(DisplayDriver::RED);
|
||||||
|
display.setCursor(0, y);
|
||||||
|
display.print("Trace timed out");
|
||||||
|
y += lineH;
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
snprintf(tmp, sizeof(tmp), "No response after %ds", TRACE_TIMEOUT_MS / 1000);
|
||||||
|
display.setCursor(0, y);
|
||||||
|
display.print(tmp);
|
||||||
|
} else {
|
||||||
|
// Duration header
|
||||||
|
display.setColor(DisplayDriver::GREEN);
|
||||||
|
snprintf(tmp, sizeof(tmp), "Complete: %dms", (int)_result.duration_ms);
|
||||||
|
display.setCursor(0, y);
|
||||||
|
display.print(tmp);
|
||||||
|
y += lineH + 2;
|
||||||
|
|
||||||
|
int maxVisible = (display.height() - y - 14) / lineH;
|
||||||
|
if (maxVisible < 1) maxVisible = 1;
|
||||||
|
|
||||||
|
// Clamp scroll
|
||||||
|
int totalItems = _result.hopCount + 1; // hops + final SNR line
|
||||||
|
if (_resultScroll > totalItems - maxVisible) _resultScroll = totalItems - maxVisible;
|
||||||
|
if (_resultScroll < 0) _resultScroll = 0;
|
||||||
|
|
||||||
|
for (int vi = 0; vi < maxVisible && (_resultScroll + vi) < totalItems; vi++) {
|
||||||
|
int idx = _resultScroll + vi;
|
||||||
|
display.setCursor(0, y);
|
||||||
|
|
||||||
|
if (idx < _result.hopCount) {
|
||||||
|
// Hop entry
|
||||||
|
int offset = idx * _bytesPerHop;
|
||||||
|
char hopName[20];
|
||||||
|
bool resolved = findNameForHash(&_result.hashes[offset], _bytesPerHop,
|
||||||
|
hopName, sizeof(hopName));
|
||||||
|
if (resolved) truncateName(hopName);
|
||||||
|
|
||||||
|
float snr = _result.snrs[idx] / 4.0f;
|
||||||
|
|
||||||
|
display.setColor(resolved ? DisplayDriver::GREEN : DisplayDriver::LIGHT);
|
||||||
|
if (resolved) {
|
||||||
|
snprintf(tmp, sizeof(tmp), "%d: %s", idx + 1, hopName);
|
||||||
|
} else {
|
||||||
|
uint16_t hashVal;
|
||||||
|
if (_bytesPerHop == 1) {
|
||||||
|
hashVal = _result.hashes[offset];
|
||||||
|
} else {
|
||||||
|
hashVal = ((uint16_t)_result.hashes[offset] << 8) | _result.hashes[offset + 1];
|
||||||
|
}
|
||||||
|
snprintf(tmp, sizeof(tmp), "%d: (%X)", idx + 1, hashVal);
|
||||||
|
}
|
||||||
|
display.print(tmp);
|
||||||
|
|
||||||
|
// SNR value on right
|
||||||
|
snprintf(tmp, sizeof(tmp), "%.1fdB", snr);
|
||||||
|
int snrW = display.getTextWidth(tmp);
|
||||||
|
int barsW = 14;
|
||||||
|
display.setCursor(display.width() - snrW - barsW - 4, y);
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.print(tmp);
|
||||||
|
|
||||||
|
// Signal bars
|
||||||
|
drawSignalBars(display, display.width() - barsW - 1, y, _result.snrs[idx]);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Final SNR (response arriving back at this node)
|
||||||
|
float snr = _result.final_snr / 4.0f;
|
||||||
|
display.setColor(DisplayDriver::YELLOW);
|
||||||
|
snprintf(tmp, sizeof(tmp), "Return SNR: %.1fdB", snr);
|
||||||
|
display.print(tmp);
|
||||||
|
drawSignalBars(display, display.width() - 15, y, _result.final_snr);
|
||||||
|
}
|
||||||
|
y += lineH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Footer
|
||||||
|
int footerY = display.height() - 12;
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.drawRect(0, footerY - 2, display.width(), 1);
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.setCursor(0, footerY);
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
|
display.print("Boot:Back Tap:New Trace");
|
||||||
|
#else
|
||||||
|
display.print("Q:Back Ent:New Trace");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
// --- Input handling ---
|
||||||
|
bool handleInput(char c) override {
|
||||||
|
// Text editing mode consumes all keys
|
||||||
|
if (_editing) {
|
||||||
|
return handleEditInput(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (_state) {
|
||||||
|
case STATE_BUILD: return handleBuildInput(c);
|
||||||
|
case STATE_PICK_HOP: return handlePickerInput(c);
|
||||||
|
case STATE_RUNNING: return handleRunningInput(c);
|
||||||
|
case STATE_RESULTS: return handleResultsInput(c);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// --- Text editor for typed path ---
|
||||||
|
bool handleEditInput(char c) {
|
||||||
|
// Enter: apply typed path
|
||||||
|
if (c == '\r' || c == 13) {
|
||||||
|
int parsed = parseTypedPath();
|
||||||
|
if (parsed < 0) {
|
||||||
|
Serial.println("[Trace] Failed to parse typed path");
|
||||||
|
// Stay in edit mode -- user can fix
|
||||||
|
} else {
|
||||||
|
Serial.printf("[Trace] Parsed %d hops from typed path\n", parsed);
|
||||||
|
_editing = false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Q or Escape: cancel edit
|
||||||
|
if (c == 'q' || c == 'Q' || c == 27) {
|
||||||
|
_editing = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Backspace
|
||||||
|
if (c == '\b') {
|
||||||
|
if (_editPos > 0) {
|
||||||
|
_editPos--;
|
||||||
|
_editBuf[_editPos] = '\0';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Accept hex digits, commas, spaces
|
||||||
|
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')
|
||||||
|
|| c == ',' || c == ' ') {
|
||||||
|
if (_editPos < TRACE_EDIT_BUF - 1) {
|
||||||
|
_editBuf[_editPos++] = c;
|
||||||
|
_editBuf[_editPos] = '\0';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true; // Consume all keys in edit mode
|
||||||
|
}
|
||||||
|
|
||||||
|
bool handleBuildInput(char c) {
|
||||||
|
int menuCount = buildMenuCount();
|
||||||
|
|
||||||
|
// W - up
|
||||||
|
if (c == 'w' || c == 'W' || c == 0xF2) {
|
||||||
|
if (_menuSel > 0) _menuSel--;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// S - down
|
||||||
|
if (c == 's' || c == 'S' || c == 0xF1) {
|
||||||
|
if (_menuSel < menuCount - 1) _menuSel++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// A/D - toggle mode on path size row
|
||||||
|
if ((c == 'a' || c == 'A' || c == 'd' || c == 'D') && menuItemAt(_menuSel) == MENU_PATH_SIZE) {
|
||||||
|
_bytesPerHop = (_bytesPerHop == 1) ? 2 : 1;
|
||||||
|
// Changing mode clears path (byte layout is different)
|
||||||
|
_hopCount = 0;
|
||||||
|
memset(_pathBuf, 0, sizeof(_pathBuf));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Q - exit
|
||||||
|
if (c == 'q' || c == 'Q' || c == '\b') {
|
||||||
|
_wantExit = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Enter - select
|
||||||
|
if (c == '\r' || c == 13) {
|
||||||
|
MenuItem item = menuItemAt(_menuSel);
|
||||||
|
switch (item) {
|
||||||
|
case MENU_TYPE_PATH:
|
||||||
|
// Enter edit mode -- pre-fill with current path if any
|
||||||
|
pathToEditBuf();
|
||||||
|
_editing = true;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case MENU_ADD_HOP:
|
||||||
|
buildRepeaterList();
|
||||||
|
_repSel = 0;
|
||||||
|
_repScroll = 0;
|
||||||
|
_state = STATE_PICK_HOP;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case MENU_REMOVE_LAST:
|
||||||
|
if (_hopCount > 0) {
|
||||||
|
_hopCount--;
|
||||||
|
if (_menuSel >= buildMenuCount()) _menuSel = buildMenuCount() - 1;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case MENU_RUN_TRACE:
|
||||||
|
return sendTrace();
|
||||||
|
|
||||||
|
case MENU_EXIT:
|
||||||
|
_wantExit = true;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool handlePickerInput(char c) {
|
||||||
|
// W - up
|
||||||
|
if (c == 'w' || c == 'W' || c == 0xF2) {
|
||||||
|
if (_repSel > 0) _repSel--;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// S - down
|
||||||
|
if (c == 's' || c == 'S' || c == 0xF1) {
|
||||||
|
if (_repSel < _repCount - 1) _repSel++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Q - back to build
|
||||||
|
if (c == 'q' || c == 'Q' || c == '\b') {
|
||||||
|
_state = STATE_BUILD;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Enter - add selected repeater
|
||||||
|
if (c == '\r' || c == 13) {
|
||||||
|
if (_repCount > 0 && _repSel >= 0 && _repSel < _repCount) {
|
||||||
|
ContactInfo contact;
|
||||||
|
if (the_mesh.getContactByIdx(_repIdx[_repSel], contact)) {
|
||||||
|
int offset = _hopCount * _bytesPerHop;
|
||||||
|
memcpy(&_pathBuf[offset], contact.id.pub_key, _bytesPerHop);
|
||||||
|
_hopCount++;
|
||||||
|
uint16_t hashVal = ((uint16_t)contact.id.pub_key[0] << 8)
|
||||||
|
| contact.id.pub_key[1];
|
||||||
|
Serial.printf("[Trace] Added hop %d: %s (%X)\n",
|
||||||
|
_hopCount, contact.name, hashVal);
|
||||||
|
}
|
||||||
|
_state = STATE_BUILD;
|
||||||
|
_menuSel = _hopCount + 1; // Point to row after last hop
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool handleRunningInput(char c) {
|
||||||
|
// Q - cancel
|
||||||
|
if (c == 'q' || c == 'Q' || c == '\b') {
|
||||||
|
_state = STATE_BUILD;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true; // Consume all keys while running
|
||||||
|
}
|
||||||
|
|
||||||
|
bool handleResultsInput(char c) {
|
||||||
|
// W - scroll up
|
||||||
|
if (c == 'w' || c == 'W' || c == 0xF2) {
|
||||||
|
if (_resultScroll > 0) _resultScroll--;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// S - scroll down
|
||||||
|
if (c == 's' || c == 'S' || c == 0xF1) {
|
||||||
|
_resultScroll++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Q - back to build screen (keep path)
|
||||||
|
if (c == 'q' || c == 'Q' || c == '\b') {
|
||||||
|
_state = STATE_BUILD;
|
||||||
|
_menuSel = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Enter - new trace (re-run with same path)
|
||||||
|
if (c == '\r' || c == 13) {
|
||||||
|
return sendTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Send trace ---
|
||||||
|
bool sendTrace() {
|
||||||
|
if (_hopCount <= 0) return true;
|
||||||
|
|
||||||
|
// Generate random tag and auth code
|
||||||
|
the_mesh.getRNG()->random((uint8_t*)&_traceTag, 4);
|
||||||
|
the_mesh.getRNG()->random((uint8_t*)&_traceAuth, 4);
|
||||||
|
|
||||||
|
// flags: lower 2 bits = path_sz
|
||||||
|
// path_sz 0 = 1-byte hashes, path_sz 1 = 2-byte hashes
|
||||||
|
uint8_t pathSz = (_bytesPerHop == 2) ? 1 : 0;
|
||||||
|
uint8_t flags = pathSz;
|
||||||
|
|
||||||
|
mesh::Packet* pkt = the_mesh.createTrace(_traceTag, _traceAuth, flags);
|
||||||
|
if (!pkt) {
|
||||||
|
Serial.println("[Trace] Failed to create trace packet (pool empty)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Path bytes to send
|
||||||
|
uint8_t pathByteLen = _hopCount * _bytesPerHop;
|
||||||
|
|
||||||
|
// sendDirect for TRACE appends path to payload and sets path_len=0
|
||||||
|
the_mesh.sendDirect(pkt, _pathBuf, pathByteLen);
|
||||||
|
|
||||||
|
_traceSentAt = millis();
|
||||||
|
_state = STATE_RUNNING;
|
||||||
|
memset(&_result, 0, sizeof(_result));
|
||||||
|
|
||||||
|
Serial.printf("[Trace] Sent: tag=0x%08X, %d hops, %d-byte, %d path bytes\n",
|
||||||
|
_traceTag, _hopCount, _bytesPerHop, pathByteLen);
|
||||||
|
Serial.printf("[Trace] Path hex:");
|
||||||
|
for (int i = 0; i < pathByteLen; i++) {
|
||||||
|
Serial.printf(" %02X", _pathBuf[i]);
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,17 +1,21 @@
|
|||||||
#include "UITask.h"
|
#include "UITask.h"
|
||||||
#include <helpers/TxtDataHelpers.h>
|
#include <helpers/TxtDataHelpers.h>
|
||||||
#include "../MyMesh.h"
|
#include "../MyMesh.h"
|
||||||
#if !defined(LILYGO_TECHO_LITE)
|
#if !defined(LILYGO_TECHO_LITE) && !defined(LILYGO_TECHO_CARD)
|
||||||
#include "NotesScreen.h"
|
#include "NotesScreen.h"
|
||||||
#endif
|
#endif
|
||||||
#include "RepeaterAdminScreen.h"
|
#include "RepeaterAdminScreen.h"
|
||||||
#include "PathEditorScreen.h"
|
#include "PathEditorScreen.h"
|
||||||
#include "DiscoveryScreen.h"
|
#include "DiscoveryScreen.h"
|
||||||
#include "LastHeardScreen.h"
|
#include "LastHeardScreen.h"
|
||||||
|
#include "Tracescreen.h"
|
||||||
|
#include "GamesMenuScreen.h"
|
||||||
|
#include "SnakeScreen.h"
|
||||||
|
#include "MinesweeperScreen.h"
|
||||||
#ifdef MECK_WEB_READER
|
#ifdef MECK_WEB_READER
|
||||||
#include "WebReaderScreen.h"
|
#include "WebReaderScreen.h"
|
||||||
#endif
|
#endif
|
||||||
#if HAS_GPS
|
#if HAS_GPS && !defined(LILYGO_TECHO_CARD)
|
||||||
#include "MapScreen.h"
|
#include "MapScreen.h"
|
||||||
#endif
|
#endif
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
@@ -52,7 +56,7 @@
|
|||||||
#include "ChannelScreen.h"
|
#include "ChannelScreen.h"
|
||||||
#include "ChannelPickerScreen.h"
|
#include "ChannelPickerScreen.h"
|
||||||
#include "ContactsScreen.h"
|
#include "ContactsScreen.h"
|
||||||
#if !defined(LILYGO_TECHO_LITE)
|
#if !defined(LILYGO_TECHO_LITE) && !defined(LILYGO_TECHO_CARD)
|
||||||
#include "TextReaderScreen.h"
|
#include "TextReaderScreen.h"
|
||||||
#endif
|
#endif
|
||||||
#include "SettingsScreen.h"
|
#include "SettingsScreen.h"
|
||||||
@@ -64,6 +68,15 @@
|
|||||||
#include "SMSScreen.h"
|
#include "SMSScreen.h"
|
||||||
#include "ModemManager.h"
|
#include "ModemManager.h"
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(MECK_AUDIO_VARIANT) || defined(HAS_4G_MODEM)
|
||||||
|
#include "NotifSounds.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Per-channel notification suppression flag.
|
||||||
|
// Set by newMsg() based on channel_notif preference, checked by notify()
|
||||||
|
// to suppress buzzer/vibration. Safe because both are called sequentially
|
||||||
|
// from the same mesh callback on the same thread.
|
||||||
|
static bool s_lastMsgSuppressed = false;
|
||||||
|
|
||||||
class SplashScreen : public UIScreen {
|
class SplashScreen : public UIScreen {
|
||||||
UITask* _task;
|
UITask* _task;
|
||||||
@@ -498,7 +511,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
const int tileW = 40;
|
const int tileW = 40;
|
||||||
const int tileH = 28;
|
const int tileH = 22;
|
||||||
const int gapX = 1;
|
const int gapX = 1;
|
||||||
const int gapY = 1;
|
const int gapY = 1;
|
||||||
const int gridW = tileW * 3 + gapX * 2;
|
const int gridW = tileW * 3 + gapX * 2;
|
||||||
@@ -517,20 +530,44 @@ public:
|
|||||||
|
|
||||||
// Icon centered in tile
|
// Icon centered in tile
|
||||||
int iconX = tx + (tileW - HOME_ICON_W) / 2;
|
int iconX = tx + (tileW - HOME_ICON_W) / 2;
|
||||||
int iconY = ty + 4;
|
int iconY = ty + 2;
|
||||||
display.drawXbm(iconX, iconY, tiles[row][col].icon, HOME_ICON_W, HOME_ICON_H);
|
display.drawXbm(iconX, iconY, tiles[row][col].icon, HOME_ICON_W, HOME_ICON_H);
|
||||||
|
|
||||||
// Label centered below icon
|
// Label centered below icon
|
||||||
display.setTextSize(_node_prefs->smallTextSize());
|
display.setTextSize(_node_prefs->smallTextSize());
|
||||||
display.drawTextCentered(tx + tileW / 2, ty + 18, tiles[row][col].label);
|
display.drawTextCentered(tx + tileW / 2, ty + 15, tiles[row][col].label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nav hint below grid
|
// Third row: Trace (col 0) + Games (col 1)
|
||||||
y = gridY + 2 * tileH + gapY + 2;
|
{
|
||||||
|
int row3y = gridY + 2 * (tileH + gapY);
|
||||||
|
|
||||||
|
// Trace tile (column 0)
|
||||||
|
int col0x = gridX;
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(col0x, row3y, tileW, tileH);
|
||||||
|
int iconX = col0x + (tileW - HOME_ICON_W) / 2;
|
||||||
|
int iconY = row3y + 2;
|
||||||
|
display.drawXbm(iconX, iconY, icon_trace, HOME_ICON_W, HOME_ICON_H);
|
||||||
|
display.setTextSize(_node_prefs->smallTextSize());
|
||||||
|
display.drawTextCentered(col0x + tileW / 2, row3y + 15, "Trace");
|
||||||
|
|
||||||
|
// Games tile (column 1)
|
||||||
|
int col1x = gridX + (tileW + gapX);
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
display.drawRect(col1x, row3y, tileW, tileH);
|
||||||
|
iconX = col1x + (tileW - HOME_ICON_W) / 2;
|
||||||
|
iconY = row3y + 2;
|
||||||
|
display.drawXbm(iconX, iconY, icon_gamepad, HOME_ICON_W, HOME_ICON_H);
|
||||||
|
display.setTextSize(_node_prefs->smallTextSize());
|
||||||
|
display.drawTextCentered(col1x + tileW / 2, row3y + 15, "Games");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nav hint at bottom of screen
|
||||||
display.setColor(DisplayDriver::GREEN);
|
display.setColor(DisplayDriver::GREEN);
|
||||||
display.setTextSize(_node_prefs->smallTextSize());
|
display.setTextSize(_node_prefs->smallTextSize());
|
||||||
display.drawTextCentered(display.width() / 2, y, "Tap tile to open");
|
display.drawTextCentered(display.width() / 2, display.height() - 8, "Tap tile to open");
|
||||||
}
|
}
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
|
|
||||||
@@ -605,7 +642,13 @@ public:
|
|||||||
#else
|
#else
|
||||||
display.setCursor(col1, y); display.print("[F] Discover");
|
display.setCursor(col1, y); display.print("[F] Discover");
|
||||||
#endif
|
#endif
|
||||||
y += menuLH + 2;
|
y += menuLH;
|
||||||
|
display.setColor(DisplayDriver::YELLOW);
|
||||||
|
display.setCursor(col1, y); display.print("[R] Trace");
|
||||||
|
display.setCursor(col2, y); display.print("[J] Games");
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
y += menuLH;
|
||||||
|
y += 2;
|
||||||
} else {
|
} else {
|
||||||
// Monospaced built-in font (Classic): centered space-padded strings
|
// Monospaced built-in font (Classic): centered space-padded strings
|
||||||
y += 6;
|
y += 6;
|
||||||
@@ -638,6 +681,10 @@ public:
|
|||||||
#else
|
#else
|
||||||
display.drawTextCentered(display.width() / 2, y, "[F] Discover ");
|
display.drawTextCentered(display.width() / 2, y, "[F] Discover ");
|
||||||
#endif
|
#endif
|
||||||
|
y += 10;
|
||||||
|
display.setColor(DisplayDriver::YELLOW);
|
||||||
|
display.drawTextCentered(display.width() / 2, y, "[R] Trace [J] Games ");
|
||||||
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
y += 14;
|
y += 14;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1029,15 +1076,15 @@ public:
|
|||||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
display.drawXbm((display.width() - 32) / 2, 28, power_icon, 32, 32);
|
display.drawXbm((display.width() - 32) / 2, 28, power_icon, 32, 32);
|
||||||
#else
|
#else
|
||||||
display.drawXbm((display.width() - 32) / 2, 10, power_icon, 32, 32);
|
display.drawXbm((display.width() - 32) / 2, 20, power_icon, 32, 32);
|
||||||
#endif
|
#endif
|
||||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
display.drawTextCentered(display.width() / 2, 64, "power off device?");
|
display.drawTextCentered(display.width() / 2, 64, "power off device?");
|
||||||
display.drawTextCentered(display.width() / 2, 76, "usb-c to wake");
|
display.drawTextCentered(display.width() / 2, 76, "usb-c to wake");
|
||||||
#else
|
#else
|
||||||
display.drawTextCentered(display.width() / 2, 50, "power off device?");
|
display.drawTextCentered(display.width() / 2, 56, "power off device?");
|
||||||
display.drawTextCentered(display.width() / 2, 60, "usb-c to wake");
|
display.drawTextCentered(display.width() / 2, 66, "usb-c to wake");
|
||||||
display.drawTextCentered(display.width() / 2, 76, "Enter:yes q:no");
|
display.drawTextCentered(display.width() / 2, 82, "Enter:yes q:no");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
// Menu: hibernate / power off
|
// Menu: hibernate / power off
|
||||||
@@ -1045,8 +1092,8 @@ public:
|
|||||||
display.drawXbm((display.width() - 32) / 2, 20, power_icon, 32, 32);
|
display.drawXbm((display.width() - 32) / 2, 20, power_icon, 32, 32);
|
||||||
const int y1 = 58, y2 = 70;
|
const int y1 = 58, y2 = 70;
|
||||||
#else
|
#else
|
||||||
display.drawXbm((display.width() - 32) / 2, 10, power_icon, 32, 32);
|
display.drawXbm((display.width() - 32) / 2, 20, power_icon, 32, 32);
|
||||||
const int y1 = 50, y2 = 62;
|
const int y1 = 56, y2 = 68;
|
||||||
#endif
|
#endif
|
||||||
char line1[48], line2[48];
|
char line1[48], line2[48];
|
||||||
#if defined(LilyGo_TDeck_Pro)
|
#if defined(LilyGo_TDeck_Pro)
|
||||||
@@ -1115,7 +1162,9 @@ public:
|
|||||||
return true; // eat all other keys while confirming
|
return true; // eat all other keys while confirming
|
||||||
}
|
}
|
||||||
// Up/down toggles between hibernate and power off
|
// Up/down toggles between hibernate and power off
|
||||||
if (c == KEY_NEXT || c == 's' || c == KEY_PREV || c == 'w') {
|
// Only 'w'/'s' (keyboard) — KEY_NEXT/KEY_PREV fall through to page cycling
|
||||||
|
// so touch swipes and taps can still navigate away from this page.
|
||||||
|
if (c == 'w' || c == 's') {
|
||||||
_poweroff_selected = !_poweroff_selected;
|
_poweroff_selected = !_poweroff_selected;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1131,11 +1180,11 @@ public:
|
|||||||
// Left/right fall through to page cycling below
|
// Left/right fall through to page cycling below
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == KEY_LEFT || c == KEY_PREV) {
|
if (c == KEY_LEFT || c == KEY_PREV || c == 'a') {
|
||||||
_page = (_page + HomePage::Count - 1) % HomePage::Count;
|
_page = (_page + HomePage::Count - 1) % HomePage::Count;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (c == KEY_NEXT || c == KEY_RIGHT) {
|
if (c == KEY_NEXT || c == KEY_RIGHT || c == 'd') {
|
||||||
_page = (_page + 1) % HomePage::Count;
|
_page = (_page + 1) % HomePage::Count;
|
||||||
if (_page == HomePage::RECENT) {
|
if (_page == HomePage::RECENT) {
|
||||||
_task->showAlert("Recent adverts", 800);
|
_task->showAlert("Recent adverts", 800);
|
||||||
@@ -1340,7 +1389,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
|
|||||||
((ChannelPickerScreen*)channel_picker_screen)->setChannelScreen((ChannelScreen*)channel_screen);
|
((ChannelPickerScreen*)channel_picker_screen)->setChannelScreen((ChannelScreen*)channel_screen);
|
||||||
contacts_screen = new ContactsScreen(this, &rtc_clock);
|
contacts_screen = new ContactsScreen(this, &rtc_clock);
|
||||||
((ContactsScreen*)contacts_screen)->setDMUnreadPtr(_dmUnread);
|
((ContactsScreen*)contacts_screen)->setDMUnreadPtr(_dmUnread);
|
||||||
#if !defined(LILYGO_TECHO_LITE)
|
#if !defined(LILYGO_TECHO_LITE) && !defined(LILYGO_TECHO_CARD)
|
||||||
text_reader = new TextReaderScreen(this, node_prefs);
|
text_reader = new TextReaderScreen(this, node_prefs);
|
||||||
notes_screen = new NotesScreen(this, node_prefs);
|
notes_screen = new NotesScreen(this, node_prefs);
|
||||||
#else
|
#else
|
||||||
@@ -1352,6 +1401,10 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
|
|||||||
path_editor = nullptr; // Lazy-initialized on first use from contacts screen
|
path_editor = nullptr; // Lazy-initialized on first use from contacts screen
|
||||||
discovery_screen = new DiscoveryScreen(this, &rtc_clock);
|
discovery_screen = new DiscoveryScreen(this, &rtc_clock);
|
||||||
last_heard_screen = new LastHeardScreen(&rtc_clock);
|
last_heard_screen = new LastHeardScreen(&rtc_clock);
|
||||||
|
trace_screen = new TraceScreen(this, &rtc_clock);
|
||||||
|
games_menu_screen = new GamesMenuScreen(this);
|
||||||
|
snake_screen = new SnakeScreen(this, &rtc_clock);
|
||||||
|
minesweeper_screen = new MinesweeperScreen(this);
|
||||||
#if defined(LilyGo_T5S3_EPaper_Pro) || defined(LilyGo_TDeck_Pro)
|
#if defined(LilyGo_T5S3_EPaper_Pro) || defined(LilyGo_TDeck_Pro)
|
||||||
lock_screen = new LockScreen(this, &rtc_clock, node_prefs);
|
lock_screen = new LockScreen(this, &rtc_clock, node_prefs);
|
||||||
#endif
|
#endif
|
||||||
@@ -1363,7 +1416,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
|
|||||||
#ifdef HAS_4G_MODEM
|
#ifdef HAS_4G_MODEM
|
||||||
sms_screen = new SMSScreen(this, node_prefs);
|
sms_screen = new SMSScreen(this, node_prefs);
|
||||||
#endif
|
#endif
|
||||||
#if HAS_GPS
|
#if HAS_GPS && !defined(LILYGO_TECHO_CARD)
|
||||||
map_screen = new MapScreen(this);
|
map_screen = new MapScreen(this);
|
||||||
#else
|
#else
|
||||||
map_screen = nullptr;
|
map_screen = nullptr;
|
||||||
@@ -1377,6 +1430,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Apply saved dark mode preference (both T-Deck Pro and T5S3)
|
// Apply saved dark mode preference (both T-Deck Pro and T5S3)
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro) || defined(LilyGo_TDeck_Pro)
|
||||||
if (_node_prefs->dark_mode) {
|
if (_node_prefs->dark_mode) {
|
||||||
::display.setDarkMode(true);
|
::display.setDarkMode(true);
|
||||||
}
|
}
|
||||||
@@ -1385,6 +1439,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
|
|||||||
if (_node_prefs->ui_font_style > 0) {
|
if (_node_prefs->ui_font_style > 0) {
|
||||||
::display.setFontStyle(_node_prefs->ui_font_style);
|
::display.setFontStyle(_node_prefs->ui_font_style);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
setCurrScreen(splash);
|
setCurrScreen(splash);
|
||||||
}
|
}
|
||||||
@@ -1424,6 +1479,15 @@ void UITask::dismissBootHint() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UITask::notify(UIEventType t) {
|
void UITask::notify(UIEventType t) {
|
||||||
|
// Per-channel notification gating: if the last message was from a
|
||||||
|
// muted channel (or mentions-only without an @mention), suppress
|
||||||
|
// buzzer and vibration. Ack events are never suppressed.
|
||||||
|
if (s_lastMsgSuppressed && t != UIEventType::ack) {
|
||||||
|
s_lastMsgSuppressed = false; // Consume the flag
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
s_lastMsgSuppressed = false;
|
||||||
|
|
||||||
#if defined(PIN_BUZZER)
|
#if defined(PIN_BUZZER)
|
||||||
switch(t){
|
switch(t){
|
||||||
case UIEventType::contactMessage:
|
case UIEventType::contactMessage:
|
||||||
@@ -1491,6 +1555,77 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Per-channel notification preference check ---
|
||||||
|
// Determines whether to suppress toast, buzzer, keyboard flash, vibration,
|
||||||
|
// display wake, and unread counter for this message. Messages are ALWAYS
|
||||||
|
// stored in history regardless -- only alerts and unread badges are gated.
|
||||||
|
bool suppressNotif = false;
|
||||||
|
{
|
||||||
|
int notifSlot = (channel_idx == 0xFF) ? MAX_GROUP_CHANNELS : (int)channel_idx;
|
||||||
|
if (notifSlot >= 0 && notifSlot < (int)sizeof(_node_prefs->channel_notif)) {
|
||||||
|
uint8_t pref = _node_prefs->channel_notif[notifSlot];
|
||||||
|
if (pref == NOTIF_NONE) {
|
||||||
|
suppressNotif = true;
|
||||||
|
} else if (pref == NOTIF_MENTIONS) {
|
||||||
|
// Check for @nodename or @[nodename] in message text (case-insensitive).
|
||||||
|
// MeshCore companion app sends mentions as @[node name] with brackets.
|
||||||
|
suppressNotif = true; // Suppress unless mention found
|
||||||
|
if (_node_prefs->node_name[0] != '\0') {
|
||||||
|
char tagPlain[36];
|
||||||
|
char tagBracket[38];
|
||||||
|
snprintf(tagPlain, sizeof(tagPlain), "@%s", _node_prefs->node_name);
|
||||||
|
snprintf(tagBracket, sizeof(tagBracket), "@[%s]", _node_prefs->node_name);
|
||||||
|
int lenPlain = strlen(tagPlain);
|
||||||
|
int lenBracket = strlen(tagBracket);
|
||||||
|
const char* p = text;
|
||||||
|
while (*p) {
|
||||||
|
if (strncasecmp(p, tagBracket, lenBracket) == 0 ||
|
||||||
|
strncasecmp(p, tagPlain, lenPlain) == 0) {
|
||||||
|
suppressNotif = false; // Mentioned -- notify
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Set the flag for notify() which is called immediately after newMsg().
|
||||||
|
// If a custom notification tone is assigned and notifications are active,
|
||||||
|
// request MP3 playback and suppress the RTTTL buzzer so they don't overlap.
|
||||||
|
#ifdef MECK_AUDIO_VARIANT
|
||||||
|
if (!suppressNotif) {
|
||||||
|
const char* customSound = notifSounds.getSoundForChannel(channel_idx);
|
||||||
|
if (customSound && customSound[0] != '\0') {
|
||||||
|
char soundPath[48];
|
||||||
|
snprintf(soundPath, sizeof(soundPath), "/alarms/%s", customSound);
|
||||||
|
notifSounds.requestPlay(soundPath);
|
||||||
|
s_lastMsgSuppressed = true; // Suppress buzzer -- MP3 replaces it
|
||||||
|
} else {
|
||||||
|
s_lastMsgSuppressed = suppressNotif;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
s_lastMsgSuppressed = suppressNotif;
|
||||||
|
}
|
||||||
|
#elif defined(HAS_4G_MODEM)
|
||||||
|
if (!suppressNotif) {
|
||||||
|
const char* customSound = notifSounds.getSoundForChannel(channel_idx);
|
||||||
|
if (customSound && customSound[0] != '\0') {
|
||||||
|
int8_t toneIdx = ModemManager::findToneByName(customSound);
|
||||||
|
if (toneIdx >= 0) {
|
||||||
|
modemManager.requestNotifTone(toneIdx);
|
||||||
|
}
|
||||||
|
s_lastMsgSuppressed = true; // Suppress buzzer -- modem tone replaces it
|
||||||
|
} else {
|
||||||
|
s_lastMsgSuppressed = suppressNotif;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
s_lastMsgSuppressed = suppressNotif;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
s_lastMsgSuppressed = suppressNotif;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Add to channel history screen with channel index, path data, and SNR
|
// Add to channel history screen with channel index, path data, and SNR
|
||||||
// For DMs (channel_idx == 0xFF):
|
// For DMs (channel_idx == 0xFF):
|
||||||
// - Regular DMs: prefix text with sender name ("NodeName: hello")
|
// - Regular DMs: prefix text with sender name ("NodeName: hello")
|
||||||
@@ -1511,15 +1646,15 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
|
|||||||
if (isRoomMsg) {
|
if (isRoomMsg) {
|
||||||
// Room server: text already has "Poster: message" format — store as-is
|
// Room server: text already has "Poster: message" format — store as-is
|
||||||
// Tag with room server name for conversation filtering
|
// Tag with room server name for conversation filtering
|
||||||
((ChannelScreen *) channel_screen)->addMessage(channel_idx, path_len, from_name, text, path, snr, from_name);
|
((ChannelScreen *) channel_screen)->addMessage(channel_idx, path_len, from_name, text, path, snr, from_name, suppressNotif);
|
||||||
} else {
|
} else {
|
||||||
// Regular DM: prefix with sender name
|
// Regular DM: prefix with sender name
|
||||||
char dmFormatted[CHANNEL_MSG_TEXT_LEN];
|
char dmFormatted[CHANNEL_MSG_TEXT_LEN];
|
||||||
snprintf(dmFormatted, sizeof(dmFormatted), "%s: %s", from_name, text);
|
snprintf(dmFormatted, sizeof(dmFormatted), "%s: %s", from_name, text);
|
||||||
((ChannelScreen *) channel_screen)->addMessage(channel_idx, path_len, from_name, dmFormatted, path, snr);
|
((ChannelScreen *) channel_screen)->addMessage(channel_idx, path_len, from_name, dmFormatted, path, snr, nullptr, suppressNotif);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
((ChannelScreen *) channel_screen)->addMessage(channel_idx, path_len, from_name, text, path, snr);
|
((ChannelScreen *) channel_screen)->addMessage(channel_idx, path_len, from_name, text, path, snr, nullptr, suppressNotif);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If user is currently viewing this channel on the device, or companion
|
// If user is currently viewing this channel on the device, or companion
|
||||||
@@ -1546,7 +1681,7 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
|
|||||||
// Don't interrupt user with popup - just show brief notification
|
// Don't interrupt user with popup - just show brief notification
|
||||||
// Messages are stored in channel history, accessible via tile/key
|
// Messages are stored in channel history, accessible via tile/key
|
||||||
// Suppress toasts for room server messages (bulk sync would spam toasts)
|
// Suppress toasts for room server messages (bulk sync would spam toasts)
|
||||||
if (!isOnRepeaterAdmin() && !isRoomMsg) {
|
if (!isOnRepeaterAdmin() && !isRoomMsg && !suppressNotif) {
|
||||||
char alertBuf[40];
|
char alertBuf[40];
|
||||||
snprintf(alertBuf, sizeof(alertBuf), "New: %s", from_name);
|
snprintf(alertBuf, sizeof(alertBuf), "New: %s", from_name);
|
||||||
showAlert(alertBuf, 2000);
|
showAlert(alertBuf, 2000);
|
||||||
@@ -1556,7 +1691,7 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
|
|||||||
forceRefresh();
|
forceRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_display != NULL) {
|
if (_display != NULL && !suppressNotif) {
|
||||||
if (!_display->isOn() && !hasConnection()) {
|
if (!_display->isOn() && !hasConnection()) {
|
||||||
_display->turnOn();
|
_display->turnOn();
|
||||||
}
|
}
|
||||||
@@ -1572,9 +1707,9 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keyboard flash notification (suppress for room sync)
|
// Keyboard flash notification (suppress for room sync and muted channels)
|
||||||
#ifdef KB_BL_PIN
|
#ifdef KB_BL_PIN
|
||||||
if (_node_prefs->kb_flash_notify && !isRoomMsg) {
|
if (_node_prefs->kb_flash_notify && !isRoomMsg && !suppressNotif) {
|
||||||
digitalWrite(KB_BL_PIN, HIGH);
|
digitalWrite(KB_BL_PIN, HIGH);
|
||||||
_kb_flash_off_at = millis() + 200; // 200ms flash
|
_kb_flash_off_at = millis() + 200; // 200ms flash
|
||||||
}
|
}
|
||||||
@@ -1721,7 +1856,7 @@ void UITask::loop() {
|
|||||||
c = checkDisplayOn(KEY_NEXT);
|
c = checkDisplayOn(KEY_NEXT);
|
||||||
} else {
|
} else {
|
||||||
// Navigate back: reader reading→file list, file list→home, others→home
|
// Navigate back: reader reading→file list, file list→home, others→home
|
||||||
#if !defined(LILYGO_TECHO_LITE)
|
#if !defined(LILYGO_TECHO_LITE) && !defined(LILYGO_TECHO_CARD)
|
||||||
if (isOnTextReader()) {
|
if (isOnTextReader()) {
|
||||||
TextReaderScreen* reader = (TextReaderScreen*)text_reader;
|
TextReaderScreen* reader = (TextReaderScreen*)text_reader;
|
||||||
if (reader && reader->isReading()) {
|
if (reader && reader->isReading()) {
|
||||||
@@ -1888,23 +2023,27 @@ if (curr) curr->poll();
|
|||||||
_next_refresh = millis() + 500; // Re-check in 500ms
|
_next_refresh = millis() + 500; // Re-check in 500ms
|
||||||
} else {
|
} else {
|
||||||
// Sync dark mode with prefs (settings toggle takes effect here)
|
// Sync dark mode with prefs (settings toggle takes effect here)
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro) || defined(LilyGo_TDeck_Pro)
|
||||||
if (_node_prefs && display.isDarkMode() != (_node_prefs->dark_mode != 0)) {
|
if (_node_prefs && display.isDarkMode() != (_node_prefs->dark_mode != 0)) {
|
||||||
display.setDarkMode(_node_prefs->dark_mode != 0);
|
display.setDarkMode(_node_prefs->dark_mode != 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
// Sync portrait mode with prefs (T5S3 only)
|
// Sync portrait mode with prefs (T5S3 only)
|
||||||
if (_node_prefs && display.isPortraitMode() != (_node_prefs->portrait_mode != 0)) {
|
if (_node_prefs && display.isPortraitMode() != (_node_prefs->portrait_mode != 0)) {
|
||||||
display.setPortraitMode(_node_prefs->portrait_mode != 0);
|
display.setPortraitMode(_node_prefs->portrait_mode != 0);
|
||||||
// Text reader layout depends on orientation — force recalculation
|
// Text reader layout depends on orientation -- force recalculation
|
||||||
if (text_reader) {
|
if (text_reader) {
|
||||||
((TextReaderScreen*)text_reader)->invalidateLayout();
|
((TextReaderScreen*)text_reader)->invalidateLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// Sync font style with prefs (settings toggle takes effect here)
|
// Sync font style with prefs (settings toggle takes effect here)
|
||||||
|
#if defined(LilyGo_T5S3_EPaper_Pro) || defined(LilyGo_TDeck_Pro)
|
||||||
if (_node_prefs && display.getFontStyle() != _node_prefs->ui_font_style) {
|
if (_node_prefs && display.getFontStyle() != _node_prefs->ui_font_style) {
|
||||||
display.setFontStyle(_node_prefs->ui_font_style);
|
display.setFontStyle(_node_prefs->ui_font_style);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
_display->startFrame();
|
_display->startFrame();
|
||||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||||
if (_vkbActive) {
|
if (_vkbActive) {
|
||||||
@@ -2423,7 +2562,7 @@ void UITask::onVKBSubmit() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case VKB_NOTES: {
|
case VKB_NOTES: {
|
||||||
#if !defined(LILYGO_TECHO_LITE)
|
#if !defined(LILYGO_TECHO_LITE) && !defined(LILYGO_TECHO_CARD)
|
||||||
NotesScreen* notes = (NotesScreen*)getNotesScreen();
|
NotesScreen* notes = (NotesScreen*)getNotesScreen();
|
||||||
if (notes && strlen(text) > 0) {
|
if (notes && strlen(text) > 0) {
|
||||||
for (int i = 0; text[i]; i++) {
|
for (int i = 0; text[i]; i++) {
|
||||||
@@ -2492,7 +2631,7 @@ void UITask::onVKBSubmit() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
case VKB_TEXT_PAGE: {
|
case VKB_TEXT_PAGE: {
|
||||||
#if !defined(LILYGO_TECHO_LITE)
|
#if !defined(LILYGO_TECHO_LITE) && !defined(LILYGO_TECHO_CARD)
|
||||||
if (strlen(text) > 0) {
|
if (strlen(text) > 0) {
|
||||||
int pageNum = atoi(text);
|
int pageNum = atoi(text);
|
||||||
TextReaderScreen* reader = (TextReaderScreen*)getTextReaderScreen();
|
TextReaderScreen* reader = (TextReaderScreen*)getTextReaderScreen();
|
||||||
@@ -2504,6 +2643,14 @@ void UITask::onVKBSubmit() {
|
|||||||
if (_screenBeforeVKB) setCurrScreen(_screenBeforeVKB);
|
if (_screenBeforeVKB) setCurrScreen(_screenBeforeVKB);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case VKB_TRACE_PATH: {
|
||||||
|
TraceScreen* ts = (TraceScreen*)getTraceScreen();
|
||||||
|
if (ts) {
|
||||||
|
ts->setTypedPath(text);
|
||||||
|
}
|
||||||
|
if (_screenBeforeVKB) setCurrScreen(_screenBeforeVKB);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_screenBeforeVKB = nullptr;
|
_screenBeforeVKB = nullptr;
|
||||||
_next_refresh = 0;
|
_next_refresh = 0;
|
||||||
@@ -2733,7 +2880,7 @@ void UITask::gotoContactsScreen() {
|
|||||||
|
|
||||||
void UITask::gotoTextReader() {
|
void UITask::gotoTextReader() {
|
||||||
if (!text_reader) return; // Not available on this platform
|
if (!text_reader) return; // Not available on this platform
|
||||||
#if !defined(LILYGO_TECHO_LITE)
|
#if !defined(LILYGO_TECHO_LITE) && !defined(LILYGO_TECHO_CARD)
|
||||||
TextReaderScreen* reader = (TextReaderScreen*)text_reader;
|
TextReaderScreen* reader = (TextReaderScreen*)text_reader;
|
||||||
if (_display != NULL) {
|
if (_display != NULL) {
|
||||||
reader->enter(*_display);
|
reader->enter(*_display);
|
||||||
@@ -2749,7 +2896,7 @@ void UITask::gotoTextReader() {
|
|||||||
|
|
||||||
void UITask::gotoNotesScreen() {
|
void UITask::gotoNotesScreen() {
|
||||||
if (!notes_screen) return; // Not available on this platform
|
if (!notes_screen) return; // Not available on this platform
|
||||||
#if !defined(LILYGO_TECHO_LITE)
|
#if !defined(LILYGO_TECHO_LITE) && !defined(LILYGO_TECHO_CARD)
|
||||||
NotesScreen* notes = (NotesScreen*)notes_screen;
|
NotesScreen* notes = (NotesScreen*)notes_screen;
|
||||||
if (_display != NULL) {
|
if (_display != NULL) {
|
||||||
notes->enter(*_display);
|
notes->enter(*_display);
|
||||||
@@ -2982,6 +3129,59 @@ void UITask::gotoLastHeardScreen() {
|
|||||||
_next_refresh = 100;
|
_next_refresh = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UITask::gotoTraceScreen() {
|
||||||
|
TraceScreen* ts = (TraceScreen*)trace_screen;
|
||||||
|
ts->enter(the_mesh.getNodePrefs()->path_hash_mode);
|
||||||
|
setCurrScreen(trace_screen);
|
||||||
|
if (_display != NULL && !_display->isOn()) {
|
||||||
|
_display->turnOn();
|
||||||
|
}
|
||||||
|
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||||
|
_next_refresh = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UITask::gotoGamesMenu() {
|
||||||
|
GamesMenuScreen* gm = (GamesMenuScreen*)games_menu_screen;
|
||||||
|
gm->enter();
|
||||||
|
setCurrScreen(games_menu_screen);
|
||||||
|
if (_display != NULL && !_display->isOn()) {
|
||||||
|
_display->turnOn();
|
||||||
|
}
|
||||||
|
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||||
|
_next_refresh = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UITask::gotoSnakeScreen() {
|
||||||
|
SnakeScreen* ss = (SnakeScreen*)snake_screen;
|
||||||
|
ss->enter();
|
||||||
|
setCurrScreen(snake_screen);
|
||||||
|
if (_display != NULL && !_display->isOn()) {
|
||||||
|
_display->turnOn();
|
||||||
|
}
|
||||||
|
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||||
|
_next_refresh = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UITask::gotoMinesweeperScreen() {
|
||||||
|
MinesweeperScreen* ms = (MinesweeperScreen*)minesweeper_screen;
|
||||||
|
ms->enter();
|
||||||
|
setCurrScreen(minesweeper_screen);
|
||||||
|
if (_display != NULL && !_display->isOn()) {
|
||||||
|
_display->turnOn();
|
||||||
|
}
|
||||||
|
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||||
|
_next_refresh = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UITask::onTraceResult(uint32_t tag, uint8_t flags, const uint8_t* path_snrs,
|
||||||
|
const uint8_t* path_hashes, uint8_t path_len, int8_t final_snr) {
|
||||||
|
TraceScreen* ts = (TraceScreen*)trace_screen;
|
||||||
|
if (ts) {
|
||||||
|
ts->onTraceResult(tag, flags, path_snrs, path_hashes, path_len, final_snr);
|
||||||
|
_next_refresh = 100; // Force refresh to show results
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef MECK_WEB_READER
|
#ifdef MECK_WEB_READER
|
||||||
void UITask::gotoWebReader() {
|
void UITask::gotoWebReader() {
|
||||||
// Lazy-initialize on first use (same pattern as audiobook player)
|
// Lazy-initialize on first use (same pattern as audiobook player)
|
||||||
@@ -3009,6 +3209,8 @@ void UITask::gotoWebReader() {
|
|||||||
|
|
||||||
#if HAS_GPS
|
#if HAS_GPS
|
||||||
void UITask::gotoMapScreen() {
|
void UITask::gotoMapScreen() {
|
||||||
|
if (!map_screen) return; // Not available on this platform (T-Echo Card)
|
||||||
|
#if !defined(LILYGO_TECHO_CARD)
|
||||||
MapScreen* map = (MapScreen*)map_screen;
|
MapScreen* map = (MapScreen*)map_screen;
|
||||||
if (_display != NULL) {
|
if (_display != NULL) {
|
||||||
map->enter(*_display);
|
map->enter(*_display);
|
||||||
@@ -3019,6 +3221,7 @@ void UITask::gotoMapScreen() {
|
|||||||
}
|
}
|
||||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||||
_next_refresh = 100;
|
_next_refresh = 100;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class UITask : public AbstractUITask {
|
|||||||
unsigned long _alert_expiry;
|
unsigned long _alert_expiry;
|
||||||
bool _hintActive = false; // Boot navigation hint overlay
|
bool _hintActive = false; // Boot navigation hint overlay
|
||||||
unsigned long _hintExpiry = 0; // Auto-dismiss time for hint
|
unsigned long _hintExpiry = 0; // Auto-dismiss time for hint
|
||||||
bool _pendingBootHint = false; // Deferred hint — show after splash screen
|
bool _pendingBootHint = false; // Deferred hint -- show after splash screen
|
||||||
int _msgcount;
|
int _msgcount;
|
||||||
unsigned long ui_started_at, next_batt_chck;
|
unsigned long ui_started_at, next_batt_chck;
|
||||||
uint8_t _low_batt_count = 0; // Consecutive low-voltage readings for debounce
|
uint8_t _low_batt_count = 0; // Consecutive low-voltage readings for debounce
|
||||||
@@ -99,6 +99,10 @@ class UITask : public AbstractUITask {
|
|||||||
UIScreen* path_editor; // Custom path editor screen (lazy-init)
|
UIScreen* path_editor; // Custom path editor screen (lazy-init)
|
||||||
UIScreen* discovery_screen; // Node discovery scan screen
|
UIScreen* discovery_screen; // Node discovery scan screen
|
||||||
UIScreen* last_heard_screen; // Last heard passive advert list
|
UIScreen* last_heard_screen; // Last heard passive advert list
|
||||||
|
UIScreen* trace_screen; // Trace path screen (standalone trace tool)
|
||||||
|
UIScreen* games_menu_screen; // Games launcher menu
|
||||||
|
UIScreen* snake_screen; // Snake game screen
|
||||||
|
UIScreen* minesweeper_screen; // Minesweeper game screen
|
||||||
#ifdef MECK_WEB_READER
|
#ifdef MECK_WEB_READER
|
||||||
UIScreen* web_reader; // Web reader screen (lazy-init, WiFi required)
|
UIScreen* web_reader; // Web reader screen (lazy-init, WiFi required)
|
||||||
#endif
|
#endif
|
||||||
@@ -118,7 +122,7 @@ class UITask : public AbstractUITask {
|
|||||||
UIScreen* _screenBeforeVKB = nullptr;
|
UIScreen* _screenBeforeVKB = nullptr;
|
||||||
unsigned long _vkbOpenedAt = 0;
|
unsigned long _vkbOpenedAt = 0;
|
||||||
|
|
||||||
// Powersaving: light sleep when locked + idle (standalone only — no BLE/WiFi)
|
// Powersaving: light sleep when locked + idle (standalone only -- no BLE/WiFi)
|
||||||
// Wakes on LoRa packet (DIO1), boot button (GPIO0), or 30-min timer
|
// Wakes on LoRa packet (DIO1), boot button (GPIO0), or 30-min timer
|
||||||
#if !defined(BLE_PIN_CODE) && !defined(MECK_WIFI_COMPANION)
|
#if !defined(BLE_PIN_CODE) && !defined(MECK_WIFI_COMPANION)
|
||||||
unsigned long _psLastActive = 0; // millis() at last wake or lock entry
|
unsigned long _psLastActive = 0; // millis() at last wake or lock entry
|
||||||
@@ -200,6 +204,10 @@ public:
|
|||||||
void gotoPathEditor(int contactIdx); // Navigate to custom path editor
|
void gotoPathEditor(int contactIdx); // Navigate to custom path editor
|
||||||
void gotoDiscoveryScreen(); // Navigate to node discovery scan
|
void gotoDiscoveryScreen(); // Navigate to node discovery scan
|
||||||
void gotoLastHeardScreen(); // Navigate to last heard passive list
|
void gotoLastHeardScreen(); // Navigate to last heard passive list
|
||||||
|
void gotoTraceScreen(); // Navigate to trace path screen
|
||||||
|
void gotoGamesMenu(); // Navigate to games launcher menu
|
||||||
|
void gotoSnakeScreen(); // Navigate to snake game
|
||||||
|
void gotoMinesweeperScreen(); // Navigate to minesweeper game
|
||||||
#if HAS_GPS
|
#if HAS_GPS
|
||||||
void gotoMapScreen(); // Navigate to map tile screen
|
void gotoMapScreen(); // Navigate to map tile screen
|
||||||
#endif
|
#endif
|
||||||
@@ -232,7 +240,7 @@ public:
|
|||||||
int getDMUnreadCount(int contactIdx) const;
|
int getDMUnreadCount(int contactIdx) const;
|
||||||
void clearDMUnread(int contactIdx);
|
void clearDMUnread(int contactIdx);
|
||||||
|
|
||||||
// Flag: suppress room→conversation redirect on next login (L key admin access)
|
// Flag: suppress room->conversation redirect on next login (L key admin access)
|
||||||
bool _skipRoomRedirect = false;
|
bool _skipRoomRedirect = false;
|
||||||
bool hasDisplay() const { return _display != NULL; }
|
bool hasDisplay() const { return _display != NULL; }
|
||||||
bool isButtonPressed() const;
|
bool isButtonPressed() const;
|
||||||
@@ -256,6 +264,10 @@ public:
|
|||||||
bool isOnPathEditor() const { return curr == path_editor; }
|
bool isOnPathEditor() const { return curr == path_editor; }
|
||||||
bool isOnDiscoveryScreen() const { return curr == discovery_screen; }
|
bool isOnDiscoveryScreen() const { return curr == discovery_screen; }
|
||||||
bool isOnLastHeardScreen() const { return curr == last_heard_screen; }
|
bool isOnLastHeardScreen() const { return curr == last_heard_screen; }
|
||||||
|
bool isOnTraceScreen() const { return curr == trace_screen; }
|
||||||
|
bool isOnGamesMenu() const { return curr == games_menu_screen; }
|
||||||
|
bool isOnSnakeScreen() const { return curr == snake_screen; }
|
||||||
|
bool isOnMinesweeperScreen() const { return curr == minesweeper_screen; }
|
||||||
bool isOnMapScreen() const { return curr == map_screen; }
|
bool isOnMapScreen() const { return curr == map_screen; }
|
||||||
#if defined(LilyGo_T5S3_EPaper_Pro) || defined(LilyGo_TDeck_Pro)
|
#if defined(LilyGo_T5S3_EPaper_Pro) || defined(LilyGo_TDeck_Pro)
|
||||||
bool isLocked() const { return _locked; }
|
bool isLocked() const { return _locked; }
|
||||||
@@ -313,6 +325,10 @@ public:
|
|||||||
void onAdminCliResponse(const char* from_name, const char* text) override;
|
void onAdminCliResponse(const char* from_name, const char* text) override;
|
||||||
void onAdminTelemetryResult(const uint8_t* data, uint8_t len) override;
|
void onAdminTelemetryResult(const uint8_t* data, uint8_t len) override;
|
||||||
|
|
||||||
|
// Trace path callback (from MyMesh::onTraceRecv)
|
||||||
|
void onTraceResult(uint32_t tag, uint8_t flags, const uint8_t* path_snrs,
|
||||||
|
const uint8_t* path_hashes, uint8_t path_len, int8_t final_snr) override;
|
||||||
|
|
||||||
// Get current screen for checking state
|
// Get current screen for checking state
|
||||||
UIScreen* getCurrentScreen() const { return curr; }
|
UIScreen* getCurrentScreen() const { return curr; }
|
||||||
UIScreen* getMsgPreviewScreen() const { return msg_preview; }
|
UIScreen* getMsgPreviewScreen() const { return msg_preview; }
|
||||||
@@ -325,6 +341,7 @@ public:
|
|||||||
NodePrefs* getNodePrefs() const { return _node_prefs; }
|
NodePrefs* getNodePrefs() const { return _node_prefs; }
|
||||||
UIScreen* getAudiobookScreen() const { return audiobook_screen; }
|
UIScreen* getAudiobookScreen() const { return audiobook_screen; }
|
||||||
void setAudiobookScreen(UIScreen* s) { audiobook_screen = s; }
|
void setAudiobookScreen(UIScreen* s) { audiobook_screen = s; }
|
||||||
|
void setHomeScreen(UIScreen* s) { if (home) delete home; home = s; }
|
||||||
#ifdef MECK_AUDIO_VARIANT
|
#ifdef MECK_AUDIO_VARIANT
|
||||||
UIScreen* getAlarmScreen() const { return alarm_screen; }
|
UIScreen* getAlarmScreen() const { return alarm_screen; }
|
||||||
void setAlarmScreen(UIScreen* s) { alarm_screen = s; }
|
void setAlarmScreen(UIScreen* s) { alarm_screen = s; }
|
||||||
@@ -335,6 +352,10 @@ public:
|
|||||||
UIScreen* getPathEditorScreen() const { return path_editor; }
|
UIScreen* getPathEditorScreen() const { return path_editor; }
|
||||||
UIScreen* getDiscoveryScreen() const { return discovery_screen; }
|
UIScreen* getDiscoveryScreen() const { return discovery_screen; }
|
||||||
UIScreen* getLastHeardScreen() const { return last_heard_screen; }
|
UIScreen* getLastHeardScreen() const { return last_heard_screen; }
|
||||||
|
UIScreen* getTraceScreen() const { return trace_screen; }
|
||||||
|
UIScreen* getGamesMenuScreen() const { return games_menu_screen; }
|
||||||
|
UIScreen* getSnakeScreen() const { return snake_screen; }
|
||||||
|
UIScreen* getMinesweeperScreen() const { return minesweeper_screen; }
|
||||||
UIScreen* getMapScreen() const { return map_screen; }
|
UIScreen* getMapScreen() const { return map_screen; }
|
||||||
#ifdef MECK_WEB_READER
|
#ifdef MECK_WEB_READER
|
||||||
UIScreen* getWebReaderScreen() const { return web_reader; }
|
UIScreen* getWebReaderScreen() const { return web_reader; }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// HomeIcons — 12x12 icon sprites for T5S3 home screen tiles
|
// HomeIcons -- 12x12 icon sprites for T5S3 home screen tiles
|
||||||
// MSB-first, 2 bytes per row (same format as emoji sprites)
|
// MSB-first, 2 bytes per row (same format as emoji sprites)
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
@@ -48,13 +48,34 @@ static const uint8_t icon_search[] PROGMEM = {
|
|||||||
0x3C,0x00, 0x03,0x00, 0x01,0x80, 0x00,0xC0, 0x00,0x40, 0x00,0x00,
|
0x3C,0x00, 0x03,0x00, 0x01,0x80, 0x00,0xC0, 0x00,0x40, 0x00,0x00,
|
||||||
};
|
};
|
||||||
|
|
||||||
// ⏰ Alarm Clock (AlarmScreen) — 12x12 home tile icon
|
// ⏰ Alarm Clock (AlarmScreen) -- 12x12 home tile icon
|
||||||
static const uint8_t icon_alarm[] PROGMEM = {
|
static const uint8_t icon_alarm[] PROGMEM = {
|
||||||
0x40,0x40, 0x9E,0x20, 0x20,0x80, 0x44,0x40, 0x44,0x40, 0x46,0x40,
|
0x40,0x40, 0x9E,0x20, 0x20,0x80, 0x44,0x40, 0x44,0x40, 0x46,0x40,
|
||||||
0x40,0x40, 0x20,0x80, 0x1F,0x00, 0x00,0x00, 0x20,0x40, 0x40,0x20,
|
0x40,0x40, 0x20,0x80, 0x1F,0x00, 0x00,0x00, 0x20,0x40, 0x40,0x20,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 🔔 Bell — 7x8 status bar indicator (alarm enabled)
|
// ➡ Right arrow (Trace Route)
|
||||||
|
static const uint8_t icon_trace[] PROGMEM = {
|
||||||
|
0x00,0x00, 0x00,0x00, 0x00,0x80, 0x00,0xC0, 0x00,0xE0, 0xFF,0xF0,
|
||||||
|
0xFF,0xF0, 0x00,0xE0, 0x00,0xC0, 0x00,0x80, 0x00,0x00, 0x00,0x00,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 🎮 Gamepad (Games)
|
||||||
|
// ..########..
|
||||||
|
// .#........#.
|
||||||
|
// .#..#..##.#.
|
||||||
|
// .#.###....#.
|
||||||
|
// .#..#..##.#.
|
||||||
|
// .#........#.
|
||||||
|
// ..##....##..
|
||||||
|
// ...#....#...
|
||||||
|
// ...######...
|
||||||
|
static const uint8_t icon_gamepad[] PROGMEM = {
|
||||||
|
0x00,0x00, 0x3F,0xC0, 0x40,0x20, 0x49,0xA0, 0x5C,0x20, 0x49,0xA0,
|
||||||
|
0x40,0x20, 0x30,0xC0, 0x10,0x80, 0x1F,0x80, 0x00,0x00, 0x00,0x00,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 🔔 Bell -- 7x8 status bar indicator (alarm enabled)
|
||||||
// MSB-first, 1 byte per row
|
// MSB-first, 1 byte per row
|
||||||
#define BELL_ICON_W 7
|
#define BELL_ICON_W 7
|
||||||
#define BELL_ICON_H 8
|
#define BELL_ICON_H 8
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ enum VKBPurpose {
|
|||||||
VKB_WEB_LINK, // Web reader link number entry
|
VKB_WEB_LINK, // Web reader link number entry
|
||||||
#endif
|
#endif
|
||||||
VKB_TEXT_PAGE, // Text reader: go to page number
|
VKB_TEXT_PAGE, // Text reader: go to page number
|
||||||
|
VKB_TRACE_PATH, // Trace screen: type comma-separated path values
|
||||||
};
|
};
|
||||||
|
|
||||||
class VirtualKeyboard {
|
class VirtualKeyboard {
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "PDM_nrf52",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "PDM microphone library for nRF52840 (from Adafruit BSP)",
|
||||||
|
"license": "LGPL-2.1",
|
||||||
|
"frameworks": "arduino",
|
||||||
|
"platforms": "*"
|
||||||
|
}
|
||||||
@@ -0,0 +1,261 @@
|
|||||||
|
/*
|
||||||
|
PDM.cpp - library to interface with nRF52840 PDM peripheral
|
||||||
|
Part of Arduino - http://www.arduino.cc/
|
||||||
|
|
||||||
|
Copyright (c) 2019 Arduino SA
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General
|
||||||
|
Public License along with this library; if not, write to the
|
||||||
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||||
|
Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PDM.h"
|
||||||
|
#include <hal/nrf_pdm.h>
|
||||||
|
|
||||||
|
#include <Adafruit_TinyUSB.h> // for Serial
|
||||||
|
|
||||||
|
#define DEFAULT_PDM_GAIN 20
|
||||||
|
#define PDM_IRQ_PRIORITY 7
|
||||||
|
|
||||||
|
#define NRF_PDM_FREQ_1280K (nrf_pdm_freq_t)(0x0A000000UL) ///< PDM_CLK= 1.280 MHz (32 MHz / 25) => Fs= 20000 Hz
|
||||||
|
#define NRF_PDM_FREQ_2000K (nrf_pdm_freq_t)(0x10000000UL) ///< PDM_CLK= 2.000 MHz (32 MHz / 16) => Fs= 31250 Hz
|
||||||
|
#define NRF_PDM_FREQ_2667K (nrf_pdm_freq_t)(0x15000000UL) ///< PDM_CLK= 2.667 MHz (32 MHz / 12) => Fs= 41667 Hz
|
||||||
|
#define NRF_PDM_FREQ_3200K (nrf_pdm_freq_t)(0x19000000UL) ///< PDM_CLK= 3.200 MHz (32 MHz / 10) => Fs= 50000 Hz
|
||||||
|
#define NRF_PDM_FREQ_4000K (nrf_pdm_freq_t)(0x20000000UL) ///< PDM_CLK= 4.000 MHz (32 MHz / 8) => Fs= 62500 Hz
|
||||||
|
|
||||||
|
PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
|
||||||
|
_dinPin(dinPin),
|
||||||
|
_clkPin(clkPin),
|
||||||
|
_pwrPin(pwrPin),
|
||||||
|
_onReceive(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PDMClass::~PDMClass()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDMClass::setPins(int dataPin, int clkPin, int pwrPin)
|
||||||
|
{
|
||||||
|
_dinPin = dataPin;
|
||||||
|
_clkPin = clkPin;
|
||||||
|
_pwrPin = pwrPin;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PDMClass::begin(int channels, long sampleRate)
|
||||||
|
{
|
||||||
|
_channels = channels;
|
||||||
|
|
||||||
|
// Enable high frequency oscillator if not already enabled
|
||||||
|
uint8_t sd_en = 0;
|
||||||
|
sd_softdevice_is_enabled(&sd_en);
|
||||||
|
|
||||||
|
if (sd_en)
|
||||||
|
{
|
||||||
|
uint32_t is_running;
|
||||||
|
sd_clock_hfclk_is_running(&is_running);
|
||||||
|
|
||||||
|
if (!is_running) {
|
||||||
|
sd_clock_hfclk_request();
|
||||||
|
|
||||||
|
while(!is_running) {
|
||||||
|
yield();
|
||||||
|
sd_clock_hfclk_is_running(&is_running);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
|
||||||
|
NRF_CLOCK->TASKS_HFCLKSTART = 1;
|
||||||
|
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// configure the sample rate and channels
|
||||||
|
switch (sampleRate) {
|
||||||
|
case 16000:
|
||||||
|
#ifndef NRF52832_XXAA
|
||||||
|
NRF_PDM->RATIO = ((PDM_RATIO_RATIO_Ratio80 << PDM_RATIO_RATIO_Pos) & PDM_RATIO_RATIO_Msk);
|
||||||
|
#endif
|
||||||
|
nrf_pdm_clock_set(NRF_PDM, NRF_PDM_FREQ_1280K);
|
||||||
|
break;
|
||||||
|
case 41667:
|
||||||
|
nrf_pdm_clock_set(NRF_PDM, NRF_PDM_FREQ_2667K);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0; // unsupported
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (channels) {
|
||||||
|
case 2:
|
||||||
|
nrf_pdm_mode_set(NRF_PDM, NRF_PDM_MODE_STEREO, NRF_PDM_EDGE_LEFTFALLING);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
nrf_pdm_mode_set(NRF_PDM, NRF_PDM_MODE_MONO, NRF_PDM_EDGE_LEFTFALLING);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0; // unsupported
|
||||||
|
}
|
||||||
|
|
||||||
|
setGain(DEFAULT_PDM_GAIN);
|
||||||
|
|
||||||
|
// configure the I/O and mux
|
||||||
|
pinMode(_clkPin, OUTPUT);
|
||||||
|
digitalWrite(_clkPin, LOW);
|
||||||
|
|
||||||
|
pinMode(_dinPin, INPUT);
|
||||||
|
|
||||||
|
nrf_pdm_psel_connect(NRF_PDM, digitalPinToPinName(_clkPin), digitalPinToPinName(_dinPin));
|
||||||
|
|
||||||
|
// clear events and enable PDM interrupts
|
||||||
|
nrf_pdm_event_clear(NRF_PDM, NRF_PDM_EVENT_STARTED);
|
||||||
|
nrf_pdm_event_clear(NRF_PDM, NRF_PDM_EVENT_END);
|
||||||
|
nrf_pdm_event_clear(NRF_PDM, NRF_PDM_EVENT_STOPPED);
|
||||||
|
nrf_pdm_int_enable(NRF_PDM, NRF_PDM_INT_STARTED | NRF_PDM_INT_STOPPED);
|
||||||
|
|
||||||
|
if (_pwrPin > -1) {
|
||||||
|
// power the mic on
|
||||||
|
pinMode(_pwrPin, OUTPUT);
|
||||||
|
digitalWrite(_pwrPin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear the buffer
|
||||||
|
_doubleBuffer.reset();
|
||||||
|
|
||||||
|
// set the PDM IRQ priority and enable
|
||||||
|
NVIC_SetPriority(PDM_IRQn, PDM_IRQ_PRIORITY);
|
||||||
|
NVIC_ClearPendingIRQ(PDM_IRQn);
|
||||||
|
NVIC_EnableIRQ(PDM_IRQn);
|
||||||
|
|
||||||
|
// set the buffer for transfer
|
||||||
|
// nrf_pdm_buffer_set((uint32_t*)_doubleBuffer.data(), _doubleBuffer.availableForWrite() / (sizeof(int16_t) * _channels));
|
||||||
|
// _doubleBuffer.swap();
|
||||||
|
|
||||||
|
// enable and trigger start task
|
||||||
|
nrf_pdm_enable(NRF_PDM);
|
||||||
|
nrf_pdm_event_clear(NRF_PDM, NRF_PDM_EVENT_STARTED);
|
||||||
|
nrf_pdm_task_trigger(NRF_PDM, NRF_PDM_TASK_START);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDMClass::end()
|
||||||
|
{
|
||||||
|
// disable PDM and IRQ
|
||||||
|
nrf_pdm_disable(NRF_PDM);
|
||||||
|
|
||||||
|
NVIC_DisableIRQ(PDM_IRQn);
|
||||||
|
|
||||||
|
if (_pwrPin > -1) {
|
||||||
|
// power the mic off
|
||||||
|
digitalWrite(_pwrPin, LOW);
|
||||||
|
pinMode(_pwrPin, INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't disable high frequency oscillator since it could be in use by RADIO
|
||||||
|
|
||||||
|
// unconfigure the I/O and un-mux
|
||||||
|
nrf_pdm_psel_disconnect(NRF_PDM);
|
||||||
|
|
||||||
|
pinMode(_clkPin, INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
int PDMClass::available()
|
||||||
|
{
|
||||||
|
NVIC_DisableIRQ(PDM_IRQn);
|
||||||
|
|
||||||
|
size_t avail = _doubleBuffer.available();
|
||||||
|
|
||||||
|
NVIC_EnableIRQ(PDM_IRQn);
|
||||||
|
|
||||||
|
return avail;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PDMClass::read(void* buffer, size_t size)
|
||||||
|
{
|
||||||
|
NVIC_DisableIRQ(PDM_IRQn);
|
||||||
|
|
||||||
|
int read = _doubleBuffer.read(buffer, size);
|
||||||
|
|
||||||
|
NVIC_EnableIRQ(PDM_IRQn);
|
||||||
|
|
||||||
|
return read;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDMClass::onReceive(void(*function)(void))
|
||||||
|
{
|
||||||
|
_onReceive = function;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDMClass::setGain(int gain)
|
||||||
|
{
|
||||||
|
nrf_pdm_gain_set(NRF_PDM, gain, gain);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDMClass::setBufferSize(int bufferSize)
|
||||||
|
{
|
||||||
|
_doubleBuffer.setSize(bufferSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDMClass::IrqHandler()
|
||||||
|
{
|
||||||
|
if (nrf_pdm_event_check(NRF_PDM, NRF_PDM_EVENT_STARTED)) {
|
||||||
|
nrf_pdm_event_clear(NRF_PDM, NRF_PDM_EVENT_STARTED);
|
||||||
|
|
||||||
|
if (_doubleBuffer.available() == 0) {
|
||||||
|
// switch to the next buffer
|
||||||
|
nrf_pdm_buffer_set(NRF_PDM, (uint32_t*)_doubleBuffer.data(), _doubleBuffer.availableForWrite() / (sizeof(int16_t) * _channels));
|
||||||
|
|
||||||
|
// make the current one available for reading
|
||||||
|
_doubleBuffer.swap(_doubleBuffer.availableForWrite());
|
||||||
|
|
||||||
|
// call receive callback if provided
|
||||||
|
if (_onReceive) {
|
||||||
|
_onReceive();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// buffer overflow, stop
|
||||||
|
nrf_pdm_disable(NRF_PDM);
|
||||||
|
}
|
||||||
|
} else if (nrf_pdm_event_check(NRF_PDM, NRF_PDM_EVENT_STOPPED)) {
|
||||||
|
nrf_pdm_event_clear(NRF_PDM, NRF_PDM_EVENT_STOPPED);
|
||||||
|
} else if (nrf_pdm_event_check(NRF_PDM, NRF_PDM_EVENT_END)) {
|
||||||
|
nrf_pdm_event_clear(NRF_PDM, NRF_PDM_EVENT_END);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
void PDM_IRQHandler(void)
|
||||||
|
{
|
||||||
|
PDM.IrqHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef PIN_PDM_DIN
|
||||||
|
#define PIN_PDM_DIN -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PIN_PDM_CLK
|
||||||
|
#define PIN_PDM_CLK -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PIN_PDM_PWR
|
||||||
|
#define PIN_PDM_PWR -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
PDMClass PDM(PIN_PDM_DIN, PIN_PDM_CLK, PIN_PDM_PWR);
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PDM_H_INCLUDED
|
||||||
|
#define _PDM_H_INCLUDED
|
||||||
|
|
||||||
|
#if !defined(ARDUINO_NRF52_ADAFRUIT)
|
||||||
|
#error "This library targets only Adafruit NRF52840 boards"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Adafruit_TinyUSB.h> // for Serial
|
||||||
|
#include "utility/PDMDoubleBuffer.h"
|
||||||
|
|
||||||
|
class PDMClass
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PDMClass(int dataPin, int clkPin, int pwrPin);
|
||||||
|
virtual ~PDMClass();
|
||||||
|
|
||||||
|
void setPins(int dataPin, int clkPin, int pwrPin);
|
||||||
|
int begin(int channels, long sampleRate);
|
||||||
|
void end();
|
||||||
|
|
||||||
|
virtual int available();
|
||||||
|
virtual int read(void* buffer, size_t size);
|
||||||
|
|
||||||
|
void onReceive(void(*)(void));
|
||||||
|
|
||||||
|
void setGain(int gain);
|
||||||
|
void setBufferSize(int bufferSize);
|
||||||
|
|
||||||
|
// private:
|
||||||
|
void IrqHandler();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int _dinPin;
|
||||||
|
int _clkPin;
|
||||||
|
int _pwrPin;
|
||||||
|
|
||||||
|
int _channels;
|
||||||
|
|
||||||
|
PDMDoubleBuffer _doubleBuffer;
|
||||||
|
|
||||||
|
void (*_onReceive)(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
extern PDMClass PDM;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2016 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "PDMDoubleBuffer.h"
|
||||||
|
|
||||||
|
PDMDoubleBuffer::PDMDoubleBuffer() :
|
||||||
|
_size(DEFAULT_PDM_BUFFER_SIZE)
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
PDMDoubleBuffer::~PDMDoubleBuffer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDMDoubleBuffer::setSize(int size)
|
||||||
|
{
|
||||||
|
_size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDMDoubleBuffer::reset()
|
||||||
|
{
|
||||||
|
_buffer[0] = (uint8_t*)realloc(_buffer[0], _size);
|
||||||
|
_buffer[1] = (uint8_t*)realloc(_buffer[1], _size);
|
||||||
|
|
||||||
|
memset(_buffer[0], 0x00, _size);
|
||||||
|
memset(_buffer[1], 0x00, _size);
|
||||||
|
|
||||||
|
_index = 0;
|
||||||
|
_length[0] = 0;
|
||||||
|
_length[1] = 0;
|
||||||
|
_readOffset[0] = 0;
|
||||||
|
_readOffset[1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t PDMDoubleBuffer::availableForWrite()
|
||||||
|
{
|
||||||
|
return (_size - (_length[_index] - _readOffset[_index]));
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t PDMDoubleBuffer::write(const void *buffer, size_t size)
|
||||||
|
{
|
||||||
|
size_t space = availableForWrite();
|
||||||
|
|
||||||
|
if (size > space) {
|
||||||
|
size = space;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&_buffer[_index][_length[_index]], buffer, size);
|
||||||
|
|
||||||
|
_length[_index] += size;
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t PDMDoubleBuffer::read(void *buffer, size_t size)
|
||||||
|
{
|
||||||
|
size_t avail = available();
|
||||||
|
|
||||||
|
if (size > avail) {
|
||||||
|
size = avail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(buffer, &_buffer[_index][_readOffset[_index]], size);
|
||||||
|
_readOffset[_index] += size;
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t PDMDoubleBuffer::peek(void *buffer, size_t size)
|
||||||
|
{
|
||||||
|
size_t avail = available();
|
||||||
|
|
||||||
|
if (size > avail) {
|
||||||
|
size = avail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(buffer, &_buffer[_index][_readOffset[_index]], size);
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* PDMDoubleBuffer::data()
|
||||||
|
{
|
||||||
|
return (void*)_buffer[_index];
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t PDMDoubleBuffer::available()
|
||||||
|
{
|
||||||
|
return _length[_index] - _readOffset[_index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDMDoubleBuffer::swap(int length)
|
||||||
|
{
|
||||||
|
if (_index == 0) {
|
||||||
|
_index = 1;
|
||||||
|
} else {
|
||||||
|
_index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_length[_index] = length;
|
||||||
|
_readOffset[_index] = 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2016 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PDM_DOUBLE_BUFFER_H_INCLUDED
|
||||||
|
#define _PDM_DOUBLE_BUFFER_H_INCLUDED
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define DEFAULT_PDM_BUFFER_SIZE 512
|
||||||
|
|
||||||
|
class PDMDoubleBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PDMDoubleBuffer();
|
||||||
|
virtual ~PDMDoubleBuffer();
|
||||||
|
|
||||||
|
void setSize(int size);
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
size_t availableForWrite();
|
||||||
|
size_t write(const void *buffer, size_t size);
|
||||||
|
size_t read(void *buffer, size_t size);
|
||||||
|
size_t peek(void *buffer, size_t size);
|
||||||
|
void* data();
|
||||||
|
size_t available();
|
||||||
|
void swap(int length = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t* _buffer[2];
|
||||||
|
int _size;
|
||||||
|
volatile int _length[2];
|
||||||
|
volatile int _readOffset[2];
|
||||||
|
volatile int _index;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "codec2_nrf52",
|
||||||
|
"version": "0.7.0",
|
||||||
|
"description": "Codec2 low-bitrate speech codec - stripped for nRF52840 (1200bps mode)",
|
||||||
|
"license": "LGPL-2.1",
|
||||||
|
"frameworks": "arduino",
|
||||||
|
"platforms": "*",
|
||||||
|
"build": {
|
||||||
|
"flags": "-DCODEC2_MODE_EN_DEFAULT"
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
FILE....: ../src/HRA_112_112.h
|
||||||
|
|
||||||
|
Static arrays for CML LDPC, generated by ldpc_gen_h_file.m.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define HRA_112_112_NUMBERPARITYBITS 112
|
||||||
|
#define HRA_112_112_MAX_ROW_WEIGHT 3
|
||||||
|
#define HRA_112_112_CODELENGTH 224
|
||||||
|
#define HRA_112_112_NUMBERROWSHCOLS 112
|
||||||
|
#define HRA_112_112_MAX_COL_WEIGHT 3
|
||||||
|
#define HRA_112_112_DEC_TYPE 0
|
||||||
|
#define HRA_112_112_MAX_ITER 100
|
||||||
|
|
||||||
|
double HRA_112_112_H_rows[] = {
|
||||||
|
22, 18, 15, 63, 16, 13, 1, 2, 29, 25, 28, 4, 36, 10, 38, 7, 60, 23, 11, 38, 28, 1, 12, 31, 57, 45, 57, 30, 23, 59, 67, 14, 16, 4, 14, 62, 15, 50, 7, 70, 64, 6, 42, 48, 9, 31, 19, 40, 49, 2, 25, 3, 41, 49, 36, 9, 29, 39, 31, 5, 17, 1, 29, 25, 11, 21, 18, 2, 8, 22, 39, 15, 8, 22, 13, 3, 19, 4, 21, 62, 34, 43, 6, 24, 17, 60, 8, 74, 6, 44, 60, 10, 33, 12, 26, 24, 45, 81, 69, 80, 41, 28, 23, 5, 10, 20, 52, 18, 13, 86, 3, 7, 59, 21, 65, 72, 34, 37, 26, 55, 47, 48, 34, 5, 44, 47, 68, 96, 82, 111, 61, 74, 30, 17, 55, 98, 81, 66, 89, 35, 74, 82, 91, 51, 55, 51, 30, 89, 61, 75, 40, 71, 73, 11, 56, 54, 19, 47, 94, 69, 64, 20, 64, 12, 54, 77, 42, 88, 36, 52, 90, 63, 70, 27, 32, 73, 91, 32, 56, 46, 9, 78, 51, 68, 88, 67, 20, 43, 40, 14, 66, 86, 39, 97, 38, 27, 50, 84, 54, 92, 61, 46, 67, 24, 58, 35, 58, 37, 98, 85, 73, 84, 48, 35, 57, 16, 26, 37, 65, 32, 72, 95, 107, 33, 77, 33, 85, 105, 106, 75, 56, 71, 79, 59, 52, 105, 79, 90, 93, 100, 88, 112, 86, 80, 65, 42, 106, 100, 93, 94, 99, 97, 93, 101, 111, 99, 83, 53, 85, 95, 108, 107, 41, 109, 84, 78, 104, 101, 69, 110, 98, 103, 80, 83, 77, 71, 76, 78, 87, 102, 104, 95, 96, 83, 87, 50, 110, 103, 112, 45, 58, 70, 94, 91, 89, 81, 101, 82, 63, 72, 100, 97, 76, 112, 53, 105, 49, 75, 109, 102, 66, 111, 68, 87, 92, 79, 96, 43, 90, 44, 110, 99, 102, 92, 103, 106, 62, 53, 27, 46, 108, 104, 107, 108, 109, 76
|
||||||
|
};
|
||||||
|
|
||||||
|
double HRA_112_112_H_cols[] = {
|
||||||
|
7, 8, 52, 12, 12, 42, 16, 69, 45, 14, 19, 23, 6, 32, 3, 5, 22, 2, 45, 50, 2, 1, 18, 84, 10, 7, 62, 11, 9, 21, 24, 63, 2, 5, 28, 13, 6, 15, 58, 39, 39, 22, 76, 13, 26, 68, 9, 10, 49, 38, 32, 11, 34, 44, 8, 7, 25, 67, 1, 17, 19, 36, 4, 41, 3, 26, 31, 15, 45, 40, 8, 4, 41, 20, 6, 53, 1, 42, 9, 20, 25, 17, 33, 41, 3, 19, 55, 17, 27, 14, 31, 88, 15, 26, 36, 16, 28, 24, 27, 16, 30, 56, 48, 43, 4, 5, 38, 37, 40, 46, 18, 18, 22, 50, 76, 34, 60, 83, 39, 73, 56, 92, 42, 52, 75, 35, 37, 33, 61, 67, 47, 75, 66, 70, 29, 92, 51, 95, 84, 21, 57, 28, 46, 66, 93, 11, 94, 55, 96, 20, 71, 48, 53, 43, 82, 90, 66, 90, 14, 44, 54, 62, 34, 58, 81, 53, 23, 43, 27, 93, 10, 86, 37, 80, 60, 49, 21, 79, 74, 72, 48, 61, 40, 76, 64, 29, 38, 79, 51, 54, 13, 49, 72, 30, 50, 86, 35, 80, 61, 56, 36, 59, 65, 91, 25, 47, 58, 59, 78, 47, 32, 24, 44, 86, 64, 57, 12, 23, 109, 107, 85, 63, 31, 65, 62, 68, 111, 78, 104, 89, 112, 87, 69, 105, 65, 94, 109, 78, 72, 104, 85, 108, 77, 106, 79, 74, 103, 96, 64, 105, 105, 102, 63, 35, 59, 108, 112, 81, 102, 57, 106, 83, 81, 77, 101, 55, 94, 96, 97, 106, 46, 101, 83, 85, 71, 107, 104, 87, 33, 67, 103, 95, 30, 91, 89, 103, 75, 51, 107, 87, 91, 89, 99, 68, 52, 109, 99, 88, 84, 112, 54, 70, 92, 100, 98, 74, 60, 100, 98, 110, 90, 73, 71, 95, 70, 100, 29, 69, 110, 93, 82, 97, 98, 77, 73, 99, 101, 108, 82, 102, 111, 110, 111, 97, 88, 80
|
||||||
|
};
|
||||||
|
|
||||||
|
double HRA_112_112_input[] = {
|
||||||
|
-5.7868467875518395, -6.340739523388657, 3.6654768375589399, 4.1452438183910827, -4.6746135252043111, -4.8353634065473701, -6.0729133999971285, 4.0335561282226271, -6.1114855315699135, 4.1029513876344916, -4.6481634503883624, 5.7650915278538646, 6.5567610490570312, 5.1810523550761207, 3.4789051916752669, 4.2678848515507122, 4.0314705275547089, 6.0297078342283799, 4.9101169653222163, -6.4577297598332324, -7.4273487270443095, 3.472130985267488, -6.5346233967202254, 7.5312028458762414, -5.2618748211985915, 6.4198074556254969, 3.7500207659511484, 5.4040878141701141, 5.7554260586578803, 3.3973620625026886, 7.1815269888532907, 5.0031747952824963, 5.1377243276145599, 5.385229914081755, -0.61384230253605643, 0.46954911161835722, 3.5182611493679663, 3.393698829567279, 6.147483866535171, 3.8374563885989228, 1.3663773773557015, -4.0917661778352352, -3.2968298202652835, -6.0371912041431148, -8.4279246895331781, -0.98556788606912304, -3.515442879601625, 4.2642476942514875, -5.5905016743156972, 3.6920101668161727, -4.035860013856472, 5.3290190966269995, -2.9729656070594057, -2.5054371041338537, 6.8683150013190115, -7.1109038108500098, 6.7301890172695158, 2.5782062882356374, 4.4161464916633282, 2.2692851122935322, -1.3682527221025034, 3.0794629981237631, -7.8655412763279973, 1.1479897597156494, 0.22370696314520414, 1.1222453403894148, -3.1335220808128219, -3.8352985265277089, -1.2463521619727009, 2.9511814015293218, -8.668811041413111, 3.0185610517830548, -6.9592962351476091, 3.9653416636625414, -3.9384322074229408, 1.6789027505247516, 2.9579632055145502, -2.1212672699995125, -3.8892168640945193, 7.516114544807583, -0.84285604179011253, 4.1295390817792512, 0.26093278495228162, -3.6071666499996047, -0.065323173773821908, -1.9146584862100915, 4.7951161310834367, 5.5440002982088803, 3.5917539980319364, -0.81416023563684481, -2.6588977758747721, -3.0404494660606227, 4.5389936536649662, 2.7870543501114082, 3.5622966707453889, 5.1982116994791161, 2.4775319712999302, 0.70541080068007755, 0.89622787904518464, 4.3789020039207758, -2.4976040580619445, -0.7201255450933205, 4.2071986295109394, -5.2418379271657001, -4.092365654835163, -4.3510198326542557, 3.7404138637596001, 1.2496890930262492, -7.1053909336149728, -4.8888279905256748, -6.3523901926735249, -1.8757980409249277, 3.6256343910366273, -3.6165398844758228, -0.38322352317510561, -0.84747550047769449, -1.2717892264620718, -2.3899810721111154, 4.1368500898628637, 3.0440159002314924, 3.4235543074310728, -2.146097053557551, -1.7537615307751735, -1.0280987119225686, 4.9009275359419204, 5.0046047156368116, -0.47700833783807428, -4.5989492891875567, 1.4154839158712684, 0.33410724822249849, -4.771937854508927, -1.1817007924012972, -2.5960865023249302, 0.30422629502493687, -2.2097849377516763, -4.343244940878872, 1.9464288912612249, -9.0976989032526809, -8.6454142547592685, -1.8164317522989997, 2.2780845702169961, -4.8775405042023356, -0.61834757216625769, -1.985554501661331, -0.87599558657596699, -8.0610201531782124, -5.9847574894882554, -10.365536404711067, 2.9782191161319376, -6.9443820217795169, 0.72935566343949876, -4.5326632961380664, 1.1307250622386897, -4.0853969692041314, 5.4926924507347596, 5.6722555096362042, -2.5069992226180222, 2.0460084066662092, 2.5375899018238197, -3.5264293517823679, 3.2103083878487557, 5.793713046583183, -2.7633653287377995, 6.482851815629938, -1.2471646528152021, 3.0010491047486085, 0.29072399293868856, -4.0686659405747738, -2.6253508133431289, -6.3896590677017171, 5.7054076607727886, 4.3053292399977092, 2.2372599539047151, -4.8975607398431897, 5.8124794005531406, -0.69648233429781359, 5.5509723605410004, 2.0900652762982923, -4.7944253330785118, -2.9224693872108287, 6.0218579796888303, 4.7027436964063387, -4.1564871824868659, -1.324779121305123, 0.38031612697724176, -0.69335927945709175, -0.4028295686263082, 2.0967669774299189, 2.7947186736855909, 2.1473880039026203, 6.368702510367898, -3.0691782325684049, 1.6125827087903837, 3.5925359669662518, 5.178224480471127, -2.5070763799556617, 4.4280512389456632, -6.5385259627250134, 2.8047951999607603, -3.0185715385981151, -0.33348983718789993, -4.3285127692183556, -7.9609407359365134, 7.064973172264966, 0.95714371675898213, -5.5481272272415545, -1.6024149180708045, -4.5740915350065992, -1.5117120929647263, 1.9996824689403947, 5.9527526663437724, 5.0239857792804967, 6.2677418491798784, -1.9758548902654505, 2.1709284879472324, 2.5054563138111572, 4.4483685492445115, 3.2098357106645676, -4.5306213859481099, 1.1291114493451548, 1.5827945023160555, -5.2733490015732292, 5.0664709821503457, 1.9652801880230106
|
||||||
|
};
|
||||||
|
|
||||||
|
char HRA_112_112_detected_data[] = {
|
||||||
|
1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0
|
||||||
|
};
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2003-2010, Mark Borgerding
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
* Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* kiss_fft.h
|
||||||
|
defines kiss_fft_scalar as either short or a float type
|
||||||
|
and defines
|
||||||
|
typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
|
||||||
|
#include "kiss_fft.h"
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#define MAXFACTORS 32
|
||||||
|
/* e.g. an fft of length 128 has 4 factors
|
||||||
|
as far as kissfft is concerned
|
||||||
|
4*4*4*2
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct kiss_fft_state{
|
||||||
|
int nfft;
|
||||||
|
int inverse;
|
||||||
|
int factors[2*MAXFACTORS];
|
||||||
|
kiss_fft_cpx twiddles[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Explanation of macros dealing with complex math:
|
||||||
|
|
||||||
|
C_MUL(m,a,b) : m = a*b
|
||||||
|
C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise
|
||||||
|
C_SUB( res, a,b) : res = a - b
|
||||||
|
C_SUBFROM( res , a) : res -= a
|
||||||
|
C_ADDTO( res , a) : res += a
|
||||||
|
* */
|
||||||
|
#ifdef FIXED_POINT
|
||||||
|
#if (FIXED_POINT==32)
|
||||||
|
# define FRACBITS 31
|
||||||
|
# define SAMPPROD int64_t
|
||||||
|
#define SAMP_MAX 2147483647
|
||||||
|
#else
|
||||||
|
# define FRACBITS 15
|
||||||
|
# define SAMPPROD int32_t
|
||||||
|
#define SAMP_MAX 32767
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SAMP_MIN -SAMP_MAX
|
||||||
|
|
||||||
|
#if defined(CHECK_OVERFLOW)
|
||||||
|
# define CHECK_OVERFLOW_OP(a,op,b) \
|
||||||
|
if ( (SAMPPROD)(a) op (SAMPPROD)(b) > SAMP_MAX || (SAMPPROD)(a) op (SAMPPROD)(b) < SAMP_MIN ) { \
|
||||||
|
fprintf(stderr,"WARNING:overflow @ " __FILE__ "(%d): (%d " #op" %d) = %ld\n",__LINE__,(a),(b),(SAMPPROD)(a) op (SAMPPROD)(b) ); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
# define smul(a,b) ( (SAMPPROD)(a)*(b) )
|
||||||
|
# define sround( x ) (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
|
||||||
|
|
||||||
|
# define S_MUL(a,b) sround( smul(a,b) )
|
||||||
|
|
||||||
|
# define C_MUL(m,a,b) \
|
||||||
|
do{ (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \
|
||||||
|
(m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0)
|
||||||
|
|
||||||
|
# define DIVSCALAR(x,k) \
|
||||||
|
(x) = sround( smul( x, SAMP_MAX/k ) )
|
||||||
|
|
||||||
|
# define C_FIXDIV(c,div) \
|
||||||
|
do { DIVSCALAR( (c).r , div); \
|
||||||
|
DIVSCALAR( (c).i , div); }while (0)
|
||||||
|
|
||||||
|
# define C_MULBYSCALAR( c, s ) \
|
||||||
|
do{ (c).r = sround( smul( (c).r , s ) ) ;\
|
||||||
|
(c).i = sround( smul( (c).i , s ) ) ; }while(0)
|
||||||
|
|
||||||
|
#else /* not FIXED_POINT*/
|
||||||
|
|
||||||
|
# define S_MUL(a,b) ( (a)*(b) )
|
||||||
|
#define C_MUL(m,a,b) \
|
||||||
|
do{ (m).r = (a).r*(b).r - (a).i*(b).i;\
|
||||||
|
(m).i = (a).r*(b).i + (a).i*(b).r; }while(0)
|
||||||
|
# define C_FIXDIV(c,div) /* NOOP */
|
||||||
|
# define C_MULBYSCALAR( c, s ) \
|
||||||
|
do{ (c).r *= (s);\
|
||||||
|
(c).i *= (s); }while(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CHECK_OVERFLOW_OP
|
||||||
|
# define CHECK_OVERFLOW_OP(a,op,b) /* noop */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define C_ADD( res, a,b)\
|
||||||
|
do { \
|
||||||
|
CHECK_OVERFLOW_OP((a).r,+,(b).r)\
|
||||||
|
CHECK_OVERFLOW_OP((a).i,+,(b).i)\
|
||||||
|
(res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \
|
||||||
|
}while(0)
|
||||||
|
#define C_SUB( res, a,b)\
|
||||||
|
do { \
|
||||||
|
CHECK_OVERFLOW_OP((a).r,-,(b).r)\
|
||||||
|
CHECK_OVERFLOW_OP((a).i,-,(b).i)\
|
||||||
|
(res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \
|
||||||
|
}while(0)
|
||||||
|
#define C_ADDTO( res , a)\
|
||||||
|
do { \
|
||||||
|
CHECK_OVERFLOW_OP((res).r,+,(a).r)\
|
||||||
|
CHECK_OVERFLOW_OP((res).i,+,(a).i)\
|
||||||
|
(res).r += (a).r; (res).i += (a).i;\
|
||||||
|
}while(0)
|
||||||
|
|
||||||
|
#define C_SUBFROM( res , a)\
|
||||||
|
do {\
|
||||||
|
CHECK_OVERFLOW_OP((res).r,-,(a).r)\
|
||||||
|
CHECK_OVERFLOW_OP((res).i,-,(a).i)\
|
||||||
|
(res).r -= (a).r; (res).i -= (a).i; \
|
||||||
|
}while(0)
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef FIXED_POINT
|
||||||
|
# define KISS_FFT_COS(phase) floorf(.5+SAMP_MAX * cosf (phase))
|
||||||
|
# define KISS_FFT_SIN(phase) floorf(.5+SAMP_MAX * sinf (phase))
|
||||||
|
# define HALF_OF(x) ((x)>>1)
|
||||||
|
#elif defined(USE_SIMD)
|
||||||
|
# define KISS_FFT_COS(phase) _mm_set1_ps( cosf(phase) )
|
||||||
|
# define KISS_FFT_SIN(phase) _mm_set1_ps( sinf(phase) )
|
||||||
|
# define HALF_OF(x) ((x)*_mm_set1_ps(.5))
|
||||||
|
#else
|
||||||
|
# define KISS_FFT_COS(phase) (kiss_fft_scalar) cosf(phase)
|
||||||
|
# define KISS_FFT_SIN(phase) (kiss_fft_scalar) sinf(phase)
|
||||||
|
# define HALF_OF(x) ((x)*.5)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define kf_cexp(x,phase) \
|
||||||
|
do{ \
|
||||||
|
(x)->r = KISS_FFT_COS(phase);\
|
||||||
|
(x)->i = KISS_FFT_SIN(phase);\
|
||||||
|
}while(0)
|
||||||
|
|
||||||
|
|
||||||
|
/* a debugging function */
|
||||||
|
#define pcpx(c)\
|
||||||
|
fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) )
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef KISS_FFT_USE_ALLOCA
|
||||||
|
// define this to allow use of alloca instead of malloc for temporary buffers
|
||||||
|
// Temporary buffers are used in two case:
|
||||||
|
// 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5
|
||||||
|
// 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform.
|
||||||
|
#include <alloca.h>
|
||||||
|
#define KISS_FFT_TMP_ALLOC(nbytes) alloca(nbytes)
|
||||||
|
#define KISS_FFT_TMP_FREE(ptr)
|
||||||
|
#else
|
||||||
|
#define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes)
|
||||||
|
#define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr)
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: ampexp.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: & August 2012
|
||||||
|
|
||||||
|
Functions for experimenting with amplitude quantisation.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not,see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __AMPEX__
|
||||||
|
#define __AMPEXP__
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
struct AEXP;
|
||||||
|
|
||||||
|
struct AEXP *amp_experiment_create();
|
||||||
|
void amp_experiment_destroy(struct AEXP *aexp);
|
||||||
|
void amp_experiment(struct AEXP *aexp, MODEL *model, char *arg);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
#define BPF_N 101
|
||||||
|
|
||||||
|
float bpf[]={
|
||||||
|
0.002174,
|
||||||
|
0.003245,
|
||||||
|
0.002147,
|
||||||
|
0.001866,
|
||||||
|
0.002764,
|
||||||
|
0.000567,
|
||||||
|
-0.001641,
|
||||||
|
-0.000565,
|
||||||
|
-0.002415,
|
||||||
|
-0.005837,
|
||||||
|
-0.003620,
|
||||||
|
-0.002828,
|
||||||
|
-0.006268,
|
||||||
|
-0.002787,
|
||||||
|
0.001963,
|
||||||
|
-0.001234,
|
||||||
|
0.001446,
|
||||||
|
0.009200,
|
||||||
|
0.005331,
|
||||||
|
0.003521,
|
||||||
|
0.011821,
|
||||||
|
0.006951,
|
||||||
|
-0.002015,
|
||||||
|
0.005137,
|
||||||
|
0.001828,
|
||||||
|
-0.013390,
|
||||||
|
-0.007058,
|
||||||
|
-0.003273,
|
||||||
|
-0.020458,
|
||||||
|
-0.014321,
|
||||||
|
0.001751,
|
||||||
|
-0.012891,
|
||||||
|
-0.009730,
|
||||||
|
0.018993,
|
||||||
|
0.008544,
|
||||||
|
0.000534,
|
||||||
|
0.035755,
|
||||||
|
0.029074,
|
||||||
|
-0.001192,
|
||||||
|
0.030852,
|
||||||
|
0.030983,
|
||||||
|
-0.029834,
|
||||||
|
-0.009550,
|
||||||
|
0.011945,
|
||||||
|
-0.081971,
|
||||||
|
-0.082875,
|
||||||
|
0.000423,
|
||||||
|
-0.133526,
|
||||||
|
-0.211778,
|
||||||
|
0.182628,
|
||||||
|
0.514906,
|
||||||
|
0.182628,
|
||||||
|
-0.211778,
|
||||||
|
-0.133526,
|
||||||
|
0.000423,
|
||||||
|
-0.082875,
|
||||||
|
-0.081971,
|
||||||
|
0.011945,
|
||||||
|
-0.009550,
|
||||||
|
-0.029834,
|
||||||
|
0.030983,
|
||||||
|
0.030852,
|
||||||
|
-0.001192,
|
||||||
|
0.029074,
|
||||||
|
0.035755,
|
||||||
|
0.000534,
|
||||||
|
0.008544,
|
||||||
|
0.018993,
|
||||||
|
-0.009730,
|
||||||
|
-0.012891,
|
||||||
|
0.001751,
|
||||||
|
-0.014321,
|
||||||
|
-0.020458,
|
||||||
|
-0.003273,
|
||||||
|
-0.007058,
|
||||||
|
-0.013390,
|
||||||
|
0.001828,
|
||||||
|
0.005137,
|
||||||
|
-0.002015,
|
||||||
|
0.006951,
|
||||||
|
0.011821,
|
||||||
|
0.003521,
|
||||||
|
0.005331,
|
||||||
|
0.009200,
|
||||||
|
0.001446,
|
||||||
|
-0.001234,
|
||||||
|
0.001963,
|
||||||
|
-0.002787,
|
||||||
|
-0.006268,
|
||||||
|
-0.002828,
|
||||||
|
-0.003620,
|
||||||
|
-0.005837,
|
||||||
|
-0.002415,
|
||||||
|
-0.000565,
|
||||||
|
-0.001641,
|
||||||
|
0.000567,
|
||||||
|
0.002764,
|
||||||
|
0.001866,
|
||||||
|
0.002147,
|
||||||
|
0.003245,
|
||||||
|
0.002174
|
||||||
|
};
|
||||||
|
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
#define BPFB_N 101
|
||||||
|
|
||||||
|
float bpfb[]={
|
||||||
|
0.003795,
|
||||||
|
0.006827,
|
||||||
|
0.002261,
|
||||||
|
0.002523,
|
||||||
|
0.005758,
|
||||||
|
-0.000264,
|
||||||
|
-0.000674,
|
||||||
|
0.003113,
|
||||||
|
-0.004144,
|
||||||
|
-0.004923,
|
||||||
|
0.000043,
|
||||||
|
-0.008017,
|
||||||
|
-0.008711,
|
||||||
|
-0.001802,
|
||||||
|
-0.010210,
|
||||||
|
-0.010428,
|
||||||
|
-0.000899,
|
||||||
|
-0.009413,
|
||||||
|
-0.009072,
|
||||||
|
0.003469,
|
||||||
|
-0.005335,
|
||||||
|
-0.004828,
|
||||||
|
0.010724,
|
||||||
|
0.000941,
|
||||||
|
0.000708,
|
||||||
|
0.018957,
|
||||||
|
0.007084,
|
||||||
|
0.004825,
|
||||||
|
0.025418,
|
||||||
|
0.010147,
|
||||||
|
0.004452,
|
||||||
|
0.027434,
|
||||||
|
0.007550,
|
||||||
|
-0.002861,
|
||||||
|
0.023483,
|
||||||
|
-0.001944,
|
||||||
|
-0.018138,
|
||||||
|
0.014122,
|
||||||
|
-0.017583,
|
||||||
|
-0.040768,
|
||||||
|
0.002598,
|
||||||
|
-0.036604,
|
||||||
|
-0.069541,
|
||||||
|
-0.004273,
|
||||||
|
-0.054876,
|
||||||
|
-0.107289,
|
||||||
|
0.010068,
|
||||||
|
-0.068052,
|
||||||
|
-0.200119,
|
||||||
|
0.207287,
|
||||||
|
0.597150,
|
||||||
|
0.207287,
|
||||||
|
-0.200119,
|
||||||
|
-0.068052,
|
||||||
|
0.010068,
|
||||||
|
-0.107289,
|
||||||
|
-0.054876,
|
||||||
|
-0.004273,
|
||||||
|
-0.069541,
|
||||||
|
-0.036604,
|
||||||
|
0.002598,
|
||||||
|
-0.040768,
|
||||||
|
-0.017583,
|
||||||
|
0.014122,
|
||||||
|
-0.018138,
|
||||||
|
-0.001944,
|
||||||
|
0.023483,
|
||||||
|
-0.002861,
|
||||||
|
0.007550,
|
||||||
|
0.027434,
|
||||||
|
0.004452,
|
||||||
|
0.010147,
|
||||||
|
0.025418,
|
||||||
|
0.004825,
|
||||||
|
0.007084,
|
||||||
|
0.018957,
|
||||||
|
0.000708,
|
||||||
|
0.000941,
|
||||||
|
0.010724,
|
||||||
|
-0.004828,
|
||||||
|
-0.005335,
|
||||||
|
0.003469,
|
||||||
|
-0.009072,
|
||||||
|
-0.009413,
|
||||||
|
-0.000899,
|
||||||
|
-0.010428,
|
||||||
|
-0.010210,
|
||||||
|
-0.001802,
|
||||||
|
-0.008711,
|
||||||
|
-0.008017,
|
||||||
|
0.000043,
|
||||||
|
-0.004923,
|
||||||
|
-0.004144,
|
||||||
|
0.003113,
|
||||||
|
-0.000674,
|
||||||
|
-0.000264,
|
||||||
|
0.005758,
|
||||||
|
0.002523,
|
||||||
|
0.002261,
|
||||||
|
0.006827,
|
||||||
|
0.003795
|
||||||
|
};
|
||||||
@@ -0,0 +1,245 @@
|
|||||||
|
/* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This intermediary file and the files that used to create it are under
|
||||||
|
* The LGPL. See the file COPYING.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp1.txt */
|
||||||
|
static const float codes0[] = {
|
||||||
|
225,
|
||||||
|
250,
|
||||||
|
275,
|
||||||
|
300,
|
||||||
|
325,
|
||||||
|
350,
|
||||||
|
375,
|
||||||
|
400,
|
||||||
|
425,
|
||||||
|
450,
|
||||||
|
475,
|
||||||
|
500,
|
||||||
|
525,
|
||||||
|
550,
|
||||||
|
575,
|
||||||
|
600
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp2.txt */
|
||||||
|
static const float codes1[] = {
|
||||||
|
325,
|
||||||
|
350,
|
||||||
|
375,
|
||||||
|
400,
|
||||||
|
425,
|
||||||
|
450,
|
||||||
|
475,
|
||||||
|
500,
|
||||||
|
525,
|
||||||
|
550,
|
||||||
|
575,
|
||||||
|
600,
|
||||||
|
625,
|
||||||
|
650,
|
||||||
|
675,
|
||||||
|
700
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp3.txt */
|
||||||
|
static const float codes2[] = {
|
||||||
|
500,
|
||||||
|
550,
|
||||||
|
600,
|
||||||
|
650,
|
||||||
|
700,
|
||||||
|
750,
|
||||||
|
800,
|
||||||
|
850,
|
||||||
|
900,
|
||||||
|
950,
|
||||||
|
1000,
|
||||||
|
1050,
|
||||||
|
1100,
|
||||||
|
1150,
|
||||||
|
1200,
|
||||||
|
1250
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp4.txt */
|
||||||
|
static const float codes3[] = {
|
||||||
|
700,
|
||||||
|
800,
|
||||||
|
900,
|
||||||
|
1000,
|
||||||
|
1100,
|
||||||
|
1200,
|
||||||
|
1300,
|
||||||
|
1400,
|
||||||
|
1500,
|
||||||
|
1600,
|
||||||
|
1700,
|
||||||
|
1800,
|
||||||
|
1900,
|
||||||
|
2000,
|
||||||
|
2100,
|
||||||
|
2200
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp5.txt */
|
||||||
|
static const float codes4[] = {
|
||||||
|
950,
|
||||||
|
1050,
|
||||||
|
1150,
|
||||||
|
1250,
|
||||||
|
1350,
|
||||||
|
1450,
|
||||||
|
1550,
|
||||||
|
1650,
|
||||||
|
1750,
|
||||||
|
1850,
|
||||||
|
1950,
|
||||||
|
2050,
|
||||||
|
2150,
|
||||||
|
2250,
|
||||||
|
2350,
|
||||||
|
2450
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp6.txt */
|
||||||
|
static const float codes5[] = {
|
||||||
|
1100,
|
||||||
|
1200,
|
||||||
|
1300,
|
||||||
|
1400,
|
||||||
|
1500,
|
||||||
|
1600,
|
||||||
|
1700,
|
||||||
|
1800,
|
||||||
|
1900,
|
||||||
|
2000,
|
||||||
|
2100,
|
||||||
|
2200,
|
||||||
|
2300,
|
||||||
|
2400,
|
||||||
|
2500,
|
||||||
|
2600
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp7.txt */
|
||||||
|
static const float codes6[] = {
|
||||||
|
1500,
|
||||||
|
1600,
|
||||||
|
1700,
|
||||||
|
1800,
|
||||||
|
1900,
|
||||||
|
2000,
|
||||||
|
2100,
|
||||||
|
2200,
|
||||||
|
2300,
|
||||||
|
2400,
|
||||||
|
2500,
|
||||||
|
2600,
|
||||||
|
2700,
|
||||||
|
2800,
|
||||||
|
2900,
|
||||||
|
3000
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp8.txt */
|
||||||
|
static const float codes7[] = {
|
||||||
|
2300,
|
||||||
|
2400,
|
||||||
|
2500,
|
||||||
|
2600,
|
||||||
|
2700,
|
||||||
|
2800,
|
||||||
|
2900,
|
||||||
|
3000
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp9.txt */
|
||||||
|
static const float codes8[] = {
|
||||||
|
2500,
|
||||||
|
2600,
|
||||||
|
2700,
|
||||||
|
2800,
|
||||||
|
2900,
|
||||||
|
3000,
|
||||||
|
3100,
|
||||||
|
3200
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp10.txt */
|
||||||
|
static const float codes9[] = {
|
||||||
|
2900,
|
||||||
|
3100,
|
||||||
|
3300,
|
||||||
|
3500
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct lsp_codebook lsp_cb[] = {
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp1.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
16,
|
||||||
|
codes0
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp2.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
16,
|
||||||
|
codes1
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp3.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
16,
|
||||||
|
codes2
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp4.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
16,
|
||||||
|
codes3
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp5.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
16,
|
||||||
|
codes4
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp6.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
16,
|
||||||
|
codes5
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp7.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
16,
|
||||||
|
codes6
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp8.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
8,
|
||||||
|
codes7
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp9.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
8,
|
||||||
|
codes8
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lsp10.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
codes9
|
||||||
|
},
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
@@ -0,0 +1,433 @@
|
|||||||
|
/* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This intermediary file and the files that used to create it are under
|
||||||
|
* The LGPL. See the file COPYING.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp1.txt */
|
||||||
|
static const float codes0[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
175,
|
||||||
|
200,
|
||||||
|
225,
|
||||||
|
250,
|
||||||
|
275,
|
||||||
|
300,
|
||||||
|
325,
|
||||||
|
350,
|
||||||
|
375,
|
||||||
|
400,
|
||||||
|
425,
|
||||||
|
450,
|
||||||
|
475,
|
||||||
|
500,
|
||||||
|
525,
|
||||||
|
550,
|
||||||
|
575,
|
||||||
|
600,
|
||||||
|
625,
|
||||||
|
650,
|
||||||
|
675,
|
||||||
|
700,
|
||||||
|
725,
|
||||||
|
750,
|
||||||
|
775,
|
||||||
|
800
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp2.txt */
|
||||||
|
static const float codes1[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
175,
|
||||||
|
200,
|
||||||
|
225,
|
||||||
|
250,
|
||||||
|
275,
|
||||||
|
300,
|
||||||
|
325,
|
||||||
|
350,
|
||||||
|
375,
|
||||||
|
400,
|
||||||
|
425,
|
||||||
|
450,
|
||||||
|
475,
|
||||||
|
500,
|
||||||
|
525,
|
||||||
|
550,
|
||||||
|
575,
|
||||||
|
600,
|
||||||
|
625,
|
||||||
|
650,
|
||||||
|
675,
|
||||||
|
700,
|
||||||
|
725,
|
||||||
|
750,
|
||||||
|
775,
|
||||||
|
800
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp3.txt */
|
||||||
|
static const float codes2[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
175,
|
||||||
|
200,
|
||||||
|
225,
|
||||||
|
250,
|
||||||
|
275,
|
||||||
|
300,
|
||||||
|
325,
|
||||||
|
350,
|
||||||
|
375,
|
||||||
|
400,
|
||||||
|
425,
|
||||||
|
450,
|
||||||
|
475,
|
||||||
|
500,
|
||||||
|
525,
|
||||||
|
550,
|
||||||
|
575,
|
||||||
|
600,
|
||||||
|
625,
|
||||||
|
650,
|
||||||
|
675,
|
||||||
|
700,
|
||||||
|
725,
|
||||||
|
750,
|
||||||
|
775,
|
||||||
|
800
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp4.txt */
|
||||||
|
static const float codes3[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
175,
|
||||||
|
200,
|
||||||
|
250,
|
||||||
|
300,
|
||||||
|
350,
|
||||||
|
400,
|
||||||
|
450,
|
||||||
|
500,
|
||||||
|
550,
|
||||||
|
600,
|
||||||
|
650,
|
||||||
|
700,
|
||||||
|
750,
|
||||||
|
800,
|
||||||
|
850,
|
||||||
|
900,
|
||||||
|
950,
|
||||||
|
1000,
|
||||||
|
1050,
|
||||||
|
1100,
|
||||||
|
1150,
|
||||||
|
1200,
|
||||||
|
1250,
|
||||||
|
1300,
|
||||||
|
1350,
|
||||||
|
1400
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp5.txt */
|
||||||
|
static const float codes4[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
175,
|
||||||
|
200,
|
||||||
|
250,
|
||||||
|
300,
|
||||||
|
350,
|
||||||
|
400,
|
||||||
|
450,
|
||||||
|
500,
|
||||||
|
550,
|
||||||
|
600,
|
||||||
|
650,
|
||||||
|
700,
|
||||||
|
750,
|
||||||
|
800,
|
||||||
|
850,
|
||||||
|
900,
|
||||||
|
950,
|
||||||
|
1000,
|
||||||
|
1050,
|
||||||
|
1100,
|
||||||
|
1150,
|
||||||
|
1200,
|
||||||
|
1250,
|
||||||
|
1300,
|
||||||
|
1350,
|
||||||
|
1400
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp6.txt */
|
||||||
|
static const float codes5[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
175,
|
||||||
|
200,
|
||||||
|
250,
|
||||||
|
300,
|
||||||
|
350,
|
||||||
|
400,
|
||||||
|
450,
|
||||||
|
500,
|
||||||
|
550,
|
||||||
|
600,
|
||||||
|
650,
|
||||||
|
700,
|
||||||
|
750,
|
||||||
|
800,
|
||||||
|
850,
|
||||||
|
900,
|
||||||
|
950,
|
||||||
|
1000,
|
||||||
|
1050,
|
||||||
|
1100,
|
||||||
|
1150,
|
||||||
|
1200,
|
||||||
|
1250,
|
||||||
|
1300,
|
||||||
|
1350,
|
||||||
|
1400
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp7.txt */
|
||||||
|
static const float codes6[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
175,
|
||||||
|
200,
|
||||||
|
225,
|
||||||
|
250,
|
||||||
|
275,
|
||||||
|
300,
|
||||||
|
325,
|
||||||
|
350,
|
||||||
|
375,
|
||||||
|
400,
|
||||||
|
425,
|
||||||
|
450,
|
||||||
|
475,
|
||||||
|
500,
|
||||||
|
525,
|
||||||
|
550,
|
||||||
|
575,
|
||||||
|
600,
|
||||||
|
625,
|
||||||
|
650,
|
||||||
|
675,
|
||||||
|
700,
|
||||||
|
725,
|
||||||
|
750,
|
||||||
|
775,
|
||||||
|
800
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp8.txt */
|
||||||
|
static const float codes7[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
175,
|
||||||
|
200,
|
||||||
|
225,
|
||||||
|
250,
|
||||||
|
275,
|
||||||
|
300,
|
||||||
|
325,
|
||||||
|
350,
|
||||||
|
375,
|
||||||
|
400,
|
||||||
|
425,
|
||||||
|
450,
|
||||||
|
475,
|
||||||
|
500,
|
||||||
|
525,
|
||||||
|
550,
|
||||||
|
575,
|
||||||
|
600,
|
||||||
|
625,
|
||||||
|
650,
|
||||||
|
675,
|
||||||
|
700,
|
||||||
|
725,
|
||||||
|
750,
|
||||||
|
775,
|
||||||
|
800
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp9.txt */
|
||||||
|
static const float codes8[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
175,
|
||||||
|
200,
|
||||||
|
225,
|
||||||
|
250,
|
||||||
|
275,
|
||||||
|
300,
|
||||||
|
325,
|
||||||
|
350,
|
||||||
|
375,
|
||||||
|
400,
|
||||||
|
425,
|
||||||
|
450,
|
||||||
|
475,
|
||||||
|
500,
|
||||||
|
525,
|
||||||
|
550,
|
||||||
|
575,
|
||||||
|
600,
|
||||||
|
625,
|
||||||
|
650,
|
||||||
|
675,
|
||||||
|
700,
|
||||||
|
725,
|
||||||
|
750,
|
||||||
|
775,
|
||||||
|
800
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp10.txt */
|
||||||
|
static const float codes9[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
175,
|
||||||
|
200,
|
||||||
|
225,
|
||||||
|
250,
|
||||||
|
275,
|
||||||
|
300,
|
||||||
|
325,
|
||||||
|
350,
|
||||||
|
375,
|
||||||
|
400,
|
||||||
|
425,
|
||||||
|
450,
|
||||||
|
475,
|
||||||
|
500,
|
||||||
|
525,
|
||||||
|
550,
|
||||||
|
575,
|
||||||
|
600,
|
||||||
|
625,
|
||||||
|
650,
|
||||||
|
675,
|
||||||
|
700,
|
||||||
|
725,
|
||||||
|
750,
|
||||||
|
775,
|
||||||
|
800
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct lsp_codebook lsp_cbd[] = {
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp1.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
32,
|
||||||
|
codes0
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp2.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
32,
|
||||||
|
codes1
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp3.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
32,
|
||||||
|
codes2
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp4.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
32,
|
||||||
|
codes3
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp5.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
32,
|
||||||
|
codes4
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp6.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
32,
|
||||||
|
codes5
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp7.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
32,
|
||||||
|
codes6
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp8.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
32,
|
||||||
|
codes7
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp9.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
32,
|
||||||
|
codes8
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/dlsp10.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
32,
|
||||||
|
codes9
|
||||||
|
},
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
@@ -0,0 +1,279 @@
|
|||||||
|
/* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This intermediary file and the files that used to create it are under
|
||||||
|
* The LGPL. See the file COPYING.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/gecb.txt */
|
||||||
|
static const float codes0[] = {
|
||||||
|
2.71, 12.0184,
|
||||||
|
0.04675, -2.73881,
|
||||||
|
0.120993, 8.38895,
|
||||||
|
-1.58028, -0.892307,
|
||||||
|
1.19307, -1.91561,
|
||||||
|
0.187101, -3.27679,
|
||||||
|
0.332251, -7.66455,
|
||||||
|
-1.47944, 31.2461,
|
||||||
|
1.52761, 27.7095,
|
||||||
|
-0.524379, 5.25012,
|
||||||
|
0.55333, 7.4388,
|
||||||
|
-0.843451, -1.95299,
|
||||||
|
2.26389, 8.61029,
|
||||||
|
0.143143, 2.36549,
|
||||||
|
0.616506, 1.28427,
|
||||||
|
-1.71133, 22.0967,
|
||||||
|
1.00813, 17.3965,
|
||||||
|
-0.106718, 1.41891,
|
||||||
|
-0.136246, 14.2736,
|
||||||
|
-1.70909, -20.5319,
|
||||||
|
1.65787, -3.39107,
|
||||||
|
0.138049, -4.95785,
|
||||||
|
0.536729, -1.94375,
|
||||||
|
0.196307, 36.8519,
|
||||||
|
1.27248, 22.5565,
|
||||||
|
-0.670219, -1.90604,
|
||||||
|
0.382092, 6.40113,
|
||||||
|
-0.756911, -4.90102,
|
||||||
|
1.82931, 4.6138,
|
||||||
|
0.318794, 0.73683,
|
||||||
|
0.612815, -2.07505,
|
||||||
|
-0.410151, 24.7871,
|
||||||
|
1.77602, 13.1909,
|
||||||
|
0.106457, -0.104492,
|
||||||
|
0.192206, 10.1838,
|
||||||
|
-1.82442, -7.71565,
|
||||||
|
0.931346, 4.34835,
|
||||||
|
0.308813, -4.086,
|
||||||
|
0.397143, -11.8089,
|
||||||
|
-0.048715, 41.2273,
|
||||||
|
0.877342, 35.8503,
|
||||||
|
-0.759794, 0.476634,
|
||||||
|
0.978593, 7.67467,
|
||||||
|
-1.19506, 3.03883,
|
||||||
|
2.63989, -3.41106,
|
||||||
|
0.191127, 3.60351,
|
||||||
|
0.402932, 1.0843,
|
||||||
|
-2.15202, 18.1076,
|
||||||
|
1.5468, 8.32271,
|
||||||
|
-0.143089, -4.07592,
|
||||||
|
-0.150142, 5.86674,
|
||||||
|
-1.40844, -3.2507,
|
||||||
|
1.56615, -10.4132,
|
||||||
|
0.178171, -10.2267,
|
||||||
|
0.362164, -0.028556,
|
||||||
|
-0.070125, 24.3907,
|
||||||
|
0.594752, 17.4828,
|
||||||
|
-0.28698, -6.90407,
|
||||||
|
0.464818, 10.2055,
|
||||||
|
-1.00684, -14.3572,
|
||||||
|
2.32957, -3.69161,
|
||||||
|
0.335745, 2.40714,
|
||||||
|
1.01966, -3.15565,
|
||||||
|
-1.25945, 7.9919,
|
||||||
|
2.38369, 19.6806,
|
||||||
|
-0.094947, -2.41374,
|
||||||
|
0.20933, 6.66477,
|
||||||
|
-2.22103, 1.37986,
|
||||||
|
1.29239, 2.04633,
|
||||||
|
0.243626, -0.890741,
|
||||||
|
0.428773, -7.19366,
|
||||||
|
-1.11374, 41.3414,
|
||||||
|
2.6098, 31.1405,
|
||||||
|
-0.446468, 2.53419,
|
||||||
|
0.490104, 4.62757,
|
||||||
|
-1.11723, -3.24174,
|
||||||
|
1.79156, 8.41493,
|
||||||
|
0.156012, 0.183336,
|
||||||
|
0.532447, 3.15455,
|
||||||
|
-0.764484, 18.514,
|
||||||
|
0.952395, 11.7713,
|
||||||
|
-0.332567, 0.346987,
|
||||||
|
0.202165, 14.7168,
|
||||||
|
-2.12924, -15.559,
|
||||||
|
1.35358, -1.92679,
|
||||||
|
-0.010963, -16.3364,
|
||||||
|
0.399053, -2.79057,
|
||||||
|
0.750657, 31.1483,
|
||||||
|
0.655743, 24.4819,
|
||||||
|
-0.45321, -0.735879,
|
||||||
|
0.2869, 6.5467,
|
||||||
|
-0.715673, -12.3578,
|
||||||
|
1.54849, 3.87217,
|
||||||
|
0.271874, 0.802339,
|
||||||
|
0.502073, -4.85485,
|
||||||
|
-0.497037, 17.7619,
|
||||||
|
1.19116, 13.9544,
|
||||||
|
0.01563, 1.33157,
|
||||||
|
0.341867, 8.93537,
|
||||||
|
-2.31601, -5.39506,
|
||||||
|
0.75861, 1.9645,
|
||||||
|
0.24132, -3.23769,
|
||||||
|
0.267151, -11.2344,
|
||||||
|
-0.273126, 32.6248,
|
||||||
|
1.75352, 40.432,
|
||||||
|
-0.784011, 3.04576,
|
||||||
|
0.705987, 5.66118,
|
||||||
|
-1.3864, 1.35356,
|
||||||
|
2.37646, 1.67485,
|
||||||
|
0.242973, 4.73218,
|
||||||
|
0.491227, 0.354061,
|
||||||
|
-1.60676, 8.65895,
|
||||||
|
1.16711, 5.9871,
|
||||||
|
-0.137601, -12.0417,
|
||||||
|
-0.251375, 10.3972,
|
||||||
|
-1.43151, -8.90411,
|
||||||
|
0.98828, -13.209,
|
||||||
|
0.261484, -6.35497,
|
||||||
|
0.395932, -0.702529,
|
||||||
|
0.283704, 26.8996,
|
||||||
|
0.420959, 15.4418,
|
||||||
|
-0.355804, -13.7278,
|
||||||
|
0.527372, 12.3985,
|
||||||
|
-1.16956, -15.9985,
|
||||||
|
1.90669, -5.81605,
|
||||||
|
0.354492, 3.85157,
|
||||||
|
0.82576, -4.16264,
|
||||||
|
-0.49019, 13.0572,
|
||||||
|
2.25577, 13.5264,
|
||||||
|
-0.004956, -3.23713,
|
||||||
|
0.026709, 7.86645,
|
||||||
|
-1.81037, -0.451183,
|
||||||
|
1.08383, -0.18362,
|
||||||
|
0.135836, -2.26658,
|
||||||
|
0.375812, -5.51225,
|
||||||
|
-1.96644, 38.6829,
|
||||||
|
1.97799, 24.5655,
|
||||||
|
-0.704656, 6.35881,
|
||||||
|
0.480786, 7.05175,
|
||||||
|
-0.976417, -2.42273,
|
||||||
|
2.50215, 6.75935,
|
||||||
|
0.083588, 3.2588,
|
||||||
|
0.543629, 0.910013,
|
||||||
|
-1.23196, 23.0915,
|
||||||
|
0.785492, 14.807,
|
||||||
|
-0.213554, 1.688,
|
||||||
|
0.004748, 18.1718,
|
||||||
|
-1.54719, -16.1168,
|
||||||
|
1.50104, -3.28114,
|
||||||
|
0.080133, -4.63472,
|
||||||
|
0.476592, -2.18093,
|
||||||
|
0.44247, 40.304,
|
||||||
|
1.07277, 27.592,
|
||||||
|
-0.594738, -4.16681,
|
||||||
|
0.42248, 7.61609,
|
||||||
|
-0.927521, -7.27441,
|
||||||
|
1.99162, 1.29636,
|
||||||
|
0.291307, 2.39878,
|
||||||
|
0.721081, -1.95062,
|
||||||
|
-0.804256, 24.9295,
|
||||||
|
1.64839, 19.1197,
|
||||||
|
0.060852, -0.590639,
|
||||||
|
0.266085, 9.10325,
|
||||||
|
-1.9574, -2.88461,
|
||||||
|
1.11693, 2.6724,
|
||||||
|
0.35458, -2.74854,
|
||||||
|
0.330733, -14.1561,
|
||||||
|
-0.527851, 39.5756,
|
||||||
|
0.991152, 43.195,
|
||||||
|
-0.589619, 1.26919,
|
||||||
|
0.787401, 8.73071,
|
||||||
|
-1.0138, 1.02507,
|
||||||
|
2.8254, 1.89538,
|
||||||
|
0.24089, 2.74557,
|
||||||
|
0.427195, 2.54446,
|
||||||
|
-1.95311, 12.244,
|
||||||
|
1.44862, 12.0607,
|
||||||
|
-0.210492, -3.37906,
|
||||||
|
-0.056713, 10.204,
|
||||||
|
-1.65237, -5.10274,
|
||||||
|
1.29475, -12.2708,
|
||||||
|
0.111608, -8.67592,
|
||||||
|
0.326634, -1.16763,
|
||||||
|
0.021781, 31.1258,
|
||||||
|
0.455335, 21.4684,
|
||||||
|
-0.37544, -3.37121,
|
||||||
|
0.39362, 11.302,
|
||||||
|
-0.851456, -19.4149,
|
||||||
|
2.10703, -2.22886,
|
||||||
|
0.373233, 1.92406,
|
||||||
|
0.884438, -1.72058,
|
||||||
|
-0.975127, 9.84013,
|
||||||
|
2.0033, 17.3954,
|
||||||
|
-0.036915, -1.11137,
|
||||||
|
0.148456, 5.39997,
|
||||||
|
-1.91441, 4.77382,
|
||||||
|
1.44791, 0.537122,
|
||||||
|
0.194979, -1.03818,
|
||||||
|
0.495771, -9.95502,
|
||||||
|
-1.05899, 32.9471,
|
||||||
|
2.01122, 32.4544,
|
||||||
|
-0.30965, 4.71911,
|
||||||
|
0.436082, 4.63552,
|
||||||
|
-1.23711, -1.25428,
|
||||||
|
2.02274, 9.42834,
|
||||||
|
0.190342, 1.46077,
|
||||||
|
0.479017, 2.48479,
|
||||||
|
-1.07848, 16.2217,
|
||||||
|
1.20764, 9.65421,
|
||||||
|
-0.258087, -1.67236,
|
||||||
|
0.071852, 13.416,
|
||||||
|
-1.87723, -16.072,
|
||||||
|
1.28957, -4.87118,
|
||||||
|
0.067713, -13.4427,
|
||||||
|
0.435551, -4.1655,
|
||||||
|
0.46614, 30.5895,
|
||||||
|
0.904895, 21.598,
|
||||||
|
-0.518369, -2.53205,
|
||||||
|
0.337363, 5.63726,
|
||||||
|
-0.554975, -17.4005,
|
||||||
|
1.69188, 1.14574,
|
||||||
|
0.227934, 0.889297,
|
||||||
|
0.587303, -5.72973,
|
||||||
|
-0.262133, 18.6666,
|
||||||
|
1.39505, 17.0029,
|
||||||
|
-0.01909, 4.30838,
|
||||||
|
0.304235, 12.6699,
|
||||||
|
-2.07406, -6.46084,
|
||||||
|
0.920546, 1.21296,
|
||||||
|
0.284927, -1.78547,
|
||||||
|
0.209724, -16.024,
|
||||||
|
-0.636067, 31.5768,
|
||||||
|
1.34989, 34.6775,
|
||||||
|
-0.971625, 5.30086,
|
||||||
|
0.590249, 4.44971,
|
||||||
|
-1.56787, 3.60239,
|
||||||
|
2.1455, 4.51666,
|
||||||
|
0.296022, 4.12017,
|
||||||
|
0.445299, 0.868772,
|
||||||
|
-1.44193, 14.1284,
|
||||||
|
1.35575, 6.0074,
|
||||||
|
-0.012814, -7.49657,
|
||||||
|
-0.43, 8.50012,
|
||||||
|
-1.20469, -7.11326,
|
||||||
|
1.10102, -6.83682,
|
||||||
|
0.196463, -6.234,
|
||||||
|
0.436747, -1.12979,
|
||||||
|
0.141052, 22.8549,
|
||||||
|
0.290821, 18.8114,
|
||||||
|
-0.529536, -7.73251,
|
||||||
|
0.63428, 10.7898,
|
||||||
|
-1.33472, -20.3258,
|
||||||
|
1.81564, -1.90332,
|
||||||
|
0.394778, 3.79758,
|
||||||
|
0.732682, -8.18382,
|
||||||
|
-0.741244, 11.7683
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct lsp_codebook ge_cb[] = {
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/gecb.txt */
|
||||||
|
{
|
||||||
|
2,
|
||||||
|
8,
|
||||||
|
256,
|
||||||
|
codes0
|
||||||
|
},
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,235 @@
|
|||||||
|
/* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This intermediary file and the files that used to create it are under
|
||||||
|
* The LGPL. See the file COPYING.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lspmelvq1.txt */
|
||||||
|
static const float codes0[] = {
|
||||||
|
640.185, 893.139, 1393.85, 1494.06, 1656.26, 1700.82,
|
||||||
|
558.516, 716.906, 1057.36, 1182.62, 1503.8, 1610.03,
|
||||||
|
615.108, 769.622, 1120.16, 1222.84, 1366.46, 1465.05,
|
||||||
|
663.458, 736.833, 964.764, 1043.54, 1623.17, 1681.29,
|
||||||
|
487.957, 577.723, 1017.43, 1177.04, 1552.1, 1615.69,
|
||||||
|
536.099, 733.407, 1292.28, 1406.09, 1577.7, 1637.49,
|
||||||
|
473.015, 542.559, 877.397, 1285.82, 1591.04, 1647.44,
|
||||||
|
525.343, 652.014, 1206.83, 1493.96, 1647.97, 1698.3,
|
||||||
|
510.887, 572.868, 945.226, 1445.68, 1678.17, 1705.53,
|
||||||
|
534.915, 721.265, 1275.92, 1415.76, 1648.5, 1695.73,
|
||||||
|
865.189, 1047, 1267.14, 1389.32, 1646.57, 1696.97,
|
||||||
|
608.033, 869.887, 1300.95, 1432.87, 1639.74, 1689.41,
|
||||||
|
554.972, 649.352, 866.845, 979.873, 1645.31, 1695.39,
|
||||||
|
696.079, 813.97, 1102.49, 1219.79, 1536.49, 1621.94,
|
||||||
|
553.879, 691.097, 1200.84, 1339.34, 1629.08, 1683.5,
|
||||||
|
778.561, 997.776, 1258.63, 1390.34, 1601.99, 1657.86,
|
||||||
|
713.107, 778.893, 992.875, 1051.95, 1497.45, 1650.66,
|
||||||
|
490.27, 598.18, 1116.02, 1244.13, 1622.26, 1672.21,
|
||||||
|
448.556, 512.085, 1271.7, 1448.18, 1579.37, 1642.48,
|
||||||
|
465.688, 535.312, 1099.19, 1535.79, 1684.29, 1710.9,
|
||||||
|
812.222, 1087.53, 1470.44, 1559.73, 1692.18, 1726.38,
|
||||||
|
428.174, 489.426, 1160.33, 1409.3, 1597.5, 1651.3,
|
||||||
|
712.81, 957.56, 1433.02, 1516.37, 1675.39, 1710.06,
|
||||||
|
717.255, 934.073, 1305.2, 1436.72, 1647.2, 1693.09,
|
||||||
|
492.888, 580.393, 1339.52, 1461.07, 1592, 1653.42,
|
||||||
|
550.467, 675.888, 990.888, 1177.44, 1615.64, 1658,
|
||||||
|
714.528, 801.792, 1072.94, 1146.08, 1637.06, 1706.58,
|
||||||
|
513.819, 590.989, 798.691, 895.755, 1557.76, 1624.56,
|
||||||
|
436.653, 518.413, 1281.99, 1547.08, 1685.12, 1717.76,
|
||||||
|
681.854, 758.354, 1046.65, 1120.92, 1412.25, 1603.42,
|
||||||
|
873.962, 1118.49, 1376.61, 1465.07, 1665.38, 1707.18,
|
||||||
|
553.529, 634.092, 1144.77, 1284.8, 1542.87, 1620.63,
|
||||||
|
448.532, 519.097, 1054.57, 1319.66, 1591.26, 1649.85,
|
||||||
|
742.267, 885.293, 1152.83, 1318.51, 1569.36, 1631.45,
|
||||||
|
529.03, 654.522, 1355.76, 1511.75, 1662.39, 1706.4,
|
||||||
|
463.794, 597.77, 1176.05, 1366.13, 1629.37, 1678.01,
|
||||||
|
626.936, 706.66, 1058.04, 1323.62, 1473.28, 1599.68,
|
||||||
|
477.322, 615.5, 1488.89, 1550.5, 1683.1, 1712.34,
|
||||||
|
547.442, 815.442, 1313.38, 1486.96, 1671.97, 1717.4,
|
||||||
|
610.671, 819.955, 1219.11, 1363.66, 1592.05, 1654.31,
|
||||||
|
547.414, 746.54, 1438.43, 1517.72, 1659.64, 1695.57,
|
||||||
|
604.823, 821.146, 1137.94, 1358.29, 1598.94, 1655.64,
|
||||||
|
525.935, 616.739, 1060.13, 1427.33, 1593.35, 1657.48,
|
||||||
|
622.5, 762.143, 1318.65, 1410.96, 1618.12, 1680.06,
|
||||||
|
436.917, 516.583, 1390.29, 1475.86, 1594.71, 1633.74,
|
||||||
|
792.487, 1031.24, 1362.62, 1472.68, 1649.26, 1697.35,
|
||||||
|
457.707, 526.207, 865.966, 1120.47, 1564.83, 1625.28,
|
||||||
|
526.39, 624.21, 1269.65, 1374.23, 1558.07, 1620.96,
|
||||||
|
483.768, 573.505, 1440.66, 1512.43, 1622.37, 1671.31,
|
||||||
|
953.061, 1194.03, 1416.67, 1515.82, 1678.82, 1718.21,
|
||||||
|
499.947, 627.358, 1299.94, 1394.23, 1643.17, 1685.33,
|
||||||
|
648.723, 838.181, 1225.5, 1383.45, 1637.46, 1691.67,
|
||||||
|
672.588, 1022.6, 1346.21, 1443.75, 1651.15, 1695.43,
|
||||||
|
581.833, 674.944, 955.167, 1020.5, 1370.5, 1503.11,
|
||||||
|
536.143, 652.531, 1243.84, 1315.27, 1425.1, 1505.73,
|
||||||
|
560.558, 786.65, 1224.66, 1373.98, 1630.06, 1682.68,
|
||||||
|
591.926, 783.722, 982, 1140.81, 1581.61, 1625.28,
|
||||||
|
548.537, 644.524, 940.451, 1048.74, 1557.89, 1609.48,
|
||||||
|
516.916, 723.253, 1135.95, 1309.19, 1600.08, 1669.48,
|
||||||
|
426.521, 506.077, 1457.73, 1535.02, 1641.35, 1678.45,
|
||||||
|
645.189, 776.595, 1020.78, 1240.07, 1597, 1648.7,
|
||||||
|
637.105, 941.474, 1242.21, 1372.49, 1646.7, 1694.8,
|
||||||
|
691.228, 788.141, 1202.12, 1294.89, 1626.97, 1681.77,
|
||||||
|
699.08, 886.655, 1300.9, 1399.28, 1579.94, 1646.79
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lspmelvq2.txt */
|
||||||
|
static const float codes1[] = {
|
||||||
|
4.44342, 51.1708, 7.45726, -27.4373, -18.5056, -18.1989,
|
||||||
|
51.58, 63.3166, 57.7796, -44.1591, -18.4834, -6.93392,
|
||||||
|
-20.2795, -21.7454, 4.66947, 52.1569, 30.4367, 36.8582,
|
||||||
|
-29.1104, -5.63933, -3.45383, -63.0261, -20.4423, -19.0485,
|
||||||
|
2.91622, 40.8374, 16.579, -51.8461, 38.5045, 18.1728,
|
||||||
|
-20.6977, -11.4022, -36.6173, -16.6116, -56.8965, -24.301,
|
||||||
|
-20.2385, 26.6332, 33.1191, 27.6284, -36.7493, -25.6041,
|
||||||
|
54.9871, 0.71748, 23.0674, -22.1031, 11.6643, 10.9938,
|
||||||
|
-62.7215, 21.7547, 21.2907, -7.64891, -4.5533, -9.71777,
|
||||||
|
-9.56338, -3.85841, 25.0454, -9.45216, 6.05017, 5.35043,
|
||||||
|
47.3823, 56.6122, -27.0315, -24.67, 4.86343, -0.225495,
|
||||||
|
26.3997, 26.7857, -1.66167, 62.8366, -19.7653, -8.55169,
|
||||||
|
-8.77648, -9.04545, -7.88996, 28.2433, -35.0963, -21.9709,
|
||||||
|
14.8423, 25.4563, -56.1262, -50.2934, -22.9393, -15.8113,
|
||||||
|
4.94186, 27.7798, 8.34579, 10.8553, -3.12587, -3.97807,
|
||||||
|
12.6426, -52.2317, 37.2487, -57.2067, -14.5125, -5.54035,
|
||||||
|
13.485, 15.3246, -23.9644, -21.3135, 19.5779, 14.1597,
|
||||||
|
-55.3543, -45.2077, 10.5185, 43.0461, -24.9859, -19.3484,
|
||||||
|
27.7226, 32.1882, 20.0321, 24.3328, -72.8194, -51.1823,
|
||||||
|
-31.3818, -5.25745, -43.7806, 14.1312, 17.6392, 9.81024,
|
||||||
|
-48.26, -26.2973, -44.1428, -31.9001, 22.5085, -0.467938,
|
||||||
|
7.37202, -7.79071, -12.5732, 27.1074, 9.34052, 14.4477,
|
||||||
|
14.5295, 8.82597, 57.0009, -16.3234, -32.4142, -21.0224,
|
||||||
|
32.4616, 48.6062, 38.5452, 9.77182, 1.82856, 11.5063,
|
||||||
|
-43.8275, -22.6263, -29.8278, 13.6115, 9.66849, -63.5218,
|
||||||
|
-11.9967, 2.74308, -73.6375, -20.9809, -4.11839, 7.71405,
|
||||||
|
24.0162, -2.29513, -6.80983, -26.4043, -21.8529, -16.3381,
|
||||||
|
-16.1484, 35.9086, -3.0837, 3.83958, 42.3003, 17.5003,
|
||||||
|
54.1225, -48.7513, -14.8712, -38.1256, 15.2903, 7.33079,
|
||||||
|
53.0929, 13.9221, 10.6536, 24.345, -16.5952, -16.0365,
|
||||||
|
33.1415, 38.5714, -26.0251, 22.021, 15.6866, 13.2593,
|
||||||
|
15.7194, -49.4061, 31.4552, 10.1896, 0.219911, 1.62902,
|
||||||
|
4.10868, 14.2755, 58.475, -1.16668, 52.6265, 43.4938,
|
||||||
|
358.653, -112.587, 85.9867, 52.08, -52.88, -249.24,
|
||||||
|
-12.5792, -6.64039, -33.0106, 1.51449, 50.3259, 61.6091,
|
||||||
|
-6.81685, 14.3146, 14.1563, 53.6363, 83.6051, 38.174,
|
||||||
|
-18.0006, 41.3575, -46.3736, 8.47794, -10.4611, -11.3847,
|
||||||
|
28.7711, 31.4689, -39.5744, 1.43977, -37.7309, -30.5309,
|
||||||
|
-34.4692, -11.0778, 44.4681, -60.0045, -44.9729, -34.8364,
|
||||||
|
38.7401, 41.0529, -7.92946, 20.0279, 74.4246, 54.6498,
|
||||||
|
81.8008, 133.531, -5.47375, 34.4759, 75.7417, 52.6112,
|
||||||
|
-61.5067, -76.6328, -47.2471, -43.5928, -9.46878, 0.832598,
|
||||||
|
-11.544, -44.7728, -13.9257, -3.32122, 24.816, 21.9064,
|
||||||
|
2.83945, -45.0522, -36.8776, -14.7577, -11.9912, -8.75366,
|
||||||
|
-8.97657, -14.0499, 39.2628, 48.8038, -14.3789, -4.79625,
|
||||||
|
31.6292, 32.0168, 5.52278, -79.8411, -24.1789, -15.7597,
|
||||||
|
15.893, 10.4667, -43.9057, -20.4885, 80.7594, 6.8023,
|
||||||
|
22.3285, -69.4942, -5.16156, 48.8868, 4.01995, -3.04376,
|
||||||
|
31.4062, -20.0952, -55.1259, 0.505988, 20.86, 15.0816,
|
||||||
|
-12.9696, 37.2548, 18.1009, 51.0767, 18.2053, 19.8474,
|
||||||
|
-45.4855, -45.3454, -4.22795, -15.8693, -6.07272, -1.99631,
|
||||||
|
-9.25462, 45.0241, 70.2879, -44.4484, 2.63165, 4.15336,
|
||||||
|
-51.1589, -27.7586, 19.7999, -9.87882, 63.4125, 48.3124,
|
||||||
|
-8.94084, -13.4815, -44.9602, 52.839, -17.2582, -1.59439,
|
||||||
|
23.18, -3.00374, 33.162, 31.5424, 29.111, 25.9327,
|
||||||
|
-28.4665, -10.6868, 88.7543, -3.88024, 17.5881, 13.7336,
|
||||||
|
-10.6578, 7.43021, -20.945, -17.6491, -11.2815, -10.8001,
|
||||||
|
-35.6182, -6.90301, 3.92829, 26.9695, 2.8894, 5.01685,
|
||||||
|
-3.78263, -19.2095, -10.5568, -67.7468, 20.3733, 29.552,
|
||||||
|
53.8109, -33.8374, -27.8223, -7.73289, -31.3462, -23.5678,
|
||||||
|
-38.8762, -17.7679, 11.457, 28.4607, 50.7006, -19.2488,
|
||||||
|
-44.6024, -60.2806, 56.35, 21.7545, 5.23677, 7.66608,
|
||||||
|
-3.80758, -39.1425, 28.8305, -3.09285, -42.7534, -25.1803,
|
||||||
|
45.2559, 28.8742, 60.0723, 64.461, 3.51203, -27.883
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lspmelvq3.txt */
|
||||||
|
static const float codes2[] = {
|
||||||
|
-9.63558, 27.5501, 15.4445, -4.34872, -1.8587, 1.27054,
|
||||||
|
-15.5343, 23.0515, -15.4436, -2.01887, -6.19433, -13.5085,
|
||||||
|
8.38867, -1.60998, -32.3903, 10.1765, 1.9467, 12.2454,
|
||||||
|
-3.06306, -9.55983, 14.367, -1.87159, 19.6192, -3.78366,
|
||||||
|
-18.495, -13.3811, -23.8928, -20.3745, -6.87856, -17.4887,
|
||||||
|
15.4925, 14.707, -0.0697855, 15.7541, 12.6051, -3.19768,
|
||||||
|
9.60466, -4.56494, 10.1616, 15.5594, 6.89224, -31.5602,
|
||||||
|
-11.5625, -23.0872, 34.9163, 12.3052, 7.67426, -1.26298,
|
||||||
|
2.5486, -3.90251, -19.1132, 7.6131, -31.0016, 12.4759,
|
||||||
|
2.74156, 12.4124, -39.5057, -0.325024, -22.9186, -28.5606,
|
||||||
|
6.30148, 15.4402, -2.6284, -20.1603, 5.22906, -12.3451,
|
||||||
|
-6.91862, 16.6335, -1.65064, 2.99602, -23.9479, -1.43947,
|
||||||
|
-14.3907, -31.417, 10.1113, 1.70013, -21.5733, 4.736,
|
||||||
|
-1.67171, 6.22751, -13.7187, 21.0936, -9.69243, -10.5756,
|
||||||
|
2.15266, 21.2198, -13.0171, -1.43135, 18.8831, 10.6664,
|
||||||
|
13.8913, 27.3565, 0.472838, -7.40477, -14.8705, 25.7448,
|
||||||
|
28.402, -2.05484, -9.32712, -17.3169, 15.643, 6.96908,
|
||||||
|
-15.863, -17.8482, -24.9238, 12.5574, 7.17566, 0.0161972,
|
||||||
|
5.99291, -41.0228, 1.95791, -6.78012, 9.20162, 4.6234,
|
||||||
|
-6.33629, -7.61679, 27.7318, -8.9214, -14.1931, 7.88247,
|
||||||
|
-12.2367, -21.245, -2.5927, 13.7776, -2.7864, -24.5072,
|
||||||
|
23.15, -9.93687, -2.92559, 3.88086, 11.2667, 11.1998,
|
||||||
|
9.67437, -9.4269, 6.2582, 36.5694, 2.88654, 1.82052,
|
||||||
|
15.385, -2.88243, 19.8377, -14.5111, 5.92264, -2.55757,
|
||||||
|
-20.9648, 3.76147, 18.5074, -13.5547, -7.84261, -19.98,
|
||||||
|
24.6032, 16.989, -19.1622, 1.35535, -0.0122027, 0.166227,
|
||||||
|
9.98886, -6.89666, -20.5111, -2.89196, 2.58467, -17.049,
|
||||||
|
-9.17761, -23.7209, 12.6088, -18.2654, 2.17718, -13.0865,
|
||||||
|
-9.73326, -12.2682, 6.80914, 20.3469, -10.2912, 4.85191,
|
||||||
|
-5.19406, 6.78014, 18.0099, 14.3782, -0.124328, -10.0141,
|
||||||
|
-4.69806, 6.71393, -19.1371, 8.19814, 23.3987, -10.3316,
|
||||||
|
1.02965, -4.63654, 21.9822, 11.5088, -30.9617, -20.6354,
|
||||||
|
-33.2824, 31.4666, -11.4837, 11.5144, -1.36834, 9.44599,
|
||||||
|
-37.5431, -3.16317, -2.09497, -2.62712, 40.4714, -33.0527,
|
||||||
|
-8.79595, -15.5174, -15.7916, 7.97003, 37.2542, 40.7063,
|
||||||
|
-14.7261, -12.6884, 2.42105, -10.2686, 25.9033, 14.8525,
|
||||||
|
22.9598, -16.6224, -3.64949, 4.44269, -22.3897, 13.6968,
|
||||||
|
-10.874, 4.18931, -24.2284, -3.63764, -15.1379, 40.9515,
|
||||||
|
28.2393, -8.63225, -12.544, 28.8282, -0.987894, -4.9824,
|
||||||
|
-25.0777, -0.481678, -3.37082, 5.55114, -9.89898, -8.07628,
|
||||||
|
23.3581, 3.12034, -8.63348, 0.63042, -18.2216, -22.1886,
|
||||||
|
44.9505, 19.8267, 23.7129, 8.58075, 7.80458, 1.78796,
|
||||||
|
-8.13112, -2.1262, -7.12776, -25.0529, -16.7287, 8.41402,
|
||||||
|
2.01965, 19.2579, 20.0963, 5.99199, 28.1098, 5.96128,
|
||||||
|
2.42493, -6.33216, -26.5858, -23.8607, 8.27049, 3.05805,
|
||||||
|
0.0153248, 0.446112, -4.92759, 19.0023, 22.7346, 15.5451,
|
||||||
|
-7.39591, 40.285, 10.8414, 25.7961, -8.81069, -13.5,
|
||||||
|
5.81306, 11.2384, 6.93765, -9.43067, 9.51418, 22.9709,
|
||||||
|
-9.17611, -16.4993, -1.56929, -2.9111, 4.17113, 10.9228,
|
||||||
|
10.0376, -27.4993, -8.25332, -1.715, -11.5063, -10.467,
|
||||||
|
23.6637, -13.8338, 14.7284, 8.00341, -2.71881, -8.80708,
|
||||||
|
27.101, 2.42801, 11.4599, -24.1577, -20.9901, 4.52358,
|
||||||
|
16.8065, 19.3315, 11.1219, 13.3391, -13.1522, 0.91428,
|
||||||
|
-25.2603, 6.04837, 12.1994, 21.9372, 14.8795, 6.93368,
|
||||||
|
-1.24639, -7.96856, 16.4064, -2.36409, -25.9093, 46.0938,
|
||||||
|
8.81687, 24.8004, 11.4475, -13.261, -19.8693, -28.4793,
|
||||||
|
15.3175, -12.5335, 24.1778, 10.5133, 22.2244, 9.93191,
|
||||||
|
-18.7982, 38.939, -20.0631, -35.4052, 7.5879, -0.599373,
|
||||||
|
-18.1388, 9.5843, 17.4375, -21.057, 8.1634, 6.31216,
|
||||||
|
-61.5486, -8.71159, 19.7502, -25.2365, 3.56558, -1.64973,
|
||||||
|
-26.9863, 0.291017, -12.5337, -10.505, 11.0614, 4.84072,
|
||||||
|
-0.630579, -3.87056, -0.707795, -13.1306, -19.6548, -16.2436,
|
||||||
|
4.87022, -5.90744, 3.46971, -40.0866, 16.8741, 10.3333,
|
||||||
|
-1.00985, 16.234, -0.475836, 28.3848, 1.75473, 28.2608
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct lsp_codebook lspmelvq_cb[] = {
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lspmelvq1.txt */
|
||||||
|
{
|
||||||
|
6,
|
||||||
|
6,
|
||||||
|
64,
|
||||||
|
codes0
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lspmelvq2.txt */
|
||||||
|
{
|
||||||
|
6,
|
||||||
|
6,
|
||||||
|
64,
|
||||||
|
codes1
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/lspmelvq3.txt */
|
||||||
|
{
|
||||||
|
6,
|
||||||
|
6,
|
||||||
|
64,
|
||||||
|
codes2
|
||||||
|
},
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
/* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This intermediary file and the files that used to create it are under
|
||||||
|
* The LGPL. See the file COPYING.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel1.txt */
|
||||||
|
static const float codes0[] = {
|
||||||
|
550,
|
||||||
|
600,
|
||||||
|
650,
|
||||||
|
700,
|
||||||
|
750,
|
||||||
|
800,
|
||||||
|
850,
|
||||||
|
900
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel2.txt */
|
||||||
|
static const float codes1[] = {
|
||||||
|
50,
|
||||||
|
100,
|
||||||
|
200,
|
||||||
|
300
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel3.txt */
|
||||||
|
static const float codes2[] = {
|
||||||
|
800,
|
||||||
|
850,
|
||||||
|
900,
|
||||||
|
950,
|
||||||
|
1000,
|
||||||
|
1050,
|
||||||
|
1100,
|
||||||
|
1150,
|
||||||
|
1200,
|
||||||
|
1250,
|
||||||
|
1300,
|
||||||
|
1350,
|
||||||
|
1400,
|
||||||
|
1450,
|
||||||
|
1500,
|
||||||
|
1650
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel4.txt */
|
||||||
|
static const float codes3[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
175,
|
||||||
|
250
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel5.txt */
|
||||||
|
static const float codes4[] = {
|
||||||
|
1350,
|
||||||
|
1400,
|
||||||
|
1450,
|
||||||
|
1500,
|
||||||
|
1550,
|
||||||
|
1600,
|
||||||
|
1650,
|
||||||
|
1700
|
||||||
|
};
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel6.txt */
|
||||||
|
static const float codes5[] = {
|
||||||
|
25,
|
||||||
|
50,
|
||||||
|
100,
|
||||||
|
150
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct lsp_codebook mel_cb[] = {
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel1.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
8,
|
||||||
|
codes0
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel2.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
codes1
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel3.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
16,
|
||||||
|
codes2
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel4.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
8,
|
||||||
|
codes3
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel5.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
8,
|
||||||
|
codes4
|
||||||
|
},
|
||||||
|
/* /Users/brandon/freetel-code/codec2/branches/0.6/src/codebook/mel6.txt */
|
||||||
|
{
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
codes5
|
||||||
|
},
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,69 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: codec2.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 21 August 2010
|
||||||
|
|
||||||
|
Codec 2 fully quantised encoder and decoder functions. If you want use
|
||||||
|
Codec 2, these are the functions you need to call.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2010 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __CODEC2__
|
||||||
|
#define __CODEC2__
|
||||||
|
|
||||||
|
#define CODEC2_MODE_3200 0
|
||||||
|
#define CODEC2_MODE_2400 1
|
||||||
|
#define CODEC2_MODE_1600 2
|
||||||
|
#define CODEC2_MODE_1400 3
|
||||||
|
#define CODEC2_MODE_1300 4
|
||||||
|
#define CODEC2_MODE_1200 5
|
||||||
|
#define CODEC2_MODE_700 6
|
||||||
|
#define CODEC2_MODE_700B 7
|
||||||
|
#define CODEC2_MODE_700C 8
|
||||||
|
|
||||||
|
struct CODEC2;
|
||||||
|
|
||||||
|
struct CODEC2 * codec2_create(int mode);
|
||||||
|
void codec2_destroy(struct CODEC2 *codec2_state);
|
||||||
|
void codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits, short speech_in[]);
|
||||||
|
void codec2_decode(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits);
|
||||||
|
void codec2_decode_ber(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits, float ber_est);
|
||||||
|
int codec2_samples_per_frame(struct CODEC2 *codec2_state);
|
||||||
|
int codec2_bits_per_frame(struct CODEC2 *codec2_state);
|
||||||
|
|
||||||
|
void codec2_set_lpc_post_filter(struct CODEC2 *codec2_state, int enable, int bass_boost, float beta, float gamma);
|
||||||
|
int codec2_get_spare_bit_index(struct CODEC2 *codec2_state);
|
||||||
|
int codec2_rebuild_spare_bit(struct CODEC2 *codec2_state, int unpacked_bits[]);
|
||||||
|
void codec2_set_natural_or_gray(struct CODEC2 *codec2_state, int gray);
|
||||||
|
void codec2_set_softdec(struct CODEC2 *c2, float *softdec);
|
||||||
|
float codec2_get_energy(struct CODEC2 *codec2_state, const unsigned char *bits);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: codec2_cohpsk.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: March 2015
|
||||||
|
|
||||||
|
Functions that implement a coherent PSK FDM modem.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CODEC2_COHPSK__
|
||||||
|
#define __CODEC2_COHPSK__
|
||||||
|
|
||||||
|
#define COHPSK_BITS_PER_FRAME 56 /* hard coded for now */
|
||||||
|
#define COHPSK_NC 7 /* hard coded for now */
|
||||||
|
#define COHPSK_NOM_SAMPLES_PER_FRAME 600
|
||||||
|
#define COHPSK_MAX_SAMPLES_PER_FRAME 625
|
||||||
|
#define COHPSK_RS 75
|
||||||
|
#define COHPSK_FS 7500 /* note this is a wierd
|
||||||
|
value to get an integer
|
||||||
|
oversampling rate */
|
||||||
|
|
||||||
|
#include "comp.h"
|
||||||
|
#include "modem_stats.h"
|
||||||
|
|
||||||
|
struct COHPSK;
|
||||||
|
|
||||||
|
extern const int test_bits_coh[];
|
||||||
|
|
||||||
|
struct COHPSK *cohpsk_create(void);
|
||||||
|
void cohpsk_destroy(struct COHPSK *coh);
|
||||||
|
void cohpsk_mod(struct COHPSK *cohpsk, COMP tx_fdm[], int tx_bits[], int nbits);
|
||||||
|
void cohpsk_clip(COMP tx_fdm[]);
|
||||||
|
void cohpsk_demod(struct COHPSK *cohpsk, float rx_bits[], int *sync, COMP rx_fdm[], int *nin_frame);
|
||||||
|
void cohpsk_get_demod_stats(struct COHPSK *cohpsk, struct MODEM_STATS *stats);
|
||||||
|
void cohpsk_set_verbose(struct COHPSK *coh, int verbose);
|
||||||
|
void cohpsk_get_test_bits(struct COHPSK *coh, int rx_bits[]);
|
||||||
|
void cohpsk_put_test_bits(struct COHPSK *coh, int *state, short error_pattern[],
|
||||||
|
int *bit_errors, char rx_bits[], int channel);
|
||||||
|
int cohpsk_error_pattern_size(void);
|
||||||
|
void cohpsk_set_frame(struct COHPSK *coh, int frame);
|
||||||
|
void fdmdv_freq_shift_coh(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, float Fs,
|
||||||
|
COMP *foff_phase_rect, int nin);
|
||||||
|
|
||||||
|
/* used for accessing upper and lower bits before diversity combination */
|
||||||
|
|
||||||
|
float *cohpsk_get_rx_bits_lower(struct COHPSK *coh);
|
||||||
|
float *cohpsk_get_rx_bits_upper(struct COHPSK *coh);
|
||||||
|
void cohpsk_set_carrier_ampl(struct COHPSK *coh, int c, float ampl);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: codec2_fdmdv.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: April 14 2012
|
||||||
|
|
||||||
|
A 1400 bit/s (nominal) Frequency Division Multiplexed Digital Voice
|
||||||
|
(FDMDV) modem. Used for digital audio over HF SSB. See
|
||||||
|
README_fdmdv.txt for more information, and fdmdv_mod.c and
|
||||||
|
fdmdv_demod.c for example usage.
|
||||||
|
|
||||||
|
The name codec2_fdmdv.h is used to make it unique when "make
|
||||||
|
installed".
|
||||||
|
|
||||||
|
References:
|
||||||
|
|
||||||
|
[1] http://n1su.com/fdmdv/FDMDV_Docs_Rel_1_4b.pdf
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __FDMDV__
|
||||||
|
#define __FDMDV__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* set up the calling convention for DLL function import/export for
|
||||||
|
WIN32 cross compiling */
|
||||||
|
|
||||||
|
#ifdef __CODEC2_WIN32__
|
||||||
|
#ifdef __CODEC2_BUILDING_DLL__
|
||||||
|
#define CODEC2_WIN32SUPPORT __declspec(dllexport) __stdcall
|
||||||
|
#else
|
||||||
|
#define CODEC2_WIN32SUPPORT __declspec(dllimport) __stdcall
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define CODEC2_WIN32SUPPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "comp.h"
|
||||||
|
#include "modem_stats.h"
|
||||||
|
|
||||||
|
#define FDMDV_NC 14 /* default number of data carriers */
|
||||||
|
#define FDMDV_NC_MAX 20 /* maximum number of data carriers */
|
||||||
|
#define FDMDV_BITS_PER_FRAME 28 /* 20ms frames, for nominal 1400 bit/s */
|
||||||
|
#define FDMDV_NOM_SAMPLES_PER_FRAME 160 /* modulator output samples/frame and nominal demod samples/frame */
|
||||||
|
/* at 8000 Hz sample rate */
|
||||||
|
#define FDMDV_MAX_SAMPLES_PER_FRAME 200 /* max demod samples/frame, use this to allocate storage */
|
||||||
|
#define FDMDV_SCALE 1000 /* suggested scaling for 16 bit shorts */
|
||||||
|
#define FDMDV_FCENTRE 1500 /* Centre frequency, Nc/2 carriers below this, Nc/2 carriers above (Hz) */
|
||||||
|
|
||||||
|
/* 8 to 48 kHz sample rate conversion */
|
||||||
|
|
||||||
|
#define FDMDV_OS 2 /* oversampling rate */
|
||||||
|
#define FDMDV_OS_TAPS_16K 48 /* number of OS filter taps at 16kHz */
|
||||||
|
#define FDMDV_OS_TAPS_8K (FDMDV_OS_TAPS_16K/FDMDV_OS) /* number of OS filter taps at 8kHz */
|
||||||
|
|
||||||
|
/* FDMDV states and stats structures */
|
||||||
|
|
||||||
|
struct FDMDV;
|
||||||
|
|
||||||
|
struct FDMDV * fdmdv_create(int Nc);
|
||||||
|
void fdmdv_destroy(struct FDMDV *fdmdv_state);
|
||||||
|
void fdmdv_use_old_qpsk_mapping(struct FDMDV *fdmdv_state);
|
||||||
|
int fdmdv_bits_per_frame(struct FDMDV *fdmdv_state);
|
||||||
|
float fdmdv_get_fsep(struct FDMDV *fdmdv_state);
|
||||||
|
void fdmdv_set_fsep(struct FDMDV *fdmdv_state, float fsep);
|
||||||
|
|
||||||
|
void fdmdv_mod(struct FDMDV *fdmdv_state, COMP tx_fdm[], int tx_bits[], int *sync_bit);
|
||||||
|
void fdmdv_demod(struct FDMDV *fdmdv_state, int rx_bits[], int *reliable_sync_bit, COMP rx_fdm[], int *nin);
|
||||||
|
|
||||||
|
void fdmdv_get_test_bits(struct FDMDV *fdmdv_state, int tx_bits[]);
|
||||||
|
int fdmdv_error_pattern_size(struct FDMDV *fdmdv_state);
|
||||||
|
void fdmdv_put_test_bits(struct FDMDV *f, int *sync, short error_pattern[], int *bit_errors, int *ntest_bits, int rx_bits[]);
|
||||||
|
|
||||||
|
void fdmdv_get_demod_stats(struct FDMDV *fdmdv_state, struct MODEM_STATS *stats);
|
||||||
|
|
||||||
|
void fdmdv_8_to_16(float out16k[], float in8k[], int n);
|
||||||
|
void fdmdv_8_to_16_short(short out16k[], short in8k[], int n);
|
||||||
|
void fdmdv_16_to_8(float out8k[], float in16k[], int n);
|
||||||
|
void fdmdv_16_to_8_short(short out8k[], short in16k[], int n);
|
||||||
|
|
||||||
|
void fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, COMP *foff_phase_rect, int nin);
|
||||||
|
|
||||||
|
/* debug/development function(s) */
|
||||||
|
|
||||||
|
void fdmdv_dump_osc_mags(struct FDMDV *f);
|
||||||
|
void fdmdv_simulate_channel(float *sig_pwr_av, COMP samples[], int nin, float target_snr);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* codec2_fft.c
|
||||||
|
*
|
||||||
|
* Created on: 24.09.2016
|
||||||
|
* Author: danilo
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "codec2_fft.h"
|
||||||
|
#ifdef USE_KISS_FFT
|
||||||
|
#include "_kiss_fft_guts.h"
|
||||||
|
|
||||||
|
#else
|
||||||
|
#if 0
|
||||||
|
// caching constants in RAM did not seem to have an effect on performance
|
||||||
|
// TODO: Decide what to with this code
|
||||||
|
#define FFT_INIT_CACHE_SIZE 4
|
||||||
|
const arm_cfft_instance_f32* fft_init_cache[FFT_INIT_CACHE_SIZE];
|
||||||
|
|
||||||
|
static const arm_cfft_instance_f32* arm_fft_instance2ram(const arm_cfft_instance_f32* in)
|
||||||
|
{
|
||||||
|
|
||||||
|
arm_cfft_instance_f32* out = malloc(sizeof(arm_cfft_instance_f32));
|
||||||
|
|
||||||
|
if (out) {
|
||||||
|
memcpy(out,in,sizeof(arm_cfft_instance_f32));
|
||||||
|
out->pBitRevTable = malloc(out->bitRevLength * sizeof(uint16_t));
|
||||||
|
out->pTwiddle = malloc(out->fftLen * sizeof(float32_t));
|
||||||
|
memcpy((void*)out->pBitRevTable,in->pBitRevTable,out->bitRevLength * sizeof(uint16_t));
|
||||||
|
memcpy((void*)out->pTwiddle,in->pTwiddle,out->fftLen * sizeof(float32_t));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const arm_cfft_instance_f32* arm_fft_cache_get(const arm_cfft_instance_f32* romfft)
|
||||||
|
{
|
||||||
|
const arm_cfft_instance_f32* retval = NULL;
|
||||||
|
static int used = 0;
|
||||||
|
for (int i = 0; fft_init_cache[i] != NULL && i < used; i++)
|
||||||
|
{
|
||||||
|
if (romfft->fftLen == fft_init_cache[i]->fftLen)
|
||||||
|
{
|
||||||
|
retval = fft_init_cache[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (retval == NULL && used < FFT_INIT_CACHE_SIZE)
|
||||||
|
{
|
||||||
|
retval = arm_fft_instance2ram(romfft);
|
||||||
|
fft_init_cache[used++] = retval;
|
||||||
|
}
|
||||||
|
if (retval == NULL)
|
||||||
|
{
|
||||||
|
retval = romfft;
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void codec2_fft_free(codec2_fft_cfg cfg)
|
||||||
|
{
|
||||||
|
#ifdef USE_KISS_FFT
|
||||||
|
KISS_FFT_FREE(cfg);
|
||||||
|
#else
|
||||||
|
free(cfg);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
codec2_fft_cfg codec2_fft_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem)
|
||||||
|
{
|
||||||
|
codec2_fft_cfg retval;
|
||||||
|
#ifdef USE_KISS_FFT
|
||||||
|
retval = kiss_fft_alloc(nfft, inverse_fft, mem, lenmem);
|
||||||
|
#else
|
||||||
|
retval = malloc(sizeof(codec2_fft_struct));
|
||||||
|
retval->inverse = inverse_fft;
|
||||||
|
switch(nfft)
|
||||||
|
{
|
||||||
|
case 128:
|
||||||
|
retval->instance = &arm_cfft_sR_f32_len128;
|
||||||
|
break;
|
||||||
|
case 256:
|
||||||
|
retval->instance = &arm_cfft_sR_f32_len256;
|
||||||
|
break;
|
||||||
|
case 512:
|
||||||
|
retval->instance = &arm_cfft_sR_f32_len512;
|
||||||
|
break;
|
||||||
|
// case 1024:
|
||||||
|
// retval->instance = &arm_cfft_sR_f32_len1024;
|
||||||
|
// break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
// retval->instance = arm_fft_cache_get(retval->instance);
|
||||||
|
#endif
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
codec2_fftr_cfg codec2_fftr_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem)
|
||||||
|
{
|
||||||
|
codec2_fftr_cfg retval;
|
||||||
|
#ifdef USE_KISS_FFT
|
||||||
|
retval = kiss_fftr_alloc(nfft, inverse_fft, mem, lenmem);
|
||||||
|
#else
|
||||||
|
retval = malloc(sizeof(codec2_fftr_struct));
|
||||||
|
retval->inverse = inverse_fft;
|
||||||
|
retval->instance = malloc(sizeof(arm_rfft_fast_instance_f32));
|
||||||
|
arm_rfft_fast_init_f32(retval->instance,nfft);
|
||||||
|
// memcpy(&retval->instance->Sint,arm_fft_cache_get(&retval->instance->Sint),sizeof(arm_cfft_instance_f32));
|
||||||
|
#endif
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
void codec2_fftr_free(codec2_fftr_cfg cfg)
|
||||||
|
{
|
||||||
|
#ifdef USE_KISS_FFT
|
||||||
|
KISS_FFT_FREE(cfg);
|
||||||
|
#else
|
||||||
|
free(cfg->instance);
|
||||||
|
free(cfg);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// there is a little overhead for inplace kiss_fft but this is
|
||||||
|
// on the powerful platforms like the Raspberry or even x86 PC based ones
|
||||||
|
// not noticeable
|
||||||
|
// the reduced usage of RAM and increased performance on STM32 platforms
|
||||||
|
// should be worth it.
|
||||||
|
void codec2_fft_inplace(codec2_fft_cfg cfg, codec2_fft_cpx* inout)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef USE_KISS_FFT
|
||||||
|
kiss_fft_cpx in[512];
|
||||||
|
// decide whether to use the local stack based buffer for in
|
||||||
|
// or to allow kiss_fft to allocate RAM
|
||||||
|
// second part is just to play safe since first method
|
||||||
|
// is much faster and uses less RAM
|
||||||
|
if (cfg->nfft <= 512)
|
||||||
|
{
|
||||||
|
memcpy(in,inout,cfg->nfft*sizeof(kiss_fft_cpx));
|
||||||
|
kiss_fft(cfg, in, (kiss_fft_cpx*)inout);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
kiss_fft(cfg, (kiss_fft_cpx*)inout, (kiss_fft_cpx*)inout);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
arm_cfft_f32(cfg->instance,(float*)inout,cfg->inverse,1);
|
||||||
|
if (cfg->inverse)
|
||||||
|
{
|
||||||
|
arm_scale_f32(inout,cfg->instance->fftLen,inout,cfg->instance->fftLen*2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* codec2_fft.h
|
||||||
|
*
|
||||||
|
* Created on: 17.09.2016
|
||||||
|
* Author: danilo
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DRIVERS_FREEDV_CODEC2_FFT_H_
|
||||||
|
#define DRIVERS_FREEDV_CODEC2_FFT_H_
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#ifdef ARM_MATH_CM4
|
||||||
|
#include "stm32f4xx.h"
|
||||||
|
#include "core_cm4.h"
|
||||||
|
#include "arm_math.h"
|
||||||
|
#include "arm_const_structs.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
#include "comp.h"
|
||||||
|
|
||||||
|
#ifndef ARM_MATH_CM4
|
||||||
|
#define USE_KISS_FFT
|
||||||
|
#endif
|
||||||
|
// #define USE_KISS_FFT
|
||||||
|
|
||||||
|
|
||||||
|
typedef COMP codec2_fft_cpx;
|
||||||
|
#include "kiss_fftr.h"
|
||||||
|
|
||||||
|
#ifdef USE_KISS_FFT
|
||||||
|
#include "kiss_fft.h"
|
||||||
|
typedef kiss_fftr_cfg codec2_fftr_cfg;
|
||||||
|
typedef kiss_fft_cfg codec2_fft_cfg;
|
||||||
|
typedef kiss_fft_scalar codec2_fft_scalar;
|
||||||
|
#else
|
||||||
|
typedef float32_t codec2_fft_scalar;
|
||||||
|
typedef struct {
|
||||||
|
arm_rfft_fast_instance_f32* instance;
|
||||||
|
int inverse;
|
||||||
|
} codec2_fftr_struct;
|
||||||
|
|
||||||
|
typedef codec2_fftr_struct* codec2_fftr_cfg;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const arm_cfft_instance_f32* instance;
|
||||||
|
int inverse;
|
||||||
|
} codec2_fft_struct;
|
||||||
|
typedef codec2_fft_struct* codec2_fft_cfg;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static inline void codec2_fftr(codec2_fftr_cfg cfg, codec2_fft_scalar* in, codec2_fft_cpx* out)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef USE_KISS_FFT
|
||||||
|
kiss_fftr(cfg, in, (kiss_fft_cpx*)out);
|
||||||
|
#else
|
||||||
|
arm_rfft_fast_f32(cfg->instance,in,(float*)out,cfg->inverse);
|
||||||
|
out->imag = 0; // remove out[FFT_ENC/2]->real stored in out[0].imag
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void codec2_fftri(codec2_fftr_cfg cfg, codec2_fft_cpx* in, codec2_fft_scalar* out)
|
||||||
|
{
|
||||||
|
#ifdef USE_KISS_FFT
|
||||||
|
kiss_fftri(cfg, (kiss_fft_cpx*)in, out);
|
||||||
|
#else
|
||||||
|
arm_rfft_fast_f32(cfg->instance,(float*)in,out,cfg->inverse);
|
||||||
|
// arm_scale_f32(out,cfg->instance->fftLenRFFT,out,cfg->instance->fftLenRFFT);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
codec2_fft_cfg codec2_fft_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem);
|
||||||
|
codec2_fftr_cfg codec2_fftr_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem);
|
||||||
|
void codec2_fft_free(codec2_fft_cfg cfg);
|
||||||
|
void codec2_fftr_free(codec2_fftr_cfg cfg);
|
||||||
|
|
||||||
|
|
||||||
|
static inline void codec2_fft(codec2_fft_cfg cfg, codec2_fft_cpx* in, codec2_fft_cpx* out)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef USE_KISS_FFT
|
||||||
|
kiss_fft(cfg, (kiss_fft_cpx*)in, (kiss_fft_cpx*)out);
|
||||||
|
#else
|
||||||
|
memcpy(out,in,cfg->instance->fftLen*2*sizeof(float));
|
||||||
|
arm_cfft_f32(cfg->instance,(float*)out,cfg->inverse,0);
|
||||||
|
// TODO: this is not nice, but for now required to keep changes minimal
|
||||||
|
// however, since main goal is to reduce the memory usage
|
||||||
|
// we should convert to an in place interface
|
||||||
|
// on PC like platforms the overhead of using the "inplace" kiss_fft calls
|
||||||
|
// is neglectable compared to the gain in memory usage on STM32 platforms
|
||||||
|
if (cfg->inverse)
|
||||||
|
{
|
||||||
|
arm_scale_f32((float*)out,cfg->instance->fftLen,(float*)out,cfg->instance->fftLen*2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void codec2_fft_inplace(codec2_fft_cfg cfg, codec2_fft_cpx* inout);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: codec2_fifo.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: Oct 15 2012
|
||||||
|
|
||||||
|
A FIFO design useful in gluing the FDMDV modem and codec together in
|
||||||
|
integrated applications.
|
||||||
|
|
||||||
|
The name codec2_fifo.h is used to make it unique when "make
|
||||||
|
installed".
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __FIFO__
|
||||||
|
#define __FIFO__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct FIFO;
|
||||||
|
|
||||||
|
struct FIFO *fifo_create(int nshort);
|
||||||
|
void fifo_destroy(struct FIFO *fifo);
|
||||||
|
int fifo_write(struct FIFO *fifo, short data[], int n);
|
||||||
|
int fifo_read(struct FIFO *fifo, short data[], int n);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Return the number of bytes stored in the FIFO.
|
||||||
|
*/
|
||||||
|
int fifo_used(const struct FIFO * const fifo);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Return the space available in the FIFO.
|
||||||
|
*/
|
||||||
|
int fifo_free(const struct FIFO * const fifo);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: codec2_fm.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: February 2015
|
||||||
|
|
||||||
|
Functions that implement analog FM, see also octave/fm.m.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CODEC2_FM__
|
||||||
|
#define __CODEC2_FM__
|
||||||
|
|
||||||
|
#include "comp.h"
|
||||||
|
|
||||||
|
struct FM {
|
||||||
|
float Fs; /* setme: sample rate */
|
||||||
|
float fm_max; /* setme: maximum modulation frequency */
|
||||||
|
float fd; /* setme: maximum deviation */
|
||||||
|
float fc; /* setme: carrier frequency */
|
||||||
|
COMP *rx_bb;
|
||||||
|
COMP rx_bb_filt_prev;
|
||||||
|
float *rx_dem_mem;
|
||||||
|
float tx_phase;
|
||||||
|
int nsam;
|
||||||
|
COMP lo_phase;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FM *fm_create(int nsam);
|
||||||
|
void fm_destroy(struct FM *fm_states);
|
||||||
|
void fm_demod(struct FM *fm, float rx_out[], float rx[]);
|
||||||
|
void fm_mod(struct FM *fm, float tx_in[], float tx_out[]);
|
||||||
|
void fm_mod_comp(struct FM *fm_states, float tx_in[], COMP tx_out[]);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: codec2_internal.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: April 16 2012
|
||||||
|
|
||||||
|
Header file for Codec2 internal states, exposed via this header
|
||||||
|
file to assist in testing.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CODEC2_INTERNAL__
|
||||||
|
#define __CODEC2_INTERNAL__
|
||||||
|
|
||||||
|
#include "codec2_fft.h"
|
||||||
|
|
||||||
|
struct CODEC2 {
|
||||||
|
int mode;
|
||||||
|
C2CONST c2const;
|
||||||
|
int Fs;
|
||||||
|
int n_samp;
|
||||||
|
int m_pitch;
|
||||||
|
codec2_fft_cfg fft_fwd_cfg; /* forward FFT config */
|
||||||
|
codec2_fftr_cfg fftr_fwd_cfg; /* forward real FFT config */
|
||||||
|
float *w; /* [m_pitch] time domain hamming window */
|
||||||
|
COMP W[FFT_ENC]; /* DFT of w[] */
|
||||||
|
float *Pn; /* [2*n_samp] trapezoidal synthesis window */
|
||||||
|
float *bpf_buf; /* buffer for band pass filter */
|
||||||
|
float *Sn; /* [m_pitch] input speech */
|
||||||
|
float hpf_states[2]; /* high pass filter states */
|
||||||
|
void *nlp; /* pitch predictor states */
|
||||||
|
int gray; /* non-zero for gray encoding */
|
||||||
|
|
||||||
|
codec2_fftr_cfg fftr_inv_cfg; /* inverse FFT config */
|
||||||
|
float *Sn_; /* [2*n_samp] synthesised output speech */
|
||||||
|
float ex_phase; /* excitation model phase track */
|
||||||
|
float bg_est; /* background noise estimate for post filter */
|
||||||
|
float prev_f0_enc; /* previous frame's f0 estimate */
|
||||||
|
MODEL prev_model_dec; /* previous frame's model parameters */
|
||||||
|
float prev_lsps_dec[LPC_ORD]; /* previous frame's LSPs */
|
||||||
|
float prev_e_dec; /* previous frame's LPC energy */
|
||||||
|
|
||||||
|
int lpc_pf; /* LPC post filter on */
|
||||||
|
int bass_boost; /* LPC post filter bass boost */
|
||||||
|
float beta; /* LPC post filter parameters */
|
||||||
|
float gamma;
|
||||||
|
|
||||||
|
float xq_enc[2]; /* joint pitch and energy VQ states */
|
||||||
|
float xq_dec[2];
|
||||||
|
|
||||||
|
int smoothing; /* enable smoothing for channels with errors */
|
||||||
|
float *softdec; /* optional soft decn bits from demod */
|
||||||
|
|
||||||
|
/* newamp1 states */
|
||||||
|
|
||||||
|
float Wo_left;
|
||||||
|
int voicing_left;
|
||||||
|
codec2_fft_cfg phase_fft_fwd_cfg;
|
||||||
|
codec2_fft_cfg phase_fft_inv_cfg;
|
||||||
|
};
|
||||||
|
|
||||||
|
// test and debug
|
||||||
|
void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]);
|
||||||
|
void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model,
|
||||||
|
COMP Aw[]);
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: codec2_ofdm.h
|
||||||
|
AUTHORS.....: David Rowe & Steve Sampson
|
||||||
|
DATE CREATED: June 2017
|
||||||
|
|
||||||
|
External user references to the modem library.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2017 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CODEC2_OFDM_H
|
||||||
|
#define CODEC2_OFDM_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes */
|
||||||
|
|
||||||
|
#include <complex.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "comp.h"
|
||||||
|
|
||||||
|
/* Defines */
|
||||||
|
|
||||||
|
struct OFDM;
|
||||||
|
|
||||||
|
/* Prototypes */
|
||||||
|
|
||||||
|
struct OFDM *ofdm_create(void);
|
||||||
|
void ofdm_destroy(struct OFDM *);
|
||||||
|
void ofdm_mod(struct OFDM *, COMP *, const int *);
|
||||||
|
void ofdm_demod(struct OFDM *, int *, COMP *);
|
||||||
|
int ofdm_get_nin(struct OFDM *);
|
||||||
|
int ofdm_get_samples_per_frame(void);
|
||||||
|
int ofdm_get_max_samples_per_frame(void);
|
||||||
|
|
||||||
|
/* option setters */
|
||||||
|
|
||||||
|
void ofdm_set_verbose(struct OFDM *, int);
|
||||||
|
void ofdm_set_timing_enable(struct OFDM *, bool);
|
||||||
|
void ofdm_set_foff_est_enable(struct OFDM *, bool);
|
||||||
|
void ofdm_set_phase_est_enable(struct OFDM *, bool);
|
||||||
|
void ofdm_set_off_est_hz(struct OFDM *, float);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/* Generated by write_pilot_file() Octave function */
|
||||||
|
|
||||||
|
#define NSYMROW 4 /* number of data symbols per carrier (number of rows) */
|
||||||
|
#define NS 4 /* number of data symbols between pilots */
|
||||||
|
#define NPILOTSFRAME 2 /* number of pilot symbols per carrier */
|
||||||
|
#define PILOTS_NC 7 /* number of carriers */
|
||||||
|
|
||||||
|
#define NSYMROWPILOT 6 /* number of rows after pilots inserted */
|
||||||
|
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: cohpsk_internal.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: March 2015
|
||||||
|
|
||||||
|
Functions that implement a coherent PSK FDM modem.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __COHPSK_INTERNAL__
|
||||||
|
#define __COHPSK_INTERNAL__
|
||||||
|
|
||||||
|
#define NCT_SYMB_BUF (2*NSYMROWPILOT+2)
|
||||||
|
#define ND 2 /* diversity factor ND 1 is no diveristy, ND we have orginal plus
|
||||||
|
one copy */
|
||||||
|
#define NSW 4 /* number of sync window frames */
|
||||||
|
#define COHPSK_ND 2 /* diversity factor */
|
||||||
|
#define COHPSK_M 100 /* oversampling rate */
|
||||||
|
#define COHPSK_NSYM 6
|
||||||
|
#define COHPSK_NFILTER (COHPSK_NSYM*COHPSK_M)
|
||||||
|
#define COHPSK_EXCESS_BW 0.5 /* excess BW factor of root nyq filter */
|
||||||
|
#define COHPSK_NT 5 /* number of symbols we estimate timing over */
|
||||||
|
#define COHPSK_CLIP 6.5 /* hard clipping for Nc*Nc=14 to reduce PAPR */
|
||||||
|
|
||||||
|
#include "fdmdv_internal.h"
|
||||||
|
#include "kiss_fft.h"
|
||||||
|
|
||||||
|
struct COHPSK {
|
||||||
|
COMP ch_fdm_frame_buf[NSW*NSYMROWPILOT*COHPSK_M]; /* buffer of several frames of symbols from channel */
|
||||||
|
float pilot2[2*NPILOTSFRAME][COHPSK_NC];
|
||||||
|
float phi_[NSYMROWPILOT][COHPSK_NC*ND]; /* phase estimates for this frame of rx data symbols */
|
||||||
|
float amp_[NSYMROW][COHPSK_NC*ND]; /* amplitude estimates for this frame of rx data symbols */
|
||||||
|
COMP rx_symb[NSYMROWPILOT][COHPSK_NC*ND]; /* demodulated symbols */
|
||||||
|
float f_est;
|
||||||
|
COMP rx_filter_memory[COHPSK_NC*ND][COHPSK_NFILTER];
|
||||||
|
COMP ct_symb_buf[NCT_SYMB_BUF][COHPSK_NC*ND];
|
||||||
|
int ct; /* coarse timing offset in symbols */
|
||||||
|
float rx_timing; /* fine timing for last symbol in frame */
|
||||||
|
int nin; /* number of samples to input for next symbol */
|
||||||
|
float f_fine_est;
|
||||||
|
COMP ff_rect;
|
||||||
|
COMP ff_phase;
|
||||||
|
COMP ct_symb_ff_buf[NSYMROWPILOT+2][COHPSK_NC*ND];
|
||||||
|
int sync;
|
||||||
|
int sync_timer;
|
||||||
|
|
||||||
|
int frame;
|
||||||
|
float ratio;
|
||||||
|
|
||||||
|
float sig_rms;
|
||||||
|
float noise_rms;
|
||||||
|
|
||||||
|
struct FDMDV *fdmdv;
|
||||||
|
|
||||||
|
int verbose;
|
||||||
|
|
||||||
|
int *ptest_bits_coh_tx;
|
||||||
|
int *ptest_bits_coh_rx[2];
|
||||||
|
int *ptest_bits_coh_end;
|
||||||
|
|
||||||
|
/* counting bit errors using pilots */
|
||||||
|
|
||||||
|
int npilotbits;
|
||||||
|
int npilotbiterrors;
|
||||||
|
|
||||||
|
/* optional log variables used for testing Octave to C port */
|
||||||
|
|
||||||
|
COMP *rx_baseband_log;
|
||||||
|
int rx_baseband_log_col_index;
|
||||||
|
int rx_baseband_log_col_sz;
|
||||||
|
|
||||||
|
COMP *rx_filt_log;
|
||||||
|
int rx_filt_log_col_index;
|
||||||
|
int rx_filt_log_col_sz;
|
||||||
|
|
||||||
|
COMP *ch_symb_log;
|
||||||
|
int ch_symb_log_r;
|
||||||
|
int ch_symb_log_col_sz;
|
||||||
|
|
||||||
|
float *rx_timing_log;
|
||||||
|
int rx_timing_log_index;
|
||||||
|
|
||||||
|
/* demodulated bits before diversity combination for test/instrumentation purposes */
|
||||||
|
|
||||||
|
float rx_bits_lower[COHPSK_BITS_PER_FRAME];
|
||||||
|
float rx_bits_upper[COHPSK_BITS_PER_FRAME];
|
||||||
|
|
||||||
|
/* tx amplitude weights for each carrier for test/instrumentation */
|
||||||
|
|
||||||
|
float carrier_ampl[COHPSK_NC*ND];
|
||||||
|
};
|
||||||
|
|
||||||
|
void bits_to_qpsk_symbols(COMP tx_symb[][COHPSK_NC*COHPSK_ND], int tx_bits[], int nbits);
|
||||||
|
void qpsk_symbols_to_bits(struct COHPSK *coh, float rx_bits[], COMP ct_symb_buf[][COHPSK_NC*COHPSK_ND]);
|
||||||
|
void tx_filter_and_upconvert_coh(COMP tx_fdm[], int Nc, COMP tx_symbols[],
|
||||||
|
COMP tx_filter_memory[COHPSK_NC][COHPSK_NSYM],
|
||||||
|
COMP phase_tx[], COMP freq[],
|
||||||
|
COMP *fbb_phase, COMP fbb_rect);
|
||||||
|
void fdm_downconvert_coh(COMP rx_baseband[COHPSK_NC][COHPSK_M+COHPSK_M/P], int Nc, COMP rx_fdm[], COMP phase_rx[], COMP freq[], int nin);
|
||||||
|
void rx_filter_coh(COMP rx_filt[COHPSK_NC+1][P+1], int Nc, COMP rx_baseband[COHPSK_NC+1][COHPSK_M+COHPSK_M/P], COMP rx_filter_memory[COHPSK_NC+1][COHPSK_NFILTER], int nin);
|
||||||
|
void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][COHPSK_NC*COHPSK_ND], int sync, int *next_sync);
|
||||||
|
void fine_freq_correct(struct COHPSK *coh, int sync, int next_sync);
|
||||||
|
int sync_state_machine(struct COHPSK *coh, int sync, int next_sync);
|
||||||
|
int cohpsk_fs_offset(COMP out[], COMP in[], int n, float sample_rate_ppm);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: comp.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 24/08/09
|
||||||
|
|
||||||
|
Complex number definition.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2009 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __COMP__
|
||||||
|
#define __COMP__
|
||||||
|
|
||||||
|
/* Complex number */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float real;
|
||||||
|
float imag;
|
||||||
|
} COMP;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: comp_prim.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: Marh 2015
|
||||||
|
|
||||||
|
Complex number maths primitives.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __COMP_PRIM__
|
||||||
|
#define __COMP_PRIM__
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTIONS
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
inline static COMP cneg(COMP a)
|
||||||
|
{
|
||||||
|
COMP res;
|
||||||
|
|
||||||
|
res.real = -a.real;
|
||||||
|
res.imag = -a.imag;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static COMP cconj(COMP a)
|
||||||
|
{
|
||||||
|
COMP res;
|
||||||
|
|
||||||
|
res.real = a.real;
|
||||||
|
res.imag = -a.imag;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static COMP cmult(COMP a, COMP b)
|
||||||
|
{
|
||||||
|
COMP res;
|
||||||
|
|
||||||
|
res.real = a.real*b.real - a.imag*b.imag;
|
||||||
|
res.imag = a.real*b.imag + a.imag*b.real;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static COMP fcmult(float a, COMP b)
|
||||||
|
{
|
||||||
|
COMP res;
|
||||||
|
|
||||||
|
res.real = a*b.real;
|
||||||
|
res.imag = a*b.imag;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static COMP cadd(COMP a, COMP b)
|
||||||
|
{
|
||||||
|
COMP res;
|
||||||
|
|
||||||
|
res.real = a.real + b.real;
|
||||||
|
res.imag = a.imag + b.imag;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static float cabsolute(COMP a)
|
||||||
|
{
|
||||||
|
return sqrtf(powf(a.real, 2.0) + powf(a.imag, 2.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Euler's formula in a new convenient function
|
||||||
|
*/
|
||||||
|
inline static COMP comp_exp_j(float phi){
|
||||||
|
COMP res;
|
||||||
|
res.real = cosf(phi);
|
||||||
|
res.imag = sinf(phi);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Quick and easy complex 0
|
||||||
|
*/
|
||||||
|
inline static COMP comp0(){
|
||||||
|
COMP res;
|
||||||
|
res.real = 0;
|
||||||
|
res.imag = 0;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Quick and easy complex subtract
|
||||||
|
*/
|
||||||
|
inline static COMP csub(COMP a, COMP b){
|
||||||
|
COMP res;
|
||||||
|
res.real = a.real-b.real;
|
||||||
|
res.imag = a.imag-b.imag;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compare the magnitude of a and b. if |a|>|b|, return true, otw false.
|
||||||
|
* This needs no square roots
|
||||||
|
*/
|
||||||
|
inline static int comp_mag_gt(COMP a,COMP b){
|
||||||
|
return ((a.real*a.real)+(a.imag*a.imag)) > ((b.real*b.real)+(b.imag*b.imag));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Normalize a complex number's magnitude to 1
|
||||||
|
*/
|
||||||
|
inline static COMP comp_normalize(COMP a){
|
||||||
|
COMP b;
|
||||||
|
float av = cabsolute(a);
|
||||||
|
b.real = a.real/av;
|
||||||
|
b.imag = a.imag/av;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: defines.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 23/4/93
|
||||||
|
|
||||||
|
Defines and structures used throughout the codec.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2009 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DEFINES__
|
||||||
|
#define __DEFINES__
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
DEFINES
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* General defines */
|
||||||
|
|
||||||
|
#define N_S 0.010 /* buffer size in s */
|
||||||
|
#define TW_S 0.005 /* trapezoidal synth window overlap */
|
||||||
|
#define MAX_AMP 160 /* maximum number of harmonics */
|
||||||
|
#ifndef PI
|
||||||
|
#define PI 3.141592654 /* mathematical constant */
|
||||||
|
#endif
|
||||||
|
#define TWO_PI 6.283185307 /* mathematical constant */
|
||||||
|
#define MAX_STR 2048 /* maximum string size */
|
||||||
|
|
||||||
|
#define FFT_ENC 512 /* size of FFT used for encoder */
|
||||||
|
#define FFT_DEC 512 /* size of FFT used in decoder */
|
||||||
|
#define V_THRESH 6.0 /* voicing threshold in dB */
|
||||||
|
#define LPC_ORD 10 /* LPC order */
|
||||||
|
#define LPC_ORD_LOW 6 /* LPC order for lower rates */
|
||||||
|
|
||||||
|
/* Pitch estimation defines */
|
||||||
|
|
||||||
|
#define M_PITCH_S 0.0400 /* pitch analysis window in s */
|
||||||
|
#define P_MIN_S 0.0025 /* minimum pitch period in s */
|
||||||
|
#define P_MAX_S 0.0200 /* maximum pitch period in s */
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
TYPEDEFS
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Structure to hold constants calculated at run time based on sample rate */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int Fs; /* sample rate of this instance */
|
||||||
|
int n_samp; /* number of samples per 10ms frame at Fs */
|
||||||
|
int max_amp; /* maximum number of harmonics */
|
||||||
|
int m_pitch; /* pitch estimation window size in samples */
|
||||||
|
int p_min; /* minimum pitch period in samples */
|
||||||
|
int p_max; /* maximum pitch period in samples */
|
||||||
|
float Wo_min;
|
||||||
|
float Wo_max;
|
||||||
|
int nw; /* analysis window size in samples */
|
||||||
|
int tw; /* trapezoidal synthesis window overlap */
|
||||||
|
} C2CONST;
|
||||||
|
|
||||||
|
/* Structure to hold model parameters for one frame */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float Wo; /* fundamental frequency estimate in radians */
|
||||||
|
int L; /* number of harmonics */
|
||||||
|
float A[MAX_AMP+1]; /* amplitiude of each harmonic */
|
||||||
|
float phi[MAX_AMP+1]; /* phase of each harmonic */
|
||||||
|
int voiced; /* non-zero if this frame is voiced */
|
||||||
|
} MODEL;
|
||||||
|
|
||||||
|
/* describes each codebook */
|
||||||
|
|
||||||
|
struct lsp_codebook {
|
||||||
|
int k; /* dimension of vector */
|
||||||
|
int log2m; /* number of bits in m */
|
||||||
|
int m; /* elements in codebook */
|
||||||
|
const float * cb; /* The elements */
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const struct lsp_codebook lsp_cb[];
|
||||||
|
extern const struct lsp_codebook lsp_cbd[];
|
||||||
|
extern const struct lsp_codebook lsp_cbvq[];
|
||||||
|
extern const struct lsp_codebook lsp_cbjnd[];
|
||||||
|
extern const struct lsp_codebook lsp_cbdt[];
|
||||||
|
extern const struct lsp_codebook lsp_cbjvm[];
|
||||||
|
extern const struct lsp_codebook lsp_cbvqanssi[];
|
||||||
|
extern const struct lsp_codebook mel_cb[];
|
||||||
|
extern const struct lsp_codebook ge_cb[];
|
||||||
|
extern const struct lsp_codebook lspmelvq_cb[];
|
||||||
|
extern const struct lsp_codebook newamp1vq_cb[];
|
||||||
|
extern const struct lsp_codebook newamp1_energy_cb[];
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,674 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: dump.c
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 25/8/09
|
||||||
|
|
||||||
|
Routines to dump data to text files for Octave analysis.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
#include "comp.h"
|
||||||
|
#include "dump.h"
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#ifdef __EMBEDDED__
|
||||||
|
#include "gdb_stdio.h"
|
||||||
|
#define fprintf gdb_stdio_fprintf
|
||||||
|
#define fopen gdb_stdio_fopen
|
||||||
|
#define fclose gdb_stdio_fclose
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DUMP
|
||||||
|
static int dumpon = 0;
|
||||||
|
|
||||||
|
static FILE *fsn = NULL;
|
||||||
|
static FILE *fsw = NULL;
|
||||||
|
static FILE *few = NULL;
|
||||||
|
static FILE *fsw_ = NULL;
|
||||||
|
static FILE *fsoftdec = NULL;
|
||||||
|
static FILE *fmodel = NULL;
|
||||||
|
static FILE *fqmodel = NULL;
|
||||||
|
static FILE *fpwb = NULL;
|
||||||
|
static FILE *fpw = NULL;
|
||||||
|
static FILE *frw = NULL;
|
||||||
|
static FILE *flsp = NULL;
|
||||||
|
static FILE *fweights = NULL;
|
||||||
|
static FILE *flsp_ = NULL;
|
||||||
|
static FILE *fmel = NULL;
|
||||||
|
static FILE *fmel_indexes = NULL;
|
||||||
|
static FILE *fphase = NULL;
|
||||||
|
static FILE *fphase_ = NULL;
|
||||||
|
static FILE *ffw = NULL;
|
||||||
|
static FILE *fe = NULL;
|
||||||
|
static FILE *fsq = NULL;
|
||||||
|
static FILE *fdec = NULL;
|
||||||
|
static FILE *fsnr = NULL;
|
||||||
|
static FILE *flpcsnr = NULL;
|
||||||
|
static FILE *fak = NULL;
|
||||||
|
static FILE *fak_ = NULL;
|
||||||
|
static FILE *fbg = NULL;
|
||||||
|
static FILE *fE = NULL;
|
||||||
|
static FILE *frk = NULL;
|
||||||
|
static FILE *fhephase = NULL;
|
||||||
|
|
||||||
|
static char prefix[MAX_STR];
|
||||||
|
|
||||||
|
void dump_on(char p[]) {
|
||||||
|
dumpon = 1;
|
||||||
|
strcpy(prefix, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_off(){
|
||||||
|
if (fsn != NULL)
|
||||||
|
fclose(fsn);
|
||||||
|
if (fsw != NULL)
|
||||||
|
fclose(fsw);
|
||||||
|
if (fsw_ != NULL)
|
||||||
|
fclose(fsw_);
|
||||||
|
if (few != NULL)
|
||||||
|
fclose(few);
|
||||||
|
if (fmodel != NULL)
|
||||||
|
fclose(fmodel);
|
||||||
|
if (fsoftdec != NULL)
|
||||||
|
fclose(fsoftdec);
|
||||||
|
if (fqmodel != NULL)
|
||||||
|
fclose(fqmodel);
|
||||||
|
if (fpwb != NULL)
|
||||||
|
fclose(fpwb);
|
||||||
|
if (fpw != NULL)
|
||||||
|
fclose(fpw);
|
||||||
|
if (frw != NULL)
|
||||||
|
fclose(frw);
|
||||||
|
if (flsp != NULL)
|
||||||
|
fclose(flsp);
|
||||||
|
if (fweights != NULL)
|
||||||
|
fclose(fweights);
|
||||||
|
if (flsp_ != NULL)
|
||||||
|
fclose(flsp_);
|
||||||
|
if (fmel != NULL)
|
||||||
|
fclose(fmel);
|
||||||
|
if (fmel_indexes != NULL)
|
||||||
|
fclose(fmel_indexes);
|
||||||
|
if (fphase != NULL)
|
||||||
|
fclose(fphase);
|
||||||
|
if (fphase_ != NULL)
|
||||||
|
fclose(fphase_);
|
||||||
|
if (ffw != NULL)
|
||||||
|
fclose(ffw);
|
||||||
|
if (fe != NULL)
|
||||||
|
fclose(fe);
|
||||||
|
if (fsq != NULL)
|
||||||
|
fclose(fsq);
|
||||||
|
if (fdec != NULL)
|
||||||
|
fclose(fdec);
|
||||||
|
if (fsnr != NULL)
|
||||||
|
fclose(fsnr);
|
||||||
|
if (flpcsnr != NULL)
|
||||||
|
fclose(flpcsnr);
|
||||||
|
if (fak != NULL)
|
||||||
|
fclose(fak);
|
||||||
|
if (fak_ != NULL)
|
||||||
|
fclose(fak_);
|
||||||
|
if (fbg != NULL)
|
||||||
|
fclose(fbg);
|
||||||
|
if (fE != NULL)
|
||||||
|
fclose(fE);
|
||||||
|
if (frk != NULL)
|
||||||
|
fclose(frk);
|
||||||
|
if (fhephase != NULL)
|
||||||
|
fclose(fhephase);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_Sn(int m_pitch, float Sn[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fsn == NULL) {
|
||||||
|
sprintf(s,"%s_sn.txt", prefix);
|
||||||
|
fsn = fopen(s, "wt");
|
||||||
|
assert(fsn != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* split across two lines to avoid max line length problems */
|
||||||
|
/* reconstruct in Octave */
|
||||||
|
|
||||||
|
for(i=0; i<m_pitch/2; i++)
|
||||||
|
fprintf(fsn,"%f\t",Sn[i]);
|
||||||
|
fprintf(fsn,"\n");
|
||||||
|
for(i=m_pitch/2; i<m_pitch; i++)
|
||||||
|
fprintf(fsn,"%f\t",Sn[i]);
|
||||||
|
fprintf(fsn,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_Sw(COMP Sw[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fsw == NULL) {
|
||||||
|
sprintf(s,"%s_sw.txt", prefix);
|
||||||
|
fsw = fopen(s, "wt");
|
||||||
|
assert(fsw != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<FFT_ENC/2; i++)
|
||||||
|
fprintf(fsw,"%f\t",
|
||||||
|
10.0*log10(Sw[i].real*Sw[i].real + Sw[i].imag*Sw[i].imag));
|
||||||
|
fprintf(fsw,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_Sw_(COMP Sw_[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fsw_ == NULL) {
|
||||||
|
sprintf(s,"%s_sw_.txt", prefix);
|
||||||
|
fsw_ = fopen(s, "wt");
|
||||||
|
assert(fsw_ != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<FFT_ENC/2; i++)
|
||||||
|
fprintf(fsw_,"%f\t",
|
||||||
|
10.0*log10(Sw_[i].real*Sw_[i].real + Sw_[i].imag*Sw_[i].imag));
|
||||||
|
fprintf(fsw_,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_Ew(COMP Ew[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (few == NULL) {
|
||||||
|
sprintf(s,"%s_ew.txt", prefix);
|
||||||
|
few = fopen(s, "wt");
|
||||||
|
assert(few != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<FFT_ENC/2; i++)
|
||||||
|
fprintf(few,"%f\t",
|
||||||
|
10.0*log10(Ew[i].real*Ew[i].real + Ew[i].imag*Ew[i].imag));
|
||||||
|
fprintf(few,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_softdec(float *softdec, int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fsoftdec == NULL) {
|
||||||
|
sprintf(s,"%s_softdec.txt", prefix);
|
||||||
|
fsoftdec = fopen(s, "wt");
|
||||||
|
assert(fsoftdec != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<n; i++)
|
||||||
|
fprintf(fsoftdec,"%f\t", softdec[i]);
|
||||||
|
fprintf(fsoftdec,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_model(MODEL *model) {
|
||||||
|
int l;
|
||||||
|
char s[MAX_STR];
|
||||||
|
char line[MAX_STR*10];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fmodel == NULL) {
|
||||||
|
sprintf(s,"%s_model.txt", prefix);
|
||||||
|
fmodel = fopen(s, "wt");
|
||||||
|
assert(fmodel != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(line,"%12f %12d ", model->Wo, model->L);
|
||||||
|
for(l=1; l<=model->L; l++) {
|
||||||
|
sprintf(s,"%12f ",model->A[l]);
|
||||||
|
strcat(line, s);
|
||||||
|
assert(strlen(line) < MAX_STR*10);
|
||||||
|
}
|
||||||
|
for(l=model->L+1; l<=MAX_AMP; l++) {
|
||||||
|
sprintf(s,"%12f ", 0.0);
|
||||||
|
strcat(line,s);
|
||||||
|
assert(strlen(line) < MAX_STR*10);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(s,"%d\n",model->voiced);
|
||||||
|
strcat(line,s);
|
||||||
|
fprintf(fmodel,"%s",line);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_quantised_model(MODEL *model) {
|
||||||
|
int l;
|
||||||
|
char s[MAX_STR];
|
||||||
|
char line[2048];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fqmodel == NULL) {
|
||||||
|
sprintf(s,"%s_qmodel.txt", prefix);
|
||||||
|
fqmodel = fopen(s, "wt");
|
||||||
|
assert(fqmodel != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(line,"%12f %12d ", model->Wo, model->L);
|
||||||
|
for(l=1; l<=model->L; l++) {
|
||||||
|
sprintf(s,"%12f ",model->A[l]);
|
||||||
|
strcat(line, s);
|
||||||
|
}
|
||||||
|
for(l=model->L+1; l<=MAX_AMP; l++) {
|
||||||
|
sprintf(s,"%12f ", 0.0);
|
||||||
|
strcat(line, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(s,"%d\n",model->voiced);
|
||||||
|
strcat(line, s);
|
||||||
|
fprintf(fqmodel, "%s", line);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_phase(float phase[], int L) {
|
||||||
|
int l;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fphase == NULL) {
|
||||||
|
sprintf(s,"%s_phase.txt", prefix);
|
||||||
|
fphase = fopen(s, "wt");
|
||||||
|
assert(fphase != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(l=1; l<=L; l++)
|
||||||
|
fprintf(fphase,"%f\t",phase[l]);
|
||||||
|
for(l=L+1; l<=MAX_AMP; l++)
|
||||||
|
fprintf(fphase,"%f\t",0.0);
|
||||||
|
fprintf(fphase,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_phase_(float phase_[], int L) {
|
||||||
|
int l;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fphase_ == NULL) {
|
||||||
|
sprintf(s,"%s_phase_.txt", prefix);
|
||||||
|
fphase_ = fopen(s, "wt");
|
||||||
|
assert(fphase_ != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(l=1; l<=L; l++)
|
||||||
|
fprintf(fphase_,"%f\t",phase_[l]);
|
||||||
|
for(l=L+1; l<MAX_AMP; l++)
|
||||||
|
fprintf(fphase_,"%f\t",0.0);
|
||||||
|
fprintf(fphase_,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void dump_hephase(int ind[], int dim) {
|
||||||
|
int m;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fhephase == NULL) {
|
||||||
|
sprintf(s,"%s_hephase.txt", prefix);
|
||||||
|
fhephase = fopen(s, "wt");
|
||||||
|
assert(fhephase != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(m=0; m<dim; m++)
|
||||||
|
fprintf(fhephase,"%d\t",ind[m]);
|
||||||
|
fprintf(fhephase,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void dump_snr(float snr) {
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fsnr == NULL) {
|
||||||
|
sprintf(s,"%s_snr.txt", prefix);
|
||||||
|
fsnr = fopen(s, "wt");
|
||||||
|
assert(fsnr != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(fsnr,"%f\n",snr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_lpc_snr(float snr) {
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (flpcsnr == NULL) {
|
||||||
|
sprintf(s,"%s_lpc_snr.txt", prefix);
|
||||||
|
flpcsnr = fopen(s, "wt");
|
||||||
|
assert(flpcsnr != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(flpcsnr,"%f\n",snr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pw "before" post filter so we can plot before and after */
|
||||||
|
|
||||||
|
void dump_Pwb(float Pwb[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fpwb == NULL) {
|
||||||
|
sprintf(s,"%s_pwb.txt", prefix);
|
||||||
|
fpwb = fopen(s, "wt");
|
||||||
|
assert(fpwb != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<FFT_ENC/2; i++)
|
||||||
|
fprintf(fpwb,"%f\t",Pwb[i]);
|
||||||
|
fprintf(fpwb,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_Pw(float Pw[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fpw == NULL) {
|
||||||
|
sprintf(s,"%s_pw.txt", prefix);
|
||||||
|
fpw = fopen(s, "wt");
|
||||||
|
assert(fpw != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<FFT_ENC/2; i++)
|
||||||
|
fprintf(fpw,"%f\t",Pw[i]);
|
||||||
|
fprintf(fpw,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_Rw(float Rw[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (frw == NULL) {
|
||||||
|
sprintf(s,"%s_rw.txt", prefix);
|
||||||
|
frw = fopen(s, "wt");
|
||||||
|
assert(frw != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<FFT_ENC/2; i++)
|
||||||
|
fprintf(frw,"%f\t",Rw[i]);
|
||||||
|
fprintf(frw,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_weights(float w[], int order) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fweights == NULL) {
|
||||||
|
sprintf(s,"%s_weights.txt", prefix);
|
||||||
|
fweights = fopen(s, "wt");
|
||||||
|
assert(fweights != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<order; i++)
|
||||||
|
fprintf(fweights,"%f\t", w[i]);
|
||||||
|
fprintf(fweights,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_lsp(float lsp[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (flsp == NULL) {
|
||||||
|
sprintf(s,"%s_lsp.txt", prefix);
|
||||||
|
flsp = fopen(s, "wt");
|
||||||
|
assert(flsp != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<10; i++)
|
||||||
|
fprintf(flsp,"%f\t",lsp[i]);
|
||||||
|
fprintf(flsp,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_lsp_(float lsp_[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (flsp_ == NULL) {
|
||||||
|
sprintf(s,"%s_lsp_.txt", prefix);
|
||||||
|
flsp_ = fopen(s, "wt");
|
||||||
|
assert(flsp_ != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<10; i++)
|
||||||
|
fprintf(flsp_,"%f\t",lsp_[i]);
|
||||||
|
fprintf(flsp_,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_mel(float mel[], int order) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fmel == NULL) {
|
||||||
|
sprintf(s,"%s_mel.txt", prefix);
|
||||||
|
fmel = fopen(s, "wt");
|
||||||
|
assert(fmel != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<order; i++)
|
||||||
|
fprintf(fmel,"%f\t",mel[i]);
|
||||||
|
fprintf(fmel,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_mel_indexes(int mel_indexes[], int order) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fmel_indexes == NULL) {
|
||||||
|
sprintf(s,"%s_mel_indexes.txt", prefix);
|
||||||
|
fmel_indexes = fopen(s, "wt");
|
||||||
|
assert(fmel_indexes != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<order; i++)
|
||||||
|
fprintf(fmel_indexes,"%d\t",mel_indexes[i]);
|
||||||
|
fprintf(fmel_indexes,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_ak(float ak[], int order) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fak == NULL) {
|
||||||
|
sprintf(s,"%s_ak.txt", prefix);
|
||||||
|
fak = fopen(s, "wt");
|
||||||
|
assert(fak != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<=order; i++)
|
||||||
|
fprintf(fak,"%f\t",ak[i]);
|
||||||
|
fprintf(fak,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_ak_(float ak_[], int order) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fak_ == NULL) {
|
||||||
|
sprintf(s,"%s_ak_.txt", prefix);
|
||||||
|
fak_ = fopen(s, "wt");
|
||||||
|
assert(fak_ != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<=order; i++)
|
||||||
|
fprintf(fak_,"%f\t",ak_[i]);
|
||||||
|
fprintf(fak_,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_Fw(COMP Fw[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (ffw == NULL) {
|
||||||
|
sprintf(s,"%s_fw.txt", prefix);
|
||||||
|
ffw = fopen(s, "wt");
|
||||||
|
assert(ffw != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<256; i++)
|
||||||
|
fprintf(ffw,"%f\t",Fw[i].real);
|
||||||
|
fprintf(ffw,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_e(float e_hz[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fe == NULL) {
|
||||||
|
sprintf(s,"%s_e.txt", prefix);
|
||||||
|
fe = fopen(s, "wt");
|
||||||
|
assert(fe != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<500/2; i++)
|
||||||
|
fprintf(fe,"%f\t",e_hz[i]);
|
||||||
|
fprintf(fe,"\n");
|
||||||
|
for(i=500/2; i<500; i++)
|
||||||
|
fprintf(fe,"%f\t",e_hz[i]);
|
||||||
|
fprintf(fe,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_sq(int m_pitch, float sq[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fsq == NULL) {
|
||||||
|
sprintf(s,"%s_sq.txt", prefix);
|
||||||
|
fsq = fopen(s, "wt");
|
||||||
|
assert(fsq != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<m_pitch/2; i++)
|
||||||
|
fprintf(fsq,"%f\t",sq[i]);
|
||||||
|
fprintf(fsq,"\n");
|
||||||
|
for(i=m_pitch/2; i<m_pitch; i++)
|
||||||
|
fprintf(fsq,"%f\t",sq[i]);
|
||||||
|
fprintf(fsq,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_dec(COMP Fw[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fdec == NULL) {
|
||||||
|
sprintf(s,"%s_dec.txt", prefix);
|
||||||
|
fdec = fopen(s, "wt");
|
||||||
|
assert(fdec != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<320/5; i++)
|
||||||
|
fprintf(fdec,"%f\t",Fw[i].real);
|
||||||
|
fprintf(fdec,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_bg(float e, float bg_est, float percent_uv) {
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fbg == NULL) {
|
||||||
|
sprintf(s,"%s_bg.txt", prefix);
|
||||||
|
fbg = fopen(s, "wt");
|
||||||
|
assert(fbg != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(fbg,"%f\t%f\t%f\n", e, bg_est, percent_uv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_E(float E) {
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (fE == NULL) {
|
||||||
|
sprintf(s,"%s_E.txt", prefix);
|
||||||
|
fE = fopen(s, "wt");
|
||||||
|
assert(fE != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(fE,"%f\n", 10.0*log10(E));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
void dump_Rk(float Rk[]) {
|
||||||
|
int i;
|
||||||
|
char s[MAX_STR];
|
||||||
|
|
||||||
|
if (!dumpon) return;
|
||||||
|
|
||||||
|
if (frk == NULL) {
|
||||||
|
sprintf(s,"%s_rk.txt", prefix);
|
||||||
|
frk = fopen(s, "wt");
|
||||||
|
assert(frk != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<P_MAX; i++)
|
||||||
|
fprintf(frk,"%f\t",Rk[i]);
|
||||||
|
fprintf(frk,"\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: dump.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 25/8/09
|
||||||
|
|
||||||
|
Routines to dump data to text files for Octave analysis.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DUMP__
|
||||||
|
#define __DUMP__
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
#include "comp.h"
|
||||||
|
#include "codec2_fft.h"
|
||||||
|
#include "codec2_internal.h"
|
||||||
|
|
||||||
|
void dump_on(char filename_prefix[]);
|
||||||
|
void dump_off();
|
||||||
|
|
||||||
|
void dump_Sn(int m_pitch, float Sn[]);
|
||||||
|
void dump_Sw(COMP Sw[]);
|
||||||
|
void dump_Sw_(COMP Sw_[]);
|
||||||
|
void dump_Ew(COMP Ew[]);
|
||||||
|
void dump_softdec(float *softdec, int n);
|
||||||
|
|
||||||
|
/* amplitude modelling */
|
||||||
|
|
||||||
|
void dump_model(MODEL *m);
|
||||||
|
void dump_quantised_model(MODEL *m);
|
||||||
|
void dump_Pwn(COMP Pw[]);
|
||||||
|
void dump_Pw(float Pw[]);
|
||||||
|
void dump_Rw(float Rw[]);
|
||||||
|
void dump_lsp(float lsp[]);
|
||||||
|
void dump_weights(float w[], int ndim);
|
||||||
|
void dump_lsp_(float lsp_[]);
|
||||||
|
void dump_mel(float mel[], int order);
|
||||||
|
void dump_mel_indexes(int mel_indexes[], int order);
|
||||||
|
void dump_ak(float ak[], int order);
|
||||||
|
void dump_ak_(float ak[], int order);
|
||||||
|
void dump_E(float E);
|
||||||
|
void dump_lpc_snr(float snr);
|
||||||
|
|
||||||
|
/* phase modelling */
|
||||||
|
|
||||||
|
void dump_snr(float snr);
|
||||||
|
void dump_phase(float phase[], int L);
|
||||||
|
void dump_phase_(float phase[], int L);
|
||||||
|
void dump_hephase(int ind[], int dim);
|
||||||
|
|
||||||
|
/* NLP states */
|
||||||
|
|
||||||
|
void dump_sq(int m_pitch, float sq[]);
|
||||||
|
void dump_dec(COMP Fw[]);
|
||||||
|
void dump_Fw(COMP Fw[]);
|
||||||
|
void dump_e(float e_hz[]);
|
||||||
|
#if 0
|
||||||
|
void dump_Rk(float Rk[]);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* post filter */
|
||||||
|
|
||||||
|
void dump_bg(float e, float bg_est, float percent_uv);
|
||||||
|
void dump_Pwb(float Pwb[]);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: fdmdv_internal.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: April 16 2012
|
||||||
|
|
||||||
|
Header file for FDMDV internal functions, exposed via this header
|
||||||
|
file for testing.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __FDMDV_INTERNAL__
|
||||||
|
#define __FDMDV_INTERNAL__
|
||||||
|
|
||||||
|
#include "comp.h"
|
||||||
|
#include "codec2_fdmdv.h"
|
||||||
|
#include "codec2_fft.h"
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
DEFINES
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef PI
|
||||||
|
#define PI 3.141592654
|
||||||
|
#endif
|
||||||
|
#define FS 8000 /* sample rate in Hz */
|
||||||
|
#define T (1.0/FS) /* sample period in seconds */
|
||||||
|
#define RS 50 /* symbol rate in Hz */
|
||||||
|
#define NC 20 /* max number of data carriers (plus one pilot in the centre) */
|
||||||
|
#define NB 2 /* Bits/symbol for QPSK modulation */
|
||||||
|
#define RB (NC*RS*NB) /* bit rate */
|
||||||
|
#define M_FAC (FS/RS) /* oversampling factor */
|
||||||
|
#define NSYM 6 /* number of symbols to filter over */
|
||||||
|
#define NFILTER (NSYM*M_FAC) /* size of tx/rx filters at sample rate M */
|
||||||
|
|
||||||
|
#define FSEP 75 /* Default separation between carriers (Hz) */
|
||||||
|
|
||||||
|
#define NT 5 /* number of symbols we estimate timing over */
|
||||||
|
#define P 4 /* oversample factor used for initial rx symbol filtering output */
|
||||||
|
#define Q (M_FAC/4) /* oversample factor used for initial rx symbol filtering input */
|
||||||
|
#define NRXDEC 31 /* number of taps in the rx decimation filter */
|
||||||
|
|
||||||
|
#define NPILOT_LUT (4*M_FAC) /* number of pilot look up table samples */
|
||||||
|
#define NPILOTCOEFF 30 /* number of FIR filter coeffs in LP filter */
|
||||||
|
#define NPILOTBASEBAND (NPILOTCOEFF+M_FAC+M_FAC/P) /* number of pilot baseband samples reqd for pilot LPF */
|
||||||
|
#define NPILOTLPF (4*M_FAC) /* number of samples we DFT pilot over, pilot est window */
|
||||||
|
#define MPILOTFFT 256
|
||||||
|
|
||||||
|
#define NSYNC_MEM 6
|
||||||
|
|
||||||
|
/* averaging filter coeffs */
|
||||||
|
|
||||||
|
#define TRACK_COEFF 0.5
|
||||||
|
#define SNR_COEFF 0.9 /* SNR est averaging filter coeff */
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
STRUCT for States
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
struct FDMDV {
|
||||||
|
|
||||||
|
int Nc;
|
||||||
|
float fsep;
|
||||||
|
|
||||||
|
/* test data (test frame) states */
|
||||||
|
|
||||||
|
int ntest_bits;
|
||||||
|
int current_test_bit;
|
||||||
|
int *rx_test_bits_mem;
|
||||||
|
|
||||||
|
/* Modulator */
|
||||||
|
|
||||||
|
int old_qpsk_mapping;
|
||||||
|
int tx_pilot_bit;
|
||||||
|
COMP prev_tx_symbols[NC+1];
|
||||||
|
COMP tx_filter_memory[NC+1][NSYM];
|
||||||
|
COMP phase_tx[NC+1];
|
||||||
|
COMP freq[NC+1];
|
||||||
|
float freq_pol[NC+1];
|
||||||
|
|
||||||
|
/* Pilot generation at demodulator */
|
||||||
|
|
||||||
|
COMP pilot_lut[NPILOT_LUT];
|
||||||
|
int pilot_lut_index;
|
||||||
|
int prev_pilot_lut_index;
|
||||||
|
|
||||||
|
/* freq offset estimation states */
|
||||||
|
|
||||||
|
codec2_fft_cfg fft_pilot_cfg;
|
||||||
|
COMP pilot_baseband1[NPILOTBASEBAND];
|
||||||
|
COMP pilot_baseband2[NPILOTBASEBAND];
|
||||||
|
COMP pilot_lpf1[NPILOTLPF];
|
||||||
|
COMP pilot_lpf2[NPILOTLPF];
|
||||||
|
COMP S1[MPILOTFFT];
|
||||||
|
COMP S2[MPILOTFFT];
|
||||||
|
|
||||||
|
/* baseband to low IF carrier states */
|
||||||
|
|
||||||
|
COMP fbb_rect;
|
||||||
|
float fbb_pol;
|
||||||
|
COMP fbb_phase_tx;
|
||||||
|
COMP fbb_phase_rx;
|
||||||
|
|
||||||
|
/* freq offset correction states */
|
||||||
|
|
||||||
|
float foff;
|
||||||
|
COMP foff_phase_rect;
|
||||||
|
float foff_filt;
|
||||||
|
|
||||||
|
/* Demodulator */
|
||||||
|
|
||||||
|
COMP rxdec_lpf_mem[NRXDEC-1+M_FAC];
|
||||||
|
COMP rx_fdm_mem[NFILTER+M_FAC];
|
||||||
|
COMP phase_rx[NC+1];
|
||||||
|
COMP rx_filter_mem_timing[NC+1][NT*P];
|
||||||
|
float rx_timing;
|
||||||
|
COMP phase_difference[NC+1];
|
||||||
|
COMP prev_rx_symbols[NC+1];
|
||||||
|
|
||||||
|
/* sync state machine */
|
||||||
|
|
||||||
|
int sync_mem[NSYNC_MEM];
|
||||||
|
int fest_state;
|
||||||
|
int sync;
|
||||||
|
int timer;
|
||||||
|
|
||||||
|
/* SNR estimation states */
|
||||||
|
|
||||||
|
float sig_est[NC+1];
|
||||||
|
float noise_est[NC+1];
|
||||||
|
|
||||||
|
/* channel simulation */
|
||||||
|
|
||||||
|
float sig_pwr_av;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION PROTOTYPES
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void bits_to_dqpsk_symbols(COMP tx_symbols[], int Nc, COMP prev_tx_symbols[], int tx_bits[], int *pilot_bit, int old_qpsk_mapping);
|
||||||
|
void tx_filter(COMP tx_baseband[NC+1][M_FAC], int Nc, COMP tx_symbols[], COMP tx_filter_memory[NC+1][NSYM]);
|
||||||
|
void fdm_upconvert(COMP tx_fdm[], int Nc, COMP tx_baseband[NC+1][M_FAC], COMP phase_tx[], COMP freq_tx[],
|
||||||
|
COMP *fbb_phase, COMP fbb_rect);
|
||||||
|
void tx_filter_and_upconvert(COMP tx_fdm[], int Nc, COMP tx_symbols[],
|
||||||
|
COMP tx_filter_memory[NC+1][NSYM],
|
||||||
|
COMP phase_tx[], COMP freq[], COMP *fbb_phase, COMP fbb_rect);
|
||||||
|
void generate_pilot_fdm(COMP *pilot_fdm, int *bit, float *symbol, float *filter_mem, COMP *phase, COMP *freq);
|
||||||
|
void generate_pilot_lut(COMP pilot_lut[], COMP *pilot_freq);
|
||||||
|
float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin, int do_fft);
|
||||||
|
void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], COMP pilot_lpf[], codec2_fft_cfg fft_pilot_cfg, COMP S[], int nin, int do_fft);
|
||||||
|
void fdm_downconvert(COMP rx_baseband[NC+1][M_FAC+M_FAC/P], int Nc, COMP rx_fdm[], COMP phase_rx[], COMP freq[], int nin);
|
||||||
|
void rxdec_filter(COMP rx_fdm_filter[], COMP rx_fdm[], COMP rxdec_lpf_mem[], int nin);
|
||||||
|
void rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_baseband[NC+1][M_FAC+M_FAC/P], COMP rx_filter_memory[NC+1][NFILTER], int nin);
|
||||||
|
void down_convert_and_rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_fdm[],
|
||||||
|
COMP rx_fdm_mem[], COMP phase_rx[], COMP freq[],
|
||||||
|
float freq_pol[], int nin, int dec_rate);
|
||||||
|
float rx_est_timing(COMP rx_symbols[], int Nc,
|
||||||
|
COMP rx_filt[NC+1][P+1],
|
||||||
|
COMP rx_filter_mem_timing[NC+1][NT*P],
|
||||||
|
float env[],
|
||||||
|
int nin,
|
||||||
|
int m);
|
||||||
|
float qpsk_to_bits(int rx_bits[], int *sync_bit, int Nc, COMP phase_difference[], COMP prev_rx_symbols[], COMP rx_symbols[], int old_qpsk_mapping);
|
||||||
|
void snr_update(float sig_est[], float noise_est[], int Nc, COMP phase_difference[]);
|
||||||
|
int freq_state(int *reliable_sync_bit, int sync_bit, int *state, int *timer, int *sync_mem);
|
||||||
|
float calc_snr(int Nc, float sig_est[], float noise_est[]);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,413 @@
|
|||||||
|
/* Generated by fm_fir_coeff_file() Octave function in fm.m */
|
||||||
|
|
||||||
|
const float bin[]={
|
||||||
|
4.79309e-05,
|
||||||
|
1.1306e-05,
|
||||||
|
-5.5983e-05,
|
||||||
|
-7.01194e-05,
|
||||||
|
7.06484e-06,
|
||||||
|
9.92193e-05,
|
||||||
|
8.58591e-05,
|
||||||
|
-4.54326e-05,
|
||||||
|
-0.000152003,
|
||||||
|
-8.65645e-05,
|
||||||
|
0.000107704,
|
||||||
|
0.000207915,
|
||||||
|
6.24307e-05,
|
||||||
|
-0.000194905,
|
||||||
|
-0.000256788,
|
||||||
|
-3.72067e-06,
|
||||||
|
0.000303862,
|
||||||
|
0.000285027,
|
||||||
|
-9.75377e-05,
|
||||||
|
-0.000426141,
|
||||||
|
-0.000276571,
|
||||||
|
0.000245596,
|
||||||
|
0.00054748,
|
||||||
|
0.000214543,
|
||||||
|
-0.000438995,
|
||||||
|
-0.000647904,
|
||||||
|
-8.35097e-05,
|
||||||
|
0.000668808,
|
||||||
|
0.000702715,
|
||||||
|
-0.000127804,
|
||||||
|
-0.000917433,
|
||||||
|
-0.000684399,
|
||||||
|
0.000423605,
|
||||||
|
0.00115821,
|
||||||
|
0.000565432,
|
||||||
|
-0.000798262,
|
||||||
|
-0.00135608,
|
||||||
|
-0.000321829,
|
||||||
|
0.00123404,
|
||||||
|
0.00146953,
|
||||||
|
-6.28411e-05,
|
||||||
|
-0.00169975,
|
||||||
|
-0.00145365,
|
||||||
|
0.000593351,
|
||||||
|
0.00215057,
|
||||||
|
0.00126444,
|
||||||
|
-0.00125906,
|
||||||
|
-0.00252937,
|
||||||
|
-0.000863858,
|
||||||
|
0.00203097,
|
||||||
|
0.00276961,
|
||||||
|
0.000225378,
|
||||||
|
-0.00286002,
|
||||||
|
-0.00279968,
|
||||||
|
0.00066048,
|
||||||
|
0.00367697,
|
||||||
|
0.00254856,
|
||||||
|
-0.00178121,
|
||||||
|
-0.00439398,
|
||||||
|
-0.00195226,
|
||||||
|
0.00309842,
|
||||||
|
0.00490791,
|
||||||
|
0.000960678,
|
||||||
|
-0.0045454,
|
||||||
|
-0.00510509,
|
||||||
|
0.000456067,
|
||||||
|
0.00602631,
|
||||||
|
0.00486678,
|
||||||
|
-0.00230217,
|
||||||
|
-0.00741688,
|
||||||
|
-0.00407467,
|
||||||
|
0.00455244,
|
||||||
|
0.00856596,
|
||||||
|
0.0026148,
|
||||||
|
-0.00715072,
|
||||||
|
-0.0092966,
|
||||||
|
-0.000377815,
|
||||||
|
0.0100109,
|
||||||
|
0.00940383,
|
||||||
|
-0.00274808,
|
||||||
|
-0.0130204,
|
||||||
|
-0.00864357,
|
||||||
|
0.00689875,
|
||||||
|
0.0160465,
|
||||||
|
0.0066998,
|
||||||
|
-0.0122874,
|
||||||
|
-0.0189444,
|
||||||
|
-0.0030966,
|
||||||
|
0.0193367,
|
||||||
|
0.0215669,
|
||||||
|
-0.00304913,
|
||||||
|
-0.0290487,
|
||||||
|
-0.0237748,
|
||||||
|
0.0138493,
|
||||||
|
0.0443198,
|
||||||
|
0.0254471,
|
||||||
|
-0.0364426,
|
||||||
|
-0.0771407,
|
||||||
|
-0.0264901,
|
||||||
|
0.120993,
|
||||||
|
0.285249,
|
||||||
|
0.366844,
|
||||||
|
0.285249,
|
||||||
|
0.120993,
|
||||||
|
-0.0264901,
|
||||||
|
-0.0771407,
|
||||||
|
-0.0364426,
|
||||||
|
0.0254471,
|
||||||
|
0.0443198,
|
||||||
|
0.0138493,
|
||||||
|
-0.0237748,
|
||||||
|
-0.0290487,
|
||||||
|
-0.00304913,
|
||||||
|
0.0215669,
|
||||||
|
0.0193367,
|
||||||
|
-0.0030966,
|
||||||
|
-0.0189444,
|
||||||
|
-0.0122874,
|
||||||
|
0.0066998,
|
||||||
|
0.0160465,
|
||||||
|
0.00689875,
|
||||||
|
-0.00864357,
|
||||||
|
-0.0130204,
|
||||||
|
-0.00274808,
|
||||||
|
0.00940383,
|
||||||
|
0.0100109,
|
||||||
|
-0.000377815,
|
||||||
|
-0.0092966,
|
||||||
|
-0.00715072,
|
||||||
|
0.0026148,
|
||||||
|
0.00856596,
|
||||||
|
0.00455244,
|
||||||
|
-0.00407467,
|
||||||
|
-0.00741688,
|
||||||
|
-0.00230217,
|
||||||
|
0.00486678,
|
||||||
|
0.00602631,
|
||||||
|
0.000456067,
|
||||||
|
-0.00510509,
|
||||||
|
-0.0045454,
|
||||||
|
0.000960678,
|
||||||
|
0.00490791,
|
||||||
|
0.00309842,
|
||||||
|
-0.00195226,
|
||||||
|
-0.00439398,
|
||||||
|
-0.00178121,
|
||||||
|
0.00254856,
|
||||||
|
0.00367697,
|
||||||
|
0.00066048,
|
||||||
|
-0.00279968,
|
||||||
|
-0.00286002,
|
||||||
|
0.000225378,
|
||||||
|
0.00276961,
|
||||||
|
0.00203097,
|
||||||
|
-0.000863858,
|
||||||
|
-0.00252937,
|
||||||
|
-0.00125906,
|
||||||
|
0.00126444,
|
||||||
|
0.00215057,
|
||||||
|
0.000593351,
|
||||||
|
-0.00145365,
|
||||||
|
-0.00169975,
|
||||||
|
-6.28411e-05,
|
||||||
|
0.00146953,
|
||||||
|
0.00123404,
|
||||||
|
-0.000321829,
|
||||||
|
-0.00135608,
|
||||||
|
-0.000798262,
|
||||||
|
0.000565432,
|
||||||
|
0.00115821,
|
||||||
|
0.000423605,
|
||||||
|
-0.000684399,
|
||||||
|
-0.000917433,
|
||||||
|
-0.000127804,
|
||||||
|
0.000702715,
|
||||||
|
0.000668808,
|
||||||
|
-8.35097e-05,
|
||||||
|
-0.000647904,
|
||||||
|
-0.000438995,
|
||||||
|
0.000214543,
|
||||||
|
0.00054748,
|
||||||
|
0.000245596,
|
||||||
|
-0.000276571,
|
||||||
|
-0.000426141,
|
||||||
|
-9.75377e-05,
|
||||||
|
0.000285027,
|
||||||
|
0.000303862,
|
||||||
|
-3.72067e-06,
|
||||||
|
-0.000256788,
|
||||||
|
-0.000194905,
|
||||||
|
6.24307e-05,
|
||||||
|
0.000207915,
|
||||||
|
0.000107704,
|
||||||
|
-8.65645e-05,
|
||||||
|
-0.000152003,
|
||||||
|
-4.54326e-05,
|
||||||
|
8.58591e-05,
|
||||||
|
9.92193e-05,
|
||||||
|
7.06484e-06,
|
||||||
|
-7.01194e-05,
|
||||||
|
-5.5983e-05,
|
||||||
|
1.1306e-05,
|
||||||
|
4.79309e-05
|
||||||
|
};
|
||||||
|
|
||||||
|
const float bout[]={
|
||||||
|
-0.000901664,
|
||||||
|
-0.00105423,
|
||||||
|
-0.00102202,
|
||||||
|
-0.000796428,
|
||||||
|
-0.0004047,
|
||||||
|
9.24929e-05,
|
||||||
|
0.000610043,
|
||||||
|
0.00105267,
|
||||||
|
0.00133217,
|
||||||
|
0.00138452,
|
||||||
|
0.00118367,
|
||||||
|
0.000749102,
|
||||||
|
0.000145346,
|
||||||
|
-0.000527025,
|
||||||
|
-0.00114777,
|
||||||
|
-0.00159812,
|
||||||
|
-0.00178311,
|
||||||
|
-0.00165083,
|
||||||
|
-0.00120494,
|
||||||
|
-0.000507584,
|
||||||
|
0.000328412,
|
||||||
|
0.0011573,
|
||||||
|
0.00182538,
|
||||||
|
0.00219909,
|
||||||
|
0.00219097,
|
||||||
|
0.00177877,
|
||||||
|
0.00101358,
|
||||||
|
1.48175e-05,
|
||||||
|
-0.00104765,
|
||||||
|
-0.00198192,
|
||||||
|
-0.00260813,
|
||||||
|
-0.00279243,
|
||||||
|
-0.00247437,
|
||||||
|
-0.00168247,
|
||||||
|
-0.000534171,
|
||||||
|
0.000780521,
|
||||||
|
0.00202976,
|
||||||
|
0.00298006,
|
||||||
|
0.00343915,
|
||||||
|
0.00329371,
|
||||||
|
0.00253482,
|
||||||
|
0.00126569,
|
||||||
|
-0.000310763,
|
||||||
|
-0.00192329,
|
||||||
|
-0.00327808,
|
||||||
|
-0.0041113,
|
||||||
|
-0.00423916,
|
||||||
|
-0.00359628,
|
||||||
|
-0.00225463,
|
||||||
|
-0.000418452,
|
||||||
|
0.00160526,
|
||||||
|
0.00345676,
|
||||||
|
0.00478613,
|
||||||
|
0.00531776,
|
||||||
|
0.00490513,
|
||||||
|
0.00356541,
|
||||||
|
0.00148629,
|
||||||
|
-0.000997692,
|
||||||
|
-0.00345694,
|
||||||
|
-0.0054391,
|
||||||
|
-0.00654985,
|
||||||
|
-0.00652835,
|
||||||
|
-0.00530323,
|
||||||
|
-0.00301796,
|
||||||
|
-1.90046e-05,
|
||||||
|
0.00319335,
|
||||||
|
0.00604515,
|
||||||
|
0.00798756,
|
||||||
|
0.00859787,
|
||||||
|
0.00766479,
|
||||||
|
0.00524199,
|
||||||
|
0.001658,
|
||||||
|
-0.00252213,
|
||||||
|
-0.00658004,
|
||||||
|
-0.00976079,
|
||||||
|
-0.011405,
|
||||||
|
-0.0110744,
|
||||||
|
-0.00864874,
|
||||||
|
-0.00437487,
|
||||||
|
0.00114403,
|
||||||
|
0.00702171,
|
||||||
|
0.0122173,
|
||||||
|
0.0157018,
|
||||||
|
0.0166372,
|
||||||
|
0.0145415,
|
||||||
|
0.00940928,
|
||||||
|
0.00176699,
|
||||||
|
-0.00735151,
|
||||||
|
-0.0165112,
|
||||||
|
-0.0240533,
|
||||||
|
-0.0283208,
|
||||||
|
-0.027902,
|
||||||
|
-0.0218568,
|
||||||
|
-0.00988994,
|
||||||
|
0.0075553,
|
||||||
|
0.0293009,
|
||||||
|
0.0535398,
|
||||||
|
0.0780316,
|
||||||
|
0.100365,
|
||||||
|
0.118251,
|
||||||
|
0.129808,
|
||||||
|
0.143804,
|
||||||
|
0.129808,
|
||||||
|
0.118251,
|
||||||
|
0.100365,
|
||||||
|
0.0780316,
|
||||||
|
0.0535398,
|
||||||
|
0.0293009,
|
||||||
|
0.0075553,
|
||||||
|
-0.00988994,
|
||||||
|
-0.0218568,
|
||||||
|
-0.027902,
|
||||||
|
-0.0283208,
|
||||||
|
-0.0240533,
|
||||||
|
-0.0165112,
|
||||||
|
-0.00735151,
|
||||||
|
0.00176699,
|
||||||
|
0.00940928,
|
||||||
|
0.0145415,
|
||||||
|
0.0166372,
|
||||||
|
0.0157018,
|
||||||
|
0.0122173,
|
||||||
|
0.00702171,
|
||||||
|
0.00114403,
|
||||||
|
-0.00437487,
|
||||||
|
-0.00864874,
|
||||||
|
-0.0110744,
|
||||||
|
-0.011405,
|
||||||
|
-0.00976079,
|
||||||
|
-0.00658004,
|
||||||
|
-0.00252213,
|
||||||
|
0.001658,
|
||||||
|
0.00524199,
|
||||||
|
0.00766479,
|
||||||
|
0.00859787,
|
||||||
|
0.00798756,
|
||||||
|
0.00604515,
|
||||||
|
0.00319335,
|
||||||
|
-1.90046e-05,
|
||||||
|
-0.00301796,
|
||||||
|
-0.00530323,
|
||||||
|
-0.00652835,
|
||||||
|
-0.00654985,
|
||||||
|
-0.0054391,
|
||||||
|
-0.00345694,
|
||||||
|
-0.000997692,
|
||||||
|
0.00148629,
|
||||||
|
0.00356541,
|
||||||
|
0.00490513,
|
||||||
|
0.00531776,
|
||||||
|
0.00478613,
|
||||||
|
0.00345676,
|
||||||
|
0.00160526,
|
||||||
|
-0.000418452,
|
||||||
|
-0.00225463,
|
||||||
|
-0.00359628,
|
||||||
|
-0.00423916,
|
||||||
|
-0.0041113,
|
||||||
|
-0.00327808,
|
||||||
|
-0.00192329,
|
||||||
|
-0.000310763,
|
||||||
|
0.00126569,
|
||||||
|
0.00253482,
|
||||||
|
0.00329371,
|
||||||
|
0.00343915,
|
||||||
|
0.00298006,
|
||||||
|
0.00202976,
|
||||||
|
0.000780521,
|
||||||
|
-0.000534171,
|
||||||
|
-0.00168247,
|
||||||
|
-0.00247437,
|
||||||
|
-0.00279243,
|
||||||
|
-0.00260813,
|
||||||
|
-0.00198192,
|
||||||
|
-0.00104765,
|
||||||
|
1.48175e-05,
|
||||||
|
0.00101358,
|
||||||
|
0.00177877,
|
||||||
|
0.00219097,
|
||||||
|
0.00219909,
|
||||||
|
0.00182538,
|
||||||
|
0.0011573,
|
||||||
|
0.000328412,
|
||||||
|
-0.000507584,
|
||||||
|
-0.00120494,
|
||||||
|
-0.00165083,
|
||||||
|
-0.00178311,
|
||||||
|
-0.00159812,
|
||||||
|
-0.00114777,
|
||||||
|
-0.000527025,
|
||||||
|
0.000145346,
|
||||||
|
0.000749102,
|
||||||
|
0.00118367,
|
||||||
|
0.00138452,
|
||||||
|
0.00133217,
|
||||||
|
0.00105267,
|
||||||
|
0.000610043,
|
||||||
|
9.24929e-05,
|
||||||
|
-0.0004047,
|
||||||
|
-0.000796428,
|
||||||
|
-0.00102202,
|
||||||
|
-0.00105423,
|
||||||
|
-0.000901664
|
||||||
|
};
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: fmfsk.h
|
||||||
|
AUTHOR......: Brady O'Brien
|
||||||
|
DATE CREATED: 6 February 2016
|
||||||
|
|
||||||
|
C Implementation of 2FSK+Manchester over FM modulator/demodulator, based
|
||||||
|
on mancyfsk.m and fmfsk.m
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2016 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __C2FMFSK_H
|
||||||
|
#define __C2FMFSK_H
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "comp.h"
|
||||||
|
#include "modem_stats.h"
|
||||||
|
|
||||||
|
#define FMFSK_SCALE 16383
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fm-me-2fsk state
|
||||||
|
*/
|
||||||
|
struct FMFSK{
|
||||||
|
/* Static fmfsk parameters */
|
||||||
|
int Rb; /* Manchester-encoded bitrate */
|
||||||
|
int Rs; /* Raw modem symbol rate */
|
||||||
|
int Fs; /* Sample rate */
|
||||||
|
int Ts; /* Samples-per-symbol */
|
||||||
|
int N; /* Sample processing buffer size */
|
||||||
|
int nsym; /* Number of raw modem symbols processed per demod call */
|
||||||
|
int nbit; /* Number of bits spit out per demod call */
|
||||||
|
int nmem; /* Number of samples kept around between demod calls */
|
||||||
|
|
||||||
|
/* State kept by demod */
|
||||||
|
int nin; /* Number of samples to be demod-ed the next cycle */
|
||||||
|
int lodd; /* Last integrated sample for odd bitstream generation */
|
||||||
|
float * oldsamps; /* Memory of old samples to make clock-offset-tolerance possible */
|
||||||
|
|
||||||
|
/* Stats generated by demod */
|
||||||
|
float norm_rx_timing; /* RX Timing, used to calculate clock offset */
|
||||||
|
int ppm; /* Clock offset in parts-per-million */
|
||||||
|
float snr_mean;
|
||||||
|
|
||||||
|
/* Modem stat structure */
|
||||||
|
struct MODEM_STATS * stats;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a new fmfsk modem instance.
|
||||||
|
*
|
||||||
|
* int Fs - sample rate
|
||||||
|
* int Rb - non-manchester bitrate
|
||||||
|
* returns - new struct FMFSK on sucess, NULL on failure
|
||||||
|
*/
|
||||||
|
struct FMFSK * fmfsk_create(int Fs,int Rb);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Destroys an fmfsk modem and deallocates memory
|
||||||
|
*/
|
||||||
|
void fmfsk_destroy(struct FMFSK *fmfsk);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Deposit demod statistics into a MODEM_STATS struct
|
||||||
|
*/
|
||||||
|
void fmfsk_get_demod_stats(struct FMFSK *fmfsk,struct MODEM_STATS *stats);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the number of samples that must be fed to fmfsk_demod the next
|
||||||
|
* cycle
|
||||||
|
*/
|
||||||
|
uint32_t fmfsk_nin(struct FMFSK *fmfsk);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Modulates nbit bits into N samples to be sent through an FM radio
|
||||||
|
*
|
||||||
|
* struct FSK *fsk - FSK config/state struct, set up by fsk_create
|
||||||
|
* float mod_out[] - Buffer for N samples of modulated FMFSK
|
||||||
|
* uint8_t tx_bits[] - Buffer containing Nbits unpacked bits
|
||||||
|
*/
|
||||||
|
void fmfsk_mod(struct FMFSK *fmfsk, float fmfsk_out[],uint8_t bits_in[]);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Demodulate some number of FMFSK samples. The number of samples to be
|
||||||
|
* demodulated can be found by calling fmfsk_nin().
|
||||||
|
*
|
||||||
|
* struct FMFSK *fsk - FMFSK config/state struct, set up by fsk_create
|
||||||
|
* uint8_t rx_bits[] - Buffer for nbit unpacked bits to be written
|
||||||
|
* float fsk_in[] - nin samples of modualted FMFSK from an FM radio
|
||||||
|
*/
|
||||||
|
void fmfsk_demod(struct FMFSK *fmfsk, uint8_t rx_bits[],float fmfsk_in[]);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: freedv_api.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: August 2014
|
||||||
|
|
||||||
|
Library of API functions that implement FreeDV "modes", useful for
|
||||||
|
embedding FreeDV in other programs. Please see the documentation
|
||||||
|
for each function in freedv_api.c, and the sample freedv_tx.c and
|
||||||
|
freedv_rx.c programs.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2014 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __FREEDV__
|
||||||
|
|
||||||
|
// This declares a single-precision (float) complex number
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include "comp.h"
|
||||||
|
|
||||||
|
#define FREEDV_MODE_1600 0
|
||||||
|
#define FREEDV_MODE_700 1
|
||||||
|
#define FREEDV_MODE_700B 2
|
||||||
|
#define FREEDV_MODE_2400A 3
|
||||||
|
#define FREEDV_MODE_2400B 4
|
||||||
|
#define FREEDV_MODE_800XA 5
|
||||||
|
#define FREEDV_MODE_700C 6
|
||||||
|
|
||||||
|
struct freedv;
|
||||||
|
|
||||||
|
/* Called when text message char is decoded */
|
||||||
|
typedef void (*freedv_callback_rx)(void *, char);
|
||||||
|
/* Called when new text message char is needed */
|
||||||
|
typedef char (*freedv_callback_tx)(void *);
|
||||||
|
typedef void (*freedv_calback_error_pattern)
|
||||||
|
(void *error_pattern_callback_state, short error_pattern[], int sz_error_pattern);
|
||||||
|
|
||||||
|
/* Protocol bits are packed MSB-first */
|
||||||
|
/* Called when a frame containing protocol data is decoded */
|
||||||
|
typedef void (*freedv_callback_protorx)(void *, char *);
|
||||||
|
/* Called when a frame containing protocol data is to be sent */
|
||||||
|
typedef void (*freedv_callback_prototx)(void *, char *);
|
||||||
|
|
||||||
|
/* Data packet callbacks */
|
||||||
|
/* Called when a packet has been received */
|
||||||
|
typedef void (*freedv_callback_datarx)(void *, unsigned char *packet, size_t size);
|
||||||
|
/* Called when a new packet can be send */
|
||||||
|
typedef void (*freedv_callback_datatx)(void *, unsigned char *packet, size_t *size);
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FreeDV API functions
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// open, close ----------------------------------------------------------------
|
||||||
|
|
||||||
|
struct freedv *freedv_open(int mode);
|
||||||
|
void freedv_close (struct freedv *freedv);
|
||||||
|
|
||||||
|
// Transmit -------------------------------------------------------------------
|
||||||
|
|
||||||
|
void freedv_tx (struct freedv *freedv, short mod_out[], short speech_in[]);
|
||||||
|
void freedv_comptx (struct freedv *freedv, COMP mod_out[], short speech_in[]);
|
||||||
|
void freedv_codectx (struct freedv *f, short mod_out[], unsigned char *packed_codec_bits);
|
||||||
|
void freedv_datatx (struct freedv *f, short mod_out[]);
|
||||||
|
int freedv_data_ntxframes (struct freedv *freedv);
|
||||||
|
|
||||||
|
// Receive -------------------------------------------------------------------
|
||||||
|
|
||||||
|
int freedv_nin (struct freedv *freedv);
|
||||||
|
int freedv_rx (struct freedv *freedv, short speech_out[], short demod_in[]);
|
||||||
|
int freedv_floatrx (struct freedv *freedv, short speech_out[], float demod_in[]);
|
||||||
|
int freedv_comprx (struct freedv *freedv, short speech_out[], COMP demod_in[]);
|
||||||
|
int freedv_codecrx (struct freedv *freedv, unsigned char *packed_codec_bits, short demod_in[]);
|
||||||
|
|
||||||
|
// Set parameters ------------------------------------------------------------
|
||||||
|
|
||||||
|
void freedv_set_callback_txt (struct freedv *freedv, freedv_callback_rx rx, freedv_callback_tx tx, void *callback_state);
|
||||||
|
void freedv_set_callback_protocol (struct freedv *freedv, freedv_callback_protorx rx, freedv_callback_prototx tx, void *callback_state);
|
||||||
|
void freedv_set_callback_data (struct freedv *freedv, freedv_callback_datarx datarx, freedv_callback_datatx datatx, void *callback_state);
|
||||||
|
void freedv_set_test_frames (struct freedv *freedv, int test_frames);
|
||||||
|
void freedv_set_test_frames_diversity (struct freedv *freedv, int test_frames_diversity);
|
||||||
|
void freedv_set_smooth_symbols (struct freedv *freedv, int smooth_symbols);
|
||||||
|
void freedv_set_squelch_en (struct freedv *freedv, int squelch_en);
|
||||||
|
void freedv_set_snr_squelch_thresh (struct freedv *freedv, float snr_squelch_thresh);
|
||||||
|
void freedv_set_clip (struct freedv *freedv, int val);
|
||||||
|
void freedv_set_total_bit_errors (struct freedv *freedv, int val);
|
||||||
|
void freedv_set_total_bits (struct freedv *freedv, int val);
|
||||||
|
void freedv_set_callback_error_pattern (struct freedv *freedv, freedv_calback_error_pattern cb, void *state);
|
||||||
|
void freedv_set_varicode_code_num (struct freedv *freedv, int val);
|
||||||
|
void freedv_set_data_header (struct freedv *freedv, unsigned char *header);
|
||||||
|
int freedv_set_alt_modem_samp_rate (struct freedv *freedv, int samp_rate);
|
||||||
|
void freedv_set_carrier_ampl (struct freedv *freedv, int c, float ampl);
|
||||||
|
|
||||||
|
// Get parameters -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct MODEM_STATS;
|
||||||
|
int freedv_get_version(void);
|
||||||
|
int freedv_get_mode (struct freedv *freedv);
|
||||||
|
void freedv_get_modem_stats (struct freedv *freedv, int *sync, float *snr_est);
|
||||||
|
void freedv_get_modem_extended_stats(struct freedv *freedv, struct MODEM_STATS *stats);
|
||||||
|
int freedv_get_test_frames (struct freedv *freedv);
|
||||||
|
int freedv_get_n_speech_samples (struct freedv *freedv);
|
||||||
|
int freedv_get_modem_sample_rate (struct freedv *freedv);
|
||||||
|
int freedv_get_n_max_modem_samples (struct freedv *freedv);
|
||||||
|
int freedv_get_n_nom_modem_samples (struct freedv *freedv);
|
||||||
|
int freedv_get_total_bits (struct freedv *freedv);
|
||||||
|
int freedv_get_total_bit_errors (struct freedv *freedv);
|
||||||
|
int freedv_get_sync (struct freedv *freedv);
|
||||||
|
struct FSK * freedv_get_fsk(struct freedv *f);
|
||||||
|
struct CODEC2 *freedv_get_codec2 (struct freedv *freedv);
|
||||||
|
int freedv_get_n_codec_bits (struct freedv *freedv);
|
||||||
|
int freedv_get_sz_error_pattern (struct freedv *freedv);
|
||||||
|
int freedv_get_protocol_bits (struct freedv *freedv);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,241 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: freedv_api_internal.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: August 2014
|
||||||
|
|
||||||
|
This declares the structure freedv. A pointer to this structure is
|
||||||
|
returned by the FreeDV API freedv_open() function. The pointer is used
|
||||||
|
by the other FreeDV API functions declared in freedv_api.h. This
|
||||||
|
structure is intended to be internal to the FreeDV API. The public
|
||||||
|
functions are declared in freedv_api.h. Changes to this structure
|
||||||
|
are expected. Changes (except additions) to freedv_api.h are
|
||||||
|
discouraged.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2014 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __FREEDV__
|
||||||
|
|
||||||
|
#include "varicode.h"
|
||||||
|
#include "fsk.h"
|
||||||
|
#include "fmfsk.h"
|
||||||
|
#include "codec2_fdmdv.h"
|
||||||
|
#include "codec2_cohpsk.h"
|
||||||
|
|
||||||
|
struct quisk_cfFilter { // Structure to hold the static data for FIR filters
|
||||||
|
float * dCoefs; // filter coefficients
|
||||||
|
int nBuf; // dimension of cBuf
|
||||||
|
int nTaps; // dimension of dSamples, cSamples, dCoefs
|
||||||
|
int decim_index; // index of next sample for decimation
|
||||||
|
COMP * cSamples; // storage for old samples
|
||||||
|
COMP * ptcSamp; // next available position in cSamples
|
||||||
|
COMP * cBuf; // auxillary buffer for interpolation
|
||||||
|
} ;
|
||||||
|
|
||||||
|
static int quisk_cfInterpDecim(COMP *, int, struct quisk_cfFilter *, int, int);
|
||||||
|
static void quisk_filt_cfInit(struct quisk_cfFilter *, float *, int);
|
||||||
|
static void quisk_filt_destroy(struct quisk_cfFilter *);
|
||||||
|
static float quiskFilt120t480[480];
|
||||||
|
|
||||||
|
struct freedv {
|
||||||
|
int mode;
|
||||||
|
|
||||||
|
struct CODEC2 *codec2;
|
||||||
|
struct FDMDV *fdmdv;
|
||||||
|
struct MODEM_STATS stats;
|
||||||
|
struct COHPSK *cohpsk;
|
||||||
|
struct FSK *fsk;
|
||||||
|
struct FMFSK *fmfsk;
|
||||||
|
|
||||||
|
struct freedv_vhf_deframer * deframer; //Extracts frames from VHF stream
|
||||||
|
|
||||||
|
struct quisk_cfFilter * ptFilter7500to8000; // Filters to change to/from 7500 and 8000 sps
|
||||||
|
struct quisk_cfFilter * ptFilter8000to7500;
|
||||||
|
|
||||||
|
int n_speech_samples;
|
||||||
|
int n_nom_modem_samples; // size of tx and most rx modem sample buffers
|
||||||
|
int n_max_modem_samples; // make your rx modem sample buffers this big
|
||||||
|
int n_nat_modem_samples; // tx modem sample block length as used by the modem before interpolation to output
|
||||||
|
|
||||||
|
int modem_sample_rate; // ATM caller is responsible for meeting this (TBC)
|
||||||
|
int clip; // non-zero for cohpsk modem output clipping for low PAPR
|
||||||
|
|
||||||
|
unsigned char *packed_codec_bits;
|
||||||
|
int *codec_bits;
|
||||||
|
int *tx_bits;
|
||||||
|
int *fdmdv_bits;
|
||||||
|
int *rx_bits;
|
||||||
|
int tx_sync_bit;
|
||||||
|
int smooth_symbols;
|
||||||
|
float *prev_rx_bits;
|
||||||
|
int n_codec_bits; // amount of codec bits in a frame
|
||||||
|
|
||||||
|
int *ptest_bits_coh;
|
||||||
|
int *ptest_bits_coh_end;
|
||||||
|
|
||||||
|
int test_frames; // set this baby for 1 to tx/rx test frames to look at bit error stats
|
||||||
|
int test_frames_diversity; // 1 -> used combined carriers for error counting on 700 waveforms
|
||||||
|
int test_frame_sync_state;
|
||||||
|
int test_frame_sync_state_upper; // when test_frames_diveristy==0 we need extra states for upper carriers
|
||||||
|
int test_frame_count;
|
||||||
|
int total_bits;
|
||||||
|
int total_bit_errors;
|
||||||
|
int sz_error_pattern;
|
||||||
|
|
||||||
|
/* optional user defined function to pass error pattern when a test frame is received */
|
||||||
|
|
||||||
|
void *error_pattern_callback_state;
|
||||||
|
void (*freedv_put_error_pattern)(void *error_pattern_callback_state, short error_pattern[], int sz_error_pattern);
|
||||||
|
|
||||||
|
int sync;
|
||||||
|
int evenframe;
|
||||||
|
float snr_est;
|
||||||
|
float snr_squelch_thresh;
|
||||||
|
int squelch_en;
|
||||||
|
int nin;
|
||||||
|
|
||||||
|
struct VARICODE_DEC varicode_dec_states;
|
||||||
|
short tx_varicode_bits[VARICODE_MAX_BITS];
|
||||||
|
int nvaricode_bits;
|
||||||
|
int varicode_bit_index;
|
||||||
|
|
||||||
|
/* user defined function ptrs to produce and consume ASCII
|
||||||
|
characters using aux txt channel */
|
||||||
|
|
||||||
|
char (*freedv_get_next_tx_char)(void *callback_state);
|
||||||
|
void (*freedv_put_next_rx_char)(void *callback_state, char c);
|
||||||
|
void *callback_state;
|
||||||
|
|
||||||
|
/* user defined functions to produce and consume protocol bits */
|
||||||
|
/* Protocol bits are packed MSB-first */
|
||||||
|
void (*freedv_put_next_proto)(void *callback_state, char *proto_bits_packed);
|
||||||
|
void (*freedv_get_next_proto)(void *callback_state, char *proto_bits_packed);
|
||||||
|
void *proto_callback_state;
|
||||||
|
int n_protocol_bits;
|
||||||
|
};
|
||||||
|
|
||||||
|
// FIR filter suitable for changing rates 7500 to/from 8000
|
||||||
|
// Sample 120000 Hz, pass 2700, stop 3730, ripple 0.1dB, atten 100 dB. Stop 0.03108.
|
||||||
|
static float quiskFilt120t480[480] = { -0.000005050567303837, -0.000000267011791999, 0.000000197734700398, 0.000001038946634000,
|
||||||
|
0.000002322193058869, 0.000004115682735322, 0.000006499942123311, 0.000009551098482930, 0.000013350669444763,
|
||||||
|
0.000017966192635412, 0.000023463361155584, 0.000029885221425020, 0.000037271082107518, 0.000045630720487935,
|
||||||
|
0.000054970017069384, 0.000065233162392019, 0.000076360900545177, 0.000088271373315159, 0.000100818605854714,
|
||||||
|
0.000113853476544409, 0.000127174196746337, 0.000140558396336177, 0.000153744508371709, 0.000166450784469067,
|
||||||
|
0.000178368313347299, 0.000189176709991702, 0.000198541881389953, 0.000206128795372885, 0.000211604878787747,
|
||||||
|
0.000214655997661182, 0.000214994859281552, 0.000212358734245594, 0.000206539880117977, 0.000197379393194548,
|
||||||
|
0.000184780318878738, 0.000168719942655099, 0.000149250512353807, 0.000126511346757621, 0.000100726393185629,
|
||||||
|
0.000072210925236429, 0.000041365841965015, 0.000008680571408025, -0.000025277165852799, -0.000059865389594949,
|
||||||
|
-0.000094384355854646, -0.000128080670195777, -0.000160170174848483, -0.000189854272533545, -0.000216333899003825,
|
||||||
|
-0.000238836419299503, -0.000256632149501508, -0.000269058714331757, -0.000275541485292432, -0.000275614059005332,
|
||||||
|
-0.000268937472718753, -0.000255317038867589, -0.000234717772155001, -0.000207273956099563, -0.000173297342436372,
|
||||||
|
-0.000133280012107173, -0.000087895370243821, -0.000037986085678081, 0.000015440388211825, 0.000071232572821451,
|
||||||
|
0.000128114399130489, 0.000184710477990398, 0.000239577162514028, 0.000291234779803098, 0.000338204791740229,
|
||||||
|
0.000379047713684221, 0.000412403761615261, 0.000437031818051652, 0.000451848709179591, 0.000455966225408344,
|
||||||
|
0.000448726371643413, 0.000429729020814434, 0.000398857326863837, 0.000356297600912998, 0.000302547334727027,
|
||||||
|
0.000238422248479072, 0.000165048886226905, 0.000083853091464077, -0.000003462782744354, -0.000094949813106744,
|
||||||
|
-0.000188451833293202, -0.000281651282503015, -0.000372121907291206, -0.000457387566635848, -0.000534985542936898,
|
||||||
|
-0.000602532044011899, -0.000657788245032425, -0.000698728981427767, -0.000723604675185869, -0.000731002305621048,
|
||||||
|
-0.000719899536922384, -0.000689709694056092, -0.000640319946685634, -0.000572115873292030, -0.000485996080304965,
|
||||||
|
-0.000383371840261246, -0.000266155252511831, -0.000136731311264191, 0.000002082667095075, 0.000147092077716480,
|
||||||
|
0.000294790953130229, 0.000441441918072383, 0.000583164190168290, 0.000716029226064227, 0.000836164238172957,
|
||||||
|
0.000939856052624227, 0.001023657909064450, 0.001084492755093968, 0.001119751426837743, 0.001127383039339373,
|
||||||
|
0.001105974243787613, 0.001054815583369999, 0.000973950761085690, 0.000864209315714227, 0.000727219011746881,
|
||||||
|
0.000565398080608305, 0.000381924396468366, 0.000180685902835315, -0.000033793183292569, -0.000256444114966522,
|
||||||
|
-0.000481764526566339, -0.000703946352348464, -0.000917016099829735, -0.001114986581270253, -0.001292014799874503,
|
||||||
|
-0.001442563411804926, -0.001561559957317790, -0.001644551048567398, -0.001687846581475964, -0.001688649703502788,
|
||||||
|
-0.001645167889846890, -0.001556702802350076, -0.001423714708648073, -0.001247857669697092, -0.001031986722557201,
|
||||||
|
-0.000780131048444402, -0.000497436825078657, -0.000190077210351809, 0.000134868279325909, 0.000469563533327739,
|
||||||
|
0.000805591531546815, 0.001134152328775355, 0.001446279849797673, 0.001733071409562941, 0.001985924997799762,
|
||||||
|
0.002196778054604388, 0.002358342626407065, 0.002464328098407475, 0.002509648218888532, 0.002490604086803692,
|
||||||
|
0.002405037734357425, 0.002252452724297770, 0.002034094661603120, 0.001752990365583534, 0.001413941154886139,
|
||||||
|
0.001023470495638453, 0.000589723521647734, 0.000122320866350319, -0.000367832138027160, -0.000868777013398284,
|
||||||
|
-0.001367771151677059, -0.001851587344265625, -0.002306838088978190, -0.002720317947026380, -0.003079353614002113,
|
||||||
|
-0.003372155891804708, -0.003588162376578369, -0.003718362558663737, -0.003755596511143005, -0.003694818131674599,
|
||||||
|
-0.003533315298404129, -0.003270878754553819, -0.002909914962857412, -0.002455496391464944, -0.001915346645364514,
|
||||||
|
-0.001299757227227888, -0.000621437066532776, 0.000104706515738248, 0.000861849931067767, 0.001631595707499856,
|
||||||
|
0.002394368911341672, 0.003129858565588139, 0.003817496679992245, 0.004436963307209760, 0.004968707287606522,
|
||||||
|
0.005394469536085115, 0.005697797543539088, 0.005864537618023589, 0.005883292537600076, 0.005745832319314692,
|
||||||
|
0.005447447099071761, 0.004987231255534477, 0.004368289529377007, 0.003597859022418248, 0.002687338851256991,
|
||||||
|
0.001652226293162047, 0.000511956075882180, -0.000710356149138656, -0.001988263330091648, -0.003292424566049982,
|
||||||
|
-0.004591123342747130, -0.005850857852106148, -0.007036991266043732, -0.008114450164977267, -0.009048456200082230,
|
||||||
|
-0.009805276478965942, -0.010352975302354198, -0.010662152577592631, -0.010706650669328861, -0.010464214075017983,
|
||||||
|
-0.009917087295446811, -0.009052534679222271, -0.007863270920348924, -0.006347789704693751, -0.004510582323649121,
|
||||||
|
-0.002362238055733795, 0.000080576968834213, 0.002795265196543707, 0.005753566158586979, 0.008921944932552510,
|
||||||
|
0.012262093950265378, 0.015731539846483594, 0.019284344624007944, 0.022871886384520687, 0.026443706729191677,
|
||||||
|
0.029948406200633094, 0.033334570666910354, 0.036551709955124537, 0.039551189200810140, 0.042287133974308874,
|
||||||
|
0.044717290029466283, 0.046803820535016104, 0.048514022996355009, 0.049820951883635139, 0.050703932928426454,
|
||||||
|
0.051148959210315710, 0.051148959210315710, 0.050703932928426454, 0.049820951883635139, 0.048514022996355009,
|
||||||
|
0.046803820535016104, 0.044717290029466283, 0.042287133974308874, 0.039551189200810140, 0.036551709955124537,
|
||||||
|
0.033334570666910354, 0.029948406200633094, 0.026443706729191677, 0.022871886384520687, 0.019284344624007944,
|
||||||
|
0.015731539846483594, 0.012262093950265378, 0.008921944932552510, 0.005753566158586979, 0.002795265196543707,
|
||||||
|
0.000080576968834213, -0.002362238055733795, -0.004510582323649121, -0.006347789704693751, -0.007863270920348924,
|
||||||
|
-0.009052534679222271, -0.009917087295446811, -0.010464214075017983, -0.010706650669328861, -0.010662152577592631,
|
||||||
|
-0.010352975302354198, -0.009805276478965942, -0.009048456200082230, -0.008114450164977267, -0.007036991266043732,
|
||||||
|
-0.005850857852106148, -0.004591123342747130, -0.003292424566049982, -0.001988263330091648, -0.000710356149138656,
|
||||||
|
0.000511956075882180, 0.001652226293162047, 0.002687338851256991, 0.003597859022418248, 0.004368289529377007,
|
||||||
|
0.004987231255534477, 0.005447447099071761, 0.005745832319314692, 0.005883292537600076, 0.005864537618023589,
|
||||||
|
0.005697797543539088, 0.005394469536085115, 0.004968707287606522, 0.004436963307209760, 0.003817496679992245,
|
||||||
|
0.003129858565588139, 0.002394368911341672, 0.001631595707499856, 0.000861849931067767, 0.000104706515738248,
|
||||||
|
-0.000621437066532776, -0.001299757227227888, -0.001915346645364514, -0.002455496391464944, -0.002909914962857412,
|
||||||
|
-0.003270878754553819, -0.003533315298404129, -0.003694818131674599, -0.003755596511143005, -0.003718362558663737,
|
||||||
|
-0.003588162376578369, -0.003372155891804708, -0.003079353614002113, -0.002720317947026380, -0.002306838088978190,
|
||||||
|
-0.001851587344265625, -0.001367771151677059, -0.000868777013398284, -0.000367832138027160, 0.000122320866350319,
|
||||||
|
0.000589723521647734, 0.001023470495638453, 0.001413941154886139, 0.001752990365583534, 0.002034094661603120,
|
||||||
|
0.002252452724297770, 0.002405037734357425, 0.002490604086803692, 0.002509648218888532, 0.002464328098407475,
|
||||||
|
0.002358342626407065, 0.002196778054604388, 0.001985924997799762, 0.001733071409562941, 0.001446279849797673,
|
||||||
|
0.001134152328775355, 0.000805591531546815, 0.000469563533327739, 0.000134868279325909, -0.000190077210351809,
|
||||||
|
-0.000497436825078657, -0.000780131048444402, -0.001031986722557201, -0.001247857669697092, -0.001423714708648073,
|
||||||
|
-0.001556702802350076, -0.001645167889846890, -0.001688649703502788, -0.001687846581475964, -0.001644551048567398,
|
||||||
|
-0.001561559957317790, -0.001442563411804926, -0.001292014799874503, -0.001114986581270253, -0.000917016099829735,
|
||||||
|
-0.000703946352348464, -0.000481764526566339, -0.000256444114966522, -0.000033793183292569, 0.000180685902835315,
|
||||||
|
0.000381924396468366, 0.000565398080608305, 0.000727219011746881, 0.000864209315714227, 0.000973950761085690,
|
||||||
|
0.001054815583369999, 0.001105974243787613, 0.001127383039339373, 0.001119751426837743, 0.001084492755093968,
|
||||||
|
0.001023657909064450, 0.000939856052624227, 0.000836164238172957, 0.000716029226064227, 0.000583164190168290,
|
||||||
|
0.000441441918072383, 0.000294790953130229, 0.000147092077716480, 0.000002082667095075, -0.000136731311264191,
|
||||||
|
-0.000266155252511831, -0.000383371840261246, -0.000485996080304965, -0.000572115873292030, -0.000640319946685634,
|
||||||
|
-0.000689709694056092, -0.000719899536922384, -0.000731002305621048, -0.000723604675185869, -0.000698728981427767,
|
||||||
|
-0.000657788245032425, -0.000602532044011899, -0.000534985542936898, -0.000457387566635848, -0.000372121907291206,
|
||||||
|
-0.000281651282503015, -0.000188451833293202, -0.000094949813106744, -0.000003462782744354, 0.000083853091464077,
|
||||||
|
0.000165048886226905, 0.000238422248479072, 0.000302547334727027, 0.000356297600912998, 0.000398857326863837,
|
||||||
|
0.000429729020814434, 0.000448726371643413, 0.000455966225408344, 0.000451848709179591, 0.000437031818051652,
|
||||||
|
0.000412403761615261, 0.000379047713684221, 0.000338204791740229, 0.000291234779803098, 0.000239577162514028,
|
||||||
|
0.000184710477990398, 0.000128114399130489, 0.000071232572821451, 0.000015440388211825, -0.000037986085678081,
|
||||||
|
-0.000087895370243821, -0.000133280012107173, -0.000173297342436372, -0.000207273956099563, -0.000234717772155001,
|
||||||
|
-0.000255317038867589, -0.000268937472718753, -0.000275614059005332, -0.000275541485292432, -0.000269058714331757,
|
||||||
|
-0.000256632149501508, -0.000238836419299503, -0.000216333899003825, -0.000189854272533545, -0.000160170174848483,
|
||||||
|
-0.000128080670195777, -0.000094384355854646, -0.000059865389594949, -0.000025277165852799, 0.000008680571408025,
|
||||||
|
0.000041365841965015, 0.000072210925236429, 0.000100726393185629, 0.000126511346757621, 0.000149250512353807,
|
||||||
|
0.000168719942655099, 0.000184780318878738, 0.000197379393194548, 0.000206539880117977, 0.000212358734245594,
|
||||||
|
0.000214994859281552, 0.000214655997661182, 0.000211604878787747, 0.000206128795372885, 0.000198541881389953,
|
||||||
|
0.000189176709991702, 0.000178368313347299, 0.000166450784469067, 0.000153744508371709, 0.000140558396336177,
|
||||||
|
0.000127174196746337, 0.000113853476544409, 0.000100818605854714, 0.000088271373315159, 0.000076360900545177,
|
||||||
|
0.000065233162392019, 0.000054970017069384, 0.000045630720487935, 0.000037271082107518, 0.000029885221425020,
|
||||||
|
0.000023463361155584, 0.000017966192635412, 0.000013350669444763, 0.000009551098482930, 0.000006499942123311,
|
||||||
|
0.000004115682735322, 0.000002322193058869, 0.000001038946634000, 0.000000197734700398, -0.000000267011791999,
|
||||||
|
-0.000005050567303837 };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: freedv_data_channel.h
|
||||||
|
AUTHOR......: Jeroen Vreeken
|
||||||
|
DATE CREATED: 03 March 2016
|
||||||
|
|
||||||
|
Data channel for ethernet like packets in freedv VHF frames.
|
||||||
|
Currently designed for-
|
||||||
|
* 2 control bits per frame
|
||||||
|
* 4 byte counter bits per frame
|
||||||
|
* 64 bits of data per frame
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2016 Jeroen Vreeken
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _FREEDV_DATA_CHANNEL_H
|
||||||
|
#define _FREEDV_DATA_CHANNEL_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define FREEDV_DATA_CHANNEL_PACKET_MAX 2048
|
||||||
|
|
||||||
|
typedef void (*freedv_data_callback_rx)(void *, unsigned char *packet, size_t size);
|
||||||
|
typedef void (*freedv_data_callback_tx)(void *, unsigned char *packet, size_t *size);
|
||||||
|
|
||||||
|
struct freedv_data_channel {
|
||||||
|
freedv_data_callback_rx cb_rx;
|
||||||
|
void *cb_rx_state;
|
||||||
|
freedv_data_callback_tx cb_tx;
|
||||||
|
void *cb_tx_state;
|
||||||
|
|
||||||
|
unsigned char rx_header[8];
|
||||||
|
unsigned char packet_rx[FREEDV_DATA_CHANNEL_PACKET_MAX + 2];
|
||||||
|
int packet_rx_cnt;
|
||||||
|
|
||||||
|
unsigned char tx_header[8];
|
||||||
|
unsigned char packet_tx[FREEDV_DATA_CHANNEL_PACKET_MAX + 2];
|
||||||
|
int packet_tx_cnt;
|
||||||
|
size_t packet_tx_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct freedv_data_channel *freedv_data_channel_create(void);
|
||||||
|
void freedv_data_channel_destroy(struct freedv_data_channel *fdc);
|
||||||
|
|
||||||
|
void freedv_data_set_cb_rx(struct freedv_data_channel *fdc, freedv_data_callback_rx cb, void *state);
|
||||||
|
void freedv_data_set_cb_tx(struct freedv_data_channel *fdc, freedv_data_callback_tx cb, void *state);
|
||||||
|
|
||||||
|
void freedv_data_channel_rx_frame(struct freedv_data_channel *fdc, unsigned char *data, size_t size, int from_bit, int bcast_bit, int crc_bit, int end_bits);
|
||||||
|
void freedv_data_channel_tx_frame(struct freedv_data_channel *fdc, unsigned char *data, size_t size, int *from_bit, int *bcast_bit, int *crc_bit, int *end_bits);
|
||||||
|
|
||||||
|
void freedv_data_set_header(struct freedv_data_channel *fdc, unsigned char *header);
|
||||||
|
int freedv_data_get_n_tx_frames(struct freedv_data_channel *fdc, size_t size);
|
||||||
|
|
||||||
|
#endif /* _FREEDV_DATA_CHANNEL_H */
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: freedv_vhf_framing.h
|
||||||
|
AUTHOR......: Brady O'Brien
|
||||||
|
DATE CREATED: 11 February 2016
|
||||||
|
|
||||||
|
Framer and deframer for VHF FreeDV modes 'A' and 'B'
|
||||||
|
Currently designed for-
|
||||||
|
* 40ms ota modem frames
|
||||||
|
* 40ms Codec2 1300 frames
|
||||||
|
* 52 bits of Codec2 per frame
|
||||||
|
* 16 bits of unique word per frame
|
||||||
|
* 28 'spare' bits per frame
|
||||||
|
* - 4 spare bits at front and end of frame (8 total) for padding
|
||||||
|
* - 20 'protocol' bits, either for higher layers of 'protocol' or
|
||||||
|
* - 18 'protocol' bits and 2 vericode sidechannel bits
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2016 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _FREEDV_VHF_FRAMING_H
|
||||||
|
#define _FREEDV_VHF_FRAMING_H
|
||||||
|
|
||||||
|
#include "freedv_data_channel.h"
|
||||||
|
|
||||||
|
/* Standard frame type */
|
||||||
|
#define FREEDV_VHF_FRAME_A 1 /* 2400A/B Frame */
|
||||||
|
#define FREEDV_HF_FRAME_B 2 /* 800XA Frame */
|
||||||
|
#define FREEDV_VHF_FRAME_AT 3 /* 4800T Frame */
|
||||||
|
|
||||||
|
struct freedv_vhf_deframer {
|
||||||
|
int ftype; /* Type of frame to be looking for */
|
||||||
|
int state; /* State of deframer */
|
||||||
|
uint8_t * bits; /* Bits currently being decanted */
|
||||||
|
uint8_t * invbits; /* Inversion of bits currently being decanted, for FMFSK */
|
||||||
|
|
||||||
|
int bitptr; /* Pointer into circular bit buffer */
|
||||||
|
int miss_cnt; /* How many UWs have been missed */
|
||||||
|
int last_uw; /* How many bits since the last UW? */
|
||||||
|
int frame_size; /* How big is a frame? */
|
||||||
|
int uw_size; /* How big is the UW */
|
||||||
|
int on_inv_bits; /* Are we using the inverted bits? */
|
||||||
|
int sym_size; /* How many bits in a modem symbol */
|
||||||
|
|
||||||
|
float ber_est; /* Bit error rate estimate */
|
||||||
|
int total_uw_bits; /* Total RX-ed bits of UW */
|
||||||
|
int total_uw_err; /* Total errors in UW bits */
|
||||||
|
|
||||||
|
struct freedv_data_channel *fdc;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Init and allocate memory for a freedv-vhf framer/deframer */
|
||||||
|
struct freedv_vhf_deframer * fvhff_create_deframer(uint8_t frame_type,int enable_bit_flip);
|
||||||
|
|
||||||
|
/* Get size of various frame parameters */
|
||||||
|
/* Frame size in bits */
|
||||||
|
int fvhff_get_frame_size(struct freedv_vhf_deframer * def);
|
||||||
|
/* Codec2 size in bytes */
|
||||||
|
int fvhff_get_codec2_size(struct freedv_vhf_deframer * def);
|
||||||
|
/* Protocol bits in bits */
|
||||||
|
int fvhff_get_proto_size(struct freedv_vhf_deframer * def);
|
||||||
|
/* Varicode bits in bits */
|
||||||
|
int fvhff_get_varicode_size(struct freedv_vhf_deframer * def);
|
||||||
|
|
||||||
|
/* Free the memory used by a freedv-vhf framer/deframer */
|
||||||
|
void fvhff_destroy_deframer(struct freedv_vhf_deframer * def);
|
||||||
|
|
||||||
|
/* Place codec and other bits into a frame */
|
||||||
|
void fvhff_frame_bits(int frame_type,uint8_t bits_out[],uint8_t codec2_in[],uint8_t proto_in[],uint8_t vc_in[]);
|
||||||
|
void fvhff_frame_data_bits(struct freedv_vhf_deframer * def, int frame_type,uint8_t bits_out[]);
|
||||||
|
|
||||||
|
/* Find and extract frames from a stream of bits */
|
||||||
|
int fvhff_deframe_bits(struct freedv_vhf_deframer * def,uint8_t codec2_out[],uint8_t proto_out[],uint8_t vc_out[],uint8_t bits_in[]);
|
||||||
|
|
||||||
|
/* Is the de-framer synchronized? */
|
||||||
|
int fvhff_synchronized(struct freedv_vhf_deframer * def);
|
||||||
|
|
||||||
|
#endif //_FREEDV_VHF_FRAMING_H
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: fsk.h
|
||||||
|
AUTHOR......: Brady O'Brien
|
||||||
|
DATE CREATED: 6 January 2016
|
||||||
|
|
||||||
|
C Implementation of 2FSK/4FSK modulator/demodulator, based on octave/fsk_horus.m
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2016 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __C2FSK_H
|
||||||
|
#define __C2FSK_H
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "comp.h"
|
||||||
|
#include "kiss_fftr.h"
|
||||||
|
#include "modem_stats.h"
|
||||||
|
|
||||||
|
#define MODE_2FSK 2
|
||||||
|
#define MODE_4FSK 4
|
||||||
|
|
||||||
|
#define MODE_M_MAX 4
|
||||||
|
|
||||||
|
#define FSK_SCALE 16383
|
||||||
|
|
||||||
|
struct FSK {
|
||||||
|
/* Static parameters set up by fsk_init */
|
||||||
|
int Ndft; /* buffer size for freq offset est fft */
|
||||||
|
int Fs; /* sample freq */
|
||||||
|
int N; /* processing buffer size */
|
||||||
|
int Rs; /* symbol rate */
|
||||||
|
int Ts; /* samples per symbol */
|
||||||
|
int Nmem; /* size of extra mem for timing adj */
|
||||||
|
int P; /* oversample rate for timing est/adj */
|
||||||
|
int Nsym; /* Number of symbols spat out in a processing frame */
|
||||||
|
int Nbits; /* Number of bits spat out in a processing frame */
|
||||||
|
int f1_tx; /* f1 for modulator */
|
||||||
|
int fs_tx; /* Space between TX freqs for modulatosr */
|
||||||
|
int mode; /* 2FSK or 4FSK */
|
||||||
|
int est_min; /* Minimum frequency for freq. estimator */
|
||||||
|
int est_max; /* Maximum frequency for freq. estimaotr */
|
||||||
|
int est_space; /* Minimum frequency spacing for freq. estimator */
|
||||||
|
float* hann_table; /* Precomputed or runtime computed hann window table */
|
||||||
|
|
||||||
|
/* Parameters used by demod */
|
||||||
|
COMP phi_c[MODE_M_MAX];
|
||||||
|
|
||||||
|
kiss_fft_cfg fft_cfg; /* Config for KISS FFT, used in freq est */
|
||||||
|
float norm_rx_timing; /* Normalized RX timing */
|
||||||
|
|
||||||
|
COMP* samp_old; /* Tail end of last batch of samples */
|
||||||
|
int nstash; /* How many elements are in there */
|
||||||
|
|
||||||
|
float* fft_est; /* Freq est FFT magnitude */
|
||||||
|
|
||||||
|
/* Memory used by demod but not important between demod frames */
|
||||||
|
|
||||||
|
/* Parameters used by mod */
|
||||||
|
COMP tx_phase_c; /* TX phase, but complex */
|
||||||
|
|
||||||
|
/* Statistics generated by demod */
|
||||||
|
float EbNodB; /* Estimated EbNo in dB */
|
||||||
|
float f_est[MODE_M_MAX];/* Estimated frequencies */
|
||||||
|
float ppm; /* Estimated PPM clock offset */
|
||||||
|
|
||||||
|
/* Parameters used by mod/demod and driving code */
|
||||||
|
int nin; /* Number of samples to feed the next demod cycle */
|
||||||
|
|
||||||
|
/* modem statistic struct */
|
||||||
|
struct MODEM_STATS *stats;
|
||||||
|
int normalise_eye; /* enables/disables normalisation of eye diagram */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create an FSK config/state struct from a set of config parameters
|
||||||
|
*
|
||||||
|
* int Fs - Sample frequency
|
||||||
|
* int Rs - Symbol rate
|
||||||
|
* int tx_f1 - '0' frequency
|
||||||
|
* int tx_fs - frequency spacing
|
||||||
|
*/
|
||||||
|
struct FSK * fsk_create(int Fs, int Rs, int M, int tx_f1, int tx_fs);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create an FSK config/state struct from a set of config parameters
|
||||||
|
*
|
||||||
|
* int Fs - Sample frequency
|
||||||
|
* int Rs - Symbol rate
|
||||||
|
* int tx_f1 - '0' frequency
|
||||||
|
* int tx_fs - frequency spacing
|
||||||
|
*/
|
||||||
|
struct FSK * fsk_create_hbr(int Fs, int Rs, int P, int M, int tx_f1, int tx_fs);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set a new number of symbols per processing frame
|
||||||
|
*/
|
||||||
|
void fsk_set_nsym(struct FSK *fsk,int nsym);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the minimum and maximum frequencies at which the freq. estimator can find tones
|
||||||
|
*/
|
||||||
|
void fsk_set_est_limits(struct FSK *fsk,int fmin, int fmax);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Clear the estimator states
|
||||||
|
*/
|
||||||
|
void fsk_clear_estimators(struct FSK *fsk);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fills MODEM_STATS struct with demod statistics
|
||||||
|
*/
|
||||||
|
void fsk_get_demod_stats(struct FSK *fsk, struct MODEM_STATS *stats);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Destroy an FSK state struct and free it's memory
|
||||||
|
*
|
||||||
|
* struct FSK *fsk - FSK config/state struct to be destroyed
|
||||||
|
*/
|
||||||
|
void fsk_destroy(struct FSK *fsk);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Modulates Nsym bits into N samples
|
||||||
|
*
|
||||||
|
* struct FSK *fsk - FSK config/state struct, set up by fsk_create
|
||||||
|
* float fsk_out[] - Buffer for N samples of modulated FSK
|
||||||
|
* uint8_t tx_bits[] - Buffer containing Nbits unpacked bits
|
||||||
|
*/
|
||||||
|
void fsk_mod(struct FSK *fsk, float fsk_out[], uint8_t tx_bits[]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Modulates Nsym bits into N complex samples
|
||||||
|
*
|
||||||
|
* struct FSK *fsk - FSK config/state struct, set up by fsk_create
|
||||||
|
* comp fsk_out[] - Buffer for N samples of modulated FSK
|
||||||
|
* uint8_t tx_bits[] - Buffer containing Nbits unpacked bits
|
||||||
|
*/
|
||||||
|
void fsk_mod_c(struct FSK *fsk, COMP fsk_out[], uint8_t tx_bits[]);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the number of samples needed for the next fsk_demod() cycle
|
||||||
|
*
|
||||||
|
* struct FSK *fsk - FSK config/state struct, set up by fsk_create
|
||||||
|
* returns - number of samples to be fed into fsk_demod next cycle
|
||||||
|
*/
|
||||||
|
uint32_t fsk_nin(struct FSK *fsk);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Demodulate some number of FSK samples. The number of samples to be
|
||||||
|
* demodulated can be found by calling fsk_nin().
|
||||||
|
*
|
||||||
|
* struct FSK *fsk - FSK config/state struct, set up by fsk_create
|
||||||
|
* uint8_t rx_bits[] - Buffer for Nbits unpacked bits to be written
|
||||||
|
* float fsk_in[] - nin samples of modualted FSK
|
||||||
|
*/
|
||||||
|
void fsk_demod(struct FSK *fsk, uint8_t rx_bits[],COMP fsk_in[]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Demodulate some number of FSK samples. The number of samples to be
|
||||||
|
* demodulated can be found by calling fsk_nin().
|
||||||
|
*
|
||||||
|
* struct FSK *fsk - FSK config/state struct, set up by fsk_create
|
||||||
|
* float rx_bits[] - Buffer for Nbits soft decision bits to be written
|
||||||
|
* float fsk_in[] - nin samples of modualted FSK
|
||||||
|
*/
|
||||||
|
void fsk_demod_sd(struct FSK *fsk, float rx_bits[],COMP fsk_in[]);
|
||||||
|
|
||||||
|
/* enables/disables normalisation of eye diagram samples */
|
||||||
|
|
||||||
|
void fsk_stats_normalise_eye(struct FSK *fsk, int normalise_enable);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: golay23.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 3 March 2013
|
||||||
|
|
||||||
|
Header file for Golay FEC.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2013 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GOLAY23__
|
||||||
|
#define __GOLAY23__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void golay23_init(void);
|
||||||
|
int golay23_encode(int data);
|
||||||
|
int golay23_decode(int received_codeword);
|
||||||
|
int golay23_count_errors(int recd_codeword, int corrected_codeword);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,644 @@
|
|||||||
|
/* Generated by hanning_file() Octave function */
|
||||||
|
|
||||||
|
const float hanning[]={
|
||||||
|
0,
|
||||||
|
2.4171e-05,
|
||||||
|
9.66816e-05,
|
||||||
|
0.000217525,
|
||||||
|
0.000386689,
|
||||||
|
0.000604158,
|
||||||
|
0.00086991,
|
||||||
|
0.00118392,
|
||||||
|
0.00154616,
|
||||||
|
0.00195659,
|
||||||
|
0.00241517,
|
||||||
|
0.00292186,
|
||||||
|
0.00347661,
|
||||||
|
0.00407937,
|
||||||
|
0.00473008,
|
||||||
|
0.00542867,
|
||||||
|
0.00617507,
|
||||||
|
0.00696922,
|
||||||
|
0.00781104,
|
||||||
|
0.00870045,
|
||||||
|
0.00963736,
|
||||||
|
0.0106217,
|
||||||
|
0.0116533,
|
||||||
|
0.0127322,
|
||||||
|
0.0138581,
|
||||||
|
0.0150311,
|
||||||
|
0.0162509,
|
||||||
|
0.0175175,
|
||||||
|
0.0188308,
|
||||||
|
0.0201906,
|
||||||
|
0.0215968,
|
||||||
|
0.0230492,
|
||||||
|
0.0245478,
|
||||||
|
0.0260923,
|
||||||
|
0.0276826,
|
||||||
|
0.0293186,
|
||||||
|
0.0310001,
|
||||||
|
0.032727,
|
||||||
|
0.034499,
|
||||||
|
0.036316,
|
||||||
|
0.0381779,
|
||||||
|
0.0400844,
|
||||||
|
0.0420354,
|
||||||
|
0.0440307,
|
||||||
|
0.04607,
|
||||||
|
0.0481533,
|
||||||
|
0.0502802,
|
||||||
|
0.0524506,
|
||||||
|
0.0546643,
|
||||||
|
0.056921,
|
||||||
|
0.0592206,
|
||||||
|
0.0615627,
|
||||||
|
0.0639473,
|
||||||
|
0.0663741,
|
||||||
|
0.0688427,
|
||||||
|
0.0713531,
|
||||||
|
0.0739048,
|
||||||
|
0.0764978,
|
||||||
|
0.0791318,
|
||||||
|
0.0818064,
|
||||||
|
0.0845214,
|
||||||
|
0.0872767,
|
||||||
|
0.0900718,
|
||||||
|
0.0929066,
|
||||||
|
0.0957807,
|
||||||
|
0.0986939,
|
||||||
|
0.101646,
|
||||||
|
0.104636,
|
||||||
|
0.107665,
|
||||||
|
0.110732,
|
||||||
|
0.113836,
|
||||||
|
0.116978,
|
||||||
|
0.120156,
|
||||||
|
0.123372,
|
||||||
|
0.126624,
|
||||||
|
0.129912,
|
||||||
|
0.133235,
|
||||||
|
0.136594,
|
||||||
|
0.139989,
|
||||||
|
0.143418,
|
||||||
|
0.146881,
|
||||||
|
0.150379,
|
||||||
|
0.153911,
|
||||||
|
0.157476,
|
||||||
|
0.161074,
|
||||||
|
0.164705,
|
||||||
|
0.168368,
|
||||||
|
0.172063,
|
||||||
|
0.17579,
|
||||||
|
0.179549,
|
||||||
|
0.183338,
|
||||||
|
0.187158,
|
||||||
|
0.191008,
|
||||||
|
0.194888,
|
||||||
|
0.198798,
|
||||||
|
0.202737,
|
||||||
|
0.206704,
|
||||||
|
0.2107,
|
||||||
|
0.214724,
|
||||||
|
0.218775,
|
||||||
|
0.222854,
|
||||||
|
0.226959,
|
||||||
|
0.231091,
|
||||||
|
0.235249,
|
||||||
|
0.239432,
|
||||||
|
0.243641,
|
||||||
|
0.247874,
|
||||||
|
0.252132,
|
||||||
|
0.256414,
|
||||||
|
0.260719,
|
||||||
|
0.265047,
|
||||||
|
0.269398,
|
||||||
|
0.273772,
|
||||||
|
0.278167,
|
||||||
|
0.282584,
|
||||||
|
0.287021,
|
||||||
|
0.29148,
|
||||||
|
0.295958,
|
||||||
|
0.300456,
|
||||||
|
0.304974,
|
||||||
|
0.30951,
|
||||||
|
0.314065,
|
||||||
|
0.318638,
|
||||||
|
0.323228,
|
||||||
|
0.327835,
|
||||||
|
0.332459,
|
||||||
|
0.3371,
|
||||||
|
0.341756,
|
||||||
|
0.346427,
|
||||||
|
0.351113,
|
||||||
|
0.355814,
|
||||||
|
0.360528,
|
||||||
|
0.365256,
|
||||||
|
0.369997,
|
||||||
|
0.374751,
|
||||||
|
0.379516,
|
||||||
|
0.384293,
|
||||||
|
0.389082,
|
||||||
|
0.393881,
|
||||||
|
0.398691,
|
||||||
|
0.40351,
|
||||||
|
0.408338,
|
||||||
|
0.413176,
|
||||||
|
0.418022,
|
||||||
|
0.422876,
|
||||||
|
0.427737,
|
||||||
|
0.432605,
|
||||||
|
0.43748,
|
||||||
|
0.44236,
|
||||||
|
0.447247,
|
||||||
|
0.452138,
|
||||||
|
0.457034,
|
||||||
|
0.461935,
|
||||||
|
0.466839,
|
||||||
|
0.471746,
|
||||||
|
0.476655,
|
||||||
|
0.481568,
|
||||||
|
0.486481,
|
||||||
|
0.491397,
|
||||||
|
0.496313,
|
||||||
|
0.501229,
|
||||||
|
0.506145,
|
||||||
|
0.511061,
|
||||||
|
0.515976,
|
||||||
|
0.520889,
|
||||||
|
0.5258,
|
||||||
|
0.530708,
|
||||||
|
0.535614,
|
||||||
|
0.540516,
|
||||||
|
0.545414,
|
||||||
|
0.550308,
|
||||||
|
0.555197,
|
||||||
|
0.560081,
|
||||||
|
0.564958,
|
||||||
|
0.56983,
|
||||||
|
0.574695,
|
||||||
|
0.579552,
|
||||||
|
0.584402,
|
||||||
|
0.589244,
|
||||||
|
0.594077,
|
||||||
|
0.598901,
|
||||||
|
0.603715,
|
||||||
|
0.60852,
|
||||||
|
0.613314,
|
||||||
|
0.618097,
|
||||||
|
0.622868,
|
||||||
|
0.627628,
|
||||||
|
0.632375,
|
||||||
|
0.63711,
|
||||||
|
0.641831,
|
||||||
|
0.646538,
|
||||||
|
0.651232,
|
||||||
|
0.655911,
|
||||||
|
0.660574,
|
||||||
|
0.665222,
|
||||||
|
0.669855,
|
||||||
|
0.67447,
|
||||||
|
0.679069,
|
||||||
|
0.683651,
|
||||||
|
0.688215,
|
||||||
|
0.69276,
|
||||||
|
0.697287,
|
||||||
|
0.701795,
|
||||||
|
0.706284,
|
||||||
|
0.710752,
|
||||||
|
0.7152,
|
||||||
|
0.719627,
|
||||||
|
0.724033,
|
||||||
|
0.728418,
|
||||||
|
0.73278,
|
||||||
|
0.73712,
|
||||||
|
0.741437,
|
||||||
|
0.74573,
|
||||||
|
0.75,
|
||||||
|
0.754246,
|
||||||
|
0.758467,
|
||||||
|
0.762663,
|
||||||
|
0.766833,
|
||||||
|
0.770978,
|
||||||
|
0.775097,
|
||||||
|
0.779189,
|
||||||
|
0.783254,
|
||||||
|
0.787291,
|
||||||
|
0.791301,
|
||||||
|
0.795283,
|
||||||
|
0.799236,
|
||||||
|
0.80316,
|
||||||
|
0.807055,
|
||||||
|
0.810921,
|
||||||
|
0.814756,
|
||||||
|
0.81856,
|
||||||
|
0.822334,
|
||||||
|
0.826077,
|
||||||
|
0.829788,
|
||||||
|
0.833468,
|
||||||
|
0.837115,
|
||||||
|
0.840729,
|
||||||
|
0.844311,
|
||||||
|
0.847859,
|
||||||
|
0.851374,
|
||||||
|
0.854855,
|
||||||
|
0.858301,
|
||||||
|
0.861713,
|
||||||
|
0.86509,
|
||||||
|
0.868431,
|
||||||
|
0.871737,
|
||||||
|
0.875007,
|
||||||
|
0.87824,
|
||||||
|
0.881437,
|
||||||
|
0.884598,
|
||||||
|
0.887721,
|
||||||
|
0.890806,
|
||||||
|
0.893854,
|
||||||
|
0.896864,
|
||||||
|
0.899835,
|
||||||
|
0.902768,
|
||||||
|
0.905661,
|
||||||
|
0.908516,
|
||||||
|
0.911331,
|
||||||
|
0.914106,
|
||||||
|
0.916841,
|
||||||
|
0.919536,
|
||||||
|
0.92219,
|
||||||
|
0.924804,
|
||||||
|
0.927376,
|
||||||
|
0.929907,
|
||||||
|
0.932397,
|
||||||
|
0.934845,
|
||||||
|
0.93725,
|
||||||
|
0.939614,
|
||||||
|
0.941935,
|
||||||
|
0.944213,
|
||||||
|
0.946448,
|
||||||
|
0.94864,
|
||||||
|
0.950789,
|
||||||
|
0.952894,
|
||||||
|
0.954955,
|
||||||
|
0.956972,
|
||||||
|
0.958946,
|
||||||
|
0.960874,
|
||||||
|
0.962759,
|
||||||
|
0.964598,
|
||||||
|
0.966393,
|
||||||
|
0.968142,
|
||||||
|
0.969846,
|
||||||
|
0.971505,
|
||||||
|
0.973118,
|
||||||
|
0.974686,
|
||||||
|
0.976207,
|
||||||
|
0.977683,
|
||||||
|
0.979112,
|
||||||
|
0.980495,
|
||||||
|
0.981832,
|
||||||
|
0.983122,
|
||||||
|
0.984365,
|
||||||
|
0.985561,
|
||||||
|
0.986711,
|
||||||
|
0.987813,
|
||||||
|
0.988868,
|
||||||
|
0.989876,
|
||||||
|
0.990837,
|
||||||
|
0.99175,
|
||||||
|
0.992616,
|
||||||
|
0.993434,
|
||||||
|
0.994204,
|
||||||
|
0.994927,
|
||||||
|
0.995601,
|
||||||
|
0.996228,
|
||||||
|
0.996807,
|
||||||
|
0.997337,
|
||||||
|
0.99782,
|
||||||
|
0.998255,
|
||||||
|
0.998641,
|
||||||
|
0.998979,
|
||||||
|
0.999269,
|
||||||
|
0.999511,
|
||||||
|
0.999704,
|
||||||
|
0.999849,
|
||||||
|
0.999946,
|
||||||
|
0.999994,
|
||||||
|
0.999994,
|
||||||
|
0.999946,
|
||||||
|
0.999849,
|
||||||
|
0.999704,
|
||||||
|
0.999511,
|
||||||
|
0.999269,
|
||||||
|
0.998979,
|
||||||
|
0.998641,
|
||||||
|
0.998255,
|
||||||
|
0.99782,
|
||||||
|
0.997337,
|
||||||
|
0.996807,
|
||||||
|
0.996228,
|
||||||
|
0.995601,
|
||||||
|
0.994927,
|
||||||
|
0.994204,
|
||||||
|
0.993434,
|
||||||
|
0.992616,
|
||||||
|
0.99175,
|
||||||
|
0.990837,
|
||||||
|
0.989876,
|
||||||
|
0.988868,
|
||||||
|
0.987813,
|
||||||
|
0.986711,
|
||||||
|
0.985561,
|
||||||
|
0.984365,
|
||||||
|
0.983122,
|
||||||
|
0.981832,
|
||||||
|
0.980495,
|
||||||
|
0.979112,
|
||||||
|
0.977683,
|
||||||
|
0.976207,
|
||||||
|
0.974686,
|
||||||
|
0.973118,
|
||||||
|
0.971505,
|
||||||
|
0.969846,
|
||||||
|
0.968142,
|
||||||
|
0.966393,
|
||||||
|
0.964598,
|
||||||
|
0.962759,
|
||||||
|
0.960874,
|
||||||
|
0.958946,
|
||||||
|
0.956972,
|
||||||
|
0.954955,
|
||||||
|
0.952894,
|
||||||
|
0.950789,
|
||||||
|
0.94864,
|
||||||
|
0.946448,
|
||||||
|
0.944213,
|
||||||
|
0.941935,
|
||||||
|
0.939614,
|
||||||
|
0.93725,
|
||||||
|
0.934845,
|
||||||
|
0.932397,
|
||||||
|
0.929907,
|
||||||
|
0.927376,
|
||||||
|
0.924804,
|
||||||
|
0.92219,
|
||||||
|
0.919536,
|
||||||
|
0.916841,
|
||||||
|
0.914106,
|
||||||
|
0.911331,
|
||||||
|
0.908516,
|
||||||
|
0.905661,
|
||||||
|
0.902768,
|
||||||
|
0.899835,
|
||||||
|
0.896864,
|
||||||
|
0.893854,
|
||||||
|
0.890806,
|
||||||
|
0.887721,
|
||||||
|
0.884598,
|
||||||
|
0.881437,
|
||||||
|
0.87824,
|
||||||
|
0.875007,
|
||||||
|
0.871737,
|
||||||
|
0.868431,
|
||||||
|
0.86509,
|
||||||
|
0.861713,
|
||||||
|
0.858301,
|
||||||
|
0.854855,
|
||||||
|
0.851374,
|
||||||
|
0.847859,
|
||||||
|
0.844311,
|
||||||
|
0.840729,
|
||||||
|
0.837115,
|
||||||
|
0.833468,
|
||||||
|
0.829788,
|
||||||
|
0.826077,
|
||||||
|
0.822334,
|
||||||
|
0.81856,
|
||||||
|
0.814756,
|
||||||
|
0.810921,
|
||||||
|
0.807055,
|
||||||
|
0.80316,
|
||||||
|
0.799236,
|
||||||
|
0.795283,
|
||||||
|
0.791301,
|
||||||
|
0.787291,
|
||||||
|
0.783254,
|
||||||
|
0.779189,
|
||||||
|
0.775097,
|
||||||
|
0.770978,
|
||||||
|
0.766833,
|
||||||
|
0.762663,
|
||||||
|
0.758467,
|
||||||
|
0.754246,
|
||||||
|
0.75,
|
||||||
|
0.74573,
|
||||||
|
0.741437,
|
||||||
|
0.73712,
|
||||||
|
0.73278,
|
||||||
|
0.728418,
|
||||||
|
0.724033,
|
||||||
|
0.719627,
|
||||||
|
0.7152,
|
||||||
|
0.710752,
|
||||||
|
0.706284,
|
||||||
|
0.701795,
|
||||||
|
0.697287,
|
||||||
|
0.69276,
|
||||||
|
0.688215,
|
||||||
|
0.683651,
|
||||||
|
0.679069,
|
||||||
|
0.67447,
|
||||||
|
0.669855,
|
||||||
|
0.665222,
|
||||||
|
0.660574,
|
||||||
|
0.655911,
|
||||||
|
0.651232,
|
||||||
|
0.646538,
|
||||||
|
0.641831,
|
||||||
|
0.63711,
|
||||||
|
0.632375,
|
||||||
|
0.627628,
|
||||||
|
0.622868,
|
||||||
|
0.618097,
|
||||||
|
0.613314,
|
||||||
|
0.60852,
|
||||||
|
0.603715,
|
||||||
|
0.598901,
|
||||||
|
0.594077,
|
||||||
|
0.589244,
|
||||||
|
0.584402,
|
||||||
|
0.579552,
|
||||||
|
0.574695,
|
||||||
|
0.56983,
|
||||||
|
0.564958,
|
||||||
|
0.560081,
|
||||||
|
0.555197,
|
||||||
|
0.550308,
|
||||||
|
0.545414,
|
||||||
|
0.540516,
|
||||||
|
0.535614,
|
||||||
|
0.530708,
|
||||||
|
0.5258,
|
||||||
|
0.520889,
|
||||||
|
0.515976,
|
||||||
|
0.511061,
|
||||||
|
0.506145,
|
||||||
|
0.501229,
|
||||||
|
0.496313,
|
||||||
|
0.491397,
|
||||||
|
0.486481,
|
||||||
|
0.481568,
|
||||||
|
0.476655,
|
||||||
|
0.471746,
|
||||||
|
0.466839,
|
||||||
|
0.461935,
|
||||||
|
0.457034,
|
||||||
|
0.452138,
|
||||||
|
0.447247,
|
||||||
|
0.44236,
|
||||||
|
0.43748,
|
||||||
|
0.432605,
|
||||||
|
0.427737,
|
||||||
|
0.422876,
|
||||||
|
0.418022,
|
||||||
|
0.413176,
|
||||||
|
0.408338,
|
||||||
|
0.40351,
|
||||||
|
0.398691,
|
||||||
|
0.393881,
|
||||||
|
0.389082,
|
||||||
|
0.384293,
|
||||||
|
0.379516,
|
||||||
|
0.374751,
|
||||||
|
0.369997,
|
||||||
|
0.365256,
|
||||||
|
0.360528,
|
||||||
|
0.355814,
|
||||||
|
0.351113,
|
||||||
|
0.346427,
|
||||||
|
0.341756,
|
||||||
|
0.3371,
|
||||||
|
0.332459,
|
||||||
|
0.327835,
|
||||||
|
0.323228,
|
||||||
|
0.318638,
|
||||||
|
0.314065,
|
||||||
|
0.30951,
|
||||||
|
0.304974,
|
||||||
|
0.300456,
|
||||||
|
0.295958,
|
||||||
|
0.29148,
|
||||||
|
0.287021,
|
||||||
|
0.282584,
|
||||||
|
0.278167,
|
||||||
|
0.273772,
|
||||||
|
0.269398,
|
||||||
|
0.265047,
|
||||||
|
0.260719,
|
||||||
|
0.256414,
|
||||||
|
0.252132,
|
||||||
|
0.247874,
|
||||||
|
0.243641,
|
||||||
|
0.239432,
|
||||||
|
0.235249,
|
||||||
|
0.231091,
|
||||||
|
0.226959,
|
||||||
|
0.222854,
|
||||||
|
0.218775,
|
||||||
|
0.214724,
|
||||||
|
0.2107,
|
||||||
|
0.206704,
|
||||||
|
0.202737,
|
||||||
|
0.198798,
|
||||||
|
0.194888,
|
||||||
|
0.191008,
|
||||||
|
0.187158,
|
||||||
|
0.183338,
|
||||||
|
0.179549,
|
||||||
|
0.17579,
|
||||||
|
0.172063,
|
||||||
|
0.168368,
|
||||||
|
0.164705,
|
||||||
|
0.161074,
|
||||||
|
0.157476,
|
||||||
|
0.153911,
|
||||||
|
0.150379,
|
||||||
|
0.146881,
|
||||||
|
0.143418,
|
||||||
|
0.139989,
|
||||||
|
0.136594,
|
||||||
|
0.133235,
|
||||||
|
0.129912,
|
||||||
|
0.126624,
|
||||||
|
0.123372,
|
||||||
|
0.120156,
|
||||||
|
0.116978,
|
||||||
|
0.113836,
|
||||||
|
0.110732,
|
||||||
|
0.107665,
|
||||||
|
0.104636,
|
||||||
|
0.101646,
|
||||||
|
0.0986939,
|
||||||
|
0.0957807,
|
||||||
|
0.0929066,
|
||||||
|
0.0900718,
|
||||||
|
0.0872767,
|
||||||
|
0.0845214,
|
||||||
|
0.0818064,
|
||||||
|
0.0791318,
|
||||||
|
0.0764978,
|
||||||
|
0.0739048,
|
||||||
|
0.0713531,
|
||||||
|
0.0688427,
|
||||||
|
0.0663741,
|
||||||
|
0.0639473,
|
||||||
|
0.0615627,
|
||||||
|
0.0592206,
|
||||||
|
0.056921,
|
||||||
|
0.0546643,
|
||||||
|
0.0524506,
|
||||||
|
0.0502802,
|
||||||
|
0.0481533,
|
||||||
|
0.04607,
|
||||||
|
0.0440307,
|
||||||
|
0.0420354,
|
||||||
|
0.0400844,
|
||||||
|
0.0381779,
|
||||||
|
0.036316,
|
||||||
|
0.034499,
|
||||||
|
0.032727,
|
||||||
|
0.0310001,
|
||||||
|
0.0293186,
|
||||||
|
0.0276826,
|
||||||
|
0.0260923,
|
||||||
|
0.0245478,
|
||||||
|
0.0230492,
|
||||||
|
0.0215968,
|
||||||
|
0.0201906,
|
||||||
|
0.0188308,
|
||||||
|
0.0175175,
|
||||||
|
0.0162509,
|
||||||
|
0.0150311,
|
||||||
|
0.0138581,
|
||||||
|
0.0127322,
|
||||||
|
0.0116533,
|
||||||
|
0.0106217,
|
||||||
|
0.00963736,
|
||||||
|
0.00870045,
|
||||||
|
0.00781104,
|
||||||
|
0.00696922,
|
||||||
|
0.00617507,
|
||||||
|
0.00542867,
|
||||||
|
0.00473008,
|
||||||
|
0.00407937,
|
||||||
|
0.00347661,
|
||||||
|
0.00292186,
|
||||||
|
0.00241517,
|
||||||
|
0.00195659,
|
||||||
|
0.00154616,
|
||||||
|
0.00118392,
|
||||||
|
0.00086991,
|
||||||
|
0.000604158,
|
||||||
|
0.000386689,
|
||||||
|
0.000217525,
|
||||||
|
9.66816e-05,
|
||||||
|
2.4171e-05,
|
||||||
|
0
|
||||||
|
};
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: horus_l2.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: Dec 2015
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef __HORUS_L2__
|
||||||
|
#define __HORUS_L2__
|
||||||
|
|
||||||
|
int horus_l2_get_num_tx_data_bytes(int num_payload_data_bytes);
|
||||||
|
|
||||||
|
/* returns number of output bytes in output_tx_data */
|
||||||
|
int horus_l2_encode_tx_packet(unsigned char *output_tx_data,
|
||||||
|
unsigned char *input_payload_data,
|
||||||
|
int num_payload_data_bytes);
|
||||||
|
|
||||||
|
void horus_l2_decode_rx_packet(unsigned char *output_payload_data,
|
||||||
|
unsigned char *input_rx_data,
|
||||||
|
int num_payload_data_bytes);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/* Hilbert Transform FIR filter coeffs */
|
||||||
|
/* Generated by make_hilb Octave script */
|
||||||
|
|
||||||
|
#define HT_N 100
|
||||||
|
|
||||||
|
COMP ht_coeff[]={
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.000001},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.000017},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,-0.000079},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,-0.000217},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,-0.000461},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.000842},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.001391},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.002140},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.003121},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,-0.004371},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,-0.005928},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.007839},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.010159},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.012957},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.016327},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,-0.020399},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.025364},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,-0.031512},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,-0.039319},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,-0.049610},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.063952},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.085722},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,-0.123718},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,-0.210249},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,-0.636250},
|
||||||
|
{0.999748,0.000000},
|
||||||
|
{0.000000,0.634969},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.208979},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.122467},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,0.084502},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.062771},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.048477},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.038242},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,0.030497},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.024418},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.019527},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,0.015532},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.012242},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,0.009524},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,0.007285},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,0.005454},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,0.003973},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.002796},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,0.001882},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,0.001196},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,0.000701},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.000367},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.000160},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.000051},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{-0.000000,0.000008},
|
||||||
|
{0.000000,0.000000},
|
||||||
|
{0.000000,0.000000}
|
||||||
|
};
|
||||||
@@ -0,0 +1,331 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: interp.c
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 9/10/09
|
||||||
|
|
||||||
|
Interpolation of 20ms frames to 10ms frames.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2009 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
#include "interp.h"
|
||||||
|
#include "lsp.h"
|
||||||
|
#include "quantise.h"
|
||||||
|
|
||||||
|
float sample_log_amp(MODEL *model, float w);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: interp()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 22/8/10
|
||||||
|
|
||||||
|
Given two frames decribed by model parameters 20ms apart, determines
|
||||||
|
the model parameters of the 10ms frame between them. Assumes
|
||||||
|
voicing is available for middle (interpolated) frame. Outputs are
|
||||||
|
amplitudes and Wo for the interpolated frame.
|
||||||
|
|
||||||
|
This version can interpolate the amplitudes between two frames of
|
||||||
|
different Wo and L.
|
||||||
|
|
||||||
|
This version works by log linear interpolation, but listening tests
|
||||||
|
showed it creates problems in background noise, e.g. hts2a and mmt1.
|
||||||
|
When this function is used (--dec mode) bg noise appears to be
|
||||||
|
amplitude modulated, and gets louder. The interp_lsp() function
|
||||||
|
below seems to do a better job.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void interpolate(
|
||||||
|
MODEL *interp, /* interpolated model params */
|
||||||
|
MODEL *prev, /* previous frames model params */
|
||||||
|
MODEL *next, /* next frames model params */
|
||||||
|
float Wo_min
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int l;
|
||||||
|
float w,log_amp;
|
||||||
|
|
||||||
|
/* Wo depends on voicing of this and adjacent frames */
|
||||||
|
|
||||||
|
if (interp->voiced) {
|
||||||
|
if (prev->voiced && next->voiced)
|
||||||
|
interp->Wo = (prev->Wo + next->Wo)/2.0;
|
||||||
|
if (!prev->voiced && next->voiced)
|
||||||
|
interp->Wo = next->Wo;
|
||||||
|
if (prev->voiced && !next->voiced)
|
||||||
|
interp->Wo = prev->Wo;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
interp->Wo = Wo_min;
|
||||||
|
}
|
||||||
|
interp->L = PI/interp->Wo;
|
||||||
|
|
||||||
|
/* Interpolate amplitudes using linear interpolation in log domain */
|
||||||
|
|
||||||
|
for(l=1; l<=interp->L; l++) {
|
||||||
|
w = l*interp->Wo;
|
||||||
|
log_amp = (sample_log_amp(prev, w) + sample_log_amp(next, w))/2.0;
|
||||||
|
interp->A[l] = powf(10.0, log_amp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: sample_log_amp()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 22/8/10
|
||||||
|
|
||||||
|
Samples the amplitude envelope at an arbitrary frequency w. Uses
|
||||||
|
linear interpolation in the log domain to sample between harmonic
|
||||||
|
amplitudes.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
float sample_log_amp(MODEL *model, float w)
|
||||||
|
{
|
||||||
|
int m;
|
||||||
|
float f, log_amp;
|
||||||
|
|
||||||
|
assert(w > 0.0); assert (w <= PI);
|
||||||
|
|
||||||
|
m = floorf(w/model->Wo + 0.5);
|
||||||
|
f = (w - m*model->Wo)/w;
|
||||||
|
assert(f <= 1.0);
|
||||||
|
|
||||||
|
if (m < 1) {
|
||||||
|
log_amp = f*log10f(model->A[1] + 1E-6);
|
||||||
|
}
|
||||||
|
else if ((m+1) > model->L) {
|
||||||
|
log_amp = (1.0-f)*log10f(model->A[model->L] + 1E-6);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_amp = (1.0-f)*log10f(model->A[m] + 1E-6) +
|
||||||
|
f*log10f(model->A[m+1] + 1E-6);
|
||||||
|
}
|
||||||
|
|
||||||
|
return log_amp;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef NOT_NEEDED
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: interp_lsp()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 10 Nov 2010
|
||||||
|
|
||||||
|
Given two frames decribed by model parameters 20ms apart, determines
|
||||||
|
the model parameters of the 10ms frame between them. Assumes
|
||||||
|
voicing is available for middle (interpolated) frame. Outputs are
|
||||||
|
amplitudes and Wo for the interpolated frame.
|
||||||
|
|
||||||
|
This version uses interpolation of LSPs, seems to do a better job
|
||||||
|
with bg noise.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void interpolate_lsp(
|
||||||
|
codec2_fft_cfg fft_fwd_cfg,
|
||||||
|
MODEL *interp, /* interpolated model params */
|
||||||
|
MODEL *prev, /* previous frames model params */
|
||||||
|
MODEL *next, /* next frames model params */
|
||||||
|
float *prev_lsps, /* previous frames LSPs */
|
||||||
|
float prev_e, /* previous frames LPC energy */
|
||||||
|
float *next_lsps, /* next frames LSPs */
|
||||||
|
float next_e, /* next frames LPC energy */
|
||||||
|
float *ak_interp, /* interpolated aks for this frame */
|
||||||
|
float *lsps_interp, /* interpolated lsps for this frame */
|
||||||
|
float Wo_min
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
float e;
|
||||||
|
float snr;
|
||||||
|
|
||||||
|
/* trap corner case where V est is probably wrong */
|
||||||
|
|
||||||
|
if (interp->voiced && !prev->voiced && !next->voiced) {
|
||||||
|
interp->voiced = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wo depends on voicing of this and adjacent frames */
|
||||||
|
|
||||||
|
if (interp->voiced) {
|
||||||
|
if (prev->voiced && next->voiced)
|
||||||
|
interp->Wo = (prev->Wo + next->Wo)/2.0;
|
||||||
|
if (!prev->voiced && next->voiced)
|
||||||
|
interp->Wo = next->Wo;
|
||||||
|
if (prev->voiced && !next->voiced)
|
||||||
|
interp->Wo = prev->Wo;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
interp->Wo = Wo_min;
|
||||||
|
}
|
||||||
|
interp->L = PI/interp->Wo;
|
||||||
|
|
||||||
|
//printf(" interp: prev_v: %d next_v: %d prev_Wo: %f next_Wo: %f\n",
|
||||||
|
// prev->voiced, next->voiced, prev->Wo, next->Wo);
|
||||||
|
//printf(" interp: Wo: %1.5f L: %d\n", interp->Wo, interp->L);
|
||||||
|
|
||||||
|
/* interpolate LSPs */
|
||||||
|
|
||||||
|
for(i=0; i<LPC_ORD; i++) {
|
||||||
|
lsps_interp[i] = (prev_lsps[i] + next_lsps[i])/2.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Interpolate LPC energy in log domain */
|
||||||
|
|
||||||
|
e = powf(10.0, (log10f(prev_e) + log10f(next_e))/2.0);
|
||||||
|
//printf(" interp: e: %f\n", e);
|
||||||
|
|
||||||
|
/* convert back to amplitudes */
|
||||||
|
|
||||||
|
lsp_to_lpc(lsps_interp, ak_interp, LPC_ORD);
|
||||||
|
aks_to_M2(fft_fwd_cfg, ak_interp, LPC_ORD, interp, e, &snr, 0, 0, 1, 1, LPCPF_BETA, LPCPF_GAMMA);
|
||||||
|
//printf(" interp: ak[1]: %f A[1] %f\n", ak_interp[1], interp->A[1]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: interp_Wo()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 22 May 2012
|
||||||
|
|
||||||
|
Interpolates centre 10ms sample of Wo and L samples given two
|
||||||
|
samples 20ms apart. Assumes voicing is available for centre
|
||||||
|
(interpolated) frame.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void interp_Wo(
|
||||||
|
MODEL *interp, /* interpolated model params */
|
||||||
|
MODEL *prev, /* previous frames model params */
|
||||||
|
MODEL *next, /* next frames model params */
|
||||||
|
float Wo_min
|
||||||
|
)
|
||||||
|
{
|
||||||
|
interp_Wo2(interp, prev, next, 0.5, Wo_min);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: interp_Wo2()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 22 May 2012
|
||||||
|
|
||||||
|
Weighted interpolation of two Wo samples.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void interp_Wo2(
|
||||||
|
MODEL *interp, /* interpolated model params */
|
||||||
|
MODEL *prev, /* previous frames model params */
|
||||||
|
MODEL *next, /* next frames model params */
|
||||||
|
float weight,
|
||||||
|
float Wo_min
|
||||||
|
)
|
||||||
|
{
|
||||||
|
/* trap corner case where voicing est is probably wrong */
|
||||||
|
|
||||||
|
if (interp->voiced && !prev->voiced && !next->voiced) {
|
||||||
|
interp->voiced = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wo depends on voicing of this and adjacent frames */
|
||||||
|
|
||||||
|
if (interp->voiced) {
|
||||||
|
if (prev->voiced && next->voiced)
|
||||||
|
interp->Wo = (1.0 - weight)*prev->Wo + weight*next->Wo;
|
||||||
|
if (!prev->voiced && next->voiced)
|
||||||
|
interp->Wo = next->Wo;
|
||||||
|
if (prev->voiced && !next->voiced)
|
||||||
|
interp->Wo = prev->Wo;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
interp->Wo = Wo_min;
|
||||||
|
}
|
||||||
|
interp->L = PI/interp->Wo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: interp_energy()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 22 May 2012
|
||||||
|
|
||||||
|
Interpolates centre 10ms sample of energy given two samples 20ms
|
||||||
|
apart.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
float interp_energy(float prev_e, float next_e)
|
||||||
|
{
|
||||||
|
//return powf(10.0, (log10f(prev_e) + log10f(next_e))/2.0);
|
||||||
|
return sqrtf(prev_e * next_e); //looks better is math. identical and faster math
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: interp_energy2()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 22 May 2012
|
||||||
|
|
||||||
|
Interpolates centre 10ms sample of energy given two samples 20ms
|
||||||
|
apart.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
float interp_energy2(float prev_e, float next_e, float weight)
|
||||||
|
{
|
||||||
|
return powf(10.0, (1.0 - weight)*log10f(prev_e) + weight*log10f(next_e));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: interpolate_lsp_ver2()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 22 May 2012
|
||||||
|
|
||||||
|
Weighted interpolation of LSPs.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void interpolate_lsp_ver2(float interp[], float prev[], float next[], float weight, int order)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i=0; i<order; i++)
|
||||||
|
interp[i] = (1.0 - weight)*prev[i] + weight*next[i];
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: interp.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 9/10/09
|
||||||
|
|
||||||
|
Interpolation of 20ms frames to 10ms frames.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2009 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __INTERP__
|
||||||
|
#define __INTERP__
|
||||||
|
|
||||||
|
#include "kiss_fft.h"
|
||||||
|
|
||||||
|
void interpolate(MODEL *interp, MODEL *prev, MODEL *next);
|
||||||
|
void interpolate_lsp(kiss_fft_cfg fft_dec_cfg,
|
||||||
|
MODEL *interp, MODEL *prev, MODEL *next,
|
||||||
|
float *prev_lsps, float prev_e,
|
||||||
|
float *next_lsps, float next_e,
|
||||||
|
float *ak_interp, float *lsps_interp, float Wo_min);
|
||||||
|
void interp_Wo(MODEL *interp, MODEL *prev, MODEL *next, float Wo_min);
|
||||||
|
void interp_Wo2(MODEL *interp, MODEL *prev, MODEL *next, float weight, float Wo_min);
|
||||||
|
float interp_energy(float prev, float next);
|
||||||
|
float interp_energy2(float prev, float next, float weight);
|
||||||
|
void interpolate_lsp_ver2(float interp[], float prev[], float next[], float weight, int order);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,408 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2003-2010, Mark Borgerding
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
* Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "_kiss_fft_guts.h"
|
||||||
|
/* The guts header contains all the multiplication and addition macros that are defined for
|
||||||
|
fixed or floating point complex numbers. It also delares the kf_ internal functions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void kf_bfly2(
|
||||||
|
kiss_fft_cpx * Fout,
|
||||||
|
const size_t fstride,
|
||||||
|
const kiss_fft_cfg st,
|
||||||
|
int m
|
||||||
|
)
|
||||||
|
{
|
||||||
|
kiss_fft_cpx * Fout2;
|
||||||
|
kiss_fft_cpx * tw1 = st->twiddles;
|
||||||
|
kiss_fft_cpx t;
|
||||||
|
Fout2 = Fout + m;
|
||||||
|
do{
|
||||||
|
C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2);
|
||||||
|
|
||||||
|
C_MUL (t, *Fout2 , *tw1);
|
||||||
|
tw1 += fstride;
|
||||||
|
C_SUB( *Fout2 , *Fout , t );
|
||||||
|
C_ADDTO( *Fout , t );
|
||||||
|
++Fout2;
|
||||||
|
++Fout;
|
||||||
|
}while (--m);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void kf_bfly4(
|
||||||
|
kiss_fft_cpx * Fout,
|
||||||
|
const size_t fstride,
|
||||||
|
const kiss_fft_cfg st,
|
||||||
|
const size_t m
|
||||||
|
)
|
||||||
|
{
|
||||||
|
kiss_fft_cpx *tw1,*tw2,*tw3;
|
||||||
|
kiss_fft_cpx scratch[6];
|
||||||
|
size_t k=m;
|
||||||
|
const size_t m2=2*m;
|
||||||
|
const size_t m3=3*m;
|
||||||
|
|
||||||
|
|
||||||
|
tw3 = tw2 = tw1 = st->twiddles;
|
||||||
|
|
||||||
|
do {
|
||||||
|
C_FIXDIV(*Fout,4); C_FIXDIV(Fout[m],4); C_FIXDIV(Fout[m2],4); C_FIXDIV(Fout[m3],4);
|
||||||
|
|
||||||
|
C_MUL(scratch[0],Fout[m] , *tw1 );
|
||||||
|
C_MUL(scratch[1],Fout[m2] , *tw2 );
|
||||||
|
C_MUL(scratch[2],Fout[m3] , *tw3 );
|
||||||
|
|
||||||
|
C_SUB( scratch[5] , *Fout, scratch[1] );
|
||||||
|
C_ADDTO(*Fout, scratch[1]);
|
||||||
|
C_ADD( scratch[3] , scratch[0] , scratch[2] );
|
||||||
|
C_SUB( scratch[4] , scratch[0] , scratch[2] );
|
||||||
|
C_SUB( Fout[m2], *Fout, scratch[3] );
|
||||||
|
tw1 += fstride;
|
||||||
|
tw2 += fstride*2;
|
||||||
|
tw3 += fstride*3;
|
||||||
|
C_ADDTO( *Fout , scratch[3] );
|
||||||
|
|
||||||
|
if(st->inverse) {
|
||||||
|
Fout[m].r = scratch[5].r - scratch[4].i;
|
||||||
|
Fout[m].i = scratch[5].i + scratch[4].r;
|
||||||
|
Fout[m3].r = scratch[5].r + scratch[4].i;
|
||||||
|
Fout[m3].i = scratch[5].i - scratch[4].r;
|
||||||
|
}else{
|
||||||
|
Fout[m].r = scratch[5].r + scratch[4].i;
|
||||||
|
Fout[m].i = scratch[5].i - scratch[4].r;
|
||||||
|
Fout[m3].r = scratch[5].r - scratch[4].i;
|
||||||
|
Fout[m3].i = scratch[5].i + scratch[4].r;
|
||||||
|
}
|
||||||
|
++Fout;
|
||||||
|
}while(--k);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void kf_bfly3(
|
||||||
|
kiss_fft_cpx * Fout,
|
||||||
|
const size_t fstride,
|
||||||
|
const kiss_fft_cfg st,
|
||||||
|
size_t m
|
||||||
|
)
|
||||||
|
{
|
||||||
|
size_t k=m;
|
||||||
|
const size_t m2 = 2*m;
|
||||||
|
kiss_fft_cpx *tw1,*tw2;
|
||||||
|
kiss_fft_cpx scratch[5];
|
||||||
|
kiss_fft_cpx epi3;
|
||||||
|
epi3 = st->twiddles[fstride*m];
|
||||||
|
|
||||||
|
tw1=tw2=st->twiddles;
|
||||||
|
|
||||||
|
do{
|
||||||
|
C_FIXDIV(*Fout,3); C_FIXDIV(Fout[m],3); C_FIXDIV(Fout[m2],3);
|
||||||
|
|
||||||
|
C_MUL(scratch[1],Fout[m] , *tw1);
|
||||||
|
C_MUL(scratch[2],Fout[m2] , *tw2);
|
||||||
|
|
||||||
|
C_ADD(scratch[3],scratch[1],scratch[2]);
|
||||||
|
C_SUB(scratch[0],scratch[1],scratch[2]);
|
||||||
|
tw1 += fstride;
|
||||||
|
tw2 += fstride*2;
|
||||||
|
|
||||||
|
Fout[m].r = Fout->r - HALF_OF(scratch[3].r);
|
||||||
|
Fout[m].i = Fout->i - HALF_OF(scratch[3].i);
|
||||||
|
|
||||||
|
C_MULBYSCALAR( scratch[0] , epi3.i );
|
||||||
|
|
||||||
|
C_ADDTO(*Fout,scratch[3]);
|
||||||
|
|
||||||
|
Fout[m2].r = Fout[m].r + scratch[0].i;
|
||||||
|
Fout[m2].i = Fout[m].i - scratch[0].r;
|
||||||
|
|
||||||
|
Fout[m].r -= scratch[0].i;
|
||||||
|
Fout[m].i += scratch[0].r;
|
||||||
|
|
||||||
|
++Fout;
|
||||||
|
}while(--k);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void kf_bfly5(
|
||||||
|
kiss_fft_cpx * Fout,
|
||||||
|
const size_t fstride,
|
||||||
|
const kiss_fft_cfg st,
|
||||||
|
int m
|
||||||
|
)
|
||||||
|
{
|
||||||
|
kiss_fft_cpx *Fout0,*Fout1,*Fout2,*Fout3,*Fout4;
|
||||||
|
int u;
|
||||||
|
kiss_fft_cpx scratch[13];
|
||||||
|
kiss_fft_cpx * twiddles = st->twiddles;
|
||||||
|
kiss_fft_cpx *tw;
|
||||||
|
kiss_fft_cpx ya,yb;
|
||||||
|
ya = twiddles[fstride*m];
|
||||||
|
yb = twiddles[fstride*2*m];
|
||||||
|
|
||||||
|
Fout0=Fout;
|
||||||
|
Fout1=Fout0+m;
|
||||||
|
Fout2=Fout0+2*m;
|
||||||
|
Fout3=Fout0+3*m;
|
||||||
|
Fout4=Fout0+4*m;
|
||||||
|
|
||||||
|
tw=st->twiddles;
|
||||||
|
for ( u=0; u<m; ++u ) {
|
||||||
|
C_FIXDIV( *Fout0,5); C_FIXDIV( *Fout1,5); C_FIXDIV( *Fout2,5); C_FIXDIV( *Fout3,5); C_FIXDIV( *Fout4,5);
|
||||||
|
scratch[0] = *Fout0;
|
||||||
|
|
||||||
|
C_MUL(scratch[1] ,*Fout1, tw[u*fstride]);
|
||||||
|
C_MUL(scratch[2] ,*Fout2, tw[2*u*fstride]);
|
||||||
|
C_MUL(scratch[3] ,*Fout3, tw[3*u*fstride]);
|
||||||
|
C_MUL(scratch[4] ,*Fout4, tw[4*u*fstride]);
|
||||||
|
|
||||||
|
C_ADD( scratch[7],scratch[1],scratch[4]);
|
||||||
|
C_SUB( scratch[10],scratch[1],scratch[4]);
|
||||||
|
C_ADD( scratch[8],scratch[2],scratch[3]);
|
||||||
|
C_SUB( scratch[9],scratch[2],scratch[3]);
|
||||||
|
|
||||||
|
Fout0->r += scratch[7].r + scratch[8].r;
|
||||||
|
Fout0->i += scratch[7].i + scratch[8].i;
|
||||||
|
|
||||||
|
scratch[5].r = scratch[0].r + S_MUL(scratch[7].r,ya.r) + S_MUL(scratch[8].r,yb.r);
|
||||||
|
scratch[5].i = scratch[0].i + S_MUL(scratch[7].i,ya.r) + S_MUL(scratch[8].i,yb.r);
|
||||||
|
|
||||||
|
scratch[6].r = S_MUL(scratch[10].i,ya.i) + S_MUL(scratch[9].i,yb.i);
|
||||||
|
scratch[6].i = -S_MUL(scratch[10].r,ya.i) - S_MUL(scratch[9].r,yb.i);
|
||||||
|
|
||||||
|
C_SUB(*Fout1,scratch[5],scratch[6]);
|
||||||
|
C_ADD(*Fout4,scratch[5],scratch[6]);
|
||||||
|
|
||||||
|
scratch[11].r = scratch[0].r + S_MUL(scratch[7].r,yb.r) + S_MUL(scratch[8].r,ya.r);
|
||||||
|
scratch[11].i = scratch[0].i + S_MUL(scratch[7].i,yb.r) + S_MUL(scratch[8].i,ya.r);
|
||||||
|
scratch[12].r = - S_MUL(scratch[10].i,yb.i) + S_MUL(scratch[9].i,ya.i);
|
||||||
|
scratch[12].i = S_MUL(scratch[10].r,yb.i) - S_MUL(scratch[9].r,ya.i);
|
||||||
|
|
||||||
|
C_ADD(*Fout2,scratch[11],scratch[12]);
|
||||||
|
C_SUB(*Fout3,scratch[11],scratch[12]);
|
||||||
|
|
||||||
|
++Fout0;++Fout1;++Fout2;++Fout3;++Fout4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* perform the butterfly for one stage of a mixed radix FFT */
|
||||||
|
static void kf_bfly_generic(
|
||||||
|
kiss_fft_cpx * Fout,
|
||||||
|
const size_t fstride,
|
||||||
|
const kiss_fft_cfg st,
|
||||||
|
int m,
|
||||||
|
int p
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int u,k,q1,q;
|
||||||
|
kiss_fft_cpx * twiddles = st->twiddles;
|
||||||
|
kiss_fft_cpx t;
|
||||||
|
int Norig = st->nfft;
|
||||||
|
|
||||||
|
kiss_fft_cpx * scratch = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC(sizeof(kiss_fft_cpx)*p);
|
||||||
|
|
||||||
|
for ( u=0; u<m; ++u ) {
|
||||||
|
k=u;
|
||||||
|
for ( q1=0 ; q1<p ; ++q1 ) {
|
||||||
|
scratch[q1] = Fout[ k ];
|
||||||
|
C_FIXDIV(scratch[q1],p);
|
||||||
|
k += m;
|
||||||
|
}
|
||||||
|
|
||||||
|
k=u;
|
||||||
|
for ( q1=0 ; q1<p ; ++q1 ) {
|
||||||
|
int twidx=0;
|
||||||
|
Fout[ k ] = scratch[0];
|
||||||
|
for (q=1;q<p;++q ) {
|
||||||
|
twidx += fstride * k;
|
||||||
|
if (twidx>=Norig) twidx-=Norig;
|
||||||
|
C_MUL(t,scratch[q] , twiddles[twidx] );
|
||||||
|
C_ADDTO( Fout[ k ] ,t);
|
||||||
|
}
|
||||||
|
k += m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KISS_FFT_TMP_FREE(scratch);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void kf_work(
|
||||||
|
kiss_fft_cpx * Fout,
|
||||||
|
const kiss_fft_cpx * f,
|
||||||
|
const size_t fstride,
|
||||||
|
int in_stride,
|
||||||
|
int * factors,
|
||||||
|
const kiss_fft_cfg st
|
||||||
|
)
|
||||||
|
{
|
||||||
|
kiss_fft_cpx * Fout_beg=Fout;
|
||||||
|
const int p=*factors++; /* the radix */
|
||||||
|
const int m=*factors++; /* stage's fft length/p */
|
||||||
|
const kiss_fft_cpx * Fout_end = Fout + p*m;
|
||||||
|
|
||||||
|
#ifdef _OPENMP
|
||||||
|
// use openmp extensions at the
|
||||||
|
// top-level (not recursive)
|
||||||
|
if (fstride==1 && p<=5)
|
||||||
|
{
|
||||||
|
int k;
|
||||||
|
|
||||||
|
// execute the p different work units in different threads
|
||||||
|
# pragma omp parallel for
|
||||||
|
for (k=0;k<p;++k)
|
||||||
|
kf_work( Fout +k*m, f+ fstride*in_stride*k,fstride*p,in_stride,factors,st);
|
||||||
|
// all threads have joined by this point
|
||||||
|
|
||||||
|
switch (p) {
|
||||||
|
case 2: kf_bfly2(Fout,fstride,st,m); break;
|
||||||
|
case 3: kf_bfly3(Fout,fstride,st,m); break;
|
||||||
|
case 4: kf_bfly4(Fout,fstride,st,m); break;
|
||||||
|
case 5: kf_bfly5(Fout,fstride,st,m); break;
|
||||||
|
default: kf_bfly_generic(Fout,fstride,st,m,p); break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (m==1) {
|
||||||
|
do{
|
||||||
|
*Fout = *f;
|
||||||
|
f += fstride*in_stride;
|
||||||
|
}while(++Fout != Fout_end );
|
||||||
|
}else{
|
||||||
|
do{
|
||||||
|
// recursive call:
|
||||||
|
// DFT of size m*p performed by doing
|
||||||
|
// p instances of smaller DFTs of size m,
|
||||||
|
// each one takes a decimated version of the input
|
||||||
|
kf_work( Fout , f, fstride*p, in_stride, factors,st);
|
||||||
|
f += fstride*in_stride;
|
||||||
|
}while( (Fout += m) != Fout_end );
|
||||||
|
}
|
||||||
|
|
||||||
|
Fout=Fout_beg;
|
||||||
|
|
||||||
|
// recombine the p smaller DFTs
|
||||||
|
switch (p) {
|
||||||
|
case 2: kf_bfly2(Fout,fstride,st,m); break;
|
||||||
|
case 3: kf_bfly3(Fout,fstride,st,m); break;
|
||||||
|
case 4: kf_bfly4(Fout,fstride,st,m); break;
|
||||||
|
case 5: kf_bfly5(Fout,fstride,st,m); break;
|
||||||
|
default: kf_bfly_generic(Fout,fstride,st,m,p); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* facbuf is populated by p1,m1,p2,m2, ...
|
||||||
|
where
|
||||||
|
p[i] * m[i] = m[i-1]
|
||||||
|
m0 = n */
|
||||||
|
static
|
||||||
|
void kf_factor(int n,int * facbuf)
|
||||||
|
{
|
||||||
|
int p=4;
|
||||||
|
double floor_sqrt;
|
||||||
|
floor_sqrt = floorf( sqrtf((double)n) );
|
||||||
|
|
||||||
|
/*factor out powers of 4, powers of 2, then any remaining primes */
|
||||||
|
do {
|
||||||
|
while (n % p) {
|
||||||
|
switch (p) {
|
||||||
|
case 4: p = 2; break;
|
||||||
|
case 2: p = 3; break;
|
||||||
|
default: p += 2; break;
|
||||||
|
}
|
||||||
|
if (p > floor_sqrt)
|
||||||
|
p = n; /* no more factors, skip to end */
|
||||||
|
}
|
||||||
|
n /= p;
|
||||||
|
*facbuf++ = p;
|
||||||
|
*facbuf++ = n;
|
||||||
|
} while (n > 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* User-callable function to allocate all necessary storage space for the fft.
|
||||||
|
*
|
||||||
|
* The return value is a contiguous block of memory, allocated with malloc. As such,
|
||||||
|
* It can be freed with free(), rather than a kiss_fft-specific function.
|
||||||
|
* */
|
||||||
|
kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem )
|
||||||
|
{
|
||||||
|
kiss_fft_cfg st=NULL;
|
||||||
|
size_t memneeded = sizeof(struct kiss_fft_state)
|
||||||
|
+ sizeof(kiss_fft_cpx)*(nfft-1); /* twiddle factors*/
|
||||||
|
|
||||||
|
if ( lenmem==NULL ) {
|
||||||
|
st = ( kiss_fft_cfg)KISS_FFT_MALLOC( memneeded );
|
||||||
|
}else{
|
||||||
|
if (mem != NULL && *lenmem >= memneeded)
|
||||||
|
st = (kiss_fft_cfg)mem;
|
||||||
|
*lenmem = memneeded;
|
||||||
|
}
|
||||||
|
if (st) {
|
||||||
|
int i;
|
||||||
|
st->nfft=nfft;
|
||||||
|
st->inverse = inverse_fft;
|
||||||
|
|
||||||
|
for (i=0;i<nfft;++i) {
|
||||||
|
const double pi=3.141592653589793238462643383279502884197169399375105820974944;
|
||||||
|
double phase = -2*pi*i / nfft;
|
||||||
|
if (st->inverse)
|
||||||
|
phase *= -1;
|
||||||
|
kf_cexp(st->twiddles+i, phase );
|
||||||
|
}
|
||||||
|
|
||||||
|
kf_factor(nfft,st->factors);
|
||||||
|
}
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void kiss_fft_stride(kiss_fft_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
|
||||||
|
{
|
||||||
|
if (fin == fout) {
|
||||||
|
//NOTE: this is not really an in-place FFT algorithm.
|
||||||
|
//It just performs an out-of-place FFT into a temp buffer
|
||||||
|
kiss_fft_cpx * tmpbuf = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC( sizeof(kiss_fft_cpx)*st->nfft);
|
||||||
|
kf_work(tmpbuf,fin,1,in_stride, st->factors,st);
|
||||||
|
memcpy(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft);
|
||||||
|
KISS_FFT_TMP_FREE(tmpbuf);
|
||||||
|
}else{
|
||||||
|
kf_work( fout, fin, 1,in_stride, st->factors,st );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
|
||||||
|
{
|
||||||
|
kiss_fft_stride(cfg,fin,fout,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void kiss_fft_cleanup(void)
|
||||||
|
{
|
||||||
|
// nothing needed any more
|
||||||
|
}
|
||||||
|
|
||||||
|
int kiss_fft_next_fast_size(int n)
|
||||||
|
{
|
||||||
|
while(1) {
|
||||||
|
int m=n;
|
||||||
|
while ( (m%2) == 0 ) m/=2;
|
||||||
|
while ( (m%3) == 0 ) m/=3;
|
||||||
|
while ( (m%5) == 0 ) m/=5;
|
||||||
|
if (m<=1)
|
||||||
|
break; /* n is completely factorable by twos, threes, and fives */
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
#ifndef KISS_FFT_H
|
||||||
|
#define KISS_FFT_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
ATTENTION!
|
||||||
|
If you would like a :
|
||||||
|
-- a utility that will handle the caching of fft objects
|
||||||
|
-- real-only (no imaginary time component ) FFT
|
||||||
|
-- a multi-dimensional FFT
|
||||||
|
-- a command-line utility to perform ffts
|
||||||
|
-- a command-line utility to perform fast-convolution filtering
|
||||||
|
|
||||||
|
Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c
|
||||||
|
in the tools/ directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef USE_SIMD
|
||||||
|
# include <xmmintrin.h>
|
||||||
|
# define kiss_fft_scalar __m128
|
||||||
|
#define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16)
|
||||||
|
#define KISS_FFT_FREE _mm_free
|
||||||
|
#else
|
||||||
|
#define KISS_FFT_MALLOC malloc
|
||||||
|
#define KISS_FFT_FREE free
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef FIXED_POINT
|
||||||
|
#include <sys/types.h>
|
||||||
|
# if (FIXED_POINT == 32)
|
||||||
|
# define kiss_fft_scalar int32_t
|
||||||
|
# else
|
||||||
|
# define kiss_fft_scalar int16_t
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# ifndef kiss_fft_scalar
|
||||||
|
/* default is float */
|
||||||
|
# define kiss_fft_scalar float
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
kiss_fft_scalar r;
|
||||||
|
kiss_fft_scalar i;
|
||||||
|
}kiss_fft_cpx;
|
||||||
|
|
||||||
|
typedef struct kiss_fft_state* kiss_fft_cfg;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* kiss_fft_alloc
|
||||||
|
*
|
||||||
|
* Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
|
||||||
|
*
|
||||||
|
* typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
|
||||||
|
*
|
||||||
|
* The return value from fft_alloc is a cfg buffer used internally
|
||||||
|
* by the fft routine or NULL.
|
||||||
|
*
|
||||||
|
* If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
|
||||||
|
* The returned value should be free()d when done to avoid memory leaks.
|
||||||
|
*
|
||||||
|
* The state can be placed in a user supplied buffer 'mem':
|
||||||
|
* If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
|
||||||
|
* then the function places the cfg in mem and the size used in *lenmem
|
||||||
|
* and returns mem.
|
||||||
|
*
|
||||||
|
* If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
|
||||||
|
* then the function returns NULL and places the minimum cfg
|
||||||
|
* buffer size in *lenmem.
|
||||||
|
* */
|
||||||
|
|
||||||
|
kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* kiss_fft(cfg,in_out_buf)
|
||||||
|
*
|
||||||
|
* Perform an FFT on a complex input buffer.
|
||||||
|
* for a forward FFT,
|
||||||
|
* fin should be f[0] , f[1] , ... ,f[nfft-1]
|
||||||
|
* fout will be F[0] , F[1] , ... ,F[nfft-1]
|
||||||
|
* Note that each element is complex and can be accessed like
|
||||||
|
f[k].r and f[k].i
|
||||||
|
* */
|
||||||
|
void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
|
||||||
|
|
||||||
|
/*
|
||||||
|
A more generic version of the above function. It reads its input from every Nth sample.
|
||||||
|
* */
|
||||||
|
void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
|
||||||
|
|
||||||
|
/* If kiss_fft_alloc allocated a buffer, it is one contiguous
|
||||||
|
buffer and can be simply free()d when no longer needed*/
|
||||||
|
#define kiss_fft_free free
|
||||||
|
|
||||||
|
/*
|
||||||
|
Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up
|
||||||
|
your compiler output to call this before you exit.
|
||||||
|
*/
|
||||||
|
void kiss_fft_cleanup(void);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5)
|
||||||
|
*/
|
||||||
|
int kiss_fft_next_fast_size(int n);
|
||||||
|
|
||||||
|
/* for real ffts, we need an even size */
|
||||||
|
#define kiss_fftr_next_fast_size_real(n) \
|
||||||
|
(kiss_fft_next_fast_size( ((n)+1)>>1)<<1)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2003-2004, Mark Borgerding
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
* Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "kiss_fftr.h"
|
||||||
|
#include "_kiss_fft_guts.h"
|
||||||
|
#include "assert.h"
|
||||||
|
|
||||||
|
struct kiss_fftr_state{
|
||||||
|
kiss_fft_cfg substate;
|
||||||
|
kiss_fft_cpx * tmpbuf;
|
||||||
|
kiss_fft_cpx * super_twiddles;
|
||||||
|
#ifdef USE_SIMD
|
||||||
|
void * pad;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
kiss_fftr_cfg st = NULL;
|
||||||
|
size_t subsize, memneeded;
|
||||||
|
|
||||||
|
if (nfft & 1) {
|
||||||
|
fprintf(stderr,"Real FFT optimization must be even.\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
nfft >>= 1;
|
||||||
|
|
||||||
|
kiss_fft_alloc (nfft, inverse_fft, NULL, &subsize);
|
||||||
|
memneeded = sizeof(struct kiss_fftr_state) + subsize + sizeof(kiss_fft_cpx) * ( nfft * 3 / 2);
|
||||||
|
|
||||||
|
if (lenmem == NULL) {
|
||||||
|
st = (kiss_fftr_cfg) KISS_FFT_MALLOC (memneeded);
|
||||||
|
} else {
|
||||||
|
if (*lenmem >= memneeded)
|
||||||
|
st = (kiss_fftr_cfg) mem;
|
||||||
|
*lenmem = memneeded;
|
||||||
|
}
|
||||||
|
if (!st)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
st->substate = (kiss_fft_cfg) (st + 1); /*just beyond kiss_fftr_state struct */
|
||||||
|
st->tmpbuf = (kiss_fft_cpx *) (((char *) st->substate) + subsize);
|
||||||
|
st->super_twiddles = st->tmpbuf + nfft;
|
||||||
|
kiss_fft_alloc(nfft, inverse_fft, st->substate, &subsize);
|
||||||
|
|
||||||
|
for (i = 0; i < nfft/2; ++i) {
|
||||||
|
double phase =
|
||||||
|
-3.14159265358979323846264338327 * ((double) (i+1) / nfft + .5);
|
||||||
|
if (inverse_fft)
|
||||||
|
phase *= -1;
|
||||||
|
kf_cexp (st->super_twiddles+i,phase);
|
||||||
|
}
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata)
|
||||||
|
{
|
||||||
|
/* input buffer timedata is stored row-wise */
|
||||||
|
int k,ncfft;
|
||||||
|
kiss_fft_cpx fpnk,fpk,f1k,f2k,tw,tdc;
|
||||||
|
|
||||||
|
assert(st->substate->inverse==0);
|
||||||
|
|
||||||
|
ncfft = st->substate->nfft;
|
||||||
|
|
||||||
|
/*perform the parallel fft of two real signals packed in real,imag*/
|
||||||
|
kiss_fft( st->substate , (const kiss_fft_cpx*)timedata, st->tmpbuf );
|
||||||
|
/* The real part of the DC element of the frequency spectrum in st->tmpbuf
|
||||||
|
* contains the sum of the even-numbered elements of the input time sequence
|
||||||
|
* The imag part is the sum of the odd-numbered elements
|
||||||
|
*
|
||||||
|
* The sum of tdc.r and tdc.i is the sum of the input time sequence.
|
||||||
|
* yielding DC of input time sequence
|
||||||
|
* The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1...
|
||||||
|
* yielding Nyquist bin of input time sequence
|
||||||
|
*/
|
||||||
|
|
||||||
|
tdc.r = st->tmpbuf[0].r;
|
||||||
|
tdc.i = st->tmpbuf[0].i;
|
||||||
|
C_FIXDIV(tdc,2);
|
||||||
|
CHECK_OVERFLOW_OP(tdc.r ,+, tdc.i);
|
||||||
|
CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i);
|
||||||
|
freqdata[0].r = tdc.r + tdc.i;
|
||||||
|
freqdata[ncfft].r = tdc.r - tdc.i;
|
||||||
|
#ifdef USE_SIMD
|
||||||
|
freqdata[ncfft].i = freqdata[0].i = _mm_set1_ps(0);
|
||||||
|
#else
|
||||||
|
freqdata[ncfft].i = freqdata[0].i = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for ( k=1;k <= ncfft/2 ; ++k ) {
|
||||||
|
fpk = st->tmpbuf[k];
|
||||||
|
fpnk.r = st->tmpbuf[ncfft-k].r;
|
||||||
|
fpnk.i = - st->tmpbuf[ncfft-k].i;
|
||||||
|
C_FIXDIV(fpk,2);
|
||||||
|
C_FIXDIV(fpnk,2);
|
||||||
|
|
||||||
|
C_ADD( f1k, fpk , fpnk );
|
||||||
|
C_SUB( f2k, fpk , fpnk );
|
||||||
|
C_MUL( tw , f2k , st->super_twiddles[k-1]);
|
||||||
|
|
||||||
|
freqdata[k].r = HALF_OF(f1k.r + tw.r);
|
||||||
|
freqdata[k].i = HALF_OF(f1k.i + tw.i);
|
||||||
|
freqdata[ncfft-k].r = HALF_OF(f1k.r - tw.r);
|
||||||
|
freqdata[ncfft-k].i = HALF_OF(tw.i - f1k.i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata)
|
||||||
|
{
|
||||||
|
/* input buffer timedata is stored row-wise */
|
||||||
|
int k, ncfft;
|
||||||
|
|
||||||
|
assert(st->substate->inverse == 1);
|
||||||
|
|
||||||
|
ncfft = st->substate->nfft;
|
||||||
|
|
||||||
|
st->tmpbuf[0].r = freqdata[0].r + freqdata[ncfft].r;
|
||||||
|
st->tmpbuf[0].i = freqdata[0].r - freqdata[ncfft].r;
|
||||||
|
C_FIXDIV(st->tmpbuf[0],2);
|
||||||
|
|
||||||
|
for (k = 1; k <= ncfft / 2; ++k) {
|
||||||
|
kiss_fft_cpx fk, fnkc, fek, fok, tmp;
|
||||||
|
fk = freqdata[k];
|
||||||
|
fnkc.r = freqdata[ncfft - k].r;
|
||||||
|
fnkc.i = -freqdata[ncfft - k].i;
|
||||||
|
C_FIXDIV( fk , 2 );
|
||||||
|
C_FIXDIV( fnkc , 2 );
|
||||||
|
|
||||||
|
C_ADD (fek, fk, fnkc);
|
||||||
|
C_SUB (tmp, fk, fnkc);
|
||||||
|
C_MUL (fok, tmp, st->super_twiddles[k-1]);
|
||||||
|
C_ADD (st->tmpbuf[k], fek, fok);
|
||||||
|
C_SUB (st->tmpbuf[ncfft - k], fek, fok);
|
||||||
|
#ifdef USE_SIMD
|
||||||
|
st->tmpbuf[ncfft - k].i *= _mm_set1_ps(-1.0);
|
||||||
|
#else
|
||||||
|
st->tmpbuf[ncfft - k].i *= -1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
kiss_fft (st->substate, st->tmpbuf, (kiss_fft_cpx *) timedata);
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#ifndef KISS_FTR_H
|
||||||
|
#define KISS_FTR_H
|
||||||
|
|
||||||
|
#include "kiss_fft.h"
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Real optimized version can save about 45% cpu time vs. complex fft of a real seq.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct kiss_fftr_state *kiss_fftr_cfg;
|
||||||
|
|
||||||
|
|
||||||
|
kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem);
|
||||||
|
/*
|
||||||
|
nfft must be even
|
||||||
|
|
||||||
|
If you don't care to allocate space, use mem = lenmem = NULL
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void kiss_fftr(kiss_fftr_cfg cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata);
|
||||||
|
/*
|
||||||
|
input timedata has nfft scalar points
|
||||||
|
output freqdata has nfft/2+1 complex points
|
||||||
|
*/
|
||||||
|
|
||||||
|
void kiss_fftri(kiss_fftr_cfg cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata);
|
||||||
|
/*
|
||||||
|
input freqdata has nfft/2+1 complex points
|
||||||
|
output timedata has nfft scalar points
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define kiss_fftr_free free
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: linreg.c
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: April 2015
|
||||||
|
|
||||||
|
Linear regression C module based on:
|
||||||
|
|
||||||
|
http://stackoverflow.com/questions/5083465/fast-efficient-least-squares-fit-algorithm-in-c
|
||||||
|
|
||||||
|
Use:
|
||||||
|
|
||||||
|
$ gcc linreg.c -o linreg -D__UNITTEST__ -Wall
|
||||||
|
$ ./linreg
|
||||||
|
|
||||||
|
Then compare yfit results with octave/tlinreg.m
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "linreg.h"
|
||||||
|
#include "comp_prim.h"
|
||||||
|
|
||||||
|
|
||||||
|
void linreg(COMP *m, COMP *b, float x[], COMP y[], int n)
|
||||||
|
{
|
||||||
|
float sumx = 0.0; /* sum of x */
|
||||||
|
float sumx2 = 0.0; /* sum of x^2 */
|
||||||
|
COMP sumxy = {0.0,0.0}; /* sum of x * y */
|
||||||
|
COMP sumy = {0.0,0.0}; /* sum of y */
|
||||||
|
COMP sumy2 = {0.0,0.0}; /* sum of y**2 */
|
||||||
|
float denom;
|
||||||
|
COMP zero;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<n; i++) {
|
||||||
|
sumx += x[i];
|
||||||
|
sumx2 += x[i]*x[i];
|
||||||
|
sumxy = cadd(sumxy, fcmult(x[i], y[i]));
|
||||||
|
sumy = cadd(sumy, y[i]);
|
||||||
|
sumy2 = cadd(sumy2, cmult(y[i],y[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
denom = (n * sumx2 - sumx*sumx);
|
||||||
|
|
||||||
|
if (denom == 0) {
|
||||||
|
/* singular matrix. can't solve the problem */
|
||||||
|
zero.real = 0.0; zero.imag = 0.0;
|
||||||
|
*m = zero;
|
||||||
|
*b = zero;
|
||||||
|
} else {
|
||||||
|
*m = fcmult(1.0/denom, cadd(fcmult(n, sumxy), cneg(fcmult(sumx,sumy))));
|
||||||
|
*b = fcmult(1.0/denom, cadd(fcmult(sumx2,sumy), cneg(fcmult(sumx, sumxy))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __UNITTEST__
|
||||||
|
|
||||||
|
|
||||||
|
static float x[] = {1, 2, 7, 8};
|
||||||
|
|
||||||
|
static COMP y[] = {
|
||||||
|
{-0.70702, 0.70708},
|
||||||
|
{-0.77314, 0.63442},
|
||||||
|
{-0.98083, 0.19511},
|
||||||
|
{-0.99508, 0.09799}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
float x1;
|
||||||
|
COMP m,b,yfit;
|
||||||
|
|
||||||
|
linreg(&m, &b, x, y, sizeof(x)/sizeof(float));
|
||||||
|
|
||||||
|
for (x1=1; x1<=8; x1++) {
|
||||||
|
yfit = cadd(fcmult(x1, m),b);
|
||||||
|
printf("%f %f\n", yfit.real, yfit.imag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: linreg.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: April 2015
|
||||||
|
|
||||||
|
Linear regression C module based
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LINREG__
|
||||||
|
#define __LINREG__
|
||||||
|
|
||||||
|
#include "comp.h"
|
||||||
|
|
||||||
|
void linreg(COMP *m, COMP *b, float x[], COMP y[], int n);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,306 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: lpc.c
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 30 Sep 1990 (!)
|
||||||
|
|
||||||
|
Linear Prediction functions written in C.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2009-2012 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LPC_MAX_N 512 /* maximum no. of samples in frame */
|
||||||
|
#define PI 3.141592654 /* mathematical constant */
|
||||||
|
|
||||||
|
#define ALPHA 1.0
|
||||||
|
#define BETA 0.94
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "defines.h"
|
||||||
|
#include "lpc.h"
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
pre_emp()
|
||||||
|
|
||||||
|
Pre-emphasise (high pass filter with zero close to 0 Hz) a frame of
|
||||||
|
speech samples. Helps reduce dynamic range of LPC spectrum, giving
|
||||||
|
greater weight and hense a better match to low energy formants.
|
||||||
|
|
||||||
|
Should be balanced by de-emphasis of the output speech.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void pre_emp(
|
||||||
|
float Sn_pre[], /* output frame of speech samples */
|
||||||
|
float Sn[], /* input frame of speech samples */
|
||||||
|
float *mem, /* Sn[-1]single sample memory */
|
||||||
|
int Nsam /* number of speech samples to use */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i=0; i<Nsam; i++) {
|
||||||
|
Sn_pre[i] = Sn[i] - ALPHA * mem[0];
|
||||||
|
mem[0] = Sn[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
de_emp()
|
||||||
|
|
||||||
|
De-emphasis filter (low pass filter with a pole close to 0 Hz).
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void de_emp(
|
||||||
|
float Sn_de[], /* output frame of speech samples */
|
||||||
|
float Sn[], /* input frame of speech samples */
|
||||||
|
float *mem, /* Sn[-1]single sample memory */
|
||||||
|
int Nsam /* number of speech samples to use */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i=0; i<Nsam; i++) {
|
||||||
|
Sn_de[i] = Sn[i] + BETA * mem[0];
|
||||||
|
mem[0] = Sn_de[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
hanning_window()
|
||||||
|
|
||||||
|
Hanning windows a frame of speech samples.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void hanning_window(
|
||||||
|
float Sn[], /* input frame of speech samples */
|
||||||
|
float Wn[], /* output frame of windowed samples */
|
||||||
|
int Nsam /* number of samples */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int i; /* loop variable */
|
||||||
|
|
||||||
|
for(i=0; i<Nsam; i++)
|
||||||
|
Wn[i] = Sn[i]*(0.5 - 0.5*cosf(2*PI*(float)i/(Nsam-1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
autocorrelate()
|
||||||
|
|
||||||
|
Finds the first P autocorrelation values of an array of windowed speech
|
||||||
|
samples Sn[].
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void autocorrelate(
|
||||||
|
float Sn[], /* frame of Nsam windowed speech samples */
|
||||||
|
float Rn[], /* array of P+1 autocorrelation coefficients */
|
||||||
|
int Nsam, /* number of windowed samples to use */
|
||||||
|
int order /* order of LPC analysis */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int i,j; /* loop variables */
|
||||||
|
|
||||||
|
for(j=0; j<order+1; j++) {
|
||||||
|
Rn[j] = 0.0;
|
||||||
|
for(i=0; i<Nsam-j; i++)
|
||||||
|
Rn[j] += Sn[i]*Sn[i+j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
levinson_durbin()
|
||||||
|
|
||||||
|
Given P+1 autocorrelation coefficients, finds P Linear Prediction Coeff.
|
||||||
|
(LPCs) where P is the order of the LPC all-pole model. The Levinson-Durbin
|
||||||
|
algorithm is used, and is described in:
|
||||||
|
|
||||||
|
J. Makhoul
|
||||||
|
"Linear prediction, a tutorial review"
|
||||||
|
Proceedings of the IEEE
|
||||||
|
Vol-63, No. 4, April 1975
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void levinson_durbin(
|
||||||
|
float R[], /* order+1 autocorrelation coeff */
|
||||||
|
float lpcs[], /* order+1 LPC's */
|
||||||
|
int order /* order of the LPC analysis */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
float a[order+1][order+1];
|
||||||
|
float sum, e, k;
|
||||||
|
int i,j; /* loop variables */
|
||||||
|
|
||||||
|
e = R[0]; /* Equation 38a, Makhoul */
|
||||||
|
|
||||||
|
for(i=1; i<=order; i++) {
|
||||||
|
sum = 0.0;
|
||||||
|
for(j=1; j<=i-1; j++)
|
||||||
|
sum += a[i-1][j]*R[i-j];
|
||||||
|
k = -1.0*(R[i] + sum)/e; /* Equation 38b, Makhoul */
|
||||||
|
if (fabsf(k) > 1.0)
|
||||||
|
k = 0.0;
|
||||||
|
|
||||||
|
a[i][i] = k;
|
||||||
|
|
||||||
|
for(j=1; j<=i-1; j++)
|
||||||
|
a[i][j] = a[i-1][j] + k*a[i-1][i-j]; /* Equation 38c, Makhoul */
|
||||||
|
|
||||||
|
e *= (1-k*k); /* Equation 38d, Makhoul */
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=1; i<=order; i++)
|
||||||
|
lpcs[i] = a[order][i];
|
||||||
|
lpcs[0] = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
inverse_filter()
|
||||||
|
|
||||||
|
Inverse Filter, A(z). Produces an array of residual samples from an array
|
||||||
|
of input samples and linear prediction coefficients.
|
||||||
|
|
||||||
|
The filter memory is stored in the first order samples of the input array.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void inverse_filter(
|
||||||
|
float Sn[], /* Nsam input samples */
|
||||||
|
float a[], /* LPCs for this frame of samples */
|
||||||
|
int Nsam, /* number of samples */
|
||||||
|
float res[], /* Nsam residual samples */
|
||||||
|
int order /* order of LPC */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int i,j; /* loop variables */
|
||||||
|
|
||||||
|
for(i=0; i<Nsam; i++) {
|
||||||
|
res[i] = 0.0;
|
||||||
|
for(j=0; j<=order; j++)
|
||||||
|
res[i] += Sn[i-j]*a[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
synthesis_filter()
|
||||||
|
|
||||||
|
C version of the Speech Synthesis Filter, 1/A(z). Given an array of
|
||||||
|
residual or excitation samples, and the the LP filter coefficients, this
|
||||||
|
function will produce an array of speech samples. This filter structure is
|
||||||
|
IIR.
|
||||||
|
|
||||||
|
The synthesis filter has memory as well, this is treated in the same way
|
||||||
|
as the memory for the inverse filter (see inverse_filter() notes above).
|
||||||
|
The difference is that the memory for the synthesis filter is stored in
|
||||||
|
the output array, wheras the memory of the inverse filter is stored in the
|
||||||
|
input array.
|
||||||
|
|
||||||
|
Note: the calling function must update the filter memory.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void synthesis_filter(
|
||||||
|
float res[], /* Nsam input residual (excitation) samples */
|
||||||
|
float a[], /* LPCs for this frame of speech samples */
|
||||||
|
int Nsam, /* number of speech samples */
|
||||||
|
int order, /* LPC order */
|
||||||
|
float Sn_[] /* Nsam output synthesised speech samples */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int i,j; /* loop variables */
|
||||||
|
|
||||||
|
/* Filter Nsam samples */
|
||||||
|
|
||||||
|
for(i=0; i<Nsam; i++) {
|
||||||
|
Sn_[i] = res[i]*a[0];
|
||||||
|
for(j=1; j<=order; j++)
|
||||||
|
Sn_[i] -= Sn_[i-j]*a[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
find_aks()
|
||||||
|
|
||||||
|
This function takes a frame of samples, and determines the linear
|
||||||
|
prediction coefficients for that frame of samples.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void find_aks(
|
||||||
|
float Sn[], /* Nsam samples with order sample memory */
|
||||||
|
float a[], /* order+1 LPCs with first coeff 1.0 */
|
||||||
|
int Nsam, /* number of input speech samples */
|
||||||
|
int order, /* order of the LPC analysis */
|
||||||
|
float *E /* residual energy */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
float Wn[LPC_MAX_N]; /* windowed frame of Nsam speech samples */
|
||||||
|
float R[order+1]; /* order+1 autocorrelation values of Sn[] */
|
||||||
|
int i;
|
||||||
|
|
||||||
|
assert(Nsam < LPC_MAX_N);
|
||||||
|
|
||||||
|
hanning_window(Sn,Wn,Nsam);
|
||||||
|
autocorrelate(Wn,R,Nsam,order);
|
||||||
|
levinson_durbin(R,a,order);
|
||||||
|
|
||||||
|
*E = 0.0;
|
||||||
|
for(i=0; i<=order; i++)
|
||||||
|
*E += a[i]*R[i];
|
||||||
|
if (*E < 0.0)
|
||||||
|
*E = 1E-12;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
weight()
|
||||||
|
|
||||||
|
Weights a vector of LPCs.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void weight(
|
||||||
|
float ak[], /* vector of order+1 LPCs */
|
||||||
|
float gamma, /* weighting factor */
|
||||||
|
int order, /* num LPCs (excluding leading 1.0) */
|
||||||
|
float akw[] /* weighted vector of order+1 LPCs */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i=1; i<=order; i++)
|
||||||
|
akw[i] = ak[i]*powf(gamma,(float)i);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: lpc.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 24/8/09
|
||||||
|
|
||||||
|
Linear Prediction functions written in C.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2009-2012 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LPC__
|
||||||
|
#define __LPC__
|
||||||
|
|
||||||
|
#define LPC_MAX_ORDER 20
|
||||||
|
|
||||||
|
void pre_emp(float Sn_pre[], float Sn[], float *mem, int Nsam);
|
||||||
|
void de_emp(float Sn_se[], float Sn[], float *mem, int Nsam);
|
||||||
|
void hanning_window(float Sn[], float Wn[], int Nsam);
|
||||||
|
void autocorrelate(float Sn[], float Rn[], int Nsam, int order);
|
||||||
|
void levinson_durbin(float R[], float lpcs[], int order);
|
||||||
|
void inverse_filter(float Sn[], float a[], int Nsam, float res[], int order);
|
||||||
|
void synthesis_filter(float res[], float a[], int Nsam, int order, float Sn_[]);
|
||||||
|
void find_aks(float Sn[], float a[], int Nsam, int order, float *E);
|
||||||
|
void weight(float ak[], float gamma, int order, float akw[]);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,321 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: lsp.c
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 24/2/93
|
||||||
|
|
||||||
|
|
||||||
|
This file contains functions for LPC to LSP conversion and LSP to
|
||||||
|
LPC conversion. Note that the LSP coefficients are not in radians
|
||||||
|
format but in the x domain of the unit circle.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2009 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
#include "lsp.h"
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
Introduction to Line Spectrum Pairs (LSPs)
|
||||||
|
------------------------------------------
|
||||||
|
|
||||||
|
LSPs are used to encode the LPC filter coefficients {ak} for
|
||||||
|
transmission over the channel. LSPs have several properties (like
|
||||||
|
less sensitivity to quantisation noise) that make them superior to
|
||||||
|
direct quantisation of {ak}.
|
||||||
|
|
||||||
|
A(z) is a polynomial of order lpcrdr with {ak} as the coefficients.
|
||||||
|
|
||||||
|
A(z) is transformed to P(z) and Q(z) (using a substitution and some
|
||||||
|
algebra), to obtain something like:
|
||||||
|
|
||||||
|
A(z) = 0.5[P(z)(z+z^-1) + Q(z)(z-z^-1)] (1)
|
||||||
|
|
||||||
|
As you can imagine A(z) has complex zeros all over the z-plane. P(z)
|
||||||
|
and Q(z) have the very neat property of only having zeros _on_ the
|
||||||
|
unit circle. So to find them we take a test point z=exp(jw) and
|
||||||
|
evaluate P (exp(jw)) and Q(exp(jw)) using a grid of points between 0
|
||||||
|
and pi.
|
||||||
|
|
||||||
|
The zeros (roots) of P(z) also happen to alternate, which is why we
|
||||||
|
swap coefficients as we find roots. So the process of finding the
|
||||||
|
LSP frequencies is basically finding the roots of 5th order
|
||||||
|
polynomials.
|
||||||
|
|
||||||
|
The root so P(z) and Q(z) occur in symmetrical pairs at +/-w, hence
|
||||||
|
the name Line Spectrum Pairs (LSPs).
|
||||||
|
|
||||||
|
To convert back to ak we just evaluate (1), "clocking" an impulse
|
||||||
|
thru it lpcrdr times gives us the impulse response of A(z) which is
|
||||||
|
{ak}.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: cheb_poly_eva()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 24/2/93
|
||||||
|
|
||||||
|
This function evalutes a series of chebyshev polynomials
|
||||||
|
|
||||||
|
FIXME: performing memory allocation at run time is very inefficient,
|
||||||
|
replace with stack variables of MAX_P size.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
static float
|
||||||
|
cheb_poly_eva(float *coef,float x,int order)
|
||||||
|
/* float coef[] coefficients of the polynomial to be evaluated */
|
||||||
|
/* float x the point where polynomial is to be evaluated */
|
||||||
|
/* int order order of the polynomial */
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
float *t,*u,*v,sum;
|
||||||
|
float T[(order / 2) + 1];
|
||||||
|
|
||||||
|
/* Initialise pointers */
|
||||||
|
|
||||||
|
t = T; /* T[i-2] */
|
||||||
|
*t++ = 1.0;
|
||||||
|
u = t--; /* T[i-1] */
|
||||||
|
*u++ = x;
|
||||||
|
v = u--; /* T[i] */
|
||||||
|
|
||||||
|
/* Evaluate chebyshev series formulation using iterative approach */
|
||||||
|
|
||||||
|
for(i=2;i<=order/2;i++)
|
||||||
|
*v++ = (2*x)*(*u++) - *t++; /* T[i] = 2*x*T[i-1] - T[i-2] */
|
||||||
|
|
||||||
|
sum=0.0; /* initialise sum to zero */
|
||||||
|
t = T; /* reset pointer */
|
||||||
|
|
||||||
|
/* Evaluate polynomial and return value also free memory space */
|
||||||
|
|
||||||
|
for(i=0;i<=order/2;i++)
|
||||||
|
sum+=coef[(order/2)-i]**t++;
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: lpc_to_lsp()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 24/2/93
|
||||||
|
|
||||||
|
This function converts LPC coefficients to LSP coefficients.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int lpc_to_lsp (float *a, int order, float *freq, int nb, float delta)
|
||||||
|
/* float *a lpc coefficients */
|
||||||
|
/* int order order of LPC coefficients (10) */
|
||||||
|
/* float *freq LSP frequencies in radians */
|
||||||
|
/* int nb number of sub-intervals (4) */
|
||||||
|
/* float delta grid spacing interval (0.02) */
|
||||||
|
{
|
||||||
|
float psuml,psumr,psumm,temp_xr,xl,xr,xm = 0;
|
||||||
|
float temp_psumr;
|
||||||
|
int i,j,m,flag,k;
|
||||||
|
float *px; /* ptrs of respective P'(z) & Q'(z) */
|
||||||
|
float *qx;
|
||||||
|
float *p;
|
||||||
|
float *q;
|
||||||
|
float *pt; /* ptr used for cheb_poly_eval()
|
||||||
|
whether P' or Q' */
|
||||||
|
int roots=0; /* number of roots found */
|
||||||
|
float Q[order + 1];
|
||||||
|
float P[order + 1];
|
||||||
|
|
||||||
|
flag = 1;
|
||||||
|
m = order/2; /* order of P'(z) & Q'(z) polynimials */
|
||||||
|
|
||||||
|
/* Allocate memory space for polynomials */
|
||||||
|
|
||||||
|
/* determine P'(z)'s and Q'(z)'s coefficients where
|
||||||
|
P'(z) = P(z)/(1 + z^(-1)) and Q'(z) = Q(z)/(1-z^(-1)) */
|
||||||
|
|
||||||
|
px = P; /* initilaise ptrs */
|
||||||
|
qx = Q;
|
||||||
|
p = px;
|
||||||
|
q = qx;
|
||||||
|
*px++ = 1.0;
|
||||||
|
*qx++ = 1.0;
|
||||||
|
for(i=1;i<=m;i++){
|
||||||
|
*px++ = a[i]+a[order+1-i]-*p++;
|
||||||
|
*qx++ = a[i]-a[order+1-i]+*q++;
|
||||||
|
}
|
||||||
|
px = P;
|
||||||
|
qx = Q;
|
||||||
|
for(i=0;i<m;i++){
|
||||||
|
*px = 2**px;
|
||||||
|
*qx = 2**qx;
|
||||||
|
px++;
|
||||||
|
qx++;
|
||||||
|
}
|
||||||
|
px = P; /* re-initialise ptrs */
|
||||||
|
qx = Q;
|
||||||
|
|
||||||
|
/* Search for a zero in P'(z) polynomial first and then alternate to Q'(z).
|
||||||
|
Keep alternating between the two polynomials as each zero is found */
|
||||||
|
|
||||||
|
xr = 0; /* initialise xr to zero */
|
||||||
|
xl = 1.0; /* start at point xl = 1 */
|
||||||
|
|
||||||
|
|
||||||
|
for(j=0;j<order;j++){
|
||||||
|
if(j%2) /* determines whether P' or Q' is eval. */
|
||||||
|
pt = qx;
|
||||||
|
else
|
||||||
|
pt = px;
|
||||||
|
|
||||||
|
psuml = cheb_poly_eva(pt,xl,order); /* evals poly. at xl */
|
||||||
|
flag = 1;
|
||||||
|
while(flag && (xr >= -1.0)){
|
||||||
|
xr = xl - delta ; /* interval spacing */
|
||||||
|
psumr = cheb_poly_eva(pt,xr,order);/* poly(xl-delta_x) */
|
||||||
|
temp_psumr = psumr;
|
||||||
|
temp_xr = xr;
|
||||||
|
|
||||||
|
/* if no sign change increment xr and re-evaluate
|
||||||
|
poly(xr). Repeat til sign change. if a sign change has
|
||||||
|
occurred the interval is bisected and then checked again
|
||||||
|
for a sign change which determines in which interval the
|
||||||
|
zero lies in. If there is no sign change between poly(xm)
|
||||||
|
and poly(xl) set interval between xm and xr else set
|
||||||
|
interval between xl and xr and repeat till root is located
|
||||||
|
within the specified limits */
|
||||||
|
|
||||||
|
if(((psumr*psuml)<0.0) || (psumr == 0.0)){
|
||||||
|
roots++;
|
||||||
|
|
||||||
|
psumm=psuml;
|
||||||
|
for(k=0;k<=nb;k++){
|
||||||
|
xm = (xl+xr)/2; /* bisect the interval */
|
||||||
|
psumm=cheb_poly_eva(pt,xm,order);
|
||||||
|
if(psumm*psuml>0.){
|
||||||
|
psuml=psumm;
|
||||||
|
xl=xm;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
psumr=psumm;
|
||||||
|
xr=xm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* once zero is found, reset initial interval to xr */
|
||||||
|
freq[j] = (xm);
|
||||||
|
xl = xm;
|
||||||
|
flag = 0; /* reset flag for next search */
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
psuml=temp_psumr;
|
||||||
|
xl=temp_xr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* convert from x domain to radians */
|
||||||
|
|
||||||
|
for(i=0; i<order; i++) {
|
||||||
|
freq[i] = acosf(freq[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(roots);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: lsp_to_lpc()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 24/2/93
|
||||||
|
|
||||||
|
This function converts LSP coefficients to LPC coefficients. In the
|
||||||
|
Speex code we worked out a way to simplify this significantly.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void lsp_to_lpc(float *lsp, float *ak, int order)
|
||||||
|
/* float *freq array of LSP frequencies in radians */
|
||||||
|
/* float *ak array of LPC coefficients */
|
||||||
|
/* int order order of LPC coefficients */
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
int i,j;
|
||||||
|
float xout1,xout2,xin1,xin2;
|
||||||
|
float *pw,*n1,*n2,*n3,*n4 = 0;
|
||||||
|
float freq[order];
|
||||||
|
float Wp[(order * 4) + 2];
|
||||||
|
|
||||||
|
/* convert from radians to the x=cos(w) domain */
|
||||||
|
|
||||||
|
for(i=0; i<order; i++)
|
||||||
|
freq[i] = cosf(lsp[i]);
|
||||||
|
|
||||||
|
pw = Wp;
|
||||||
|
|
||||||
|
/* initialise contents of array */
|
||||||
|
|
||||||
|
for(i=0;i<=4*(order/2)+1;i++){ /* set contents of buffer to 0 */
|
||||||
|
*pw++ = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set pointers up */
|
||||||
|
|
||||||
|
pw = Wp;
|
||||||
|
xin1 = 1.0;
|
||||||
|
xin2 = 1.0;
|
||||||
|
|
||||||
|
/* reconstruct P(z) and Q(z) by cascading second order polynomials
|
||||||
|
in form 1 - 2xz(-1) +z(-2), where x is the LSP coefficient */
|
||||||
|
|
||||||
|
for(j=0;j<=order;j++){
|
||||||
|
for(i=0;i<(order/2);i++){
|
||||||
|
n1 = pw+(i*4);
|
||||||
|
n2 = n1 + 1;
|
||||||
|
n3 = n2 + 1;
|
||||||
|
n4 = n3 + 1;
|
||||||
|
xout1 = xin1 - 2*(freq[2*i]) * *n1 + *n2;
|
||||||
|
xout2 = xin2 - 2*(freq[2*i+1]) * *n3 + *n4;
|
||||||
|
*n2 = *n1;
|
||||||
|
*n4 = *n3;
|
||||||
|
*n1 = xin1;
|
||||||
|
*n3 = xin2;
|
||||||
|
xin1 = xout1;
|
||||||
|
xin2 = xout2;
|
||||||
|
}
|
||||||
|
xout1 = xin1 + *(n4+1);
|
||||||
|
xout2 = xin2 - *(n4+2);
|
||||||
|
ak[j] = (xout1 + xout2)*0.5;
|
||||||
|
*(n4+1) = xin1;
|
||||||
|
*(n4+2) = xin2;
|
||||||
|
|
||||||
|
xin1 = 0.0;
|
||||||
|
xin2 = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: lsp.c
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 24/2/93
|
||||||
|
|
||||||
|
|
||||||
|
This file contains functions for LPC to LSP conversion and LSP to
|
||||||
|
LPC conversion. Note that the LSP coefficients are not in radians
|
||||||
|
format but in the x domain of the unit circle.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2009 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LSP__
|
||||||
|
#define __LSP__
|
||||||
|
|
||||||
|
int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta);
|
||||||
|
void lsp_to_lpc(float *freq, float *ak, int lpcrdr);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: machdep.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: May 2 2013
|
||||||
|
|
||||||
|
Machine dependant functions, e.g. profiling that requires access to a clock
|
||||||
|
counter register.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2013 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __MACHDEP__
|
||||||
|
#define __MACHDEP__
|
||||||
|
|
||||||
|
#ifdef PROFILE
|
||||||
|
#define PROFILE_VAR(...) unsigned int __VA_ARGS__
|
||||||
|
#define PROFILE_SAMPLE(timestamp) timestamp = machdep_profile_sample()
|
||||||
|
#define PROFILE_SAMPLE_AND_LOG(timestamp, prev_timestamp, label) \
|
||||||
|
timestamp = machdep_profile_sample_and_log(prev_timestamp, label)
|
||||||
|
#define PROFILE_SAMPLE_AND_LOG2(prev_timestamp, label) \
|
||||||
|
machdep_profile_sample_and_log(prev_timestamp, label)
|
||||||
|
#else
|
||||||
|
#define PROFILE_VAR(...)
|
||||||
|
#define PROFILE_SAMPLE(timestamp)
|
||||||
|
#define PROFILE_SAMPLE_AND_LOG(timestamp, prev_timestamp, label)
|
||||||
|
#define PROFILE_SAMPLE_AND_LOG2(prev_timestamp, label)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void machdep_profile_init(void);
|
||||||
|
void machdep_profile_reset(void);
|
||||||
|
unsigned int machdep_profile_sample(void);
|
||||||
|
unsigned int machdep_profile_sample_and_log(unsigned int start, char s[]);
|
||||||
|
void machdep_profile_print_logged_samples(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: mbest.c
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: Jan 2017
|
||||||
|
|
||||||
|
Multistage vector quantiser search algorithm that keeps multiple
|
||||||
|
candidates from each stage.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright David Rowe 2017
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "mbest.h"
|
||||||
|
|
||||||
|
struct MBEST *mbest_create(int entries) {
|
||||||
|
int i,j;
|
||||||
|
struct MBEST *mbest;
|
||||||
|
|
||||||
|
assert(entries > 0);
|
||||||
|
mbest = (struct MBEST *)malloc(sizeof(struct MBEST));
|
||||||
|
assert(mbest != NULL);
|
||||||
|
|
||||||
|
mbest->entries = entries;
|
||||||
|
mbest->list = (struct MBEST_LIST *)malloc(entries*sizeof(struct MBEST_LIST));
|
||||||
|
assert(mbest->list != NULL);
|
||||||
|
|
||||||
|
for(i=0; i<mbest->entries; i++) {
|
||||||
|
for(j=0; j<MBEST_STAGES; j++)
|
||||||
|
mbest->list[i].index[j] = 0;
|
||||||
|
mbest->list[i].error = 1E32;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mbest;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mbest_destroy(struct MBEST *mbest) {
|
||||||
|
assert(mbest != NULL);
|
||||||
|
free(mbest->list);
|
||||||
|
free(mbest);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
mbest_insert
|
||||||
|
|
||||||
|
Insert the results of a vector to codebook entry comparison. The
|
||||||
|
list is ordered in order or error, so those entries with the
|
||||||
|
smallest error will be first on the list.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void mbest_insert(struct MBEST *mbest, int index[], float error) {
|
||||||
|
int i, j, found;
|
||||||
|
struct MBEST_LIST *list = mbest->list;
|
||||||
|
int entries = mbest->entries;
|
||||||
|
|
||||||
|
found = 0;
|
||||||
|
for(i=0; i<entries && !found; i++)
|
||||||
|
if (error < list[i].error) {
|
||||||
|
found = 1;
|
||||||
|
for(j=entries-1; j>i; j--)
|
||||||
|
list[j] = list[j-1];
|
||||||
|
for(j=0; j<MBEST_STAGES; j++)
|
||||||
|
list[i].index[j] = index[j];
|
||||||
|
list[i].error = error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MBEST_PRINT_OUT
|
||||||
|
static void mbest_print(char title[], struct MBEST *mbest) {
|
||||||
|
int i,j;
|
||||||
|
|
||||||
|
fprintf(stderr, "%s\n", title);
|
||||||
|
for(i=0; i<mbest->entries; i++) {
|
||||||
|
for(j=0; j<MBEST_STAGES; j++)
|
||||||
|
fprintf(stderr, " %4d ", mbest->list[i].index[j]);
|
||||||
|
fprintf(stderr, " %f\n", mbest->list[i].error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
mbest_search
|
||||||
|
|
||||||
|
Searches vec[] to a codebbook of vectors, and maintains a list of the mbest
|
||||||
|
closest matches.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void mbest_search(
|
||||||
|
const float *cb, /* VQ codebook to search */
|
||||||
|
float vec[], /* target vector */
|
||||||
|
float w[], /* weighting vector */
|
||||||
|
int k, /* dimension of vector */
|
||||||
|
int m, /* number on entries in codebook */
|
||||||
|
struct MBEST *mbest, /* list of closest matches */
|
||||||
|
int index[] /* indexes that lead us here */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
float e;
|
||||||
|
int i,j;
|
||||||
|
float diff;
|
||||||
|
|
||||||
|
for(j=0; j<m; j++) {
|
||||||
|
e = 0.0;
|
||||||
|
for(i=0; i<k; i++) {
|
||||||
|
diff = cb[j*k+i]-vec[i];
|
||||||
|
e += powf(diff*w[i],2.0);
|
||||||
|
}
|
||||||
|
index[0] = j;
|
||||||
|
mbest_insert(mbest, index, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: mbest.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: Jan 2017
|
||||||
|
|
||||||
|
Multistage vector quantiser search algorithm that keeps multiple
|
||||||
|
candidates from each stage.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright David Rowe 2017
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __MBEST__
|
||||||
|
#define __MBEST__
|
||||||
|
|
||||||
|
#define MBEST_STAGES 4
|
||||||
|
|
||||||
|
struct MBEST_LIST {
|
||||||
|
int index[MBEST_STAGES]; /* index of each stage that lead us to this error */
|
||||||
|
float error;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MBEST {
|
||||||
|
int entries; /* number of entries in mbest list */
|
||||||
|
struct MBEST_LIST *list;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MBEST *mbest_create(int entries);
|
||||||
|
void mbest_destroy(struct MBEST *mbest);
|
||||||
|
void mbest_insert(struct MBEST *mbest, int index[], float error);
|
||||||
|
void mbest_search(const float *cb, float vec[], float w[], int k, int m, struct MBEST *mbest, int index[]);
|
||||||
|
|
||||||
|
// #define MBEST_PRINT_OUT
|
||||||
|
#ifdef MBEST_PRINT_OUT
|
||||||
|
#define MBEST_PRINT(a,b) mbest_print((a),(b))
|
||||||
|
#else
|
||||||
|
#define MBEST_PRINT(a,b)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: modem_probe.h
|
||||||
|
AUTHOR......: Brady O'Brien
|
||||||
|
DATE CREATED: 9 January 2016
|
||||||
|
|
||||||
|
Library to easily extract debug traces from modems during development
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2016 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __MODEMPROBE_H
|
||||||
|
#define __MODEMPROBE_H
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "comp.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MODEMPROBE_ENABLE
|
||||||
|
|
||||||
|
/* Internal functions */
|
||||||
|
void modem_probe_init_int(char *modname, char *runname);
|
||||||
|
void modem_probe_close_int();
|
||||||
|
|
||||||
|
void modem_probe_samp_i_int(char * tracename,int samp[],size_t cnt);
|
||||||
|
void modem_probe_samp_f_int(char * tracename,float samp[],size_t cnt);
|
||||||
|
void modem_probe_samp_c_int(char * tracename,COMP samp[],size_t cnt);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Init the probe library.
|
||||||
|
* char *modname - Name of the modem under test
|
||||||
|
* char *runname - Name/path of the file data is dumped to
|
||||||
|
*/
|
||||||
|
static inline void modem_probe_init(char *modname,char *runname){
|
||||||
|
modem_probe_init_int(modname,runname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dump traces to a file and clean up
|
||||||
|
*/
|
||||||
|
static inline void modem_probe_close(){
|
||||||
|
modem_probe_close_int();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Save some number of int samples to a named trace
|
||||||
|
* char *tracename - name of trace being saved to
|
||||||
|
* int samp[] - int samples
|
||||||
|
* size_t cnt - how many samples to save
|
||||||
|
*/
|
||||||
|
static inline void modem_probe_samp_i(char *tracename,int samp[],size_t cnt){
|
||||||
|
modem_probe_samp_i_int(tracename,samp,cnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Save some number of float samples to a named trace
|
||||||
|
* char *tracename - name of trace being saved to
|
||||||
|
* float samp[] - int samples
|
||||||
|
* size_t cnt - how many samples to save
|
||||||
|
*/
|
||||||
|
static inline void modem_probe_samp_f(char *tracename,float samp[],size_t cnt){
|
||||||
|
modem_probe_samp_f_int(tracename,samp,cnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Save some number of complex samples to a named trace
|
||||||
|
* char *tracename - name of trace being saved to
|
||||||
|
* COMP samp[] - int samples
|
||||||
|
* size_t cnt - how many samples to save
|
||||||
|
*/
|
||||||
|
static inline void modem_probe_samp_c(char *tracename,COMP samp[],size_t cnt){
|
||||||
|
modem_probe_samp_c_int(tracename,samp,cnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline void modem_probe_init(char *modname,char *runname){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void modem_probe_close(){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void modem_probe_samp_i(char *name,int samp[],size_t sampcnt){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void modem_probe_samp_f(char *name,float samp[],size_t cnt){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void modem_probe_samp_c(char *name,COMP samp[],size_t cnt){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: modem_stats.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: June 2015
|
||||||
|
|
||||||
|
Common structure for returning demod stats from fdmdv and cohpsk modems.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __MODEM_STATS__
|
||||||
|
#define __MODEM_STATS__
|
||||||
|
|
||||||
|
#include "comp.h"
|
||||||
|
#include "kiss_fft.h"
|
||||||
|
|
||||||
|
#define MODEM_STATS_NC_MAX 20
|
||||||
|
#define MODEM_STATS_NR_MAX 6
|
||||||
|
#define MODEM_STATS_ET_MAX 8
|
||||||
|
#define MODEM_STATS_NSPEC 512
|
||||||
|
#define MODEM_STATS_MAX_F_HZ 4000
|
||||||
|
|
||||||
|
struct MODEM_STATS {
|
||||||
|
int Nc;
|
||||||
|
float snr_est; /* estimated SNR of rx signal in dB (3 kHz noise BW) */
|
||||||
|
COMP rx_symbols[MODEM_STATS_NR_MAX][MODEM_STATS_NC_MAX+1];
|
||||||
|
/* latest received symbols, for scatter plot */
|
||||||
|
int nr; /* number of rows in rx_symbols */
|
||||||
|
int sync; /* demod sync state */
|
||||||
|
float foff; /* estimated freq offset in Hz */
|
||||||
|
float rx_timing; /* estimated optimum timing offset in samples */
|
||||||
|
float clock_offset; /* Estimated tx/rx sample clock offset in ppm */
|
||||||
|
|
||||||
|
/* eye diagram traces */
|
||||||
|
/* Eye diagram plot -- first dim is trace number, second is the trace idx */
|
||||||
|
float rx_eye[MODEM_STATS_ET_MAX][80];
|
||||||
|
int neyetr; /* How many eye traces are plotted */
|
||||||
|
int neyesamp; /* How many samples in the eye diagram */
|
||||||
|
|
||||||
|
/* Buf for FFT/waterfall */
|
||||||
|
|
||||||
|
float fft_buf[2*MODEM_STATS_NSPEC];
|
||||||
|
kiss_fft_cfg fft_cfg;
|
||||||
|
};
|
||||||
|
|
||||||
|
void modem_stats_open(struct MODEM_STATS *f);
|
||||||
|
void modem_stats_close(struct MODEM_STATS *f);
|
||||||
|
void modem_stats_get_rx_spectrum(struct MODEM_STATS *f, float mag_spec_dB[], COMP rx_fdm[], int nin);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
FILE...: mpdecode_core.h
|
||||||
|
AUTHOR.: David Rowe
|
||||||
|
CREATED: Sep 2016
|
||||||
|
|
||||||
|
C-callable core functions for MpDecode, so they can be used for
|
||||||
|
Octave and C programs. Also some convenience functions to help use
|
||||||
|
the C-callable LDPC decoder in C programs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __MPDECODE_CORE__
|
||||||
|
#define __MPDECODE_CORE__
|
||||||
|
|
||||||
|
struct LDPC {
|
||||||
|
int max_iter;
|
||||||
|
int dec_type;
|
||||||
|
int q_scale_factor;
|
||||||
|
int r_scale_factor;
|
||||||
|
int CodeLength;
|
||||||
|
int NumberParityBits;
|
||||||
|
int NumberRowsHcols;
|
||||||
|
int max_row_weight;
|
||||||
|
int max_col_weight;
|
||||||
|
double *H_rows;
|
||||||
|
double *H_cols;
|
||||||
|
};
|
||||||
|
|
||||||
|
int run_ldpc_decoder(struct LDPC *ldpc, char out_char[], double input[]);
|
||||||
|
|
||||||
|
void sd_to_llr(double llr[], double sd[], int n);
|
||||||
|
|
||||||
|
struct v_node {
|
||||||
|
int degree;
|
||||||
|
float initial_value;
|
||||||
|
int *index; /* the index of a c_node it is connected to */
|
||||||
|
int *socket; /* socket number at the c_node */
|
||||||
|
float *message;
|
||||||
|
int *sign;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct c_node {
|
||||||
|
int degree;
|
||||||
|
int *index;
|
||||||
|
float *message;
|
||||||
|
int *socket; /* socket number at the v_node */
|
||||||
|
};
|
||||||
|
|
||||||
|
void init_c_v_nodes(struct c_node *c_nodes,
|
||||||
|
int shift,
|
||||||
|
int NumberParityBits,
|
||||||
|
int max_row_weight,
|
||||||
|
double *H_rows,
|
||||||
|
int H1,
|
||||||
|
int CodeLength,
|
||||||
|
struct v_node *v_nodes,
|
||||||
|
int NumberRowsHcols,
|
||||||
|
double *H_cols,
|
||||||
|
int max_col_weight,
|
||||||
|
int dec_type,
|
||||||
|
double *input);
|
||||||
|
|
||||||
|
void ApproximateMinStar( int BitErrors[],
|
||||||
|
int DecodedBits[],
|
||||||
|
struct c_node c_nodes[],
|
||||||
|
struct v_node v_nodes[],
|
||||||
|
int CodeLength,
|
||||||
|
int NumberParityBits,
|
||||||
|
int max_iter );
|
||||||
|
|
||||||
|
void MinSum( int BitErrors[],
|
||||||
|
int DecodedBits[],
|
||||||
|
struct c_node c_nodes[],
|
||||||
|
struct v_node v_nodes[],
|
||||||
|
int CodeLength,
|
||||||
|
int NumberParityBits,
|
||||||
|
int max_iter,
|
||||||
|
float r_scale_factor,
|
||||||
|
float q_scale_factor,
|
||||||
|
int data[] );
|
||||||
|
|
||||||
|
|
||||||
|
void SumProduct( int BitErrors[],
|
||||||
|
int DecodedBits[],
|
||||||
|
struct c_node c_nodes[],
|
||||||
|
struct v_node v_nodes[],
|
||||||
|
int CodeLength,
|
||||||
|
int NumberParityBits,
|
||||||
|
int max_iter,
|
||||||
|
float r_scale_factor,
|
||||||
|
float q_scale_factor,
|
||||||
|
int data[]);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,702 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: nlp.c
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 23/3/93
|
||||||
|
|
||||||
|
Non Linear Pitch (NLP) estimation functions.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2009 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
#include "nlp.h"
|
||||||
|
#include "dump.h"
|
||||||
|
#include "codec2_fft.h"
|
||||||
|
#undef PROFILE
|
||||||
|
#include "machdep.h"
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
DEFINES
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define PMAX_M 320 /* maximum NLP analysis window size */
|
||||||
|
#define COEFF 0.95 /* notch filter parameter */
|
||||||
|
#define PE_FFT_SIZE 512 /* DFT size for pitch estimation */
|
||||||
|
#define DEC 5 /* decimation factor */
|
||||||
|
#define SAMPLE_RATE 8000
|
||||||
|
#define PI 3.141592654 /* mathematical constant */
|
||||||
|
#define T 0.1 /* threshold for local minima candidate */
|
||||||
|
#define F0_MAX 500
|
||||||
|
#define CNLP 0.3 /* post processor constant */
|
||||||
|
#define NLP_NTAP 48 /* Decimation LPF order */
|
||||||
|
#undef POST_PROCESS_MBE /* choose post processor */
|
||||||
|
|
||||||
|
/* 8 to 16 kHz sample rate conversion */
|
||||||
|
|
||||||
|
#define FDMDV_OS 2 /* oversampling rate */
|
||||||
|
#define FDMDV_OS_TAPS_16K 48 /* number of OS filter taps at 16kHz */
|
||||||
|
#define FDMDV_OS_TAPS_8K (FDMDV_OS_TAPS_16K/FDMDV_OS) /* number of OS filter taps at 8kHz */
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
GLOBALS
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* 48 tap 600Hz low pass FIR filter coefficients */
|
||||||
|
|
||||||
|
const float nlp_fir[] = {
|
||||||
|
-1.0818124e-03,
|
||||||
|
-1.1008344e-03,
|
||||||
|
-9.2768838e-04,
|
||||||
|
-4.2289438e-04,
|
||||||
|
5.5034190e-04,
|
||||||
|
2.0029849e-03,
|
||||||
|
3.7058509e-03,
|
||||||
|
5.1449415e-03,
|
||||||
|
5.5924666e-03,
|
||||||
|
4.3036754e-03,
|
||||||
|
8.0284511e-04,
|
||||||
|
-4.8204610e-03,
|
||||||
|
-1.1705810e-02,
|
||||||
|
-1.8199275e-02,
|
||||||
|
-2.2065282e-02,
|
||||||
|
-2.0920610e-02,
|
||||||
|
-1.2808831e-02,
|
||||||
|
3.2204775e-03,
|
||||||
|
2.6683811e-02,
|
||||||
|
5.5520624e-02,
|
||||||
|
8.6305944e-02,
|
||||||
|
1.1480192e-01,
|
||||||
|
1.3674206e-01,
|
||||||
|
1.4867556e-01,
|
||||||
|
1.4867556e-01,
|
||||||
|
1.3674206e-01,
|
||||||
|
1.1480192e-01,
|
||||||
|
8.6305944e-02,
|
||||||
|
5.5520624e-02,
|
||||||
|
2.6683811e-02,
|
||||||
|
3.2204775e-03,
|
||||||
|
-1.2808831e-02,
|
||||||
|
-2.0920610e-02,
|
||||||
|
-2.2065282e-02,
|
||||||
|
-1.8199275e-02,
|
||||||
|
-1.1705810e-02,
|
||||||
|
-4.8204610e-03,
|
||||||
|
8.0284511e-04,
|
||||||
|
4.3036754e-03,
|
||||||
|
5.5924666e-03,
|
||||||
|
5.1449415e-03,
|
||||||
|
3.7058509e-03,
|
||||||
|
2.0029849e-03,
|
||||||
|
5.5034190e-04,
|
||||||
|
-4.2289438e-04,
|
||||||
|
-9.2768838e-04,
|
||||||
|
-1.1008344e-03,
|
||||||
|
-1.0818124e-03
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int Fs; /* sample rate in Hz */
|
||||||
|
int m;
|
||||||
|
float w[PMAX_M/DEC]; /* DFT window */
|
||||||
|
float sq[PMAX_M]; /* squared speech samples */
|
||||||
|
float mem_x,mem_y; /* memory for notch filter */
|
||||||
|
float mem_fir[NLP_NTAP]; /* decimation FIR filter memory */
|
||||||
|
codec2_fft_cfg fft_cfg; /* kiss FFT config */
|
||||||
|
float *Sn16k; /* Fs=16kHz input speech vector */
|
||||||
|
FILE *f;
|
||||||
|
} NLP;
|
||||||
|
|
||||||
|
#ifdef POST_PROCESS_MBE
|
||||||
|
float test_candidate_mbe(COMP Sw[], COMP W[], float f0);
|
||||||
|
float post_process_mbe(COMP Fw[], int pmin, int pmax, float gmax, COMP Sw[], COMP W[], float *prev_Wo);
|
||||||
|
#endif
|
||||||
|
float post_process_sub_multiples(COMP Fw[],
|
||||||
|
int pmin, int pmax, float gmax, int gmax_bin,
|
||||||
|
float *prev_f0);
|
||||||
|
static void fdmdv_16_to_8(float out8k[], float in16k[], int n);
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
nlp_create()
|
||||||
|
|
||||||
|
Initialisation function for NLP pitch estimator.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void *nlp_create(C2CONST *c2const)
|
||||||
|
{
|
||||||
|
NLP *nlp;
|
||||||
|
int i;
|
||||||
|
int m = c2const->m_pitch;
|
||||||
|
int Fs = c2const->Fs;
|
||||||
|
|
||||||
|
nlp = (NLP*)malloc(sizeof(NLP));
|
||||||
|
if (nlp == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
assert((Fs == 8000) || (Fs == 16000));
|
||||||
|
nlp->Fs = Fs;
|
||||||
|
|
||||||
|
nlp->m = m;
|
||||||
|
|
||||||
|
/* if running at 16kHz allocate storage for decimating filter memory */
|
||||||
|
|
||||||
|
if (Fs == 16000) {
|
||||||
|
nlp->Sn16k = (float*)malloc(sizeof(float)*(FDMDV_OS_TAPS_16K + c2const->n_samp));
|
||||||
|
for(i=0; i<FDMDV_OS_TAPS_16K; i++) {
|
||||||
|
nlp->Sn16k[i] = 0.0;
|
||||||
|
}
|
||||||
|
if (nlp->Sn16k == NULL) {
|
||||||
|
free(nlp);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* most processing occurs at 8 kHz sample rate so halve m */
|
||||||
|
|
||||||
|
m /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(m <= PMAX_M);
|
||||||
|
|
||||||
|
for(i=0; i<m/DEC; i++) {
|
||||||
|
nlp->w[i] = 0.5 - 0.5*cosf(2*PI*i/(m/DEC-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<PMAX_M; i++)
|
||||||
|
nlp->sq[i] = 0.0;
|
||||||
|
nlp->mem_x = 0.0;
|
||||||
|
nlp->mem_y = 0.0;
|
||||||
|
for(i=0; i<NLP_NTAP; i++)
|
||||||
|
nlp->mem_fir[i] = 0.0;
|
||||||
|
|
||||||
|
nlp->fft_cfg = codec2_fft_alloc (PE_FFT_SIZE, 0, NULL, NULL);
|
||||||
|
assert(nlp->fft_cfg != NULL);
|
||||||
|
|
||||||
|
return (void*)nlp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
nlp_destroy()
|
||||||
|
|
||||||
|
Shut down function for NLP pitch estimator.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void nlp_destroy(void *nlp_state)
|
||||||
|
{
|
||||||
|
NLP *nlp;
|
||||||
|
assert(nlp_state != NULL);
|
||||||
|
nlp = (NLP*)nlp_state;
|
||||||
|
|
||||||
|
codec2_fft_free(nlp->fft_cfg);
|
||||||
|
if (nlp->Fs == 16000) {
|
||||||
|
free(nlp->Sn16k);
|
||||||
|
}
|
||||||
|
free(nlp_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
nlp()
|
||||||
|
|
||||||
|
Determines the pitch in samples using the Non Linear Pitch (NLP)
|
||||||
|
algorithm [1]. Returns the fundamental in Hz. Note that the actual
|
||||||
|
pitch estimate is for the centre of the M sample Sn[] vector, not
|
||||||
|
the current N sample input vector. This is (I think) a delay of 2.5
|
||||||
|
frames with N=80 samples. You should align further analysis using
|
||||||
|
this pitch estimate to be centred on the middle of Sn[].
|
||||||
|
|
||||||
|
Two post processors have been tried, the MBE version (as discussed
|
||||||
|
in [1]), and a post processor that checks sub-multiples. Both
|
||||||
|
suffer occasional gross pitch errors (i.e. neither are perfect). In
|
||||||
|
the presence of background noise the sub-multiple algorithm tends
|
||||||
|
towards low F0 which leads to better sounding background noise than
|
||||||
|
the MBE post processor.
|
||||||
|
|
||||||
|
A good way to test and develop the NLP pitch estimator is using the
|
||||||
|
tnlp (codec2/unittest) and the codec2/octave/plnlp.m Octave script.
|
||||||
|
|
||||||
|
A pitch tracker searching a few frames forward and backward in time
|
||||||
|
would be a useful addition.
|
||||||
|
|
||||||
|
References:
|
||||||
|
|
||||||
|
[1] http://rowetel.com/downloads/1997_rowe_phd_thesis.pdf Chapter 4
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
float nlp(
|
||||||
|
void *nlp_state,
|
||||||
|
float Sn[], /* input speech vector */
|
||||||
|
int n, /* frames shift (no. new samples in Sn[]) */
|
||||||
|
float *pitch, /* estimated pitch period in samples at current Fs */
|
||||||
|
COMP Sw[], /* Freq domain version of Sn[] */
|
||||||
|
COMP W[], /* Freq domain window */
|
||||||
|
float *prev_f0 /* previous pitch f0 in Hz, memory for pitch tracking */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
NLP *nlp;
|
||||||
|
float notch; /* current notch filter output */
|
||||||
|
COMP Fw[PE_FFT_SIZE]; /* DFT of squared signal (input/output) */
|
||||||
|
float gmax;
|
||||||
|
int gmax_bin;
|
||||||
|
int m, i, j;
|
||||||
|
float best_f0;
|
||||||
|
PROFILE_VAR(start, tnotch, filter, peakpick, window, fft, magsq, shiftmem);
|
||||||
|
|
||||||
|
assert(nlp_state != NULL);
|
||||||
|
nlp = (NLP*)nlp_state;
|
||||||
|
m = nlp->m;
|
||||||
|
|
||||||
|
/* Square, notch filter at DC, and LP filter vector */
|
||||||
|
|
||||||
|
/* If running at 16 kHz decimate to 8 kHz, as NLP ws designed for
|
||||||
|
Fs = 8kHz. The decimating filter introduces about 3ms of delay,
|
||||||
|
that shouldn't be a problem as pitch changes slowly. */
|
||||||
|
|
||||||
|
if (nlp->Fs == 8000) {
|
||||||
|
/* Square latest input samples */
|
||||||
|
|
||||||
|
for(i=m-n; i<m; i++) {
|
||||||
|
nlp->sq[i] = Sn[i]*Sn[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert(nlp->Fs == 16000);
|
||||||
|
|
||||||
|
/* re-sample at 8 KHz */
|
||||||
|
|
||||||
|
for(i=0; i<n; i++) {
|
||||||
|
nlp->Sn16k[FDMDV_OS_TAPS_16K+i] = Sn[m-n+i];
|
||||||
|
}
|
||||||
|
|
||||||
|
m /= 2; n /= 2;
|
||||||
|
|
||||||
|
float Sn8k[n];
|
||||||
|
fdmdv_16_to_8(Sn8k, &nlp->Sn16k[FDMDV_OS_TAPS_16K], n);
|
||||||
|
|
||||||
|
/* Square latest input samples */
|
||||||
|
|
||||||
|
for(i=m-n, j=0; i<m; i++, j++) {
|
||||||
|
nlp->sq[i] = Sn8k[j]*Sn8k[j];
|
||||||
|
}
|
||||||
|
assert(j <= n);
|
||||||
|
}
|
||||||
|
//fprintf(stderr, "n: %d m: %d\n", n, m);
|
||||||
|
|
||||||
|
PROFILE_SAMPLE(start);
|
||||||
|
|
||||||
|
for(i=m-n; i<m; i++) { /* notch filter at DC */
|
||||||
|
notch = nlp->sq[i] - nlp->mem_x;
|
||||||
|
notch += COEFF*nlp->mem_y;
|
||||||
|
nlp->mem_x = nlp->sq[i];
|
||||||
|
nlp->mem_y = notch;
|
||||||
|
nlp->sq[i] = notch + 1.0; /* With 0 input vectors to codec,
|
||||||
|
kiss_fft() would take a long
|
||||||
|
time to execute when running in
|
||||||
|
real time. Problem was traced
|
||||||
|
to kiss_fft function call in
|
||||||
|
this function. Adding this small
|
||||||
|
constant fixed problem. Not
|
||||||
|
exactly sure why. */
|
||||||
|
}
|
||||||
|
|
||||||
|
PROFILE_SAMPLE_AND_LOG(tnotch, start, " square and notch");
|
||||||
|
|
||||||
|
for(i=m-n; i<m; i++) { /* FIR filter vector */
|
||||||
|
|
||||||
|
for(j=0; j<NLP_NTAP-1; j++)
|
||||||
|
nlp->mem_fir[j] = nlp->mem_fir[j+1];
|
||||||
|
nlp->mem_fir[NLP_NTAP-1] = nlp->sq[i];
|
||||||
|
|
||||||
|
nlp->sq[i] = 0.0;
|
||||||
|
for(j=0; j<NLP_NTAP; j++)
|
||||||
|
nlp->sq[i] += nlp->mem_fir[j]*nlp_fir[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
PROFILE_SAMPLE_AND_LOG(filter, tnotch, " filter");
|
||||||
|
|
||||||
|
/* Decimate and DFT */
|
||||||
|
|
||||||
|
for(i=0; i<PE_FFT_SIZE; i++) {
|
||||||
|
Fw[i].real = 0.0;
|
||||||
|
Fw[i].imag = 0.0;
|
||||||
|
}
|
||||||
|
for(i=0; i<m/DEC; i++) {
|
||||||
|
Fw[i].real = nlp->sq[i*DEC]*nlp->w[i];
|
||||||
|
}
|
||||||
|
PROFILE_SAMPLE_AND_LOG(window, filter, " window");
|
||||||
|
#ifdef DUMP
|
||||||
|
dump_dec(Fw);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// FIXME: check if this can be converted to a real fft
|
||||||
|
// since all imag inputs are 0
|
||||||
|
codec2_fft_inplace(nlp->fft_cfg, Fw);
|
||||||
|
PROFILE_SAMPLE_AND_LOG(fft, window, " fft");
|
||||||
|
|
||||||
|
for(i=0; i<PE_FFT_SIZE; i++)
|
||||||
|
Fw[i].real = Fw[i].real*Fw[i].real + Fw[i].imag*Fw[i].imag;
|
||||||
|
|
||||||
|
PROFILE_SAMPLE_AND_LOG(magsq, fft, " mag sq");
|
||||||
|
#ifdef DUMP
|
||||||
|
dump_sq(m, nlp->sq);
|
||||||
|
dump_Fw(Fw);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* todo: express everything in f0, as pitch in samples is dep on Fs */
|
||||||
|
|
||||||
|
int pmin = floor(SAMPLE_RATE*P_MIN_S);
|
||||||
|
int pmax = floor(SAMPLE_RATE*P_MAX_S);
|
||||||
|
|
||||||
|
/* find global peak */
|
||||||
|
|
||||||
|
gmax = 0.0;
|
||||||
|
gmax_bin = PE_FFT_SIZE*DEC/pmax;
|
||||||
|
for(i=PE_FFT_SIZE*DEC/pmax; i<=PE_FFT_SIZE*DEC/pmin; i++) {
|
||||||
|
if (Fw[i].real > gmax) {
|
||||||
|
gmax = Fw[i].real;
|
||||||
|
gmax_bin = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PROFILE_SAMPLE_AND_LOG(peakpick, magsq, " peak pick");
|
||||||
|
|
||||||
|
#ifdef POST_PROCESS_MBE
|
||||||
|
best_f0 = post_process_mbe(Fw, pmin, pmax, gmax, Sw, W, prev_f0);
|
||||||
|
#else
|
||||||
|
best_f0 = post_process_sub_multiples(Fw, pmin, pmax, gmax, gmax_bin, prev_f0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
PROFILE_SAMPLE_AND_LOG(shiftmem, peakpick, " post process");
|
||||||
|
|
||||||
|
/* Shift samples in buffer to make room for new samples */
|
||||||
|
|
||||||
|
for(i=0; i<m-n; i++)
|
||||||
|
nlp->sq[i] = nlp->sq[i+n];
|
||||||
|
|
||||||
|
/* return pitch period in samples and F0 estimate */
|
||||||
|
|
||||||
|
*pitch = (float)nlp->Fs/best_f0;
|
||||||
|
|
||||||
|
PROFILE_SAMPLE_AND_LOG2(shiftmem, " shift mem");
|
||||||
|
|
||||||
|
PROFILE_SAMPLE_AND_LOG2(start, " nlp int");
|
||||||
|
|
||||||
|
*prev_f0 = best_f0;
|
||||||
|
|
||||||
|
return(best_f0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
post_process_sub_multiples()
|
||||||
|
|
||||||
|
Given the global maximma of Fw[] we search integer submultiples for
|
||||||
|
local maxima. If local maxima exist and they are above an
|
||||||
|
experimentally derived threshold (OK a magic number I pulled out of
|
||||||
|
the air) we choose the submultiple as the F0 estimate.
|
||||||
|
|
||||||
|
The rational for this is that the lowest frequency peak of Fw[]
|
||||||
|
should be F0, as Fw[] can be considered the autocorrelation function
|
||||||
|
of Sw[] (the speech spectrum). However sometimes due to phase
|
||||||
|
effects the lowest frequency maxima may not be the global maxima.
|
||||||
|
|
||||||
|
This works OK in practice and favours low F0 values in the presence
|
||||||
|
of background noise which means the sinusoidal codec does an OK job
|
||||||
|
of synthesising the background noise. High F0 in background noise
|
||||||
|
tends to sound more periodic introducing annoying artifacts.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
float post_process_sub_multiples(COMP Fw[],
|
||||||
|
int pmin, int pmax, float gmax, int gmax_bin,
|
||||||
|
float *prev_f0)
|
||||||
|
{
|
||||||
|
int min_bin, cmax_bin;
|
||||||
|
int mult;
|
||||||
|
float thresh, best_f0;
|
||||||
|
int b, bmin, bmax, lmax_bin;
|
||||||
|
float lmax;
|
||||||
|
int prev_f0_bin;
|
||||||
|
|
||||||
|
/* post process estimate by searching submultiples */
|
||||||
|
|
||||||
|
mult = 2;
|
||||||
|
min_bin = PE_FFT_SIZE*DEC/pmax;
|
||||||
|
cmax_bin = gmax_bin;
|
||||||
|
prev_f0_bin = *prev_f0*(PE_FFT_SIZE*DEC)/SAMPLE_RATE;
|
||||||
|
|
||||||
|
while(gmax_bin/mult >= min_bin) {
|
||||||
|
|
||||||
|
b = gmax_bin/mult; /* determine search interval */
|
||||||
|
bmin = 0.8*b;
|
||||||
|
bmax = 1.2*b;
|
||||||
|
if (bmin < min_bin)
|
||||||
|
bmin = min_bin;
|
||||||
|
|
||||||
|
/* lower threshold to favour previous frames pitch estimate,
|
||||||
|
this is a form of pitch tracking */
|
||||||
|
|
||||||
|
if ((prev_f0_bin > bmin) && (prev_f0_bin < bmax))
|
||||||
|
thresh = CNLP*0.5*gmax;
|
||||||
|
else
|
||||||
|
thresh = CNLP*gmax;
|
||||||
|
|
||||||
|
lmax = 0;
|
||||||
|
lmax_bin = bmin;
|
||||||
|
for (b=bmin; b<=bmax; b++) /* look for maximum in interval */
|
||||||
|
if (Fw[b].real > lmax) {
|
||||||
|
lmax = Fw[b].real;
|
||||||
|
lmax_bin = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lmax > thresh)
|
||||||
|
if ((lmax > Fw[lmax_bin-1].real) && (lmax > Fw[lmax_bin+1].real)) {
|
||||||
|
cmax_bin = lmax_bin;
|
||||||
|
}
|
||||||
|
|
||||||
|
mult++;
|
||||||
|
}
|
||||||
|
|
||||||
|
best_f0 = (float)cmax_bin*SAMPLE_RATE/(PE_FFT_SIZE*DEC);
|
||||||
|
|
||||||
|
return best_f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef POST_PROCESS_MBE
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
post_process_mbe()
|
||||||
|
|
||||||
|
Use the MBE pitch estimation algorithm to evaluate pitch candidates. This
|
||||||
|
works OK but the accuracy at low F0 is affected by NW, the analysis window
|
||||||
|
size used for the DFT of the input speech Sw[]. Also favours high F0 in
|
||||||
|
the presence of background noise which causes periodic artifacts in the
|
||||||
|
synthesised speech.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
float post_process_mbe(COMP Fw[], int pmin, int pmax, float gmax, COMP Sw[], COMP W[], float *prev_Wo)
|
||||||
|
{
|
||||||
|
float candidate_f0;
|
||||||
|
float f0,best_f0; /* fundamental frequency */
|
||||||
|
float e,e_min; /* MBE cost function */
|
||||||
|
int i;
|
||||||
|
#ifdef DUMP
|
||||||
|
float e_hz[F0_MAX];
|
||||||
|
#endif
|
||||||
|
#if !defined(NDEBUG) || defined(DUMP)
|
||||||
|
int bin;
|
||||||
|
#endif
|
||||||
|
float f0_min, f0_max;
|
||||||
|
float f0_start, f0_end;
|
||||||
|
|
||||||
|
f0_min = (float)SAMPLE_RATE/pmax;
|
||||||
|
f0_max = (float)SAMPLE_RATE/pmin;
|
||||||
|
|
||||||
|
/* Now look for local maxima. Each local maxima is a candidate
|
||||||
|
that we test using the MBE pitch estimation algotithm */
|
||||||
|
|
||||||
|
#ifdef DUMP
|
||||||
|
for(i=0; i<F0_MAX; i++)
|
||||||
|
e_hz[i] = -1;
|
||||||
|
#endif
|
||||||
|
e_min = 1E32;
|
||||||
|
best_f0 = 50;
|
||||||
|
for(i=PE_FFT_SIZE*DEC/pmax; i<=PE_FFT_SIZE*DEC/pmin; i++) {
|
||||||
|
if ((Fw[i].real > Fw[i-1].real) && (Fw[i].real > Fw[i+1].real)) {
|
||||||
|
|
||||||
|
/* local maxima found, lets test if it's big enough */
|
||||||
|
|
||||||
|
if (Fw[i].real > T*gmax) {
|
||||||
|
|
||||||
|
/* OK, sample MBE cost function over +/- 10Hz range in 2.5Hz steps */
|
||||||
|
|
||||||
|
candidate_f0 = (float)i*SAMPLE_RATE/(PE_FFT_SIZE*DEC);
|
||||||
|
f0_start = candidate_f0-20;
|
||||||
|
f0_end = candidate_f0+20;
|
||||||
|
if (f0_start < f0_min) f0_start = f0_min;
|
||||||
|
if (f0_end > f0_max) f0_end = f0_max;
|
||||||
|
|
||||||
|
for(f0=f0_start; f0<=f0_end; f0+= 2.5) {
|
||||||
|
e = test_candidate_mbe(Sw, W, f0);
|
||||||
|
#if !defined(NDEBUG) || defined(DUMP)
|
||||||
|
bin = floorf(f0); assert((bin > 0) && (bin < F0_MAX));
|
||||||
|
#endif
|
||||||
|
#ifdef DUMP
|
||||||
|
e_hz[bin] = e;
|
||||||
|
#endif
|
||||||
|
if (e < e_min) {
|
||||||
|
e_min = e;
|
||||||
|
best_f0 = f0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* finally sample MBE cost function around previous pitch estimate
|
||||||
|
(form of pitch tracking) */
|
||||||
|
|
||||||
|
candidate_f0 = *prev_Wo * SAMPLE_RATE/TWO_PI;
|
||||||
|
f0_start = candidate_f0-20;
|
||||||
|
f0_end = candidate_f0+20;
|
||||||
|
if (f0_start < f0_min) f0_start = f0_min;
|
||||||
|
if (f0_end > f0_max) f0_end = f0_max;
|
||||||
|
|
||||||
|
for(f0=f0_start; f0<=f0_end; f0+= 2.5) {
|
||||||
|
e = test_candidate_mbe(Sw, W, f0);
|
||||||
|
#if !defined(NDEBUG) || defined(DUMP)
|
||||||
|
bin = floorf(f0); assert((bin > 0) && (bin < F0_MAX));
|
||||||
|
#endif
|
||||||
|
#ifdef DUMP
|
||||||
|
e_hz[bin] = e;
|
||||||
|
#endif
|
||||||
|
if (e < e_min) {
|
||||||
|
e_min = e;
|
||||||
|
best_f0 = f0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DUMP
|
||||||
|
dump_e(e_hz);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return best_f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
test_candidate_mbe()
|
||||||
|
|
||||||
|
Returns the error of the MBE cost function for the input f0.
|
||||||
|
|
||||||
|
Note: I think a lot of the operations below can be simplified as
|
||||||
|
W[].imag = 0 and has been normalised such that den always equals 1.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
float test_candidate_mbe(
|
||||||
|
COMP Sw[],
|
||||||
|
COMP W[],
|
||||||
|
float f0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
COMP Sw_[FFT_ENC]; /* DFT of all voiced synthesised signal */
|
||||||
|
int l,al,bl,m; /* loop variables */
|
||||||
|
COMP Am; /* amplitude sample for this band */
|
||||||
|
int offset; /* centers Hw[] about current harmonic */
|
||||||
|
float den; /* denominator of Am expression */
|
||||||
|
float error; /* accumulated error between originl and synthesised */
|
||||||
|
float Wo; /* current "test" fundamental freq. */
|
||||||
|
int L;
|
||||||
|
|
||||||
|
L = floorf((SAMPLE_RATE/2.0)/f0);
|
||||||
|
Wo = f0*(2*PI/SAMPLE_RATE);
|
||||||
|
|
||||||
|
error = 0.0;
|
||||||
|
|
||||||
|
/* Just test across the harmonics in the first 1000 Hz (L/4) */
|
||||||
|
|
||||||
|
for(l=1; l<L/4; l++) {
|
||||||
|
Am.real = 0.0;
|
||||||
|
Am.imag = 0.0;
|
||||||
|
den = 0.0;
|
||||||
|
al = ceilf((l - 0.5)*Wo*FFT_ENC/TWO_PI);
|
||||||
|
bl = ceilf((l + 0.5)*Wo*FFT_ENC/TWO_PI);
|
||||||
|
|
||||||
|
/* Estimate amplitude of harmonic assuming harmonic is totally voiced */
|
||||||
|
|
||||||
|
for(m=al; m<bl; m++) {
|
||||||
|
offset = FFT_ENC/2 + m - l*Wo*FFT_ENC/TWO_PI + 0.5;
|
||||||
|
Am.real += Sw[m].real*W[offset].real + Sw[m].imag*W[offset].imag;
|
||||||
|
Am.imag += Sw[m].imag*W[offset].real - Sw[m].real*W[offset].imag;
|
||||||
|
den += W[offset].real*W[offset].real + W[offset].imag*W[offset].imag;
|
||||||
|
}
|
||||||
|
|
||||||
|
Am.real = Am.real/den;
|
||||||
|
Am.imag = Am.imag/den;
|
||||||
|
|
||||||
|
/* Determine error between estimated harmonic and original */
|
||||||
|
|
||||||
|
for(m=al; m<bl; m++) {
|
||||||
|
offset = FFT_ENC/2 + m - l*Wo*FFT_ENC/TWO_PI + 0.5;
|
||||||
|
Sw_[m].real = Am.real*W[offset].real - Am.imag*W[offset].imag;
|
||||||
|
Sw_[m].imag = Am.real*W[offset].imag + Am.imag*W[offset].real;
|
||||||
|
error += (Sw[m].real - Sw_[m].real)*(Sw[m].real - Sw_[m].real);
|
||||||
|
error += (Sw[m].imag - Sw_[m].imag)*(Sw[m].imag - Sw_[m].imag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: fdmdv_16_to_8()
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 9 May 2012
|
||||||
|
|
||||||
|
Changes the sample rate of a signal from 16 to 8 kHz.
|
||||||
|
|
||||||
|
n is the number of samples at the 8 kHz rate, there are FDMDV_OS*n
|
||||||
|
samples at the 48 kHz rate. As above however a memory of
|
||||||
|
FDMDV_OS_TAPS samples is reqd for in16k[] (see t16_8.c unit test as example).
|
||||||
|
|
||||||
|
Low pass filter the 16 kHz signal at 4 kHz using the same filter as
|
||||||
|
the upsampler, then just output every FDMDV_OS-th filtered sample.
|
||||||
|
|
||||||
|
Note: this function copied from fdmdv.c, included in nlp.c as a convenience
|
||||||
|
to avoid linking with another source file.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static void fdmdv_16_to_8(float out8k[], float in16k[], int n)
|
||||||
|
{
|
||||||
|
float acc;
|
||||||
|
int i,j,k;
|
||||||
|
|
||||||
|
for(i=0, k=0; k<n; i+=FDMDV_OS, k++) {
|
||||||
|
acc = 0.0;
|
||||||
|
for(j=0; j<FDMDV_OS_TAPS_16K; j++)
|
||||||
|
acc += fdmdv_os_filter[j]*in16k[i-j];
|
||||||
|
out8k[k] = acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* update filter memory */
|
||||||
|
|
||||||
|
for(i=-FDMDV_OS_TAPS_16K; i<0; i++)
|
||||||
|
in16k[i] = in16k[i + n*FDMDV_OS];
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: nlp.c
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 23/3/93
|
||||||
|
|
||||||
|
Non Linear Pitch (NLP) estimation functions.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2009 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __NLP__
|
||||||
|
#define __NLP__
|
||||||
|
|
||||||
|
#include "comp.h"
|
||||||
|
|
||||||
|
void *nlp_create(C2CONST *c2const);
|
||||||
|
void nlp_destroy(void *nlp_state);
|
||||||
|
float nlp(void *nlp_state, float Sn[], int n,
|
||||||
|
float *pitch_samples, COMP Sw[], COMP W[], float *prev_f0);
|
||||||
|
|
||||||
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: octave.h
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: April 28 2012
|
||||||
|
|
||||||
|
Functions to save C arrays in Octave matrix format. the output text
|
||||||
|
file can be directly read into octave using "load filename".
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __OCTAVE__
|
||||||
|
#define __OCTAVE__
|
||||||
|
|
||||||
|
#include "comp.h"
|
||||||
|
|
||||||
|
void octave_save_int(FILE *f, char name[], int data[], int rows, int cols);
|
||||||
|
void octave_save_float(FILE *f, char name[], float data[], int rows, int cols, int col_len);
|
||||||
|
void octave_save_complex(FILE *f, char name[], COMP data[], int rows, int cols, int col_len);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: ofdm_internal.h
|
||||||
|
AUTHORS.....: David Rowe & Steve Sampson
|
||||||
|
DATE CREATED: June 2017
|
||||||
|
|
||||||
|
OFDM Internal definitions.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2017 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OFDM_INTERNAL_H
|
||||||
|
#define OFDM_INTERNAL_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <complex.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.14159265358979323846f /* math constant */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TAU (2.0f * M_PI) /* mathematical constant */
|
||||||
|
|
||||||
|
#define OFDM_NC 16
|
||||||
|
#define OFDM_TS 0.018f
|
||||||
|
#define OFDM_RS (1.0f / OFDM_TS)
|
||||||
|
#define OFDM_FS 8000.0f
|
||||||
|
#define OFDM_BPS 2
|
||||||
|
#define OFDM_TCP 0.002f
|
||||||
|
#define OFDM_NS 8
|
||||||
|
#define OFDM_CENTRE 1500.0f
|
||||||
|
|
||||||
|
/* To prevent C99 warning */
|
||||||
|
|
||||||
|
#define OFDM_M 144
|
||||||
|
#define OFDM_NCP 16
|
||||||
|
|
||||||
|
#ifdef OLD_STYLE
|
||||||
|
/* This will produce a warning in C99 as (int) makes these variable */
|
||||||
|
|
||||||
|
#define OFDM_M ((int)(OFDM_FS / OFDM_RS))
|
||||||
|
#define OFDM_NCP ((int)(OFDM_TCP * OFDM_FS))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define OFDM_FTWINDOWWIDTH 11
|
||||||
|
#define OFDM_BITSPERFRAME ((OFDM_NS - 1) * (OFDM_NC * OFDM_BPS))
|
||||||
|
#define OFDM_ROWSPERFRAME (OFDM_BITSPERFRAME / (OFDM_NC * OFDM_BPS))
|
||||||
|
#define OFDM_SAMPLESPERFRAME (OFDM_NS * (OFDM_M + OFDM_NCP))
|
||||||
|
#define OFDM_MAX_SAMPLESPERFRAME (OFDM_SAMPLESPERFRAME + (OFDM_M + OFDM_NCP)/4)
|
||||||
|
#define OFDM_RXBUF (3 * OFDM_SAMPLESPERFRAME + 3 * (OFDM_M + OFDM_NCP))
|
||||||
|
|
||||||
|
struct OFDM {
|
||||||
|
float foff_est_gain;
|
||||||
|
float foff_est_hz;
|
||||||
|
|
||||||
|
int verbose;
|
||||||
|
int sample_point;
|
||||||
|
int timing_est;
|
||||||
|
int nin;
|
||||||
|
|
||||||
|
bool timing_en;
|
||||||
|
bool foff_est_en;
|
||||||
|
bool phase_est_en;
|
||||||
|
|
||||||
|
complex float pilot_samples[OFDM_M + OFDM_NCP];
|
||||||
|
complex float W[OFDM_NC + 2][OFDM_M];
|
||||||
|
complex float rxbuf[OFDM_RXBUF];
|
||||||
|
complex float pilots[OFDM_NC + 2];
|
||||||
|
float w[OFDM_NC + 2];
|
||||||
|
|
||||||
|
/* Demodulator data */
|
||||||
|
|
||||||
|
complex float rx_sym[OFDM_NS + 3][OFDM_NC + 2];
|
||||||
|
complex float rx_np[OFDM_ROWSPERFRAME * OFDM_NC];
|
||||||
|
float rx_amp[OFDM_ROWSPERFRAME * OFDM_NC];
|
||||||
|
float aphase_est_pilot_log[OFDM_ROWSPERFRAME * OFDM_NC];
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/* Generate using fir1(47,1/2) in Octave */
|
||||||
|
|
||||||
|
static const float fdmdv_os_filter[]= {
|
||||||
|
-0.0008215855034550382,
|
||||||
|
-0.0007833023901802921,
|
||||||
|
0.001075563790768233,
|
||||||
|
0.001199092367787555,
|
||||||
|
-0.001765309502928316,
|
||||||
|
-0.002055372115328064,
|
||||||
|
0.002986877604154257,
|
||||||
|
0.003462567920638414,
|
||||||
|
-0.004856570111126334,
|
||||||
|
-0.005563143845031497,
|
||||||
|
0.007533613299748122,
|
||||||
|
0.008563932468880897,
|
||||||
|
-0.01126857129039911,
|
||||||
|
-0.01280782411693687,
|
||||||
|
0.01651443896361847,
|
||||||
|
0.01894875110322284,
|
||||||
|
-0.02421604439474981,
|
||||||
|
-0.02845107338464062,
|
||||||
|
0.03672973563400258,
|
||||||
|
0.04542046150312214,
|
||||||
|
-0.06189165826716491,
|
||||||
|
-0.08721876380763803,
|
||||||
|
0.1496157094199961,
|
||||||
|
0.4497962274137046,
|
||||||
|
0.4497962274137046,
|
||||||
|
0.1496157094199961,
|
||||||
|
-0.08721876380763803,
|
||||||
|
-0.0618916582671649,
|
||||||
|
0.04542046150312216,
|
||||||
|
0.03672973563400257,
|
||||||
|
-0.02845107338464062,
|
||||||
|
-0.02421604439474984,
|
||||||
|
0.01894875110322284,
|
||||||
|
0.01651443896361848,
|
||||||
|
-0.01280782411693687,
|
||||||
|
-0.0112685712903991,
|
||||||
|
0.008563932468880899,
|
||||||
|
0.007533613299748123,
|
||||||
|
-0.005563143845031501,
|
||||||
|
-0.004856570111126346,
|
||||||
|
0.003462567920638419,
|
||||||
|
0.002986877604154259,
|
||||||
|
-0.002055372115328063,
|
||||||
|
-0.001765309502928318,
|
||||||
|
0.001199092367787557,
|
||||||
|
0.001075563790768233,
|
||||||
|
-0.0007833023901802925,
|
||||||
|
-0.0008215855034550383
|
||||||
|
};
|
||||||
|
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2010 Perens LLC <bruce@perens.com>
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
#include "quantise.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* Compile-time constants */
|
||||||
|
/* Size of unsigned char in bits. Assumes 8 bits-per-char. */
|
||||||
|
static const unsigned int WordSize = 8;
|
||||||
|
|
||||||
|
/* Mask to pick the bit component out of bitIndex. */
|
||||||
|
static const unsigned int IndexMask = 0x7;
|
||||||
|
|
||||||
|
/* Used to pick the word component out of bitIndex. */
|
||||||
|
static const unsigned int ShiftRight = 3;
|
||||||
|
|
||||||
|
/** Pack a bit field into a bit string, encoding the field in Gray code.
|
||||||
|
*
|
||||||
|
* The output is an array of unsigned char data. The fields are efficiently
|
||||||
|
* packed into the bit string. The Gray coding is a naive attempt to reduce
|
||||||
|
* the effect of single-bit errors, we expect to do a better job as the
|
||||||
|
* codec develops.
|
||||||
|
*
|
||||||
|
* This code would be simpler if it just set one bit at a time in the string,
|
||||||
|
* but would hit the same cache line more often. I'm not sure the complexity
|
||||||
|
* gains us anything here.
|
||||||
|
*
|
||||||
|
* Although field is currently of int type rather than unsigned for
|
||||||
|
* compatibility with the rest of the code, indices are always expected to
|
||||||
|
* be >= 0.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
pack(
|
||||||
|
unsigned char * bitArray, /* The output bit string. */
|
||||||
|
unsigned int * bitIndex, /* Index into the string in BITS, not bytes.*/
|
||||||
|
int field, /* The bit field to be packed. */
|
||||||
|
unsigned int fieldWidth/* Width of the field in BITS, not bytes. */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
pack_natural_or_gray(bitArray, bitIndex, field, fieldWidth, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
pack_natural_or_gray(
|
||||||
|
unsigned char * bitArray, /* The output bit string. */
|
||||||
|
unsigned int * bitIndex, /* Index into the string in BITS, not bytes.*/
|
||||||
|
int field, /* The bit field to be packed. */
|
||||||
|
unsigned int fieldWidth,/* Width of the field in BITS, not bytes. */
|
||||||
|
unsigned int gray /* non-zero for gray coding */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (gray) {
|
||||||
|
/* Convert the field to Gray code */
|
||||||
|
field = (field >> 1) ^ field;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
unsigned int bI = *bitIndex;
|
||||||
|
unsigned int bitsLeft = WordSize - (bI & IndexMask);
|
||||||
|
unsigned int sliceWidth =
|
||||||
|
bitsLeft < fieldWidth ? bitsLeft : fieldWidth;
|
||||||
|
unsigned int wordIndex = bI >> ShiftRight;
|
||||||
|
|
||||||
|
bitArray[wordIndex] |=
|
||||||
|
((unsigned char)((field >> (fieldWidth - sliceWidth))
|
||||||
|
<< (bitsLeft - sliceWidth)));
|
||||||
|
|
||||||
|
*bitIndex = bI + sliceWidth;
|
||||||
|
fieldWidth -= sliceWidth;
|
||||||
|
} while ( fieldWidth != 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Unpack a field from a bit string, converting from Gray code to binary.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
unpack(
|
||||||
|
const unsigned char * bitArray, /* The input bit string. */
|
||||||
|
unsigned int * bitIndex, /* Index into the string in BITS, not bytes.*/
|
||||||
|
unsigned int fieldWidth/* Width of the field in BITS, not bytes. */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return unpack_natural_or_gray(bitArray, bitIndex, fieldWidth, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Unpack a field from a bit string, to binary, optionally using
|
||||||
|
* natural or Gray code.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
unpack_natural_or_gray(
|
||||||
|
const unsigned char * bitArray, /* The input bit string. */
|
||||||
|
unsigned int * bitIndex, /* Index into the string in BITS, not bytes.*/
|
||||||
|
unsigned int fieldWidth,/* Width of the field in BITS, not bytes. */
|
||||||
|
unsigned int gray /* non-zero for Gray coding */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
unsigned int field = 0;
|
||||||
|
unsigned int t;
|
||||||
|
|
||||||
|
do {
|
||||||
|
unsigned int bI = *bitIndex;
|
||||||
|
unsigned int bitsLeft = WordSize - (bI & IndexMask);
|
||||||
|
unsigned int sliceWidth =
|
||||||
|
bitsLeft < fieldWidth ? bitsLeft : fieldWidth;
|
||||||
|
|
||||||
|
field |= (((bitArray[bI >> ShiftRight] >> (bitsLeft - sliceWidth)) & ((1 << sliceWidth) - 1)) << (fieldWidth - sliceWidth));
|
||||||
|
|
||||||
|
*bitIndex = bI + sliceWidth;
|
||||||
|
fieldWidth -= sliceWidth;
|
||||||
|
} while ( fieldWidth != 0 );
|
||||||
|
|
||||||
|
if (gray) {
|
||||||
|
/* Convert from Gray code to binary. Works for maximum 8-bit fields. */
|
||||||
|
t = field ^ (field >> 8);
|
||||||
|
t ^= (t >> 4);
|
||||||
|
t ^= (t >> 2);
|
||||||
|
t ^= (t >> 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
t = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
@@ -0,0 +1,289 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FILE........: phase.c
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: 1/2/09
|
||||||
|
|
||||||
|
Functions for modelling and synthesising phase.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 2009 David Rowe
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License version 2.1, as
|
||||||
|
published by the Free Software Foundation. This program is
|
||||||
|
distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not,see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
#include "phase.h"
|
||||||
|
#include "kiss_fft.h"
|
||||||
|
#include "comp.h"
|
||||||
|
#include "comp_prim.h"
|
||||||
|
#include "sine.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
sample_phase()
|
||||||
|
|
||||||
|
Samples phase at centre of each harmonic from and array of FFT_ENC
|
||||||
|
DFT samples.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void sample_phase(MODEL *model,
|
||||||
|
COMP H[],
|
||||||
|
COMP A[] /* LPC analysis filter in freq domain */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int m, b;
|
||||||
|
float r;
|
||||||
|
|
||||||
|
r = TWO_PI/(FFT_ENC);
|
||||||
|
|
||||||
|
/* Sample phase at harmonics */
|
||||||
|
|
||||||
|
for(m=1; m<=model->L; m++) {
|
||||||
|
b = (int)(m*model->Wo/r + 0.5);
|
||||||
|
H[m] = cconj(A[b]); /* synth filter 1/A is opposite phase to analysis filter */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
phase_synth_zero_order()
|
||||||
|
|
||||||
|
Synthesises phases based on SNR and a rule based approach. No phase
|
||||||
|
parameters are required apart from the SNR (which can be reduced to a
|
||||||
|
1 bit V/UV decision per frame).
|
||||||
|
|
||||||
|
The phase of each harmonic is modelled as the phase of a synthesis
|
||||||
|
filter excited by an impulse. In many Codec 2 modes the synthesis
|
||||||
|
filter is a LPC filter. Unlike the first order model the position
|
||||||
|
of the impulse is not transmitted, so we create an excitation pulse
|
||||||
|
train using a rule based approach.
|
||||||
|
|
||||||
|
Consider a pulse train with a pulse starting time n=0, with pulses
|
||||||
|
repeated at a rate of Wo, the fundamental frequency. A pulse train
|
||||||
|
in the time domain is equivalent to harmonics in the frequency
|
||||||
|
domain. We can make an excitation pulse train using a sum of
|
||||||
|
sinsusoids:
|
||||||
|
|
||||||
|
for(m=1; m<=L; m++)
|
||||||
|
ex[n] = cos(m*Wo*n)
|
||||||
|
|
||||||
|
Note: the Octave script ../octave/phase.m is an example of this if
|
||||||
|
you would like to try making a pulse train.
|
||||||
|
|
||||||
|
The phase of each excitation harmonic is:
|
||||||
|
|
||||||
|
arg(E[m]) = mWo
|
||||||
|
|
||||||
|
where E[m] are the complex excitation (freq domain) samples,
|
||||||
|
arg(x), just returns the phase of a complex sample x.
|
||||||
|
|
||||||
|
As we don't transmit the pulse position for this model, we need to
|
||||||
|
synthesise it. Now the excitation pulses occur at a rate of Wo.
|
||||||
|
This means the phase of the first harmonic advances by N_SAMP samples
|
||||||
|
over a synthesis frame of N_SAMP samples. For example if Wo is pi/20
|
||||||
|
(200 Hz), then over a 10ms frame (N_SAMP=80 samples), the phase of the
|
||||||
|
first harmonic would advance (pi/20)*80 = 4*pi or two complete
|
||||||
|
cycles.
|
||||||
|
|
||||||
|
We generate the excitation phase of the fundamental (first
|
||||||
|
harmonic):
|
||||||
|
|
||||||
|
arg[E[1]] = Wo*N_SAMP;
|
||||||
|
|
||||||
|
We then relate the phase of the m-th excitation harmonic to the
|
||||||
|
phase of the fundamental as:
|
||||||
|
|
||||||
|
arg(E[m]) = m*arg(E[1])
|
||||||
|
|
||||||
|
This E[m] then gets passed through the LPC synthesis filter to
|
||||||
|
determine the final harmonic phase.
|
||||||
|
|
||||||
|
Comparing to speech synthesised using original phases:
|
||||||
|
|
||||||
|
- Through headphones speech synthesised with this model is not as
|
||||||
|
good. Through a loudspeaker it is very close to original phases.
|
||||||
|
|
||||||
|
- If there are voicing errors, the speech can sound clicky or
|
||||||
|
staticy. If V speech is mistakenly declared UV, this model tends to
|
||||||
|
synthesise impulses or clicks, as there is usually very little shift or
|
||||||
|
dispersion through the LPC synthesis filter.
|
||||||
|
|
||||||
|
- When combined with LPC amplitude modelling there is an additional
|
||||||
|
drop in quality. I am not sure why, theory is interformant energy
|
||||||
|
is raised making any phase errors more obvious.
|
||||||
|
|
||||||
|
NOTES:
|
||||||
|
|
||||||
|
1/ This synthesis model is effectively the same as a simple LPC-10
|
||||||
|
vocoders, and yet sounds much better. Why? Conventional wisdom
|
||||||
|
(AMBE, MELP) says mixed voicing is required for high quality
|
||||||
|
speech.
|
||||||
|
|
||||||
|
2/ I am pretty sure the Lincoln Lab sinusoidal coding guys (like xMBE
|
||||||
|
also from MIT) first described this zero phase model, I need to look
|
||||||
|
up the paper.
|
||||||
|
|
||||||
|
3/ Note that this approach could cause some discontinuities in
|
||||||
|
the phase at the edge of synthesis frames, as no attempt is made
|
||||||
|
to make sure that the phase tracks are continuous (the excitation
|
||||||
|
phases are continuous, but not the final phases after filtering
|
||||||
|
by the LPC spectra). Technically this is a bad thing. However
|
||||||
|
this may actually be a good thing, disturbing the phase tracks a
|
||||||
|
bit. More research needed, e.g. test a synthesis model that adds
|
||||||
|
a small delta-W to make phase tracks line up for voiced
|
||||||
|
harmonics.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void phase_synth_zero_order(
|
||||||
|
int n_samp,
|
||||||
|
MODEL *model,
|
||||||
|
float *ex_phase, /* excitation phase of fundamental */
|
||||||
|
COMP H[] /* L synthesis filter freq domain samples */
|
||||||
|
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int m;
|
||||||
|
float new_phi;
|
||||||
|
COMP Ex[MAX_AMP+1]; /* excitation samples */
|
||||||
|
COMP A_[MAX_AMP+1]; /* synthesised harmonic samples */
|
||||||
|
|
||||||
|
/*
|
||||||
|
Update excitation fundamental phase track, this sets the position
|
||||||
|
of each pitch pulse during voiced speech. After much experiment
|
||||||
|
I found that using just this frame's Wo improved quality for UV
|
||||||
|
sounds compared to interpolating two frames Wo like this:
|
||||||
|
|
||||||
|
ex_phase[0] += (*prev_Wo+model->Wo)*N_SAMP/2;
|
||||||
|
*/
|
||||||
|
|
||||||
|
ex_phase[0] += (model->Wo)*n_samp;
|
||||||
|
ex_phase[0] -= TWO_PI*floorf(ex_phase[0]/TWO_PI + 0.5);
|
||||||
|
|
||||||
|
for(m=1; m<=model->L; m++) {
|
||||||
|
|
||||||
|
/* generate excitation */
|
||||||
|
|
||||||
|
if (model->voiced) {
|
||||||
|
|
||||||
|
Ex[m].real = cosf(ex_phase[0]*m);
|
||||||
|
Ex[m].imag = sinf(ex_phase[0]*m);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
/* When a few samples were tested I found that LPC filter
|
||||||
|
phase is not needed in the unvoiced case, but no harm in
|
||||||
|
keeping it.
|
||||||
|
*/
|
||||||
|
float phi = TWO_PI*(float)codec2_rand()/CODEC2_RAND_MAX;
|
||||||
|
Ex[m].real = cosf(phi);
|
||||||
|
Ex[m].imag = sinf(phi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* filter using LPC filter */
|
||||||
|
|
||||||
|
A_[m].real = H[m].real*Ex[m].real - H[m].imag*Ex[m].imag;
|
||||||
|
A_[m].imag = H[m].imag*Ex[m].real + H[m].real*Ex[m].imag;
|
||||||
|
|
||||||
|
/* modify sinusoidal phase */
|
||||||
|
|
||||||
|
new_phi = atan2f(A_[m].imag, A_[m].real+1E-12);
|
||||||
|
model->phi[m] = new_phi;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|
||||||
|
FUNCTION....: mag_to_phase
|
||||||
|
AUTHOR......: David Rowe
|
||||||
|
DATE CREATED: Jan 2017
|
||||||
|
|
||||||
|
Algorithm for http://www.dsprelated.com/showcode/20.php ported to C. See
|
||||||
|
also Octave function mag_to_phase.m
|
||||||
|
|
||||||
|
Given a magnitude spectrum in dB, returns a minimum-phase phase
|
||||||
|
spectra.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void mag_to_phase(float phase[], /* Nfft/2+1 output phase samples in radians */
|
||||||
|
float Gdbfk[], /* Nfft/2+1 postive freq amplitudes samples in dB */
|
||||||
|
int Nfft,
|
||||||
|
codec2_fft_cfg fft_fwd_cfg,
|
||||||
|
codec2_fft_cfg fft_inv_cfg
|
||||||
|
)
|
||||||
|
{
|
||||||
|
COMP Sdb[Nfft], c[Nfft], cf[Nfft], Cf[Nfft];
|
||||||
|
int Ns = Nfft/2+1;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* install negative frequency components, 1/Nfft takes into
|
||||||
|
account kiss fft lack of scaling on ifft */
|
||||||
|
|
||||||
|
Sdb[0].real = Gdbfk[0];
|
||||||
|
Sdb[0].imag = 0.0;
|
||||||
|
for(i=1; i<Ns; i++) {
|
||||||
|
Sdb[i].real = Sdb[Nfft-i].real = Gdbfk[i];
|
||||||
|
Sdb[i].imag = Sdb[Nfft-i].imag = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* compute real cepstrum from log magnitude spectrum */
|
||||||
|
|
||||||
|
codec2_fft(fft_inv_cfg, Sdb, c);
|
||||||
|
for(i=0; i<Nfft; i++) {
|
||||||
|
c[i].real /= (float)Nfft;
|
||||||
|
c[i].imag /= (float)Nfft;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fold cepstrum to reflect non-min-phase zeros inside unit circle */
|
||||||
|
|
||||||
|
cf[0] = c[0];
|
||||||
|
for(i=1; i<Ns-1; i++) {
|
||||||
|
cf[i] = cadd(c[i],c[Nfft-i]);
|
||||||
|
}
|
||||||
|
cf[Ns-1] = c[Ns-1];
|
||||||
|
for(i=Ns; i<Nfft; i++) {
|
||||||
|
cf[i].real = 0.0;
|
||||||
|
cf[i].imag = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cf = dB_magnitude + j * minimum_phase */
|
||||||
|
|
||||||
|
codec2_fft(fft_fwd_cfg, cf, Cf);
|
||||||
|
|
||||||
|
/* The maths says we are meant to be using log(x), not 20*log10(x),
|
||||||
|
so we need to scale the phase to account for this:
|
||||||
|
log(x) = 20*log10(x)/scale */
|
||||||
|
|
||||||
|
float scale = (20.0/logf(10.0));
|
||||||
|
|
||||||
|
for(i=0; i<Ns; i++) {
|
||||||
|
phase[i] = Cf[i].imag/scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user