Search in sources :

Example 1 with AudioOut

use of ddf.minim.spi.AudioOut in project Minim by ddf.

the class JSMinim method getAudioSampleImp.

private JSAudioSample getAudioSampleImp(FloatSampleBuffer samples, AudioFormat format, int bufferSize) {
    AudioOut out = getAudioOutput(samples.getChannelCount(), bufferSize, format.getSampleRate(), format.getSampleSizeInBits());
    if (out != null) {
        SampleSignal ssig = new SampleSignal(samples);
        out.setAudioSignal(ssig);
        long length = AudioUtils.frames2Millis(samples.getSampleCount(), format);
        BasicMetaData meta = new BasicMetaData(samples.toString(), length, samples.getSampleCount());
        return new JSAudioSample(meta, ssig, out);
    } else {
        error("Couldn't acquire an output.");
    }
    return null;
}
Also used : AudioOut(ddf.minim.spi.AudioOut)

Example 2 with AudioOut

use of ddf.minim.spi.AudioOut in project Minim by ddf.

the class JSMinim method getAudioSample.

public AudioSample getAudioSample(String filename, int bufferSize) {
    AudioInputStream ais = getAudioInputStream(filename);
    if (ais != null) {
        AudioMetaData meta = null;
        AudioFormat format = ais.getFormat();
        FloatSampleBuffer samples = null;
        if (format instanceof MpegAudioFormat) {
            AudioFormat baseFormat = format;
            format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
            // converts the stream to PCM audio from mp3 audio
            ais = getAudioInputStream(format, ais);
            // get a map of properties so we can find out how long it is
            Map<String, Object> props = getID3Tags(filename);
            // there is a property called mp3.length.bytes, but that is
            // the length in bytes of the mp3 file, which will of course
            // be much shorter than the decoded version. so we use the
            // duration of the file to figure out how many bytes the
            // decoded file will be.
            long dur = ((Long) props.get("duration")).longValue();
            int toRead = (int) AudioUtils.millis2Bytes(dur / 1000, format);
            samples = loadFloatAudio(ais, toRead);
            meta = new MP3MetaData(filename, dur / 1000, props);
        } else {
            samples = loadFloatAudio(ais, (int) ais.getFrameLength() * format.getFrameSize());
            long length = AudioUtils.frames2Millis(samples.getSampleCount(), format);
            meta = new BasicMetaData(filename, length, samples.getSampleCount());
        }
        AudioOut out = getAudioOutput(format.getChannels(), bufferSize, format.getSampleRate(), format.getSampleSizeInBits());
        if (out != null) {
            SampleSignal ssig = new SampleSignal(samples);
            out.setAudioSignal(ssig);
            return new JSAudioSample(meta, ssig, out);
        } else {
            error("Couldn't acquire an output.");
        }
    }
    return null;
}
Also used : AudioMetaData(ddf.minim.AudioMetaData) MpegAudioFormat(javazoom.spi.mpeg.sampled.file.MpegAudioFormat) AudioInputStream(javax.sound.sampled.AudioInputStream) AudioFormat(javax.sound.sampled.AudioFormat) MpegAudioFormat(javazoom.spi.mpeg.sampled.file.MpegAudioFormat) AudioOut(ddf.minim.spi.AudioOut)

Example 3 with AudioOut

use of ddf.minim.spi.AudioOut in project Minim by ddf.

the class Minim method getLineIn.

/**
	 * Gets an {@link AudioInput}.
	 * 
	 * @param type
	 *            Minim.MONO or Minim.STEREO
	 * @param bufferSize
	 *            int: how long you want the <code>AudioInput</code>'s sample buffer
	 *            to be (ie the size of left, right, and mix buffers)
	 * @param sampleRate
	 *            float: the desired sample rate in Hertz (typically 44100)
	 * @param bitDepth
	 *            int: the desired bit depth (typically 16)
	 * @return an <code>AudioInput</code> with the requested attributes
	 */
public AudioInput getLineIn(int type, int bufferSize, float sampleRate, int bitDepth) {
    AudioInput input = null;
    AudioStream stream = mimp.getAudioInput(type, bufferSize, sampleRate, bitDepth);
    if (stream != null) {
        AudioOut out = mimp.getAudioOutput(type, bufferSize, sampleRate, bitDepth);
        // that will pull samples from it and so forth
        if (out == null) {
            out = new BasicAudioOut(stream.getFormat(), bufferSize);
        }
        input = new AudioInput(stream, out);
    }
    if (input != null) {
        addSource(input);
    } else {
        error("Minim.getLineIn: attempt failed, could not secure an AudioInput.");
    }
    return input;
}
Also used : AudioStream(ddf.minim.spi.AudioStream) AudioOut(ddf.minim.spi.AudioOut)

Example 4 with AudioOut

use of ddf.minim.spi.AudioOut in project Minim by ddf.

the class Minim method getLineOut.

/**
	 * Gets an {@link AudioOutput}.
	 * 
	 * @param type
	 *            Minim.MONO or Minim.STEREO
	 * @param bufferSize
	 *            int: how long you want the AudioOutput's sample buffer
	 *            to be (ie the size of the left, right, and mix buffers)
	 * @param sampleRate
	 *            float: the desired sample rate in Hertz (typically 44100)
	 * @param bitDepth
	 *            int: the desired bit depth (typically 16)
	 * @return an <code>AudioOutput</code> with the requested attributes
	 */
public AudioOutput getLineOut(int type, int bufferSize, float sampleRate, int bitDepth) {
    AudioOut out = mimp.getAudioOutput(type, bufferSize, sampleRate, bitDepth);
    if (out != null) {
        AudioOutput output = new AudioOutput(out);
        addSource(output);
        return output;
    }
    error("Minim.getLineOut: attempt failed, could not secure a LineOut.");
    return null;
}
Also used : AudioOut(ddf.minim.spi.AudioOut)

Example 5 with AudioOut

use of ddf.minim.spi.AudioOut in project Minim by ddf.

the class Minim method loadFile.

/**
	 * Loads the requested file into an {@link AudioPlayer} with the request
	 * buffer size.
	 * 
	 * @param filename
	 *            the file or URL you want to load
	 * @param bufferSize
	 *            int: the sample buffer size you want, which determines the 
	 *            size of the left, right, and mix AudioBuffer fields of the 
	 *            returned AudioPlayer.
	 * 
	 * @return an <code>AudioPlayer</code> with a sample buffer of the requested
	 *         size, or null if we were unable to load the file
	 */
public AudioPlayer loadFile(String filename, int bufferSize) {
    AudioPlayer player = null;
    AudioRecordingStream rec = mimp.getAudioRecordingStream(filename, bufferSize, false);
    if (rec != null) {
        AudioFormat format = rec.getFormat();
        AudioOut out = mimp.getAudioOutput(format.getChannels(), bufferSize, format.getSampleRate(), format.getSampleSizeInBits());
        if (out != null) {
            player = new AudioPlayer(rec, out);
        } else {
            rec.close();
        }
    }
    if (player != null) {
        addSource(player);
    } else {
        error("Couldn't load the file " + filename);
    }
    return player;
}
Also used : AudioRecordingStream(ddf.minim.spi.AudioRecordingStream) AudioFormat(javax.sound.sampled.AudioFormat) AudioOut(ddf.minim.spi.AudioOut)

Aggregations

AudioOut (ddf.minim.spi.AudioOut)5 AudioFormat (javax.sound.sampled.AudioFormat)2 AudioMetaData (ddf.minim.AudioMetaData)1 AudioRecordingStream (ddf.minim.spi.AudioRecordingStream)1 AudioStream (ddf.minim.spi.AudioStream)1 AudioInputStream (javax.sound.sampled.AudioInputStream)1 MpegAudioFormat (javazoom.spi.mpeg.sampled.file.MpegAudioFormat)1