本文整理汇总了Java中javazoom.jl.decoder.SampleBuffer类的典型用法代码示例。如果您正苦于以下问题:Java SampleBuffer类的具体用法?Java SampleBuffer怎么用?Java SampleBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SampleBuffer类属于javazoom.jl.decoder包,在下文中一共展示了SampleBuffer类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import javazoom.jl.decoder.SampleBuffer; //导入依赖的package包/类
@Override
public void decode(SWFInputStream sis, OutputStream os) throws IOException {
byte[] data = sis.readBytesEx(sis.available(), "soundStream");
inputStream.add(data);
SampleBuffer buf;
while ((buf = readFrame(decoder, bitStream)) != null) {
short[] audio = buf.getBuffer();
byte[] d = new byte[buf.getBufferLength() * 2];
for (int i = 0; i < buf.getBufferLength(); i++) {
int s = audio[i];
d[i * 2] = (byte) (s & 0xff);
d[i * 2 + 1] = (byte) ((s >> 8) & 0xff);
}
os.write(d);
}
}
示例2: decodeFrame
import javazoom.jl.decoder.SampleBuffer; //导入依赖的package包/类
/**
* Decodes a single frame.
*
* @return true if there are no more frames to decode, false otherwise.
*/
protected boolean decodeFrame() throws JavaLayerException
{
try
{
AudioDevice out = audio;
if (out == null) return false;
Header h = bitstream.readFrame();
if (h == null) return false;
// sample buffer set when decoder constructed
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(h, bitstream);
synchronized (this)
{
out = audio;
if(out != null)
{
out.write(output.getBuffer(), 0, output.getBufferLength());
}
}
bitstream.closeFrame();
}
catch (RuntimeException ex)
{
throw new JavaLayerException("Exception decoding audio frame", ex);
}
return true;
}
示例3: decodeFrame
import javazoom.jl.decoder.SampleBuffer; //导入依赖的package包/类
/**
* Decodes a single frame.
*
* @return true if there are no more frames to decode, false otherwise.
*/
protected boolean decodeFrame() throws JavaLayerException {
try {
AudioDevice out = audio;
if (out == null)
return false;
Header h = bitstream.readFrame();
if (h == null)
return false;
// sample buffer set when decoder constructed
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(h, bitstream);
synchronized (this) {
out = audio;
if (out != null) {
out.write(output.getBuffer(), 0, output.getBufferLength());
}
}
bitstream.closeFrame();
} catch (RuntimeException ex) {
throw new JavaLayerException("Exception decoding audio frame", ex);
}
return true;
}
示例4: decodeFrame
import javazoom.jl.decoder.SampleBuffer; //导入依赖的package包/类
/**
* Decodes a single frame.
*
* @return true if there are no more frames to decode, false otherwise.
*/
protected boolean decodeFrame() throws JavaLayerException {
try {
AudioDevice out = audio;
if (out == null) {
return false;
}
Header h = bitstream.readFrame();
if (h == null) {
return false;
}
// sample buffer set when decoder constructed
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(h, bitstream);
synchronized (this) {
out = audio;
if (out != null) {
out.write(output.getBuffer(), 0, output.getBufferLength());
}
}
bitstream.closeFrame();
} catch (RuntimeException ex) {
throw new JavaLayerException("Exception decoding audio frame", ex);
}
return true;
}
示例5: decode
import javazoom.jl.decoder.SampleBuffer; //导入依赖的package包/类
@Override
public void decode(InputStream inputStream) throws Exception {
Decoder decoder = new Decoder();
Bitstream bitstream = new Bitstream(inputStream);
Header header;
isStopRead = false;
isGetMp3InfoFinished = false;
int count = 0;
while (!isStopRead && (header = bitstream.readFrame()) != null) {
isDecoding = true;
long start = System.currentTimeMillis();
SampleBuffer sampleBuffer = (SampleBuffer) decoder.decodeFrame(header, bitstream);
// 获取采样率等
if (!isGetMp3InfoFinished) {
fireOnDecodeInfo(sampleBuffer.getSampleFrequency(), sampleBuffer.getChannelCount());
isGetMp3InfoFinished = true;
}
short[] buffer = sampleBuffer.getBuffer();
byte[] pcm = new byte[buffer.length / 2];
for (int i = 0; i < buffer.length / 2 / 2; i++) {
int j = i * 2;
pcm[j] = (byte) (buffer[i] & 0xff);
pcm[j + 1] = (byte) ((buffer[i] >> 8) & 0xff);
}
if (count == 0 || count == 1) {
byte[] newPcm = avoidNullPcm(pcm);
if (newPcm != null) {
fireOnDecodePcm(newPcm);
}
} else {
fireOnDecodePcm(pcm);
}
count++;
bitstream.closeFrame();
long end = System.currentTimeMillis();
Log.i(TAG, "after decode pcm.length:" + pcm.length + "," + (end - start));
}
isDecoding = false;
fireOnDecodeFinished();
inputStream.close();
}
示例6: decodeFrame
import javazoom.jl.decoder.SampleBuffer; //导入依赖的package包/类
/**
* Decodes a single frame.
*
* @return true if there are no more frames to decode, false otherwise.
*/
protected boolean decodeFrame() throws JavaLayerException
{
try
{
AudioDevice out = audio;
if (out==null)
return false;
Header h = bitstream.readFrame();
if (h==null)
return false;
// sample buffer set when decoder constructed
SampleBuffer output = (SampleBuffer)decoder.decodeFrame(h, bitstream);
synchronized (this)
{
out = audio;
if (out!=null)
{
out.write(output.getBuffer(), 0, output.getBufferLength());
}
}
bitstream.closeFrame();
}
catch (RuntimeException ex)
{
throw new JavaLayerException("Exception decoding audio frame", ex);
}
/*
catch (IOException ex)
{
System.out.println("exception decoding audio frame: "+ex);
return false;
}
catch (BitstreamException bitex)
{
System.out.println("exception decoding audio frame: "+bitex);
return false;
}
catch (DecoderException decex)
{
System.out.println("exception decoding audio frame: "+decex);
return false;
}
*/
return true;
}
示例7: getSamples
import javazoom.jl.decoder.SampleBuffer; //导入依赖的package包/类
public SampleBuffer getSamples() {
return samples;
}
示例8: decodeFrame
import javazoom.jl.decoder.SampleBuffer; //导入依赖的package包/类
/**
* Decodes a single frame.
*
* @return true if there are no more frames to decode, false otherwise.
*/
protected boolean decodeFrame() throws JavaLayerException
{
try
{
AudioDevice out = audio;
if (out == null)
return false;
Header h = bitstream.readFrame();
if (h == null)
return false;
// sample buffer set when decoder constructed
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(h, bitstream);
synchronized (this)
{
out = audio;
if (out != null)
{
out.write(output.getBuffer(), 0, output.getBufferLength());
}
}
bitstream.closeFrame();
} catch (RuntimeException ex)
{
throw new JavaLayerException("Exception decoding audio frame", ex);
}
/*
catch (IOException ex)
{
System.out.println("exception decoding audio frame: "+ex);
return false;
}
catch (BitstreamException bitex)
{
System.out.println("exception decoding audio frame: "+bitex);
return false;
}
catch (DecoderException decex)
{
System.out.println("exception decoding audio frame: "+decex);
return false;
}
*/
return true;
}
示例9: decodeFrame
import javazoom.jl.decoder.SampleBuffer; //导入依赖的package包/类
protected boolean decodeFrame() throws JavaLayerException {
boolean returnValue = false;
if (this.stopped) { // nothing for decode
return false;
}
/*
* Fix NullPointer
*/
if(bitstream == null)
throw new JavaLayerException("Could not open Stream");
try {
if (this.audioDevice != null) {
Header header = this.bitstream.readFrame();
if (header != null) {
// sample buffer set when decoder constructed
SampleBuffer output = (SampleBuffer) this.decoder
.decodeFrame(header, this.bitstream);
synchronized (this) {
if (this.audioDevice != null) {
this.audioDevice.write(output.getBuffer(), 0,
output.getBufferLength());
}
}
this.bitstream.closeFrame();
if (listener != null)
listener.frameDecoded(new PlaybackEvent(this, PlaybackEvent.EventType.FrameDecoded, audioDevice.getPosition()));
returnValue = true;
} else {
System.out.println("End of file"); // end of file
returnValue = false;
}
}
} catch (RuntimeException ex) {
throw new JavaLayerException("Exception decoding audio frame", ex);
}
return returnValue;
}