Skip to content

Instantly share code, notes, and snippets.

@jorg1piano
jorg1piano / gist:54cd2382815757e4c4f5f0f0eb2ae3c6
Created February 1, 2018 07:35 — forked from mpuz/gist:78e9e875df646698243affe1870dda58
Android, Java: mix 2 PCM audio files
private void mixSound() throws IOException {
AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, 44100, AudioTrack.MODE_STREAM);
InputStream in1=getResources().openRawResource(R.raw.track1);
InputStream in2=getResources().openRawResource(R.raw.track2);
byte[] music1 = null;
music1= new byte[in1.available()];
music1=convertStreamToByteArray(in1);
in1.close();