Okay, here's what I am up to now. I am trying to figure out how to write sin waves to a .wav file, for playback. Here's the issue: I have no idea what I'm doing. I looked up the documentation for the wave module, and have been able to open a wav file and write to it. It'll save a .wav file for a number of seconds, playing a frequency. Here's the code for that:
import numpy as N import wave # Here, create all files to playback class SoundFile: def __init__(self, duration=5, frequency=400, samplerate=44100): sr = samplerate samples = duration*samplerate period = samplerate / float(frequency) omega = N.pi * 2 / period xaxis = N.arange(int(period),dtype = N.float) * omega ydata = 16384 * N.sin(xaxis) signal = N.resize(ydata, (samples,)) ssignal = '' for i in range(len(signal)): ssignal += wave.struct.pack('h',signal[i]) filewriteto = frequency self.file = wave.open(str(filewriteto)+'.wav', 'wb') self.file.setparams((1, 2, sr, 44100*4, 'NONE', 'noncompressed')) self.file.writeframes(ssignal) self.file.close() # Test that the soundfile class works S = SoundFile(5, 220)
I have a small gist of what's going on here. Now, I know how sine wavs work, and can add/subtract them. The only issue I have is writing them. No, I don't want a premade module for it. I don't even know if there's anything that exists for it. I've googled multiple times for information, but none have been found by me.
So, I guess what I need help with is just writing sine waves to a .wav file.
Any help would be much appreciated :D