Package ptolemy.media.javasound

Examples of ptolemy.media.javasound.SoundPlayback


        // size!
        int putSamplesSize = 25;

        // Construct a sound playback object that plays audio
        //through the computer's speaker.
        SoundPlayback soundPlayback = new SoundPlayback(sampleRate,
                sampleSizeInBits, channels, outBufferSize, putSamplesSize);

        // Initialize and begin playback.
        try {
            soundPlayback.startPlayback();
        } catch (Exception ex) {
            System.err.println(ex);
        }

        double[][] samplesArray = new double[channels][putSamplesSize];

        // keep track of time, used in calculating the sine wave values.
        double[] samples = new double[channels];

        try {
            // Loop forever.
            while (true) {
                for (int j = 0; j < channels; j++) {
                    for (int i = 0; i < putSamplesSize; i++) {
                        // Generate a harmonic signal.
                        samplesArray[j][i] = (java.lang.Math.sin(fundamental_Hz
                                * 2 * java.lang.Math.PI * samples[j]) * 0.4)
                                + (java.lang.Math.sin(2 * fundamental_Hz * 2
                                        * java.lang.Math.PI * samples[j]) * 0.3)
                                + (java.lang.Math.sin(3 * fundamental_Hz * 2
                                        * java.lang.Math.PI * samples[j]) * 0.25)
                                + (java.lang.Math.sin(4 * fundamental_Hz * 2
                                        * java.lang.Math.PI * samples[j]) * 0.2);

                        // Increment time.
                        samples[j] = samples[j] + (1.0 / sampleRate);
                    }
                }

                // Play the processed audio samples.
                soundPlayback.putSamples(samplesArray);
            }
        } catch (Exception ex) {
            System.err.println(ex);
        }
    }
View Full Code Here

TOP

Related Classes of ptolemy.media.javasound.SoundPlayback

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.