Buffer Management and Threads

Hi,

I'm trying to program an audio editor for wav files. At the moment I am struggling to handle playing the large files. I want to implement some sort of buffer management, possibly LRU.

As one buffer is playing, I need another buffer to read in the next block of the sound file and get ready to play it. I then need the blocks to play seamlessly I.e. no gap in sound output when the SourceDataLine is changing from one buffer to another.

Eventually I need a set number of fixed size buffers to play without the user being able to hear the transitions.

Does anybody have any ideas about where to start?

Any help would be greatly appreciated, I'm really stuck!

Jimbo

[713 byte] By [Jimboba] at [2007-10-3 11:32:04]
# 1
What API are you using?
kajbja at 2007-7-15 13:58:51 > top of Java-index,Java Essentials,Java Programming...
# 2
I don't really understand. I do this using a BufferedInputStream for MP3, OGG and WAV files without any 'gaps' .
sabre150a at 2007-7-15 13:58:51 > top of Java-index,Java Essentials,Java Programming...
# 3

I don't mean I'm experiencing any gaps in playback, i mean I need to code a system that manages a certain number of buffers, and manages to play transitions between buffers seamlessy - i.e. without noticing.

The following is my code for the Thread that writes the data to the SourceDataLine.

class PlayThread extends Thread {

int bufLen = frameSize*bufferFrames/2;

byte[] aBuffer = new byte[bufLen];

public void run() {

int counter;

playButton.setEnabled(false);

try {

sDL.open(format);

sDL.start();

while((counter = theStream.read(

aBuffer,0,aBuffer.length)) != -1 && currentlyPlaying == false){

if(counter > 0){

CurrentTime = currentFrame / frameRate;

System.out.println("Timer : "+currentTime+" "+counter+" Bytes");

sDL.write(aBuffer, 0, counter);

currentFrame = currentFrame + framesReadSoFar;

}

}

sDL.drain();

sDL.close();

playButton.setEnabled(true);

} catch (Exception e) {

System.out.println(e);

}

}

}

Jimboba at 2007-7-15 13:58:51 > top of Java-index,Java Essentials,Java Programming...