Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.nio.ByteBuffer;
- import java.nio.ByteOrder;
- public class SndGen {
- public static void main(String[] args) throws IOException {
- double freqs[]=new double[]{440, 660, 880};
- double amplitudes[]=new double[]{1,1,1};
- double sampleFreq=44000;
- double lengthInSecs=5;
- int nSample=(int)(lengthInSecs*sampleFreq);
- ByteBuffer bb=ByteBuffer.allocate(8);
- bb.order(ByteOrder.LITTLE_ENDIAN);
- byte[] buffer=new byte[8];
- for(int i=0;i<nSample;++i)
- {
- double t=i*1.0/sampleFreq;
- double sample=0;
- for(int j=0;j<freqs.length;++j)
- {
- double omega=freqs[j]*2.0*Math.PI;
- sample+=amplitudes[j]*Math.sin(omega*t);
- }
- bb.clear();
- bb.putDouble(sample);
- bb.flip();
- bb.get(buffer);
- System.out.write(buffer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement