Javasound不是通过JAAD打的.m4a文件(一个SPI) [英] Javasound not playing .m4a files through JAAD (an SPI)

查看:192
本文介绍了Javasound不是通过JAAD打的.m4a文件(一个SPI)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一些文件的.m4a,我明白只有 JAAD 支持解码AAC,但也有我能够得到来自SourceDataLine的,然后当我去尝试玩他们,我得到这样的行为歌曲:

I'm trying to play some .m4a files, and I understand that JAAD only supports decoding AAC, but there are songs that I am able to get the sourceDataLine from, and then when I go to try to play them, I get behavior like this:

我们读到:1024字节

We read: 1024 bytes.

我们读到:512字节

我们读到:-1字节

在运行此:

// read from the input
bytesRead = audioInputStream.read(tempBuffer, 0, tempBuffer.length);

System.out.println("We read: " + bytesRead + " bytes.");

直到读取动作== -1

until bytesRead == -1

对于这个特定的文件,我得到的AudioFormat的baseformat是这样的:
MPEG1L1 48000.0赫兹,每次采样,单声道的,未知的帧大小,125.0帧/秒。

For this particular file, I'm getting the AudioFormat baseformat to be this: MPEG1L1 48000.0 Hz, unknown bits per sample, mono, unknown frame size, 125.0 frames/second.

然后AudioFormat的德codedFormat是这样的:
PCM_SIGNED 48000.0赫兹,16位,单声道,2个字节/帧,小尾数

Then the AudioFormat decodedFormat to be this: PCM_SIGNED 48000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian

我使用这些线code的进行转换:

I use these line of code to make the conversion:

AudioFormat baseFormat = audioInputStream.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 
                baseFormat.getSampleRate(),
                16,
                baseFormat.getChannels(),
                baseFormat.getChannels() * 2,
                baseFormat.getSampleRate(),
                false);

我是不是做错了什么吗?我不完全明白,那第二行确实,但它已经使用的 MP3SPI

我想在这里真的AP preciate任何指导。

I'd really appreciate any guidance here.

推荐答案

这是你的文件只显示长度1024 + 512字节的问题? (这将是非常短暂的音频文件!)抑或是关于文件格式的问题?我见过一些人碰到一个问题,当他们尝试去code .wav文件的MP3出现这种情况是与WAV格式的文件,由Java支持的范围是不相容的。

Is the problem that your file is only showing 1024 + 512 bytes in length? (That would be awfully short for an audio file!) Or is the question about File Formats? I've seen some people run into a problem when they try to decode an mp3 of a .wav file that happens to be incompatible with the range of wav file formats supported by Java.

我假设的二线你指的是一个新的FILEFORMAT的创建,是吗?这就是简单地使基于您的InputStream的一个是德$ C $光盘新格式的行为。 presumably,您将使用新的格式在您的播放。

I'm assuming the "second line" you refer to is the creation of a new FileFormat, yes? That is simply the act of making a new Format based upon the one being decoded from your inputstream. Presumably, you will use the new format in your playback.

新格式的点可能是保证将与系统兼容的格式播放的数据。它说:
(1)无论传入编码格式,签名的PCM将被使用。
(2)相同的采样率将被使用(我的系统只支持44100,很惊讶地看到你的允许48000)。
(3)16位将是每样本的比特的新号码,而不管在原原始文件中使用的比特的数量。
(4)相同数量的信道的将被用作原始文件。
(5)* 2将被认为是帧大小信道的数量(是有道理的,每次采样给出16位)
(6)每秒速率相同的帧
(7)字节顺序将是小端,无论输入文件顺序的。

The point of the new format is probably to ensure the data will be played with a format compatible with your system. It says: (1) that no matter the incoming encoding format, Signed PCM will be used. (2) the same sample rate will be used (my system only supports 44100, am surprised to see yours allowing 48000). (3) 16-bits will be the new number of bits per sample, regardless of the number of bits used in the original original file. (4) the same number of channels will be used as the original file. (5) the number of channels * 2 will be deemed to be the frame size (makes sense, given 16 bits per sample) (6) the same frames per second rate (7) the byte order will be little-endian, regardless of the input file order.

您可以看看此构造下的构造函数详细信息在这个环节的API(一些好的文档):的 http://docs.oracle.com/javase/6/docs/api/javax/sound/sampled/AudioFormat.html

You can look into the API of this constructor (some good documentation) under "Constructor Detail" at this link: http://docs.oracle.com/javase/6/docs/api/javax/sound/sampled/AudioFormat.html

如果你需要一些音频数据转换的,为了让播放,然后事情就变得更加复杂。你有没有通过本教程的音频文件和读取放大器;格式转换?
http://docs.oracle.com/javase/tutorial/sound/converters.html

If you need to convert some of the audio data in order to allow playback, then things get more involved. Have you read through this tutorial on audio file & format conversion? http://docs.oracle.com/javase/tutorial/sound/converters.html

我希望这至少是部分的帮助。我没有用JAAD自己,所以,如果这个职位是不是非常有帮助我能理解。

I hope this is at least of partial help. I haven't used JAAD myself, so I can understand if this post isn't very helpful.

这篇关于Javasound不是通过JAAD打的.m4a文件(一个SPI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆