user961772
user961772

Reputation: 1

Retrieve audio samples from javax.sound.sampled.Clip

I have an audio clip created by the following. Now I'd like to edit the audio samples in this clip. How do I read and write audio samples from and to this clip?

    AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);
    DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());
    clip = (Clip) AudioSystem.getLine(info);
    clip.open(sound);

Upvotes: 0

Views: 519

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168845

Clip is a convenience class for playing sounds that is not intended for anything more complex (so it will not provide the AudioInputStream for further processing).

It will be necessary to get the audio frames directly from the AudioInputStream before it is passed to the Clip. At that stage, write the altered frames to an AudioOutputStream wrapped in a ByteArrayOutputStream. Then use the BAOS to establish a new, altered, AudioInputStream.

Sound complicated? And that is before even touching on altering the audio bytes. Left as an exercise for the reader. ;)

Upvotes: 1

Related Questions