{"id":13862904,"url":"https://github.com/NibbleRealm/twang","last_synced_at":"2025-07-14T13:32:52.742Z","repository":{"id":44636496,"uuid":"144396044","full_name":"NibbleRealm/twang","owner":"NibbleRealm","description":"Library for pure Rust advanced audio synthesis.","archived":false,"fork":false,"pushed_at":"2024-06-19T04:23:39.000Z","size":1436,"stargazers_count":131,"open_issues_count":7,"forks_count":8,"subscribers_count":4,"default_branch":"v0","last_synced_at":"2024-11-20T22:16:19.804Z","etag":null,"topics":["audio","audio-processing","audio-programming","audio-synthesis","music","rust-crate","rust-library","sound-synthesis","synthesizer"],"latest_commit_sha":null,"homepage":"https://nibblerealm.com/twang/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NibbleRealm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE_APACHE_2_0.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2018-08-11T15:23:00.000Z","updated_at":"2024-08-11T06:48:36.000Z","dependencies_parsed_at":"2024-05-18T03:32:32.253Z","dependency_job_id":"01838139-65cc-4dff-95cd-f56eba54fc8c","html_url":"https://github.com/NibbleRealm/twang","commit_stats":{"total_commits":94,"total_committers":4,"mean_commits":23.5,"dds":"0.26595744680851063","last_synced_commit":"8c2d45a1e0e522956c5561856e38b6bb356db5ce"},"previous_names":["nibblerealm/twang","aldaronlau/twang"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NibbleRealm%2Ftwang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NibbleRealm%2Ftwang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NibbleRealm%2Ftwang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NibbleRealm%2Ftwang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NibbleRealm","download_url":"https://codeload.github.com/NibbleRealm/twang/tar.gz/refs/heads/v0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225980898,"owners_count":17554919,"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":["audio","audio-processing","audio-programming","audio-synthesis","music","rust-crate","rust-library","sound-synthesis","synthesizer"],"created_at":"2024-08-05T06:01:55.616Z","updated_at":"2025-07-14T13:32:52.728Z","avatar_url":"https://github.com/NibbleRealm.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Twang\n\n**Library for advanced audio synthesis and mixing**\n\n## Goals\n- Fast: Auto-vectorized audio synthesis.\n- Pure Rust: No system dependencies outside std.\n\nLinks to examples for each will be provided as they are implemented.\n- [Additive synthesis](https://github.com/NibbleRealm/twang/blob/v0/examples/piano.rs)\n  (Compositing sounds, usually sine waves - used in analysis / resynthesis along\n  with FFT)\n- Subtractive synthesis (Shaping sawtooth wave, which contains both odd and even\n  frequencies, with filters to boost or reduce frequencies)\n- Frequency Modulation synthesis (Modulating *frequency* with a waveform)\n  - Phase Modulation (PM) synthesis - An implementation of FM used in popular\n    1980s synthesizers\n- Phase Distortion synthesis (Inverted **Frequency Counter** multiplied by sine\n  wave at resonance frequency: A higher frequency counter that starts over /\n  resets at the end of the fundamental frequency)\n- Physical modeling synthesis (Karplus-Strong algorithm, other Digital waveguide\n  synthesis using d'Alembert's algorithm)\n- Sample-Based / Wavetable Lookup synthesis (Whats used in MIDI)\n- Linear arithmetic synthesis (PCM sampled attack + subtractive synthesis\n  sustain)\n- Vector synthesis (Mix of four sounds based on an X-Y plane)\n- Phase Offset Modulation Synthesis (two instances of a periodic waveform kept\n  slightly out of sync with each other, then are either multiplied or\n  subtracted)\n- Arbitrary waveform synthesis (Defined samples occuring at different times in\n  a waveform, called waypoints - either jump or interpolate {video game music})\n\n### Waveforms\nOscillators:\n- [Frequency Counter (Fc / Sawtooth)](https://docs.rs/twang/latest/twang/struct.Fc.html) -\n  odd and even harmonics that decrease at -6 dB/octave\n- [Pulse Wave](https://docs.rs/twang/latest/twang/sig/struct.Signal.html#method.pulse)\n  (When ½ duty cycle set to 1.0 is a Square Wave - odd harmonics that decrease\n  at -6 dB/octave)\n- [Sine Wave](https://docs.rs/twang/latest/twang/sig/struct.Signal.html#method.sine) -\n  no harmonics\n- Triangle Wave - odd harmonics that decrease at -12 dB/octave\n\n\"Voltage\" Controlled filter:\n- Lowpass (Most Common) / Highpass\n- Bandpass / Notch\n\nEnvelope (example: ADSR):\n- Press: Attack (time, oscillator:Fc), Hold?, Decay (time, oscillator:Fc.inv), …\n- Hold: Sustain (oscillator:Pulse(1.0).Gain(level))\n- Release: Release (time, oscillator:Fc.inv)\n\n\"Voltage\" Controlled amplifier (multiplication)\n\n## Effects\n### Gated Reverb\nReverb without reflections.\n\n[Gated Reverb](https://github.com/NibbleRealm/twang/blob/v0/examples/gate.rs)\n\n### Reverb And Echo\nReverb is just echo that takes place in less than 50 milliseconds, so you can\nuse the same APIs.\n\n## Decibel Normalization\nWhen generating waveforms you may want to normalize by the volume of the wave,\nwhich the amplitude doesn't always accurately approximate.  First, calculate the\nRMS (Root Mean Square).\n```\nlet sum = 0\nfor sample in samples {\n    sum += sample * sample\n}\nsum /= samples.len()\nlet rms = sum.sqrt()\n```\n\nNow the peak value:\n```\nlet mut peak_amplitude = 0\nfor sample in samples {\n    peak_amplitude = peak_amplitude.max(sample.abs())\n}\n```\n\nNext the crest factor:\n```\nlet crest_factor = peak_amplitude / rms\n```\n\nThen decibels:\n\n```\nlet papr = 20 * log10(crest_factor)\n```\n\nCrest Factor Post-processed Recording 4–8 / 12–18 dB headroom\nCrest Factor Unprocessed Recording 8–10 / 18–20 dB headroom\n\nAnd actual perceived volume should be calculated with\n[ITU-R BS.1770-4](https://www.itu.int/dms_pubrec/itu-r/rec/bs/R-REC-BS.1770-4-201510-I!!PDF-E.pdf)\n\n## Getting Started\nExamples can be found in the [Documentation](https://docs.rs/twang) and the\nexamples folder.\n\n## MSRV\nThe minimum supported Rust version of twang is 1.85.0.  MSRV may only be updated\nwhen increasing the leftmost version number of twang.\n\n## License\nCopyright © 2018-2025 The Twang Contributors.\n\nLicensed under either of\n - Apache License, Version 2.0\n   ([LICENSE_APACHE_2_0.txt](https://github.com/NibbleRealm/twang/blob/v0/LICENSE_APACHE_2_0.txt) or\n   [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0))\n - Boost License, Version 1.0\n   ([LICENSE_BOOST_1_0.txt](https://github.com/NibbleRealm/twang/blob/v0/LICENSE_BOOST_1_0.txt) or\n   [https://www.boost.org/LICENSE_1_0.txt](https://www.boost.org/LICENSE_1_0.txt))\n - MIT License, ([LICENSE_MIT.txt](https://github.com/NibbleRealm/twang/blob/v0/LICENSE_MIT.txt) or\n   [https://mit-license.org/](https://mit-license.org/))\n\nat your option.\n\n### Contribution\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n\nAnyone is more than welcome to contribute!  Don't be shy about getting involved,\nwhether with a question, idea, bug report, bug fix, feature request, feature\nimplementation, or other enhancement.  Other projects have strict contributing\nguidelines, but this project accepts any and all formats for pull requests and\nissues.  For ongoing code contributions, if you wish to ensure your code is\nused, open a draft PR so that I know not to write the same code.  If a feature\nneeds to be bumped in importance, I may merge an unfinished draft PR into it's\nown branch and finish it (after a week's deadline for the person who openned\nit).  Contributors will always be notified in this situation, and given a choice\nto merge early.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNibbleRealm%2Ftwang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNibbleRealm%2Ftwang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNibbleRealm%2Ftwang/lists"}