{"id":18823869,"url":"https://github.com/h1romas4/nts1mkii-rust-wave","last_synced_at":"2025-04-14T01:31:00.626Z","repository":{"id":238254766,"uuid":"796183202","full_name":"h1romas4/nts1mkii-rust-wave","owner":"h1romas4","description":"This repository provides custom oscillators written in Rust for the KORG NTS-1 Digital Kit mkII. ","archived":false,"fork":false,"pushed_at":"2024-11-21T12:50:06.000Z","size":891,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T15:47:37.724Z","etag":null,"topics":["esg","korg","louge-sdk","nts-1"],"latest_commit_sha":null,"homepage":"https://another.maple4ever.net/archives/3901/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/h1romas4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-05T07:26:36.000Z","updated_at":"2025-03-22T00:54:54.000Z","dependencies_parsed_at":"2024-05-30T14:11:44.670Z","dependency_job_id":"13531f6c-fb56-45d3-9671-68ad490e39bd","html_url":"https://github.com/h1romas4/nts1mkii-rust-wave","commit_stats":null,"previous_names":["h1romas4/nts1mkii-rust-wave"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h1romas4%2Fnts1mkii-rust-wave","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h1romas4%2Fnts1mkii-rust-wave/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h1romas4%2Fnts1mkii-rust-wave/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h1romas4%2Fnts1mkii-rust-wave/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h1romas4","download_url":"https://codeload.github.com/h1romas4/nts1mkii-rust-wave/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248807398,"owners_count":21164681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esg","korg","louge-sdk","nts-1"],"created_at":"2024-11-08T00:54:54.692Z","updated_at":"2025-04-14T01:31:00.588Z","avatar_url":"https://github.com/h1romas4.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nts1mkii-rust-wave\n\n![](https://github.com/h1romas4/nts1mkii-rust-wave/workflows/Build/badge.svg)\n![](https://github.com/h1romas4/nts1mkii-rust-wave/workflows/Release/badge.svg)\n\n![NTS-1](https://raw.githubusercontent.com/h1romas4/nts1mkii-rust-wave/main/docs/images/nts1mkii-rust-wave-01.jpg)\n\nThis repository provides custom oscillators written in Rust for the KORG NTS-1 Digital Kit mkII.\n\nIt includes a Rust port of Waves provided by [logue-sdk](https://github.com/korginc/logue-sdk), a 32-byte wavetable synth, and source code templates for the instruments.\n\nIf you are interested in creating a sound source for the NTS-1 Digital Kit mkII in Rust, you may find this repository useful.\n\n## Demo\n\n🎥 [Rust build custom oscillator on KORG NTS-1 digital kit mkII](https://www.youtube.com/watch?v=8V_X-8huvJ0)\n\n🎥 [ Rust build table32 custom oscillator on KORG NTS-1 digital kit mkII ](https://www.youtube.com/watch?v=EQm9mchfxXw)\n\n## Release\n\n[Pre-built binaries](https://github.com/h1romas4/nts1mkii-rust-wave/releases/latest)\n\n|Unit name||\n|---|---|\n|osc_waves.nts1mkiiunit| Rust ports louge-sdk Waves |\n|osc_dummy.nts1mkiiunit| osc_sinf for operation check |\n|osc_table32.nts1mkiiunit| 32 byte waveform memory oscillator |\n\n## Build\n\nClone repository:\n\n```bash\ngit clone --recursive https://github.com/h1romas4/nts1mkii-rust-wave\n```\n\nInstall `gcc-arm-none-eabi-10.3` toolchaine:\n\nThis project uses the gcc-ld and thumbv7em sysroot provided by gcc-arm-none-eabi. [Install](https://github.com/korginc/logue-sdk/tree/master/tools/gcc) them according to the OS on which the build will be executed.\n\nLinux:\n\n```bash\ncd nts1mkii-rust-wave/toolchain\nrm -Rf gcc-arm-none-eabi/\nwget https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2\ntar xvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2\nrm gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2\nmv gcc-arm-none-eabi-10.3-2021.10 gcc-arm-none-eabi # rename directory for .cargo/config\ntouch gcc-arm-none-eabi/EMPTY # for git\ncd ..\n```\n\nmacOS:\n\n```bash\ncd nts1mkii-rust-wave/toolchain\nrm -Rf gcc-arm-none-eabi/\nwget https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-mac.tar.bz2\ntar xvf gcc-arm-none-eabi-10.3-2021.10-mac.tar.bz2\nrm gcc-arm-none-eabi-10.3-2021.10-mac.tar.bz2\nmv gcc-arm-none-eabi-10.3-2021.10 gcc-arm-none-eabi # rename directory for .cargo/config\ntouch gcc-arm-none-eabi/EMPTY # for git\ncd ..\n```\n\nWindows 11 pwsh:\n\n```pwsh\ncd nts1mkii-rust-wave/toolchain\ncurl -L https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-win32.zip -o gcc-arm-none-eabi-10.3-2021.10-win32.zip\nExpand-Archive -Path \".\\gcc-arm-none-eabi-10.3-2021.10-win32.zip\"\nCopy-Item -Path \".\\gcc-arm-none-eabi-10.3-2021.10-win32\\gcc-arm-none-eabi-10.3-2021.10\\*\" -Destination \".\\gcc-arm-none-eabi\" -Recurse\nRemove-Item -Path \".\\gcc-arm-none-eabi-10.3-2021.10-win32\" -Recurse -Force\nRemove-Item .\\gcc-arm-none-eabi-10.3-2021.10-win32.zip -Force\ncd ..\n```\n\nBuild NTS-1 digital kit mkII sound unit:\n\n```bash\nrustup target add thumbv7em-none-eabihf\ncargo build --release --target=thumbv7em-none-eabihf\n```\n\nDistribute:\n\n```bash\ncargo xtask dist\n```\n\nTransfer `dist/*.nts1mkiiunit` to NTS-1 digital kit mkII.\n\nSee [GitHub Actions](https://github.com/h1romas4/nts1mkii-rust-wave/blob/main/.github/workflows/build-release.yml\n) for build details.\n\nEnjoy!\n\n## How to add a new sound unit\n\nex. `osc_hello`\n\n```bash\n# add project to workspace\n$ cargo new components/osc_hello\n# copy template\n$ cp -p components/osc_dummy/src/*.rs components/osc_hello/src\n# update template\n$ rm components/osc_hello/src/main.rs\n$ cp -p components/osc_dummy/Cargo.toml components/osc_hello\n$ sed -i 's/name = \"osc_dummy\"/name = \"osc_hello\"/' components/osc_hello/Cargo.toml\n# add to xtask UNIT_NAME xtask/src/build.rs\n$ code -g $(grep -Hn UNIT_NAME: xtask/src/build.rs | cut -d':' -f1,2)\nconst UNIT_NAME: [\u0026str; 4] = [ // increase the number of array elements\n    \"osc_waves\",\n    \"osc_dummy\",\n    \"osc_table32\",\n    \"osc_hello\", // add this line\n];\n```\n\nSound unit Settings:\n\n```bash\n# edit attribute components/osc_hello/src/header.rs\n$ code -g $(grep -Hn dev_id: components/osc_hello/src/header.rs | cut -d':' -f1,2)\n    dev_id: sound_unit_dev_id_string!(b\"H1RO\"),\n    // ID for this unit. Scoped within the context of a given dev_id.\n    unit_id: 0x050401,\n    // Name for this unit, will be displayed on device\n    name: sound_unit_string!(b\"DMMY\", 20),\n```\n\nBuild:\n\n```bash\n$ cargo build --release --target=thumbv7em-none-eabihf\n$ cargo xtask dist\n$ ls -laF dist/osc_hello.nts1mkiiunit\n-rwxrwxr-x 1 hiromasa hiromasa 28208  6月 21 19:18 dist/osc_hello.nts1mkiiunit*\n```\n## License\n\nBSD-3-Clause License\n\n## Dependencies\n\nThanks for all the open source.\n\n|Name|Version|License|Note|\n|-|-|-|-|\n|[logue-sdk](https://github.com/korginc/logue-sdk)|`67ad379`|BSD-3-Clause||\n\n---\n## WIP\n\n- [ ] `osc_waves`\n    - [x] `K_SHAPE`, `K_SUB_MIX` is not working properly. The setpoints are not being evaluated correctly.\n    - [ ] Does not implement `dither` and `bit_res_recip`.\n\n## Build (with libnts1mkii.a and bindgen)\n\nThis repository already contains a pre-build of the louge-sdk library and bindings, so there is essentially no need to do this build.\n\n- `components/logue_bind/dist/libnts1mkii.a`\n- `components/logue_bind/src/bindings_libnts1mkii.rs`\n\nIf you build, please do so under Linux, as cmake is tuned for Linux.\n\nBuild logue-sdk: `components/logue_bind/dist/libnts1mkii.a`\n\n```bash\n# remove inline attribute for libnts1mkii.a\npushd components/logue-sdk\ngit apply ../logue_bind/script/louge-sdk-remove-inline.patch\npopd\n# build\npushd components/logue_bind\nmkdir build \u0026\u0026 cd build\ncmake ..\nmake\ncd ..\nnm dist/libnts1mkii.a | tee dist/libnts1mkii.obj.txt\npopd\n```\n\nBuild Rust with bindgen: `components/logue_bind/src/bindings_libnts1mkii.rs`\n\n```bash\nWITH_LOGUE_SDK_BINDGEN=true cargo build --release --target=thumbv7em-none-eabihf\n```\n\n## A note about linkers\n\nCalling system interface functions in the machine via PLT freezes. ex. `osc_white()`\n\n```rust\n#[no_mangle]\npub extern \"C\" fn unit_note_on(_arg1: u8, _arg2: u8) {\n    // TODO: The problem is that it freezes.\n    // Relocation section '.rel.plt' at offset 0x5cc contains 1 entry:\n    // Offset     Info    Type            Sym.Value  Sym. Name\n    // 00000854  00001316 R_ARM_JUMP_SLOT   00000000   osc_white\n    unsafe { osc_white() };\n}\n```\n\n### Rust \u0026 lld ver\n\nDoes not work.\n\nProbably the PLT code freezes because it moves the pc to the address of the function in the Thumb code it is calling while in Arm mode.\n\n```bash\n$ rustc -V\nrustc 1.77.2 (25ef9e3d8 2024-04-09)\n```\n\n```asm\n000005cc \u003c.rel.plt\u003e:\n 5cc:\t00000854 \tandeq\tr0, r0, r4, asr r8       ; 0x854 Indicates the address of the GOT.\n 5d0:\t00001316 \tandeq\tr1, r0, r6, lsl r3\n\n00000600 \u003c__ThumbV7PILongThunk_osc_white\u003e:\n ;; Thumb mode\n 600:   f240 0c24       movw    ip, #36 ; 0x24\n 604:   f2c0 0c00       movt    ip, #0\n 608:   44fc            add     ip, pc               ; 0x608 + 4 = 0x60c\n ;; to Arm mode\n 60a:   4760            bx      ip                   ; 0x24 + 0x60c = 0x630 --\u003e\n\n00000610 \u003c.plt\u003e:\n ;; snip..\n ;;\n ;; 0x630 \u003c--\n ;; Arm mode\n 630:\te28fc600 \tadd\tip, pc, #0, 12               ; 0x630 + 8 = 0x638\n 634:\te28cca00 \tadd\tip, ip, #0, 20\n ;; Is the pc moving to Thumb code while in Arm mode?\n 638:\te5bcf21c \tldr\tpc, [ip, #540]!\t; 0x21c      ; 0x638 + 540 = 0x854\n 63c:\td4d4d4d4 \tldrble\tsp, [r4], #1236\t; 0x4d4\n\nDisassembly of section .got:\n\n00000848 \u003c.got\u003e:\n\t...\n ;; Perhaps this is where the elf loader writes the function address\n 854:\t00000610 \tandeq\tr0, r0, r0, lsl r6\n```\n\nWould a merge of `config-\u003earmThumbPLTs` fix this?\n\n- [[lld] Support thumb PLTs #86223](https://github.com/llvm/llvm-project/pull/86223)\n\n### Rust \u0026 arm-none-eabi-ld ver\n\nDoes not work.\n\nFor some reason, it becomes out of bounds. Late binaries are overwritten in the next section.\n\n```asm\n000005c0 \u003cosc_white@plt\u003e:\n 5c0:   0000            movs    r0, r0          ; ?\n 5c2:   0000            movs    r0, r0          ; ?\n 5c4:   f240 2c1c       movw    ip, #540        ; 0x21c\n 5c8:   f2c0 0c00       movt    ip, #0\n 5cc:   44fc            add     ip, pc\n 5ce:   Address 0x00000000000005ce is out of bounds.\n```\n\nPassing the `--long-plt` option to linker fixes it, but not sure if it is correct.\n\n```asm\n476c \u003cosc_white@plt\u003e:\n476c:   0000        movs    r0, r0              ; ?\n476e:   0000        movs    r0, r0              ; ?\n4770:   f240 2c40   movw    ip, #576            ; 0x240\n4774:   f2c0 0c00   movt    ip, #0\n4778:   44fc        add\t    ip, pc\n477a:   f8dc f000   ldr.w\tpc, [ip]\n477e:   e7fc        b.n\t477a \u003cosc_white@plt+0xe\u003e\n```\n\nThis repository uses this approach.\n\n### Original louge-sdk gcc \u0026 arm-none-eabi-ld ver\n\nGood work.\n\n```asm\n000011e0 \u003cosc_white@plt\u003e:\n    11e0:\tf240 4c28 \tmovw\tip, #1064\t; 0x428\n    11e4:\tf2c0 0c00 \tmovt\tip, #0\n    11e8:\t44fc      \tadd\tip, pc\n    11ea:\tf8dc f000 \tldr.w\tpc, [ip]\n    11ee:\te7fc      \tb.n\t11ea \u003cosc_white@plt+0xa\u003e\n```\n\n## A note about ELF\n\n- Requre ELF header magic: Note that OS/ABI is UNIX - System V (0x00).\n\n```\nELF Header:\n  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00\n  Class:                             ELF32\n  Data:                              2's complement, little endian\n  Version:                           1 (current)\n  OS/ABI:                            UNIX - System V\n  ABI Version:                       0\n  Type:                              DYN (Shared object file)\n  Machine:                           ARM\n  Version:                           0x1\n  Entry point address:               0x0\n  Start of program headers:          52 (bytes into file)\n  Start of section headers:          17276 (bytes into file)\n  Flags:                             0x0\n  Size of this header:               52 (bytes)\n  Size of program headers:           32 (bytes)\n  Number of program headers:         5\n  Size of section headers:           40 (bytes)\n  Number of section headers:         19\n  Section header string table index: 18\n```\n\n- Section .unit_header: It must be of type `unit_header_t`.\n\n```\nDisassembly of section .unit_header\n\n00003fb0 \u003cunit_header\u003e:\n    3fb0:\t00000198 \tmuleq\tr0, r8, r1\n    3fb4:\t00000504 \tandeq\tr0, r0, r4, lsl #10\n    3fb8:\t00020000 \tandeq\tr0, r2, r0\n    3fbc:\t4831524f \tldmdami\tr1!, {r0, r1, r2, r3, r6, r9, ip, lr}\n    3fc0:\t00050400 \tandeq\tr0, r5, r0, lsl #8\n    3fc4:\t00020000 \tandeq\tr0, r2, r0\n    ...snip...\n```\n\n- Section `.rel.plt` and `.rel.dyn`: Dynamic link must contain only system calls.\n\n```\nRelocation section '.rel.plt' at offset 0x18a0 contains 1 entry:\n Offset     Info    Type            Sym.Value  Sym. Name\n000041e4  00000f16 R_ARM_JUMP_SLOT   00000000   osc_white\n\nRelocation section '.rel.dyn' at offset 0x1810 contains 18 entries:\n Offset     Info    Type            Sym.Value  Sym. Name\n000041e8  00000e15 R_ARM_GLOB_DAT    00000000   bitres_lut_f\n000041ec  00002615 R_ARM_GLOB_DAT    00000000   wavesF\n000041f0  00002715 R_ARM_GLOB_DAT    00000000   wavesC\n000041f4  00003b15 R_ARM_GLOB_DAT    00000000   tanpi_lut_f\n000041f8  00004115 R_ARM_GLOB_DAT    00000000   sqrtm2log_lut_f\n000041fc  00004215 R_ARM_GLOB_DAT    00000000   wt_saw_lut_f\n00004200  00004e15 R_ARM_GLOB_DAT    00000000   schetzen_lut_f\n00004204  00005615 R_ARM_GLOB_DAT    00000000   cubicsat_lut_f\n00004208  00005815 R_ARM_GLOB_DAT    00000000   wavesE\n0000420c  00007715 R_ARM_GLOB_DAT    00000000   wavesA\n00004210  00007c15 R_ARM_GLOB_DAT    00000000   log_lut_f\n00004214  00008315 R_ARM_GLOB_DAT    00000000   wt_sine_lut_f\n00004218  00008f15 R_ARM_GLOB_DAT    00000000   wavesB\n0000421c  00009115 R_ARM_GLOB_DAT    00000000   wavesD\n00004220  00009315 R_ARM_GLOB_DAT    00000000   pow2_lut_f\n00004224  00009c15 R_ARM_GLOB_DAT    00000000   wt_sqr_lut_f\n00004228  00009f15 R_ARM_GLOB_DAT    00000000   midi_to_hz_lut_f\n0000422c  0000a215 R_ARM_GLOB_DAT    00000000   wt_par_lut_f\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh1romas4%2Fnts1mkii-rust-wave","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh1romas4%2Fnts1mkii-rust-wave","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh1romas4%2Fnts1mkii-rust-wave/lists"}