Package ptolemy.media.javasound

Examples of ptolemy.media.javasound.SoundReader


        // Each read this many samples per channel when
        // _soundReader.getSamples() is called.
        // This value was chosen somewhat arbitrarily.
        int getSamplesArraySize = 1;
        _soundReader = new SoundReader(theURL, getSamplesArraySize);

        // Read the number of audio channels and set
        // parameter accordingly.
        //_channels = _soundReader.getChannels();
View Full Code Here


            // _soundReader.getSamples() is called.
            // This value was chosen arbitrarily.
            int getSamplesArraySize = 64;

            try {
                _soundReader = new SoundReader(fileOrURL.asURL(),
                        getSamplesArraySize);
            } catch (IOException ex) {
                String newFileOrURL = ((StringToken) fileOrURL.getToken())
                        .stringValue();
                throw new IllegalActionException(this, ex,
View Full Code Here

        int getSamplesSize = 256;

        try {
            // Construct a SoundReader object that is used to read
            // sound samples from an audio file.
            SoundReader soundReader = new SoundReader(sourceURL, getSamplesSize);

            // The sample rate to playback at, in Hz.
            // Set the playback sample rate to the sample rate of the
            // input sound file.
            float sampleRate = soundReader.getSampleRate();

            if (_debug) {
                System.out.println("Sample rate of the input file is "
                        + sampleRate + " Hz.");
            }

            // Number of bits per sample.
            int bitsPerSample = soundReader.getBitsPerSample();

            if (_debug) {
                System.out.println("Bits per sample for the input file is "
                        + bitsPerSample);
            }

            // 1 for mono, 2 for stereo, etc.
            int channels = soundReader.getChannels();

            if (_debug) {
                System.out.println("Number of channels for the input file is "
                        + channels);
            }

            int putSamplesSize = getSamplesSize;

            // Construct a sound writer object that is used to write
            // audio samples to a sound file.
            SoundWriter soundWriter = new SoundWriter(writeFile, sampleRate,
                    bitsPerSample, channels, putSamplesSize);

            double[][] capturedSamplesArray = new double[channels][getSamplesSize];
            boolean done = false;

            // The main loop.
            while (!done) {
                // Read in some audio samples.
                capturedSamplesArray = soundReader.getSamples();

                if (_debug) {
                    System.out.println("Read some samples...");
                }

                if (capturedSamplesArray == null) {
                    // reached end of file.
                    done = true;
                    System.out.println("Reached end of file.");
                } else {
                    // Do some simple processing on the
                    // captured audio.
                    for (int j = 0; j < channels; j++) {
                        for (int i = 0; i < getSamplesSize; i++) {
                            //  ********** INSERT PROCESSING CODE HERE ****
                            // Perform soft clipping using the arc tangent.
                            capturedSamplesArray[j][i] = java.lang.Math
                                    .atan(capturedSamplesArray[j][i]) * 0.6;
                        }
                    }

                    // Write the processed audio samples.
                    soundWriter.putSamples(capturedSamplesArray);
                }
            }

            // Close the input sound file, because we are done with it.
            soundReader.closeFile();

            // Close the output sound file, because we are done with it.
            soundWriter.closeFile();
        } catch (Exception ex) {
            System.err.println(ex);
View Full Code Here

TOP

Related Classes of ptolemy.media.javasound.SoundReader

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.