简体   繁体   English

如何在android中添加echo效果到wav文件?

[英]How to add echo effect to wav file in android?

I have been struggling for a while now on how to modify a wav file by adding echo effect on it; 我一直在努力研究如何通过在其上添加回声效果来修改wav文件; My app does pitch sifting, speed and volume, but I can't add effects. 我的应用程序测量筛选,速度和音量,但我无法添加效果。 I'm a total begginer at audio engineering or something like that. 我是音频工程或类似的人。

My main goal is to find an algorithm and make a function that takes the byte[] samples and modifies it. 我的主要目标是找到一个算法,并创建一个采用byte []样本并修改它的函数。

I'm using this current code right now:



sonic = new Sonic(44100, 1);
            byte samples[] = new byte[4096];
            byte modifiedSamples[] = new byte[2048];
            int bytesRead;

            if (soundFile != null) {
                sonic.setSpeed(params[0]);
                sonic.setVolume(params[1]);
                sonic.setPitch(params[2]);
                do {
                    try {
                        bytesRead = soundFile.read(samples, 0, samples.length);
                    } catch (IOException e) {
                        e.printStackTrace();
                        return null;
                    }

                    if (bytesRead > 0) {
                        sonic.putBytes(samples, bytesRead);
                    } else {
                        sonic.flush();
                    }

                    int available = sonic.availableBytes();

                    if (available > 0) {
                        if (modifiedSamples.length < available) {
                            modifiedSamples = new byte[available * 2];
                        }

                        sonic.receiveBytes(modifiedSamples, available);
                        if (thread.getTrack() != null && thread.getTrack().getState() != AudioTrack.STATE_UNINITIALIZED)

                            thread.WriteTrack(modifiedSamples, available);
                    }

                } while (bytesRead > 0);

As you can see I use sonic ndk to alter the pitch speed and volume by passing another byte[] array there "modifiedSamples" and I need to know if there is a way to modify this "modifiedSamples" to get the echo effect. 正如你所看到的,我使用sonic ndk来改变音高速度和音量,方法是将另一个byte []数组传递给“modifiedSamples”,我需要知道是否有办法修改这个“modifiedSamples”来获得回声效果。 I know this sounds like I'm asking for the function, but I don't. 我知道这听起来像我要求的功能,但我没有。 I just don't know anything about audio processing stuff and I would apreciate a starting point or even if what i'm trying to do is possible with my byte array. 我只是对音频处理的东西一无所知,我会指望一个起点,或者即使我的字节数组可以实现我想做的事情。

Continuing from the comments - here's an implementation that post-processes the wav file to add echo. 继续评论 - 这是一个后处理wav文件以添加echo的实现。

//Clone original Bytes
byte[] temp = bytesTemp.clone();
RandomAccessFile randomAccessFile = new RandomAccessFile(fileRecording, "rw");
//seek to skip 44 bytes
randomAccessFile.seek(44);
//Echo
int N = sampleRate / 8;
for (int n = N + 1; n < bytesTemp.length; n++) {
   bytesTemp[n] = (byte) (temp[n] + .5 * temp[n - N]);
}
randomAccessFile.write(bytesTemp);

The same process will work in real-time as well, with a few changes. 同样的过程也会实时工作,只需进行一些更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM