- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
之前我提出了一个关于将 byte[]
转换为 short[]
的问题,我遇到的一个新问题是转换/不转换来自 byte 的数据[]
到 BigEndian。
这是正在发生的事情:
TargetDataLine
将数据读入 byte[10000]
。 AudioFormat
对象将 BigEndian
任意设置为 true。 byte[]
需要转换成 short[]
才能使用 Xuggler 编码 我不知道 AudioFormat
BigEndian 应该设置为 true 还是 false。
我已经尝试了这两种情况,并且在这两种情况下都出现了异常。
要将 byte[]
转换为 short[]
,我这样做:
fromMic.read(tempBufferByte, 0, tempBufferByte.length);
for(int i=0;i<tempBufferShort.length;i++){
tempBufferShort[i] = (short) tempBufferByte[i];
}
地点:fromMic
是 TargetDataLine
tempBufferbyte
是 byte[10000]
tempBufferShort
是 short[10000]
我得到异常:
java.lang.RuntimeException: failed to write packet: com.xuggle.xuggler.IPacket@90098448[complete:true;dts:12;pts:12;size:72;key:true;flags:1;stream index:1;duration:1;position:-1;time base:9/125;]
writer.addAudioStream(0,1,fmt.getChannels(),(int)fmt.getSampleRate());
writer.encodeAudio(1,tempBufferShort,timeStamp,TimeUnit.NANOSECONDS);
...In addition to the encoding, the audio format includes other properties that further specify the exact arrangement of the data. These include the number of channels, sample rate, sample size, byte order, frame rate, and frame size...
和
For 16-bit samples (or any other sample size larger than a byte), byte order is important; the bytes in each sample are arranged in either the "little-endian" or "big-endian" style.
javax.sound.sampled.AudioFormat
对象中将 BigEndian
保持为 true? 最佳答案
如果你的数据确实是big endian,你可以像这样直接将它转换成一个(big endian)短数组:
ByteBuffer buf = ByteBuffer.wrap(originalByteArray);
short[] shortArray = buf.asShortBuffer().array();
生成的 short
数组将直接包含所有原始 byte
数组,并且正确映射,前提是您的数据是大端。所以,一个原始数组,例如:
// bytes
[00], [ae], [00], [7f]
将转换为:
// shorts
[00ae], [007f]
关于java - Xuggler 中的 BigEndian、LittleEndian 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14033778/
默认情况下,BinaryWriter 类写入 int 值,低位在左侧(例如,在十六进制编辑器中查看结果文件时,(int)6 变为 06 00 00 00)。我需要右边的低位(例如 00 00 00 0
我需要通过网络获取一个整数。这是转换为大端字节的正确方法吗? pack("I",socket.htonl(integer_value)) 我将其解压为: socket.ntohl(unpack("I"
有人能告诉我为什么大端/小端会影响音频信号的波形表示吗? 最佳答案 比喻: 如果互联网上的陌生人给你日期“10/11”,那么你不能确定他们是指 11 月 10 日还是 10 月 11 日,所以你需要知
我考虑从库中丢弃处理大端情况的代码,如果平台不是小端,则在初始化期间简单地抛出一个异常。如果我们限制为,我无法想象会有任何大端硬件 托管任何网站的典型服务器硬件 服务器根据开放计算项目规范 所有常见的
这个问题在这里已经有了答案: How do I convert between big-endian and little-endian values in C++? (35 个答案) 关闭 6 年
当我尝试在文件中写入具有如下值的二进制文件时: public static main(String[] args){ ByteBuffer output = ByteBuffer.alloca
我正在处理为 ipv4 编写的遗留代码。现在我已经为 ipv6 添加了类似的代码。我已经在主机上进行了尝试和测试..但我担心它是否会在 powerpc 上工作,因为字节序...代码是从传入流中提取 i
请原谅我用词不当,但我找不到更好的解释方式。 据我了解,C# 是一种 WORA 语言 - 您可以在一台机器上编写它并在另一台机器上部署它,因为 MSIL 直到应用程序实际运行时才会编译。 那么为什么
之前我提出了一个关于将 byte[] 转换为 short[] 的问题,我遇到的一个新问题是转换/不转换来自 byte 的数据[] 到 BigEndian。 这是正在发生的事情: 我正在使用 Targe
我想要一个带有字符串参数的 lua 函数。字符串有 N+2 字节的数据。前两个字节具有 bigendian 格式的长度,其余 N 个字节包含数据。 Say data is "abcd" So the
我想要一个带有字符串参数的 lua 函数。字符串有 N+2 字节的数据。前两个字节具有 bigendian 格式的长度,其余 N 个字节包含数据。 Say data is "abcd" So the
我有: Float(bitPattern: UInt32(bigEndian: data.withUnsafeBytes { $0.pointee } )) 这段代码正在将数据转换为 float ,但
这段代码: import Data.Binary import qualified Data.ByteString.Internal as BS (c2w, w2c) import qualified
我有一个 BigEndian 格式的 QbyteArray 变量我想用最少的过程从该变量中获取一个 float 组。最快的方法是什么? 现在我正在使用以下代码,但效率不高,我认为应该有更好的方法吗?
我正在使用 Kryo 反序列化最初在 Spark 中序列化的类。 Kryo 以 BigEndian 格式编写其所有原语,但是当我尝试在另一台计算机上反序列化这些值时,该值将像 LittleEndian
我有一台在 power-pc-7 bigendian 64 位上运行的 AIX 机器,我知道在 Windows、Linux 和 Mac 上安装 Go 编译器很容易,但如果我们想在 AIX 上安装它,那
我正在尝试将通过蓝牙连接获得的 NSData 类型的 6 字节十六进制转换为适当的整数值。我知道这是 Big Endian 类型,我需要转换为 little Endian。然而,每次我尝试转换它时,我
我是一名优秀的程序员,十分优秀!