本文整理汇总了Java中javazoom.jl.decoder.Bitstream.readFrame方法的典型用法代码示例。如果您正苦于以下问题:Java Bitstream.readFrame方法的具体用法?Java Bitstream.readFrame怎么用?Java Bitstream.readFrame使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javazoom.jl.decoder.Bitstream
的用法示例。
在下文中一共展示了Bitstream.readFrame方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Music
import javazoom.jl.decoder.Bitstream; //导入方法依赖的package包/类
public Music (OpenALAudio audio, FileHandle file) {
super(audio, file);
if (audio.noDevice) return;
bitstream = new Bitstream(file.read());
decoder = new MP3Decoder();
bufferOverhead = 4096;
try {
Header header = bitstream.readFrame();
if (header == null) throw new GdxRuntimeException("Empty MP3");
int channels = header.mode() == Header.SINGLE_CHANNEL ? 1 : 2;
outputBuffer = new OutputBuffer(channels, false);
decoder.setOutputBuffer(outputBuffer);
setup(channels, header.getSampleRate());
} catch (BitstreamException e) {
throw new GdxRuntimeException("error while preloading mp3", e);
}
}
示例2: Music
import javazoom.jl.decoder.Bitstream; //导入方法依赖的package包/类
public Music(OpenALAudio audio, FileHandle file) {
super(audio, file);
if (audio.noDevice) {
return;
}
bitstream = new Bitstream(file.read());
decoder = new MP3Decoder();
try {
Header header = bitstream.readFrame();
if (header == null) {
throw new GdxRuntimeException("empty ogg");
}
int channels = header.mode() == Header.SINGLE_CHANNEL ? 1 : 2;
outputBuffer = new OutputBuffer(channels, false);
decoder.setOutputBuffer(outputBuffer);
setup(channels, header.getSampleRate());
} catch (BitstreamException e) {
throw new GdxRuntimeException("error while preloading mp3", e);
}
}
示例3: decode
import javazoom.jl.decoder.Bitstream; //导入方法依赖的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();
}
示例4: initialize
import javazoom.jl.decoder.Bitstream; //导入方法依赖的package包/类
@Override
public boolean initialize(URL url)
{
initialized(SET, false);
cleanup();
if(url == null)
{
errorMessage("url null in method 'initialize'");
cleanup();
return false;
}
try
{
bitstream = new Bitstream(new BufferedInputStream(url.openStream()));
decoder = new Decoder();
mainHeader = bitstream.readFrame();
buffer = new DMAISObuffer(2);
decoder.setOutputBuffer(buffer);
int channels;
if(mainHeader.mode() < 3)
channels = 2;
else channels = 1;
bitstream.closeFrame();
bitstream.close();
myAudioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
mainHeader.frequency(), 16, channels, channels * 2, mainHeader.frequency(),
false);
AudioFormat mpegAudioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, -1.0f,
16, channels, channels * 2, -1.0f, false);
myAudioInputStream = new DecodedMpegAudioInputStream(myAudioFormat,
new AudioInputStream(new BufferedInputStream(url.openStream()),
mpegAudioFormat, -1));
} catch (Exception e)
{
errorMessage("Unable to set up input streams in method " + "'initialize'");
printStackTrace(e);
cleanup();
return false;
}
if(myAudioInputStream == null)
{
errorMessage("Unable to set up audio input stream in method " + "'initialize'");
cleanup();
return false;
}
endOfStream(SET, false);
initialized(SET, true);
return true;
}