Android:混合多个AudioTrack实例?

我需要同时运行两个AudioTrack实例。 它们必须分开运行,因为我以不同的可变采样播放它们。 我发现,如果我在同一个线程中运行它们,它们“轮stream”。 我在他们自己的线程中运行它们,但audio是口吃。

任何两个实例的想法打好? 如果不是这样的话,即使我想以不同的采样率播放这两个短缓冲区,也不能将两个短缓冲区混合成一个。

Solutions Collecting From Web of "Android:混合多个AudioTrack实例?"

我有4个音轨同时播放,他们似乎玩的很好。 testingHTC Desire 1.1GHz的OC。 有时候我会遇到线程故障。 有时候,如果所有四个人都在玩,当我尝试join这个线程时,一个人不会停下来。 需要做更多的testing。 这里是我的class回放录制的wav文件在给定的path

package com.ron.audio.functions; import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import android.media.AudioFormat; import android.media.AudioManager; import android.media.AudioTrack; public class AudioPlayManager implements Runnable { private File fileName; private volatile boolean playing; public AudioPlayManager() { super(); setPlaying(false); } public void run(){ // Get the length of the audio stored in the file (16 bit so 2 bytes per short) // and create a short array to store the recorded audio. int musicLength = (int)(fileName.length()/2); short[] music = new short[musicLength]; try { // Create a DataInputStream to read the audio data back from the saved file. InputStream is = new FileInputStream(fileName); BufferedInputStream bis = new BufferedInputStream(is); DataInputStream dis = new DataInputStream(bis); // Read the file into the music array. int i = 0; while (dis.available() > 0) { music[i] = dis.readShort(); i++; } // Close the input streams. dis.close(); // Create a new AudioTrack object using the same parameters as the AudioRecord // object used to create the file. AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, musicLength, AudioTrack.MODE_STREAM); // Start playback audioTrack.play(); // Write the music buffer to the AudioTrack object while(playing){ audioTrack.write(music, 0, musicLength); } } catch(Exception e){ e.printStackTrace(); } } public void setFileName(File fileName) { this.fileName = fileName; } public File getFileName() { return fileName; } public void setPlaying(boolean playing) { this.playing = playing; } public boolean isPlaying() { return playing; } 

}