Gunky Funky
  • Blog
  • Projects
  • Writings
    • How and Why I Write
    • Short Quotes
    • Travel Stories >
      • Around the World >
        • Korea
        • Philippines
        • Hong Kong
        • Singapore
        • Retrospective
      • Europe >
        • London Disrupt 2014
        • London 1998 >
          • The Search for Drugs
          • The Ethics of Cities
          • The history of the London Underground
          • A Poem
        • Italy Corsica Amsterdam France
        • Paris in the Spring
      • North America >
        • Yucatan, Mexico
        • Jamiroquai in Mexico
        • Ayahuasca in Costa Rica
        • Fear and Laughter in the Pacific Northwest
        • Burning Flipside >
          • Flipside 2007
          • Flipside 2008
          • Dr Tikis Script
        • Super Bowl XL
      • Morocco 2003
      • Australia 2010
    • Technical Writings >
      • NIME 2013
      • ITT Tech Courses I Taught >
        • Java I
        • Java II
        • Software Application Programming
        • Scripting and Web Authoring
      • Software Development Methodologies
      • Home Wine and Beer Making
    • Book Reviews >
      • The Miracle of Right Thought
      • The Source Field Investigations
      • The God Conspiracy
      • Chinese Health and Healing
    • Show Reviews >
      • Phish
      • Bonnaroo >
        • Bonnaroo I
        • Bonnaroo II
      • Skerik Syncopated Taint
      • Cleveland, Ohio >
        • Galactic 2006 Cleveland
        • Ernie Krivda
        • Medeski Martin and Wood >
          • MMW 2003
          • MMW 8-2005 Cleveland
      • Toast Tour 2009
    • College Musings >
      • Ethics Papers
      • The Story of Cybil and Charlotte
      • Full Circle or Straight Line
  • Music History
  • Infinite Creator

Open Source Binaural Beats

1/28/2017

4 Comments

 
PictureScreenshot from Android Version
My first smartphone apps were these basic tools to allow users to create their own binaural beats. The app was called Binaural, and this past December, I made both the iOS and Android versions free for anyone to download and use. Now, I've decided to take this a step further and make the core of these apps open source! This means that you can go to my github page and download fully working sample apps that generate binaural beats and isochronic pulses. Then, you can use these algorithms in your own apps. If you find any of this useful, I'd appreciate you give me shout, and perhaps I'll feature your app on my Guided Meditation Treks blog!

Here's the source code for iOS.
Here's the source code for Android.

Or you can just download the app and not worry about how it works!

​Generating Binaural Beats With a Computer

Binaural beats are simply two discrete sine waves, each played in different ears. So, all the app needed to do is to generate a sine wave of a specific frequency in one ear, then a separate sine wave of a different frequency in the other. There are many different ways to generate sine waves, depending on our operating system and how you approach the problem, but the underlying idea is still the same. 

All I had to do was:
  1. Generate two sine waves: one for each ear
  2. Allow the user to manage the amplitude of the waves (for volume if needed)
  3. Use a stereo "render" method, so that the left ear and right ear can have a different sine wave
  4. Allow the user to manage the "carrier frequency" and "binaural frequency," then use these values to calculate the frequencies for the left and right sine wave:
    1. ​Left ear sine wave frequency = carrier frequency - (binaural frequency / 2)
    2. Right ear sine wave frequency = carrier frequency + (binaural frequency / 2)​
  5. Since the human ear perceives higher frequencies as louder (for example, an 800hz tone is perceived as twice as loud as a 400hz tone at the same amplitude), I added a compensation to automatically adjust the amplitude when a user changes to frequency, based on the frequency they are changing from and the frequency they are changing to. So, if a user changes from 100hz to 200hz, I cut the amplitude in half, and when going from 200hz to 100hz, i double it.

​Generating Isochronic Tones With A Computer

​Unlike Binaural Beats, isochronic tones are a single mono sine wave. The difference is that this sine wave's amplitude is modulated across time. For example, an isochronic tone at 8hz would turn on and off 8 times per second. Therefore, the render algorithm looks a little bit different, and essentially fades the sine wave in and out very quickly.

What I had to do:
  1. Generate a single mono sine wave, which is played into both ears at the same time
  2. The sine wave's frequency equals the carrier frequency entered by the user
  3. Using 48,000 samples per second, divide that in half, then divide it again by the user-entered "isochronic frequency." For example, if we have an isochronic frequency of 1 hz and 48,000 samples per second, then when we hit sample 0, the sine wav is ON and when we hit 24,000 samples, the sine wave is OFF. If our frequency is 2hz, then at sample 0 it's on, then at 12,000 it's off, then at 24,000, its on again, then at 36,000 its off again.
  4. Due to rounding, I had to tweak it a little bit in case these numbers above didn't match perfectly at the top of each second.
  5. I found that when I abruptly turned the sine wav off or on in the middle of its period, this would cause artifacts that resulted in a "chirping" sound. So, I had to add faders so that the wave was not abruptly turned on and off, thus preventing chirping by smoothly fading in and out during each period.
  6. The same amplitude compensation for tone frequency changes as noted above.

Relevant Methods in iOS

For iOS, I started with some code from Matt Gallager to generate sine waves using Apple's Audio Units. This was my starting point for this app, though, in my later apps like the sleep app, I used a totally different method. Anyway, in Binaural, the  audio unit is generated in the RenderTone static classes of the two viewControllers, and the actual playback of the audio unit takes place in the renderTone() method of each of the respective viewControllers. You'll notice that the algorithms of RenderTone are significantly different between Binaural Beats and Isochronic Tones, based on the explanations above, but the only major difference between the two renderTone() methods is that binaural beats uses two channels per frame, and isoChronic uses only one.

Relevant Methods in Android

For Android, again, I started with some sample code to generate sine waves using android's AudioTrack object. Then, I made the relevant changes listed above. The android project has two relevant classes that contain the construction of these tones: Binaural.java and Isochronic.java Everything regarding the algorithms is nicely modularized in those two classes!

Here's the 
source code for iOS.
Here's the source code for Android.

Or you can just download the app and not worry about how it works!
4 Comments
Charly
3/1/2017 06:50:52 pm

So great, thank you for sharing your work :)

Reply
Dean W link
11/27/2020 11:05:57 pm

Thank you foor this

Reply
Chris H
12/17/2020 09:01:18 pm

Thanks for all this hard work man, appreciate it

Reply
San Pedro Gutter Cleaning link
9/7/2022 11:24:50 pm

Greatt blog you have

Reply



Leave a Reply.

    RSS Feed

    Russ

    Spin the World Around

      Contact Me

    Submit

    Categories

    All
    Ahaucha
    Airbnb
    Alaska
    Alto Sax
    Amazon
    And Fire
    Android
    Aparigraha
    Around The World
    Around The World Travel
    Asana
    Asia
    Asteya
    Astral Projection
    Audiotrip
    Austin
    Austin Silent Disco
    Authority
    Ayahuasca
    Ayahusca
    Baritone Sax
    Best Travel Blog
    Bhagavad Gita
    Bikram Yoga
    Binaural Beats
    Bitches
    Boulder
    Bramacharya
    Budget Travel
    Burning Flipside
    Burning Man
    Cajun
    Caning
    Caribbean
    Celtic Cross
    Central America
    Cheltenham
    Chicken Adobo
    China
    Chinese Food
    Christmas
    Cleansing
    Colorado
    Columbia
    Conspiracy Theory
    Coronavirus
    Corona Virus
    Costa Rica
    Couchsurfing
    Covid-19
    Crazy Dance
    Create Your Reality
    Daejeon
    Dave Brubeck
    Debate
    Denali
    Dharana
    Dhyana
    Dim Sum
    Disco
    Dmt
    Double Sax
    Dr. Tiki
    Earth
    Editing
    Emperador Light
    Empire Of The Sun
    Ethics
    Europe
    Facebook
    False Dichotomy
    Fantasy
    Fela
    Fela Kuti
    Flikr
    Flipside
    Fluoride
    Food Courts
    Forgetting
    Free
    Free Will
    Funky
    Galactic Signature
    Gangnam Style
    Girdwood
    Goenka
    Groceries
    Guided Meditation Treks
    Guru
    Gymnastics
    Hatha Yoga
    Headphone Concert
    HEB
    Higher Self
    Hinduism
    Holiday Lettings
    Honey White
    Hong Kong
    Imgr
    Incline
    Inside Job
    Instagram
    Ios
    Ishvarapranidhana
    Jamiroquai
    Japan
    Java
    Javascript
    Jazzfest
    Job Search
    Jp Sears
    Judgement
    Juice Cleanse
    Jungle
    Kali Uchis
    Karma
    King Crimson
    King Super 20
    King Zephyr
    Kiss And Tell
    Korea
    Kundalini
    Labels
    Lamma Island
    Later
    Latin America
    Law Of One
    London
    Lucid Dreaming
    Manifestation
    Mark Sandman
    Materialism
    Mattress
    Meditation
    Melting Pot
    Memoir
    Memorial Day Weekend
    Mexico
    Michael Jackson
    Middle East
    Mindful Travel
    Mobile Clubbing
    Monterrey
    Montreux Jazz
    Morals
    Morphine
    Mrt
    Music
    Music Is A Meditation
    Music Tutorial
    Nacpan Beach
    Napsan Beach
    Nature Sounds
    Neurolinguistic Programming
    New Age
    New Interfaces For Musical Expression
    Nice Jazz Festival
    Nime
    Niyama
    Octopus Card
    Okcupid
    Old Flavours
    Oppression
    Out Of Body Experience
    Palawan
    Personal Growth
    Peru
    Philippines
    Photographs
    Photojournalism
    Piano Tutorial
    Pintrest
    Pittsburgh
    Platform
    Podcast
    Pranayama
    Pratyahara
    Prince Karma
    Psychedelics
    Puerto Princessa
    Pyropolis
    Quarantine
    Racism
    Reddit
    Reincarnation
    Religion
    Retreat
    Right Thought
    Rigveda
    Samadhi
    Sanskrit
    Santosha
    Satya
    Savasana
    Saxophone
    Saxophonics
    Science
    Seoul
    Sex
    Shaman
    Sheet Music
    Silent Disco
    Singapore
    Singapore Sling
    Singlish
    Skerik
    Sleep
    Smart Phone Development
    Smartphone Travel
    Social Network Platform
    Software Development
    Soju
    South America
    South Korea
    Spin The World Around
    Spirituality
    Startup
    Steelers
    Steemit
    St Lucia Jazz
    Supermarket
    Svadhyaya
    Swift
    Synervoz
    Take Five
    Talk Radio
    Tapas
    Tarot
    Techcrunch
    Telepatia
    Tenor Sax
    Tensorflow
    Texas
    They Live
    Tinder
    Topo Chico
    Travel Blog
    Travel Book
    Travel Guide
    Travel Hacking
    Travel Technology
    Tripadvisor
    Tripping Balls
    Trip Review
    Truth
    Tsa
    Tumblr
    Turkey
    Turnmeup
    Twitter
    Upanishads
    Urban Mattress
    Video Blog
    Vipassana
    Vomiting
    Waterfalls
    Wawa
    White Supremacy
    Whole Foods
    Wind
    Writing
    Xchox
    Yama
    Ymca
    Yoga
    Yogasutra
    Zombie

    Archives

    June 2022
    March 2022
    February 2022
    January 2022
    December 2021
    November 2021
    October 2021
    August 2021
    May 2021
    April 2021
    March 2021
    October 2020
    April 2020
    July 2019
    August 2018
    March 2018
    February 2018
    December 2017
    July 2017
    March 2017
    January 2017
    August 2016
    March 2016
    February 2016
    December 2015
    November 2015
    October 2015
    July 2015
    May 2015
    April 2015
    February 2015
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    July 2014
    June 2014
    May 2014
    April 2014
    March 2014
    February 2014
    January 2014
    December 2013
    October 2013
    August 2013
    July 2013
    June 2013
    May 2013
    April 2013

    Copyright (c) 2015 Russell Eric Dobda
Powered by Create your own unique website with customizable templates.
  • Blog
  • Projects
  • Writings
    • How and Why I Write
    • Short Quotes
    • Travel Stories >
      • Around the World >
        • Korea
        • Philippines
        • Hong Kong
        • Singapore
        • Retrospective
      • Europe >
        • London Disrupt 2014
        • London 1998 >
          • The Search for Drugs
          • The Ethics of Cities
          • The history of the London Underground
          • A Poem
        • Italy Corsica Amsterdam France
        • Paris in the Spring
      • North America >
        • Yucatan, Mexico
        • Jamiroquai in Mexico
        • Ayahuasca in Costa Rica
        • Fear and Laughter in the Pacific Northwest
        • Burning Flipside >
          • Flipside 2007
          • Flipside 2008
          • Dr Tikis Script
        • Super Bowl XL
      • Morocco 2003
      • Australia 2010
    • Technical Writings >
      • NIME 2013
      • ITT Tech Courses I Taught >
        • Java I
        • Java II
        • Software Application Programming
        • Scripting and Web Authoring
      • Software Development Methodologies
      • Home Wine and Beer Making
    • Book Reviews >
      • The Miracle of Right Thought
      • The Source Field Investigations
      • The God Conspiracy
      • Chinese Health and Healing
    • Show Reviews >
      • Phish
      • Bonnaroo >
        • Bonnaroo I
        • Bonnaroo II
      • Skerik Syncopated Taint
      • Cleveland, Ohio >
        • Galactic 2006 Cleveland
        • Ernie Krivda
        • Medeski Martin and Wood >
          • MMW 2003
          • MMW 8-2005 Cleveland
      • Toast Tour 2009
    • College Musings >
      • Ethics Papers
      • The Story of Cybil and Charlotte
      • Full Circle or Straight Line
  • Music History
  • Infinite Creator