Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # wav_stereo.py
- from struct import pack
- import math
- import wave
- import random
- import sys
- import array
- dir='C://py//audio//'
- RATE=44100
- def makeSineWaveFile(freq=100, duration=3, sampleRate=44100):
- freq = int(freq)
- duration = int(duration)
- sampleRate = int(sampleRate)
- #duration = 3 # seconds
- #freq = 100 # of cycles per second (Hz) (frequency of the sine waves)
- volume = 100 # percent
- data = array.array('h') # signed short integer (-32768 to 32767) data
- #sampleRate = 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
- numSamplesPerCyc = int(sampleRate / freq)
- numSamples = (sampleRate * duration) / 2
- for i in range(numSamples):
- for hz in (200,500):
- sample = 32767 * float(volume) / hz
- sample *= math.sin(math.pi * 2 * (i % numSamplesPerCyc) / numSamplesPerCyc)
- data.append(int(sample))
- f = wave.open(dir+'wav_stereo.wav', 'w') # .mp3 or .wav
- f.setparams((numChan, dataSize, sampleRate, numSamples, "NONE", "Uncompressed"))
- f.writeframes(data.tostring())
- f.close()
- makeSineWaveFile()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement