问题标签 [audioinputstream]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
235 浏览

java - Get AudioInputStream of FloatBuffer

I have a callback that gets incoming audio data as FloatBuffer containing 1024 floats that gets called several times per second. But I need an AudioInputStream since my system only works with them.

Converting the floats into 16bit PCM isgned audio data is not a problem, but I cannot create an InputStream out of it. The AudioInputStream constructor only accepts data with known length, but I have a constant stream. The AudioSystem.getAudioInputStream throws an "java.io.IOException: mark/reset not supported" if I feed it with a PipedInputStream containing the audio data.

Any ideas?


Here's my current code:

It uses the JnaJack library, but it doesn't really matter where the data comes from. The conversion to bytes is fine by the way: writing that data directly to a SourceDataLine will work correctly. But I need the data as AudioInputStream.

0 投票
1 回答
176 浏览

java - 当我删除 System.out.println 时,while 循环似乎不起作用

所以这个while循环几乎什么都不做,直到我改变bgmPlaying的值。它工作正常。但是,如果我删除上面写着 //testing 的部分(没有任何换行符),它就不起作用。

这段代码实际上一直在检查音乐是打开还是关闭。

知道为什么当我删除 System.out.println() 部分时它停止工作吗???

这是我的代码:

这段代码在我的 Controller 类中,它调用了 stop 和 play 方法。

0 投票
1 回答
269 浏览

java - 如何将多个文件附加到音频输入流

我有一个音频播放器,我找到了如何将单个文件添加到音频输入流,但我有一个要添加的文件的数组列表。我该怎么做?

0 投票
3 回答
57 浏览

java - 为什么在调用方法时,它说我已经捕获了异常,但我需要捕获它?

我有一个循环一些音频的类:

我可以编译这个方法并且编译器不会报告任何错误(我已经用 print 语句测试过)。PlayGameMusic但是,当我尝试在另一个类中调用上述类()的主要方法时......

...我得到这个编译器错误:

我正在捕获可能的异常,并且PlayGameMusic该类在自己运行时可以正常工作。为什么我不能从另一个班级调用它?

0 投票
2 回答
4314 浏览

java - 使用 Java 增加/减少 AudioInputStream 的音频播放速度

使用 Java 进入复杂的音频世界我正在使用这个库,它基本上是我改进并发布在 Github 上的。

该库的主要类是StreamPlayer,代码有​​注释,易于理解。


问题是它支持许多功能,除了速度增加/减少音频速度。比方说,当您更改视频速度时,就像 YouTube 所做的那样。

我不知道如何实现这样的功能。我的意思是,将音频写入采样率时我该怎么办targetFormat?我每次都必须一次又一次地重新启动音频....


播放音频的代码是:

如果需要,请随意下载并单独查看库。:) 我需要一些帮助...图书馆链接

0 投票
0 回答
405 浏览

java - Clip 可以播放 mp3,但 OpenAL 只提供静音(Java)

当我使用 sound.sampled.Clip 测试 mp3 文件时,它按预期播放。但是,当我使用 OpenAL 对其进行测试时,我没有听到任何声音,也没有例外

(我正在使用 JMF 的 mp3plugin.jar 以及 OpenAL 库)

这是一个很难用简单代码演示的问题,因为使用 openal 需要许多库和一些设置代码,但是我已经尽力了:

这就是我在控制台中得到的全部内容:

如果您想知道为什么我需要使用 OpenAL,OpenAL 提供了 Clip 更敏感的平移和音高操作。我已经能够平移和倾斜我给它的任何 wav 文件,而 Clip 通常也不会这样做(并且在调整平移/增益时有延迟,而 OpenAL 是即时的)。

0 投票
1 回答
304 浏览

java - 带有负数字节的 Java AudioInputStream 跳过总是返回 0

我正在尝试使用AudioInputStream skip(long bytes)method 跳过负数的字节。

问题是试图(假设是少量字节......):

总是返回 0 .... 我不知道该怎么办。


这是github 上库的完整代码。

我所做的是每次用户跳过音频时重新创建线路,这非常慢,而我当然可以做得更好......只需向后或向前。现在它只支持转发...


这个问题的继续在这里... Java AudioInputStream 如何支持负字节数的跳过

0 投票
2 回答
321 浏览

java - Java AudioInputStream如何支持负字节数的跳过

我正在尝试使用AudioInputStream skip(long bytes)method 跳过负数的字节。

问题是试图(假设是少量字节......):

总是返回 0 如本答案所述Java AudioInputStream 跳过负数字节总是返回 0

我需要创建一个支持负字节数或类似向后的实现。


这是github 上库的完整代码。

我所做的是每次用户跳过音频时重新创建线路,这非常慢,而我当然可以做得更好......只需向后或向前。现在它只支持转发...

0 投票
0 回答
745 浏览

java - How does the AudioInputStream.read(byte[] b) function work?

I have a problem with this method. In the following i have written a test code that reads an audio stream into a byte array (and does a convertion [i have mp3plugin.jar as external jar, if you should wonder why this works] and some other stuff, but i have only let that in to make the code executable). The problem is that the method seams not allways to do the same thing. Sometimes the AudioInputStream is getting smaller and sometimes it is not. My question is why?

Ok, so this is the original size of the audio stream. (Until here everything is fine)

Why is my Stream getting smaller? (in the documentation they say it is reading into the array so i kinda understand that part)

Why is my Stream not getting smaller, as it did the first time? (for this is the part i have no clue)

Why is the Stream now getting smaller every eleven times? (here I don't understand the world anymore)

Finally this is the output i get:

Thanks for your help.

John

0 投票
1 回答
60 浏览

java - 从 ipcam 播放音频流的极端延迟

(对不起,不是说英语的人,预计会有很多语法/句法错误)

我正在开发一款软件来管理 D-Link Ip Cam(DCS-xxxx 系列和其他)。因为这台相机暴露了一个音频流(有些型号甚至有一个用于双向通信的扬声器),我想根据用户的要求播放它。

所有入口点都在 http 基本身份验证之后(但奇怪的是我不能使用 http:\USER:PASS@192.168.1.100,因为我得到了 401)。

我使用 javax.sound.* 包来做到这一点,但由于某种原因,音频在15 到 20 秒后开始播放,总延迟为 30-40 秒 编辑:平均 45 秒,但音频是从开始,所以情况更糟。

这是课程(最低限度,仅用于测试目的)

需要 Authenticator 部分,因为 ipcam 使用基本的 http autentication。

我在某处读过,AudioSystem使用不同的算法进行多次传递以获得正确的传递,然后将流重置到开头,然后才开始播放。因此,正因为如此,可能AudioSystem在意识到要使用哪种类型的编解码器(可能需要某种标头)方面存在一些问题,并且在开始播放音频之前花了相当长的时间。

值得知道的是,即使是 VLC 也很难跟上流媒体播放的速度,在播放前最多会损失 8 秒(8 秒比 20 秒好得多)。IpCam 在本地网络上。

我的代码有问题吗?一些我看不到的方法?

真的不知道在哪里看这个。

我无法在这里或其他地方找到任何有意义的答案。