Hi everyone,
It seems like BASS version for android is not complete, yet. I think BASSENC plugin can solve my issue but it not provide for android yet. So I do like this:
//for example, mix 2 channel to a channel mchal = BASSmix.BASS_Mixer_StreamCreate(44100, 2, BASS.BASS_SAMPLE_8BITS);
BASS.BASS_StreamFree(bchal);
bchal = BASS.BASS_StreamCreateFile(bfile.getPath(), 0, 0, BASS.BASS_STREAM_DECODE);
BASSmix.BASS_Mixer_StreamAddChannel(mchal, bchal, BASSmix.BASS_MIXER_BUFFER);
BASS.BASS_StreamFree(vchal);
vchal = BASS.BASS_StreamCreateFile(vfile.getPath(), 0, 0, BASS.BASS_STREAM_DECODE);
BASSmix.BASS_Mixer_StreamAddChannel(mchal, vchal, BASSmix.BASS_MIXER_BUFFER);
//play the mixed channel if (mchal != 0) {
boolean success = BASS.BASS_ChannelPlay(mchal, false);
}
//register callback BASS.BASS_ChannelSetDSP(mchal, dspcallback, 0, 2);
//process callback private boolean unlock = true;
BASS.DSPPROC dspcallback = new BASS.DSPPROC() {
public void DSPPROC(int handle, int channel, ByteBuffer buffer, int length, Object user) {
if (unlock) {
// buffer the data
try {
outbuf.put(buffer);
}
catch (BufferOverflowException e) {
// increase buffer size
ByteBuffer temp;
try {
temp = ByteBuffer.allocateDirect(outbuf.position() + length + BUFSTEP);
}
catch (Error e2) {
Log.d("test", "out of memory!");
return;
}
outbuf.limit(outbuf.position());
outbuf.position(0);
temp.put(outbuf);
outbuf = temp;
outbuf.put(buffer);
}
}
}
};
//save to a fileunlock = false;
outbuf.limit(outbuf.position());
// complete the WAVE header
outbuf.putInt(4, outbuf.position() -
;
outbuf.putInt(40, outbuf.position() - 44);
Log.d("test",
outbuf.get(0) + " " + outbuf.get(1) + " " + outbuf.get(67) + " " + outbuf.get(68) + " " + outbuf.get(69) + " " + outbuf.get(70) + " " + outbuf.get(71)
+ " " + outbuf.get(72) + " " + outbuf.get(73) + " " + outbuf.get(74) + " " + outbuf.get(75));
File outfile = new File("/sdcard/mixed.wav");
try {
FileChannel fc = new FileOutputStream(outfile).getChannel();
outbuf.position(0);
// fc.write(writeHeader(length));
fc.write(outbuf);
fc.close();
}
catch (IOException e) {
Log.d("test", "Can't save the file");
}
It can save to file but it's acceptable because 2 things:
1. Only save when playing, save buffers into file until stop playing (DSP signal only receive when playing)
2. The sound when playing the file is not acceptable, too low quality. I'm so sure playing with channels is better than plaing with saved file a lot.