Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # binaural_beta.py ZZZ this code needs to be verified
- '''
- 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.
- '''
- from struct import pack
- import math
- import wave
- import random
- import sys
- import array
- dir='C://py//audio//'
- # very basic choice of parameters
- channels = 2
- hertz = 30 # beta pattern
- volume = 100 # percent
- def makeSineWaveFile(freq=100, duration=60, bitrate=44100): # took 10 seconds to process 1 minute in length
- freq = int(freq)
- duration = int(duration)
- bitrate = int(bitrate)
- vol=max(0,volume-1)*0.01*32767
- # channel 1 frequency
- freq1=freq-10
- # channel 2 frequency
- freq2=freq
- # duration: 3600 seconds = 1 hour (60 seconds x 60 minutes)
- # freq = 100 # of cycles per second (Hz) (frequency of the sine waves)
- data = array.array('h') # signed short integer (-32768 to 32767) data
- # bitrate = 44100 # of samples per second (standard)
- numChan = 2 # of channels (1: mono, 2: stereo)
- dataSize = 2 # 2 bytes because of using signed short integers => bit depth = 16
- numSamples = (bitrate * duration)
- for i in range(numSamples):
- for hz in (freq1,freq2):
- bit = int((math.sin((hz*i*1.0)/bitrate*2*math.pi)*vol))
- data.append(bit)
- f = wave.open(dir+'wav_binural_stereo.wav', 'w') # .mp3 or .wav
- f.setparams((numChan, dataSize, bitrate, numSamples, "NONE", "Uncompressed"))
- f.writeframes(data.tostring())
- f.close()
- makeSineWaveFile(hertz)
Add Comment
Please, Sign In to add comment