Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

java - Processing sound is slower than the original

My program is essentially this:

import processing.sound.*;

void setup() {
    SoundFile file = new SoundFile(this, "E:/Coding/Tetris/data/Soundtrack.mp3");
    file.loop();
}

void draw() {}

When I execute it, the audio is about 1.08 times slower than the original sound.

Of course I can just add file.rate(1.08); but that's just a workaround and doesn't actually "fix" the problem. How can the slowed down audio be explained?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

"How can the slowed down audio be explained?"

48000 / 44100 = 1.088435374

The change in speed is likely due to the difference in frames per second. Your source sound was probably recorded at 48000 and the playback is running at 44100 fps.

There is a tutorial on Using Files and Format Converters which might be helpful in terms of working with the asset, but I don't know that 48000 is a supported format. Also, whatever library you are using to decode the .mp3 may also pose limitations.

I'd consider using a tool like Audacity to convert the asset to 44100, prior to bringing it into Java as an asset. Or if you are working with a sound designer, let them know you need the assets they deliver to be encoded at 44100 fps.

But if it's easy to play back the asset at 1.08, maybe that is an acceptable path of least resistance?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...