throw new IOException("Invalid bytes per second value"); audioData.setupFormat(channels, bitsPerSample, sampleRate);
int bytesPerSecond = (data.getSampleRate() * data.getChannels() * data.getBitsPerSample() / 8);
/** * Get the Type of the underlying AudioData to see if it's streamed or buffered. * This is a shortcut to getAudioData().getType() * <b>Warning</b>: Can return null! * @return The {@link com.jme3.audio.AudioData.DataType} of the audio node. */ public DataType getType() { if (data == null) return null; else return data.getDataType(); }
private int convertFormat(AudioData ad) { switch (ad.getBitsPerSample()) { case 8: if (ad.getChannels() == 1) { return AL_FORMAT_MONO8; } else if (ad.getChannels() == 2) { return AL_FORMAT_STEREO8; } break; case 16: if (ad.getChannels() == 1) { return AL_FORMAT_MONO16; } else { return AL_FORMAT_STEREO16; } } throw new UnsupportedOperationException("Unsupported channels/bits combination: " + "bits=" + ad.getBitsPerSample() + ", channels=" + ad.getChannels()); }
/** * Start playing the audio. */ public void play(){ if (positional && data.getChannels() > 1) { throw new IllegalStateException("Only mono audio is supported for positional audio nodes"); } getRenderer().playSource(this); }
public void playSourceInstance(AudioSource src) { checkDead(); synchronized (threadLock) { if (audioDisabled) { return; } if (src.getAudioData() instanceof AudioStream) { throw new UnsupportedOperationException( "Cannot play instances " + "of audio streams. Use play() instead."); } if (src.getAudioData().isUpdateNeeded()) { updateAudioData(src.getAudioData()); } // create a new index for an audio-channel int index = newChannel(); if (index == -1) { return; } int sourceId = channels[index]; clearChannel(index); // set parameters, like position and max distance setSourceParams(sourceId, src, true); attachAudioToSource(sourceId, src.getAudioData(), false); chanSrcs[index] = src; // play the channel al.alSourcePlay(sourceId); } }
musicLength = musicData.getDuration(); updateTime();
private int convertFormat(AudioData ad) { switch (ad.getBitsPerSample()) { case 8: if (ad.getChannels() == 1) { return AL_FORMAT_MONO8; } else if (ad.getChannels() == 2) { return AL_FORMAT_STEREO8; } break; case 16: if (ad.getChannels() == 1) { return AL_FORMAT_MONO16; } else { return AL_FORMAT_STEREO16; } } throw new UnsupportedOperationException("Unsupported channels/bits combination: " + "bits=" + ad.getBitsPerSample() + ", channels=" + ad.getChannels()); }
/** * Start playing an instance of this audio. This method can be used * to play the same <code>AudioNode</code> multiple times. Note * that changes to the parameters of this AudioNode will not affect the * instances already playing. */ public void playInstance(){ if (positional && data.getChannels() > 1) { throw new IllegalStateException("Only mono audio is supported for positional audio nodes"); } getRenderer().playSourceInstance(this); }
if (data.isUpdateNeeded()) { updateAudioData(data);
int bytesPerSecond = (data.getSampleRate() * data.getChannels() * data.getBitsPerSample() / 8);
throw new IOException("Invalid bytes per second value"); audioData.setupFormat(channels, bitsPerSample, sampleRate);
/** * Start playing an instance of this audio. This method can be used * to play the same <code>AudioNode</code> multiple times. Note * that changes to the parameters of this AudioNode will not affect the * instances already playing. */ public void playInstance(){ if (positional && data.getChannels() > 1) { throw new IllegalStateException("Only mono audio is supported for positional audio nodes"); } getRenderer().playSourceInstance(this); }
public void playSourceInstance(AudioSource src) { checkDead(); synchronized (threadLock) { if (audioDisabled) { return; } if (src.getAudioData() instanceof AudioStream) { throw new UnsupportedOperationException( "Cannot play instances " + "of audio streams. Use play() instead."); } if (src.getAudioData().isUpdateNeeded()) { updateAudioData(src.getAudioData()); } // create a new index for an audio-channel int index = newChannel(); if (index == -1) { return; } int sourceId = channels[index]; clearChannel(index); // set parameters, like position and max distance setSourceParams(sourceId, src, true); attachAudioToSource(sourceId, src.getAudioData(), false); chanSrcs[index] = src; // play the channel al.alSourcePlay(sourceId); } }
/** * Get the Type of the underlying AudioData to see if it's streamed or buffered. * This is a shortcut to getAudioData().getType() * <b>Warning</b>: Can return null! * @return The {@link com.jme3.audio.AudioData.DataType} of the audio node. */ public DataType getType() { if (data == null) return null; else return data.getDataType(); }
throw new IOException("Invalid bytes per second value"); audioData.setupFormat(channels, bitsPerSample, sampleRate);
/** * Start playing the audio. */ public void play(){ if (positional && data.getChannels() > 1) { throw new IllegalStateException("Only mono audio is supported for positional audio nodes"); } getRenderer().playSource(this); }
if (data.isUpdateNeeded()) { updateAudioData(data);
private AudioData load(InputStream inputStream, boolean stream) throws IOException { readStream = stream; if (readStream) { audioStream = new AudioStream(); audioData = audioStream; } else { audioBuffer = new AudioBuffer(); audioData = audioBuffer; } try { MpxReader reader = new MpxReader(); MediaInformation info = reader.readInformation(inputStream, true); Decoder decoder = reader.getDecoder(inputStream, true); // Setup audio audioData.setupFormat((int) info.get(AudioInformation.I_CHANNEL_NUMBER), (int) decoder.get(AudioInformation.I_SAMPLE_SIZE), (int) info.get(AudioInformation.I_SAMPLE_RATE)); // Read the file while (true) { if (readStream) { readDataChunkForStream(inputStream, decoder); } else { readDataChunkForBuffer(decoder); } return audioData; } } catch (Exception ex) { logger.log(Level.SEVERE, "Failed to read a frame!", ex); throw new IOException("Failed to read a frame!"); } }