{"id":17623682,"url":"https://github.com/zachgrayio/binaural-beats","last_synced_at":"2025-04-23T16:42:26.594Z","repository":{"id":90044245,"uuid":"233002333","full_name":"zachgrayio/binaural-beats","owner":"zachgrayio","description":"A binaural beat generation toolkit.","archived":false,"fork":false,"pushed_at":"2020-02-11T20:03:27.000Z","size":52,"stargazers_count":10,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T01:37:01.728Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zachgrayio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-01-10T08:34:56.000Z","updated_at":"2024-11-07T23:30:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"081f8b1f-fa2d-4d0a-a177-93bb5afbcc46","html_url":"https://github.com/zachgrayio/binaural-beats","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachgrayio%2Fbinaural-beats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachgrayio%2Fbinaural-beats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachgrayio%2Fbinaural-beats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachgrayio%2Fbinaural-beats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zachgrayio","download_url":"https://codeload.github.com/zachgrayio/binaural-beats/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250472048,"owners_count":21436071,"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":[],"created_at":"2024-10-22T21:23:29.802Z","updated_at":"2025-04-23T16:42:26.561Z","avatar_url":"https://github.com/zachgrayio.png","language":"Starlark","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Binaural Beats Generator\n\nA binaural beat is an [auditory illusion](https://en.wikipedia.org/wiki/Auditory_illusion)  [perceived](https://en.wikipedia.org/wiki/Perception) when two different pure-tone [sine waves](https://en.wikipedia.org/wiki/Sine_wave), both with [frequencies](https://en.wikipedia.org/wiki/Frequency) lower than 1500 Hz, with less than a 40 Hz difference between them, are presented to a [listener](https://en.wikipedia.org/wiki/Hearing) dichotically (one through each [ear](https://en.wikipedia.org/wiki/Ear)).\n\nThis project defines a number of programs and utilities for generating binaural beats:\n\n- `//engine`: The binaural audio engine: a Scala library which can be consumed by JVM programs\n- `//cli`: A Scala CLI program which can generate binaural audio files based on input arguments\n- `//dubber`: Some various pydub-based audio utility programs, used during the ensembling steps\n- `//dsl`: A declarative DSL (domain-specific-language) implemented in Bazel which can be used to define Bazel targets which will generate binaural beats audio files when invoked with Bazel. \n\n## Binaural DSL\n\nThe binaural DSL (domain-specific-language) is the easiest way to work with this toolkit, as each of the libraries and programs defined within is in service to enabling this easy, expressive DSL.\n\n### Tutorial\n\nThese steps are all that is needed to define advanced, multi-staged binaural beats.\n\nNote: this tutorial assumes you're editing a BUILD file in the root of this repository, and have installed the prerequisites. Examples of consuming these rules in your own WORKSPACE or making use of individual components is coming soon.\n\n#### 1: Load the binaural DSL operations we'd like to make use of:\n\n```starlark\nload(\n    \"//dsl:dsl.bzl\",\n    \"binaural_stems\",\n    \"binaural_sequence\",\n)\n```\n\n#### 2: Generate Binaural Stems\n\nNext, we'll invoke the Scala CLI program to generate some \"binaural stem tracks\".\n\nA \"binaural stem track\" is a 2 channel (stereo) wav file containing a pure sine wave oscillating at some frequency on exactly one of the channels, with the other being blank. On it's own, there's nothing \"binaural\" about this audio file, but the CLI program will output two of these files which when taken together will have a binaural beat playing between them.\n\nThe binaural CLI program is capable of interleaving these for us, but this is something we'll do manually in a later step for greater control and fidelity.\n\n##### Define some shared parameters:\n\n```starlark\nPITCH = 300     # 300 Hz\nDURATION = 60   # 60 seconds\n```\n\n##### Define first Stem:\n\nThis will generate two wav files (left+right) for an alpha wave binaural beat with a baseline pitch of `PITCH`.\n\nBinaural beats in the alpha pattern are at a frequency of 7–13 Hz and may encourage relaxation.\n\n```starlark\nbinaural_stems(\n    name = \"alpha-stems\",\n    pitch = PITCH,\n    binaural_pitch = 10,\n    duration = DURATION,\n)\n```\n\n\n##### Define a second Stem\n \nThis will output two intermediate wav files for a beta binaural beat.\n\nBinaural beats in the beta pattern are at a frequency of 13–30 Hz. This frequency range may help promote concentration and alertness.\n\n```starlark\nbinaural_stems(\n    name = \"beta-stems\",\n    pitch = PITCH,\n    binaural_pitch = 20,\n    duration = DURATION\n)\n```\n\n#### 3: Define Binaural Sequence\n\nNow we'll use these stem tracks as inputs to a Binaural Sequence.\n\nA Binaural Sequence generates a stereo wav file output from an input list of stem tracks. Each \"stem\" consists of two wav files (one for each channel) so these are first combined into a single merged stem track, and then each of these merged intermediate files are concatenated together in the order specified below to produce the final output audio file.\n\nThis creates the final output, `alpha-beta-sequence.wav`, and applies crossfading between stems for a smooth transition, as well as fade-in and fade-out at the beginning and end of the track, respectively:\n\n```starlark\nbinaural_sequence(\n    name = \"alpha-beta-sequence\",\n    stems = [\n        \"//:alpha-stems\",\n        \"//:beta-stems\",\n    ],\n    crossfade = True,\n    fade_in = True,\n    fade_out = True\n)\n```\n\nSee below for information on how to invoke these targets if you're new to Bazel.\n\n### Running:\n\nThe `BUILD` file in the repository root defines some targets which can be built with Bazel to generate binarual beats audio files.\n\n- `bazel build //:alpha-beta-sequence` will invoke a target in the root `BUILD` file which defines a sequence of binaural beats which first play an alpha wave and then a beta wave.\n\n## Scala CLI program\n\nThis program may be useful on it's own to some users - as such, a simple CLI interface is defined and it can be invoked directly if desired.\n\n### Build \u0026 Run from Source:\n\n```bash\nbazel run //cli:app -- alpha\n```\n\n### Usage:\n\n```\nUsage: binaural [delta|theta|alpha|beta|gamma] [options]\n\nCommand: delta\nDelta pattern preset; Binaural beats in the delta pattern operate at a frequency of 0.5–4 Hz with links to a dreamless sleep.\nCommand: theta\nTheta pattern preset; Practitioners set binaural beats in the theta pattern to a frequency of 4–7 Hz. Theta patterns contribute to improved meditation, creativity, and sleep in the rapid eye movement (REM) phase.\nCommand: alpha\nAlpha pattern preset; Binaural beats in the alpha pattern are at a frequency of 7–13 Hz and may encourage relaxation.\nCommand: beta\nBeta pattern preset; Binaural beats in the beta pattern are at a frequency of 13–30 Hz. This frequency range may help promote concentration and alertness. However, it can also increase anxiety at the higher end of the range.\nCommand: gamma\nGamma pattern preset; This frequency pattern accounts for a range of 30–50 Hz. The study authors suggest that frequencies promote maintenance of arousal while a person is awake.\n  -p, --pitch \u003cvalue\u003e           the frequency in Hz - an integer property\n  -b, --binaural_pitch \u003cvalue\u003e  the binaural tone's frequency - a decimal property\n  -d, --duration \u003cvalue\u003e        the duration for which to play the binaural audio - an integer property\n```\n\n## Prerequisites\n\n- bazel, python, jdk, scala\n- ffmpeg (dependency of pydub): `brew install ffmpeg`\n- sox will soon be required if you want to make use of advanced audio effects\n\n\n## More About Binaural Beats:\n\n(via Wikipedia)\n\nA binaural beat is an [auditory illusion](https://en.wikipedia.org/wiki/Auditory_illusion)  [perceived](https://en.wikipedia.org/wiki/Perception) when two different pure-tone [sine waves](https://en.wikipedia.org/wiki/Sine_wave), both with [frequencies](https://en.wikipedia.org/wiki/Frequency) lower than 1500 Hz, with less than a 40 Hz difference between them, are presented to a [listener](https://en.wikipedia.org/wiki/Hearing) dichotically (one through each [ear](https://en.wikipedia.org/wiki/Ear)).\n\nFor example, if a 530 Hz pure [tone](https://en.wikipedia.org/wiki/Pitch_(music)) is presented to a subject's right ear, while a 520 Hz pure tone is presented to the subject's left ear, the listener will perceive the [auditory illusion](https://en.wikipedia.org/wiki/Auditory_illusion) of a third tone, in addition to the two pure-tones presented to each ear. The third sound is called a binaural beat, and in this example would have a perceived pitch correlating to a frequency of 10 Hz, that being the difference between the 530 Hz and 520 Hz pure tones presented to each ear.[[citation needed](https://en.wikipedia.org/wiki/Wikipedia:Citation_needed)]\n\nBinaural-beat perception originates in the [inferior colliculus](https://en.wikipedia.org/wiki/Inferior_colliculus) of the [midbrain](https://en.wikipedia.org/wiki/Midbrain) and the [superior olivary complex](https://en.wikipedia.org/wiki/Superior_olivary_complex) of the [brainstem](https://en.wikipedia.org/wiki/Brainstem), where [auditory signals](https://en.wikipedia.org/wiki/Audio_signal_processing) from each [ear](https://en.wikipedia.org/wiki/Ear) are integrated and precipitate [electrical impulses](https://en.wikipedia.org/wiki/Action_potential) along [neural pathways](https://en.wikipedia.org/wiki/Neural_pathway) through the [reticular formation](https://en.wikipedia.org/wiki/Reticular_formation) up the midbrain to the [thalamus](https://en.wikipedia.org/wiki/Thalamus), [auditory cortex](https://en.wikipedia.org/wiki/Auditory_cortex), and other cortical regions.[[6]](https://en.wikipedia.org/wiki/Beat_(acoustics)#cite_note-oster-6)\n\nSome potential benefits of binaural beats therapy may include: reduced [stress](https://en.wikipedia.org/wiki/Psychological_stress), reduced [anxiety](https://en.wikipedia.org/wiki/Anxiety), increased focus, increased concentration, increased motivation, increased confidence, and deeper [meditation](https://en.wikipedia.org/wiki/Meditation).[[7]](https://en.wikipedia.org/wiki/Beat_(acoustics)#cite_note-MedicalNewsToday-7)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzachgrayio%2Fbinaural-beats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzachgrayio%2Fbinaural-beats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzachgrayio%2Fbinaural-beats/lists"}