1

I am using JLayer sound framework to play wav files with basic functionality (seek,play/pause/stop), I need now to also allow playback speed changes.

  1. Does anyone know if JLayer allows this functionality (I have looked everywhere and I cant find it), and how do I implement it?
  2. If JLayer does not support it how can I implement this?
  3. Can anyone direct me to any source code, documentation or the theoretical aspects behind changing the playback speed?
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
RicardoDuarte
  • 728
  • 7
  • 23
  • 1
    [Time stretching](http://en.wikipedia.org/wiki/Audio_timescale-pitch_modification) is a complex matter that usually requires two separate steps -- the simple step is the mere *resampling* (usually accompanied by a preceding low-pass interpolation *anti-aliasing* filter). You must also take care to preserve pitch, though, and this can be done a number of ways. My question is why you're using JLayer at all... you can probably do this with more ease using [JMF](http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html). – obataku Aug 21 '12 at 23:36
  • A 'quick and dirty' way to double the speed is to access the frames of the audio, then build a new set of frames based on 'every 2nd one' of the original frames. – Andrew Thompson Aug 21 '12 at 23:53
  • ..It is not as common a requirement as you might think. I doubt that JLayer would directly support either the proper method as outlined by @veer, or the Q&D method I outlined. JMF does not offer a method, but probably would give access to the frames. Neither API is necessary for the task. It can be done using Java Sound API, using the Q&D method as seen in [`BigClip`](http://stackoverflow.com/a/5668510/418556). – Andrew Thompson Aug 22 '12 at 00:00
  • 1
    @AndrewThompson JMF `Player` extends `Clock`, which exposes [`setRate`](http://docs.oracle.com/cd/E17802_01/j2se/javase/technologies/desktop/media/jmf/2.1.1/apidocs/javax/media/Clock.html#setRate(float)) :-) I do see your point that you can merely just e.g. select every other frame to attempt to double the speed, but this can cause some issues by distorting the pitch of the audio. – obataku Aug 22 '12 at 00:04
  • @veer Good point, but reviewing the JavaDocs and seeing **"Sets the temporal scale factor. The argument *suggests* the scale factor to use."** (*emphasis* by Sun/Oracle) reminded me vaguely that I tried that method long ago, to no good effect. Note that I cannot remember for sure. Have you seen it work with pure sound files? – Andrew Thompson Aug 22 '12 at 00:09
  • @veer i am using JLayer because as far as I know JMF does not support seek with audio files, and its mp3 support is basic, (I think)! also I am creating wave lines graph, etc. In paulscode.com audio system he seems to use a doppler effect to increase the rate of playback, does anyone knows how could I achieve similar effect? If anyone knows of any books in the matter it would also be great. – RicardoDuarte Aug 22 '12 at 10:01
  • Try reading opsu's implementation of this it might help you https://github.com/fluddokt/opsu/blob/master/src/fluddokt/opsu/fake/Music.java https://github.com/fluddokt/opsu/blob/master/src/fluddokt/opsu/fake/openal/Mp3InputStream.java – harveyhans Jul 17 '20 at 01:47

0 Answers0