在Android的反向音频文件 [英] Reverse audio file in Android

查看:215
本文介绍了在Android的反向音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发这个应用程序,但寻找到它的非常EALY阶段,我已经达到了一个问题。我需要能够向后播放音频文件(你知道就好,揭示隐藏的消息;))。我没有经验与音频Android上工作,不知道如果这甚至有可能。

I am in the very ealy stages of developing this app but looking into it I have already reached a problem. I need to be able to play an audio file backwards (you know like to reveal hidden messages ;)). I have no experience working with audio on android and have no idea if this is even possible.

我发现这里的问题解决了问题的Java(点击这里提问

I found a question on here which solves the problem in java (Click Here For Question)

但是,这利用了javax.sound库,Android不支持。我需要这个库来解决这个问题,或者是有另一种方式来扭转音频文件?

But this makes use of the javax.sound library which android does not support. Will I need this library to solve this problem or is there another way to reverse an audio file?

推荐答案

一个典型的WAV文件包含一个44字节的头后面是实际采样值。一帧的大小取决于WAV文件的属性:一个文件,它是立体声和16位每样本将具有4字节的帧大小(两字节用于左样本和两个字节的权利样品)。

A typical WAV file consists of a 44-byte header followed by the actual sample values. The size of a "frame" is dependent upon the WAV file's properties: a file that is stereo and 16-bits-per-sample will have a 4-byte frame size (two bytes for the left sample and two bytes for the right sample).

因此​​,在code,你通过创建一个字节数组相同的整体尺寸与原始创建第二个WAV文件。从原始拷贝44字节报头进副本,然后通过原始帧处开始的最后和工作着的第一迭代。您复制每一帧进副本数组中的倒数位置(也就是最后一个原始帧的标题之后复制到复制数组;第一帧等之后第二次到最后一帧被复制)。随后刚刚上场的反向文件。

So in code, you would create a second WAV file by creating a byte array the same overall size as the original. You copy the 44-byte header from the original into the copy, and then iterate through the original frames starting at the last and working forward to the first. You copy each frame into the inverse location in the copy array (i.e. last original frame is copied into the copy array immediately after the header; second-to-last frame is copied after the first frame etc.). Then just play the reversed file.

所以,你不需要javax.sound库来做到这一点 - 你只需要能够复制和操作字节。仅供参考,并非所有的WAV文件是规范这样的(规范是指44字节的头加样值,而不是其他)。 WAV格式实际上是一个RIFF格式,这意味着在理论上,你需要做的采样值更复杂的提取。在实际应用中(尤其是如果你正在创建的WAV文件自己),你通常可以逃脱,因为我在这里说明一个更简单的方法。

So you don't need the javax.sound library to do this - you just need to be able to copy and manipulate bytes. FYI, not all WAV files are "canonical" like this (canonical means 44-byte header plus sample values, and nothing else). The WAV format is actually a RIFF format, which means in theory you need to do more complex extraction of the sample values. In practice (especially if you're creating the WAV files yourself) you can usually get away with a much simpler approach as I've described here.

请注意:如果你的声音的MP3文件,再倒转是一个比较复杂的任务,因为样本数据不存储在MP3文件的样本。如果你使用的MP3,扭转他们的一种方法是将它们转换为WAV再反向WAV文件。

NOTE: if your sounds are MP3 files, then reversing is a more complicated task, since the sample data are not stored as samples in an MP3 file. If you're using MP3s, one way to reverse them is to convert them to WAV and then reverse the WAV file.

这篇关于在Android的反向音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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