Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (784)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (858)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [AudioCue] setSpeed(handle, value) not working  (Read 1642 times)
0 Members and 1 Guest are viewing this topic.
Offline slemmuh

Junior Newbie





« Posted 2019-01-08 18:23:09 »

I have this very rough draft of a class to manage an AudioCue instance. The "setSpeed" method is called in another method every game frame and the values are managed in said method, too.

Here's the code for the class

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
package ...
import ...

public class Player {

    private URL url;
    private AudioCue cue;
    private int handle;

    public Player(String audioPath) throws MalformedURLException, IOException, UnsupportedAudioFileException {
        this.url = new URL(audioPath);
        cue = AudioCue.makeStereoCue(url, 1);
    }

    public void start() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
        AudioInputStream ais = AudioSystem.getAudioInputStream(url);
        int frameLength = (int) ais.getFrameLength();
        cue.open(frameLength);
        handle = cue.play();
    }

    public void setSpeed(float speed) {
        System.out.println("Previous speed: " + cue.getSpeed(handle));
        System.out.println("Changing speed: " + speed);
        cue.setSpeed(handle, speed);
    }

    public void setVolume(float volume) {
        cue.setVolume(handle, volume);
    }

    public boolean getIsActive() {
        return cue.getIsActive(handle);
    }

    public void stop() {
        cue.stop(handle);
        cue.close();
    }
}


But when I call setSpeed() the speed of the AudioCue instance never changes.



I'm fairly sure I'm doing something wrong but I don't really know where the error could be. Any help would be great. Thanks in advance.
Offline philfrei
« Reply #1 - Posted 2019-01-08 22:15:57 »

On the face of it, your code looks fine to me.

It's curious that the speed is .128...
The lowest possible speed value is .125 (three octaves below the recording pitch).
Yet, you are trying to play the cue at 0.85 which is close to the natural pitch.

Are you hearing the cue at a low, fixed pitch?

I am trying to imagine possible causes:

> It seems clear that you are reading from and writing to the same cue instance. Sometimes this sort of behavior indicates a disconnect (e.g., reading from one, writing to another), but I don't see how that would be possible given the directness of your method. Maybe it would be possible if the cue being read and set wasn't the one that is playing and being heard.

> Is it possible that there is something repeatedly calling the same cue that is setting it back to this low value?

> Are you calling it so quickly that it hasn't had the time needed to start transitioning? (Seems unlikely, the transition only takes 1028 audio frames at 44100 fps).

Would it be possible to see the code that makes the call to your Player class, and how it's timing is controlled? (Is it in a game loop, or, occurring via a Timer call of some sort? Or is it occurring directly from some sort of control (e.g., slider) that is sending values? Or is there an intermediary between the control and the game loop?)

I'm curious, are you running AudioCue from a jar or did you load the code into your project directly?

Maybe you already saw this. Here is an example where setSpeed is being used in a program.
https://github.com/philfrei/AudioCue/blob/master/src/main/java/com/adonax/audiocue/supportpack/SlidersTest.java
See the class SoundHandler, method "update". Only thing non-obvious (I think) is the calculation where the input (ranging from 0 to 1) is scaled to accommodate an output ranging +/- two octaves (0.25 to 4).

music and music apps: http://adonax.com
Offline slemmuh

Junior Newbie





« Reply #2 - Posted 2019-01-10 06:48:18 »

Hi! Thanks for replying to my thread.

To answer your questions:

>Are you hearing the cue at a low, fixed pitch?
Yes, the pitch stays at whatever speed it was initially given and never changes. So a .128 value makes it perpetually slow.

>Maybe it would be possible if the cue being read and set wasn't the one that is playing and being heard.
Yes, I think that's actually the problem. Here's how the cue behaves when opening, playing, and then trying to manipulate things like the speed.



There's not much to how setSpeed() is called from player, really. I changed it so it only happened when I clicked a button and all it does is call player.setSpeed(value) directly.

It looks like the AudioCue play process ends for some reason, I think? Do I have to run it through a thread and sleep it myself?

> Is it possible that there is something repeatedly calling the same cue that is setting it back to this low value?
Only one button is calling it right now

> Are you calling it so quickly that it hasn't had the time needed to start transitioning? (Seems unlikely, the transition only takes 1028 audio frames at 44100 fps).
I wanted to check if I was indeed calling it too quickly but now that I've changed it so it's only called on a button press I don't think that's the case.

I'm curious, are you running AudioCue from a jar or did you load the code into your project directly?
I added it to my libs as a .jar

I studied the SlidersDemo when I first downloaded the library, thanks!

I'll keep looking into this myself, and I'll report back if I find out what's wrong. Thanks again for answering.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline philfrei
« Reply #3 - Posted 2019-01-10 21:59:16 »

Thanks for keeping me in the loop. I'm curious what you find.

The clip that shows the cue going from Active to Inactive in the break between playing and the speed change is not showing expected results. Once Active, a cue should remain Active as long as it is Playing. If you have set it to looping, that would be indefinitely. Otherwise, the cue would be returned to the pool of inactives at the end of a play.

Here's another idea to look at: you may have two instances of Player, one that is initially called by your program and another that is attached to your button. Each Player loads its own AudioCue, albeit from the same url, and the two resulting AudioCues would be independent.

music and music apps: http://adonax.com
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (1630 views)
2018-11-16 13:46:03

hadezbladez (645 views)
2018-11-16 13:41:33

hadezbladez (1629 views)
2018-11-16 13:35:35

hadezbladez (336 views)
2018-11-16 13:32:03

EgonOlsen (2680 views)
2018-06-10 19:43:48

EgonOlsen (2946 views)
2018-06-10 19:43:44

EgonOlsen (1643 views)
2018-06-10 19:43:20

DesertCoockie (2354 views)
2018-05-13 18:23:11

nelsongames (2258 views)
2018-04-24 18:15:36

nelsongames (2952 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!