On second thought, cancel that; since we're not unbinding and rebinding,
there's no point in keeping the data buffers around. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4111 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
package com.threerings.openal;
|
package com.threerings.openal;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import org.lwjgl.openal.AL10;
|
import org.lwjgl.openal.AL10;
|
||||||
@@ -30,7 +28,7 @@ import org.lwjgl.openal.AL10;
|
|||||||
/**
|
/**
|
||||||
* Contains data for a single sampled sound.
|
* Contains data for a single sampled sound.
|
||||||
*/
|
*/
|
||||||
public abstract class Clip
|
public class Clip
|
||||||
{
|
{
|
||||||
/** The OpenAL format of this clip: {@link AL10#AL_FORMAT_MONO8}, etc. */
|
/** The OpenAL format of this clip: {@link AL10#AL_FORMAT_MONO8}, etc. */
|
||||||
public int format;
|
public int format;
|
||||||
@@ -38,9 +36,6 @@ public abstract class Clip
|
|||||||
/** The frequency of this clip in samples per second. */
|
/** The frequency of this clip in samples per second. */
|
||||||
public int frequency;
|
public int frequency;
|
||||||
|
|
||||||
/**
|
/** The audio data. */
|
||||||
* Returns a buffer containing the clip's audio data.
|
public ByteBuffer data;
|
||||||
*/
|
|
||||||
public abstract ByteBuffer getData ()
|
|
||||||
throws IOException;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,15 +194,8 @@ public class ClipBuffer
|
|||||||
*/
|
*/
|
||||||
protected boolean bind (Clip clip)
|
protected boolean bind (Clip clip)
|
||||||
{
|
{
|
||||||
try {
|
AL10.alBufferData(
|
||||||
AL10.alBufferData(
|
_bufferId.get(0), clip.format, clip.data, clip.frequency);
|
||||||
_bufferId.get(0), clip.format, clip.getData(), clip.frequency);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.warning("Error decoding clip [key=" + getKey() +
|
|
||||||
", error=" + e + "].");
|
|
||||||
failed();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int errno = AL10.alGetError();
|
int errno = AL10.alGetError();
|
||||||
if (errno != AL10.AL_NO_ERROR) {
|
if (errno != AL10.AL_NO_ERROR) {
|
||||||
Log.warning("Failed to bind clip [key=" + getKey() +
|
Log.warning("Failed to bind clip [key=" + getKey() +
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
//
|
|
||||||
// $Id$
|
|
||||||
//
|
|
||||||
// Narya library - tools for developing networked games
|
|
||||||
// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved
|
|
||||||
// http://www.threerings.net/code/narya/
|
|
||||||
//
|
|
||||||
// This library is free software; you can redistribute it and/or modify it
|
|
||||||
// under the terms of the GNU Lesser General Public License as published
|
|
||||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public
|
|
||||||
// License along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
package com.threerings.openal;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
import org.lwjgl.openal.AL10;
|
|
||||||
|
|
||||||
import com.samskivert.io.ByteArrayOutInputStream;
|
|
||||||
|
|
||||||
import com.jmex.sound.openAL.objects.util.OggInputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A sound clip backed by Ogg Vorbis data loaded from a file.
|
|
||||||
*/
|
|
||||||
public class OggFileClip extends Clip
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Loads the clip from the given file.
|
|
||||||
*/
|
|
||||||
public OggFileClip (File file)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
// read the file in completely
|
|
||||||
FileInputStream in = new FileInputStream(file);
|
|
||||||
_data = new ByteArrayOutInputStream((int)file.length());
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
int read;
|
|
||||||
while ((read = in.read(buffer)) > 0) {
|
|
||||||
_data.write(buffer, 0, read);
|
|
||||||
}
|
|
||||||
_istream = new OggInputStream(_data.getInputStream());
|
|
||||||
format = (_istream.getFormat() == OggInputStream.FORMAT_MONO16) ?
|
|
||||||
AL10.AL_FORMAT_MONO16 : AL10.AL_FORMAT_STEREO16;
|
|
||||||
frequency = _istream.getRate();
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
public ByteBuffer getData ()
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
// we keep the Ogg stream from initialization, but reset it when we
|
|
||||||
// re-read the data
|
|
||||||
if (_istream == null) {
|
|
||||||
_istream = new OggInputStream(_data.getInputStream());
|
|
||||||
}
|
|
||||||
// decompress the entire stream
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
int read;
|
|
||||||
while ((read = _istream.read(buffer, 0, buffer.length)) > 0) {
|
|
||||||
out.write(buffer, 0, read);
|
|
||||||
}
|
|
||||||
byte[] bytes = out.toByteArray();
|
|
||||||
ByteBuffer data = ByteBuffer.allocateDirect(bytes.length);
|
|
||||||
data.put(bytes);
|
|
||||||
data.rewind();
|
|
||||||
_istream = null;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The entire encoded file. */
|
|
||||||
protected ByteArrayOutInputStream _data;
|
|
||||||
|
|
||||||
/** The Ogg input stream for decoding the data. */
|
|
||||||
protected OggInputStream _istream;
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
//
|
|
||||||
// $Id$
|
|
||||||
//
|
|
||||||
// Narya library - tools for developing networked games
|
|
||||||
// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved
|
|
||||||
// http://www.threerings.net/code/narya/
|
|
||||||
//
|
|
||||||
// This library is free software; you can redistribute it and/or modify it
|
|
||||||
// under the terms of the GNU Lesser General Public License as published
|
|
||||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public
|
|
||||||
// License along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
package com.threerings.openal;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A clip that contains uncompressed wave data.
|
|
||||||
*/
|
|
||||||
public class WaveDataClip extends Clip
|
|
||||||
{
|
|
||||||
/** The audio data. */
|
|
||||||
public ByteBuffer data;
|
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
public ByteBuffer getData ()
|
|
||||||
{
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -23,8 +23,6 @@ package com.threerings.openal;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
import org.lwjgl.util.WaveData;
|
import org.lwjgl.util.WaveData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +33,7 @@ public class WaveDataClipProvider implements ClipProvider
|
|||||||
{
|
{
|
||||||
public Clip loadClip (String path) throws IOException
|
public Clip loadClip (String path) throws IOException
|
||||||
{
|
{
|
||||||
WaveDataClip clip = new WaveDataClip();
|
Clip clip = new Clip();
|
||||||
WaveData file = WaveData.create(path);
|
WaveData file = WaveData.create(path);
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
throw new IOException("Error loading " + path);
|
throw new IOException("Error loading " + path);
|
||||||
|
|||||||
Reference in New Issue
Block a user