1 /*******************************************************************************
\r
2 * Copyright 2011 See AUTHORS file.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
15 ******************************************************************************/
\r
17 package com.badlogic.gdx.audio;
\r
19 import com.badlogic.gdx.Audio;
\r
20 import com.badlogic.gdx.files.FileHandle;
\r
21 import com.badlogic.gdx.utils.Disposable;
\r
24 * A Sound is a short audio clip that can be played numerous times in parallel. It's completely loaded into memory so only load
\r
25 * small audio files. Call the {@link #dispose()} method when you're done using the Sound.
\r
29 * Sound instances are created via a call to {@link Audio#newSound(FileHandle)}.
\r
33 * Calling the {@link #play()} or {@link #play(float)} method will return a long which is an id to that instance of the sound. You
\r
34 * can use this id to modify the playback of that sound instance.
\r
37 * @author badlogicgames@gmail.com */
\r
38 public interface Sound extends Disposable {
\r
39 /** Plays the sound. If the sound is already playing, it will be played again, concurrently.
\r
40 * @return the id of the sound instance if successful, or -1 on failure. */
\r
41 public long play ();
\r
43 /** Plays the sound. If the sound is already playing, it will be played again, concurrently.
\r
44 * @param volume the volume in the range [0,1]
\r
45 * @return the id of the sound instance if successful, or -1 on failure. */
\r
46 public long play (float volume);
\r
48 /** Plays the sound. If the sound is already playing, it will be played again, concurrently.
\r
49 * @param volume the volume in the range [0,1]
\r
50 * @param pitch the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
\r
51 * @param pan panning in the range -1 (full left) to 1 (full right). 0 is center position.
\r
52 * @return the id of the sound instance if successful, or -1 on failure. */
\r
53 public long play (float volume, float pitch, float pan);
\r
55 /** Plays the sound, looping. If the sound is already playing, it will be played again, concurrently.
\r
56 * @return the id of the sound instance if successful, or -1 on failure. */
\r
57 public long loop ();
\r
59 /** Plays the sound, looping. If the sound is already playing, it will be played again, concurrently. You need to stop the sound
\r
60 * via a call to {@link #stop(long)} using the returned id.
\r
61 * @param volume the volume in the range [0, 1]
\r
62 * @return the id of the sound instance if successful, or -1 on failure. */
\r
63 public long loop (float volume);
\r
65 /** Plays the sound, looping. If the sound is already playing, it will be played again, concurrently. You need to stop the sound
\r
66 * via a call to {@link #stop(long)} using the returned id.
\r
67 * @param volume the volume in the range [0,1]
\r
68 * @param pitch the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
\r
69 * @param pan panning in the range -1 (full left) to 1 (full right). 0 is center position.
\r
70 * @return the id of the sound instance if successful, or -1 on failure. */
\r
71 public long loop (float volume, float pitch, float pan);
\r
73 /** Stops playing all instances of this sound. */
\r
74 public void stop ();
\r
76 /** Pauses all instances of this sound. */
\r
77 public void pause ();
\r
79 /** Resumes all paused instances of this sound. */
\r
80 public void resume ();
\r
82 /** Releases all the resources. */
\r
83 public void dispose ();
\r
85 /** Stops the sound instance with the given id as returned by {@link #play()} or {@link #play(float)}. If the sound is no longer
\r
86 * playing, this has no effect.
\r
87 * @param soundId the sound id */
\r
88 public void stop (long soundId);
\r
90 /** Pauses the sound instance with the given id as returned by {@link #play()} or {@link #play(float)}. If the sound is no longer
\r
91 * playing, this has no effect.
\r
92 * @param soundId the sound id */
\r
93 public void pause (long soundId);
\r
95 /** Resumes the sound instance with the given id as returned by {@link #play()} or {@link #play(float)}. If the sound is not
\r
96 * paused, this has no effect.
\r
97 * @param soundId the sound id */
\r
98 public void resume (long soundId);
\r
100 /** Sets the sound instance with the given id to be looping. If the sound is no longer playing this has no effect.s
\r
101 * @param soundId the sound id
\r
102 * @param looping whether to loop or not. */
\r
103 public void setLooping (long soundId, boolean looping);
\r
105 /** Changes the pitch multiplier of the sound instance with the given id as returned by {@link #play()} or {@link #play(float)}.
\r
106 * If the sound is no longer playing, this has no effect.
\r
107 * @param soundId the sound id
\r
108 * @param pitch the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0 */
\r
109 public void setPitch (long soundId, float pitch);
\r
111 /** Changes the volume of the sound instance with the given id as returned by {@link #play()} or {@link #play(float)}. If the
\r
112 * sound is no longer playing, this has no effect.
\r
113 * @param soundId the sound id
\r
114 * @param volume the volume in the range 0 (silent) to 1 (max volume). */
\r
115 public void setVolume (long soundId, float volume);
\r
117 /** Sets the panning and volume of the sound instance with the given id as returned by {@link #play()} or {@link #play(float)}.
\r
118 * If the sound is no longer playing, this has no effect.
\r
119 * @param soundId the sound id
\r
120 * @param pan panning in the range -1 (full left) to 1 (full right). 0 is center position.
\r
121 * @param volume the volume in the range [0,1]. */
\r
122 public void setPan (long soundId, float pan, float volume);
\r
125 * Sets the priority of a sound currently being played back. Higher priority sounds will be considered last
\r
126 * if the maximum number of concurrently playing sounds is exceeded. This is only a
\r
127 * hint and might not be honored by a backend implementation.
\r
128 * @param soundId the sound id as returned by {@link #play()} or {@link #loop()} and their overloaded equivalents.
\r
129 * @param priority the priority (0 == lowest)
\r
131 public void setPriority(long soundId, int priority);
\r