here2share

# binaural_beta.py

Feb 11th, 2021 (edited)
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. # binaural_beta.py ZZZ this code needs to be verified
  2.  
  3. '''
  4. Please Note: Binaural beats in the beta pattern are at a frequency of 13 to 30 Hz. This frequency range may help promote concentration and alertness. However, it can also very much increase anxiety when you are in need of rest.
  5. '''
  6.  
  7. from struct import pack
  8. import math
  9. import wave
  10. import random
  11. import sys
  12. import array
  13.  
  14. dir='C://py//audio//'
  15.  
  16. # very basic choice of parameters
  17. channels = 2
  18.  
  19. hertz = 30 # beta pattern
  20.  
  21. volume = 100 # percent
  22.  
  23. def makeSineWaveFile(freq=100, duration=60, bitrate=44100): # took 10 seconds to process 1 minute in length
  24.     freq = int(freq)
  25.     duration = int(duration)
  26.     bitrate = int(bitrate)
  27.    
  28.     vol=max(0,volume-1)*0.01*32767
  29.     # channel 1 frequency
  30.     freq1=freq-10
  31.     # channel 2 frequency
  32.     freq2=freq
  33.     # duration: 3600 seconds = 1 hour (60 seconds x 60 minutes)
  34.     # freq = 100 # of cycles per second (Hz) (frequency of the sine waves)
  35.     data = array.array('h') # signed short integer (-32768 to 32767) data
  36.     # bitrate = 44100 # of samples per second (standard)
  37.     numChan = 2 # of channels (1: mono, 2: stereo)
  38.     dataSize = 2 # 2 bytes because of using signed short integers => bit depth = 16
  39.     numSamples = (bitrate * duration)
  40.     for i in range(numSamples):
  41.         for hz in (freq1,freq2):
  42.             bit = int((math.sin((hz*i*1.0)/bitrate*2*math.pi)*vol))
  43.             data.append(bit)
  44.     f = wave.open(dir+'wav_binural_stereo.wav', 'w') # .mp3 or .wav
  45.     f.setparams((numChan, dataSize, bitrate, numSamples, "NONE", "Uncompressed"))
  46.     f.writeframes(data.tostring())
  47.     f.close()
  48.  
  49. makeSineWaveFile(hertz)
  50.  
Add Comment
Please, Sign In to add comment