Hello again,
I've been wondering how to change the speed of a playback. When I googled, is just found other questions and answers on how to adjust the pitch when changing the playback speed. Even though I know that sound appears lower when playing it slower and higher when playing it faster, that's way to much for what I intend. It might be interesting for me later but first I'm trying to figure out how to simply change the speed.
Back in the days of my very first lines of java sound code I already slowed down a playback accidentaly which sounded quite awful. I unfortunately don't remember how I made it but I guess I messes up something with sample rates. That's why I tried the following:
if(AudioSystem.isLineSupported(Port.Info.SPEAKER))
{
soundPort = (Port)AudioSystem.getLine(Port.Info.SPEAKER);
soundPort.open();
volumeKnob = // worked fine with FloatControl.Type.VOLUME
(FloatControl)soundPort.getControl(FloatControl.Type.SAMPLE_RATE);
if(volumeKnob.getMaximum() < fVolume)
fVolume = volumeKnob.getMaximum();
volumeKnob.setValue(fVolume);
}
This results in:
Exception in thread "main" java.lang.IllegalArgumentException: Unsupported control type: Sample Rate
Another approach:
FloatControl fc = (FloatControl)line.getControl(FloatControl.Type.SAMPLE_RATE);
// line is the SourceDataLine object on which the playback is actually put out
Does also result in:
Exception in thread "main" java.lang.IllegalArgumentException: Unsupported control type: Sample Rate
I somehow believe that the second one is the better one but I feel uncertain about both aproaches failing with the same result.
Can someone please tell me if I am totally wrong and maybe give me a hint into the right direction? I would be greatful!
Thanks!