.. index:: pair: class; EE::Audio::Sound .. _doxid-class_e_e_1_1_audio_1_1_sound: class EE::Audio::Sound ====================== .. toctree:: :hidden: Overview ~~~~~~~~ Regular sound that can be played in the audio environment. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class Sound: public :ref:`EE::Audio::SoundSource` { public: // construction :target:`Sound`(); :ref:`Sound`(const :ref:`SoundBuffer`& buffer); :ref:`Sound`(const Sound& copy); :target:`~Sound`(); // methods virtual void :ref:`play`(); virtual void :ref:`pause`(); virtual void :ref:`stop`(); void :ref:`setBuffer`(const :ref:`SoundBuffer`& buffer); void :ref:`setLoop`(bool loop); void :ref:`setPlayingOffset`(:ref:`Time` timeOffset); const :ref:`SoundBuffer`* :ref:`getBuffer`() const; bool :ref:`getLoop`() const; :ref:`Time` :ref:`getPlayingOffset`() const; virtual :ref:`Status` :ref:`getStatus`() const; Sound& :ref:`operator=`(const Sound& right); void :ref:`resetBuffer`(); }; Inherited Members ----------------- .. ref-code-block:: cpp :class: doxyrest-overview-inherited-code-block public: // enums enum :ref:`Status`; // methods void :ref:`setPitch`(float pitch); void :ref:`setVolume`(float volume); void :ref:`setPosition`(float x, float y, float z); void :ref:`setPosition`(const :ref:`Vector3f`& position); void :ref:`setRelativeToListener`(bool relative); void :ref:`setMinDistance`(float distance); void :ref:`setAttenuation`(float attenuation); float :ref:`getPitch`() const; float :ref:`getVolume`() const; :ref:`Vector3f` :ref:`getPosition`() const; bool :ref:`isRelativeToListener`() const; float :ref:`getMinDistance`() const; float :ref:`getAttenuation`() const; :ref:`SoundSource`& :ref:`operator=`(const :ref:`SoundSource`& right); virtual void :ref:`play`() = 0; virtual void :ref:`pause`() = 0; virtual void :ref:`stop`() = 0; virtual :ref:`Status` :ref:`getStatus`() const; .. _details-class_e_e_1_1_audio_1_1_sound: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Regular sound that can be played in the audio environment. :ref:`Sound ` is the class to use to play sounds. It provides: * Control (play, pause, stop) * Ability to modify output parameters in real-time (pitch, volume, ...) * 3D spatial features (position, attenuation, ...). :ref:`Sound ` is perfect for playing short sounds that can fit in memory and require no latency, like foot steps or gun shots. For longer sounds, like background musics or long speeches, rather see :ref:`Music ` (which is based on streaming). In order to work, a sound must be given a buffer of audio data to play. :ref:`Audio ` data (samples) is stored in :ref:`SoundBuffer `, and attached to a sound with the :ref:`setBuffer() ` function. The buffer object attached to a sound must remain alive as long as the sound uses it. Note that multiple sounds can use the same sound buffer at the same time. Usage example: .. ref-code-block:: cpp SoundBuffer buffer; buffer.loadFromFile("sound.wav"); Sound sound; sound.setBuffer(buffer); sound.play(); .. rubric:: See also: :ref:`SoundBuffer `, :ref:`Music ` Construction ------------ .. index:: pair: function; Sound .. _doxid-class_e_e_1_1_audio_1_1_sound_1af29695cf0ad32e8e1c36d7222f659205: .. ref-code-block:: cpp :class: doxyrest-title-code-block Sound(const :ref:`SoundBuffer`& buffer) Construct the sound with a buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - buffer - :ref:`Sound ` buffer containing the audio data to play with the sound .. index:: pair: function; Sound .. _doxid-class_e_e_1_1_audio_1_1_sound_1af66fb90be9cacdbde250eda911804a20: .. ref-code-block:: cpp :class: doxyrest-title-code-block Sound(const Sound& copy) Copy constructor. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - copy - Instance to copy Methods ------- .. index:: pair: function; play .. _doxid-class_e_e_1_1_audio_1_1_sound_1a1af57556b8f8d70659616cdbfcc33f98: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual void play() Start or resume playing the sound. This function starts the stream if it was stopped, resumes it if it was paused, and restarts it from beginning if it was it already playing. This function uses its own thread so that it doesn't block the rest of the program while the sound is played. .. rubric:: See also: :ref:`pause `, :ref:`stop ` .. index:: pair: function; pause .. _doxid-class_e_e_1_1_audio_1_1_sound_1a20565c559e77aa551240c33208a1e888: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual void pause() Pause the sound. This function pauses the sound if it was playing, otherwise (sound already paused or stopped) it has no effect. .. rubric:: See also: :ref:`play `, :ref:`stop ` .. index:: pair: function; stop .. _doxid-class_e_e_1_1_audio_1_1_sound_1a37473426c02a2a40aea482b627483da0: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual void stop() stop playing the sound This function stops the sound if it was playing or paused, and does nothing if it was already stopped. It also resets the playing position (unlike :ref:`pause() `). .. rubric:: See also: :ref:`play `, :ref:`pause ` .. index:: pair: function; setBuffer .. _doxid-class_e_e_1_1_audio_1_1_sound_1aef046d995252bb0f9f06045fae1a667d: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setBuffer(const :ref:`SoundBuffer`& buffer) Set the source buffer containing the audio data to play. It is important to note that the sound buffer is not copied, thus the :ref:`SoundBuffer ` instance must remain alive as long as it is attached to the sound. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - buffer - :ref:`Sound ` buffer to attach to the sound .. rubric:: See also: :ref:`getBuffer ` .. index:: pair: function; setLoop .. _doxid-class_e_e_1_1_audio_1_1_sound_1ac68f88d1c3c6b565cc6570dd4e34f010: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setLoop(bool loop) Set whether or not the sound should loop after reaching the end. If set, the sound will restart from beginning after reaching the end and so on, until it is stopped or setLoop(false) is called. The default looping state for sound is false. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - loop - True to play in loop, false to play once .. rubric:: See also: :ref:`getLoop ` .. index:: pair: function; setPlayingOffset .. _doxid-class_e_e_1_1_audio_1_1_sound_1ace4cae883a487e02d3943460d1ee101b: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setPlayingOffset(:ref:`Time` timeOffset) Change the current playing position of the sound. The playing position can be changed when the sound is either paused or playing. Changing the playing position when the sound is stopped has no effect, since playing the sound will reset its position. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - timeOffset - New playing position, from the beginning of the sound .. rubric:: See also: :ref:`getPlayingOffset ` .. index:: pair: function; getBuffer .. _doxid-class_e_e_1_1_audio_1_1_sound_1ac6bb54ebad4c8bc6c82197580ed30abe: .. ref-code-block:: cpp :class: doxyrest-title-code-block const :ref:`SoundBuffer`* getBuffer() const Get the audio buffer attached to the sound. .. rubric:: Returns: :ref:`Sound ` buffer attached to the sound (can be NULL) .. index:: pair: function; getLoop .. _doxid-class_e_e_1_1_audio_1_1_sound_1acaf4550c701cf1b97a232a20d683303c: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool getLoop() const Tell whether or not the sound is in loop mode. .. rubric:: Returns: True if the sound is looping, false otherwise .. rubric:: See also: :ref:`setLoop ` .. index:: pair: function; getPlayingOffset .. _doxid-class_e_e_1_1_audio_1_1_sound_1ac680797e54ecebd52c6af9ac1e81cef8: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Time` getPlayingOffset() const Get the current playing position of the sound. .. rubric:: Returns: Current playing position, from the beginning of the sound .. rubric:: See also: :ref:`setPlayingOffset ` .. index:: pair: function; getStatus .. _doxid-class_e_e_1_1_audio_1_1_sound_1a3fc95be5b1e1a76b21314463a29d1f73: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual :ref:`Status` getStatus() const Get the current status of the sound (stopped, paused, playing) .. rubric:: Returns: Current status of the sound .. index:: pair: function; operator= .. _doxid-class_e_e_1_1_audio_1_1_sound_1a5d5942920584b9cf2ceeb0d06ac8ce9d: .. ref-code-block:: cpp :class: doxyrest-title-code-block Sound& operator=(const Sound& right) Overload of assignment operator. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - right - Instance to assign .. rubric:: Returns: Reference to self .. index:: pair: function; resetBuffer .. _doxid-class_e_e_1_1_audio_1_1_sound_1aa18c9e657954e4cb0cdf580865ae47ac: .. ref-code-block:: cpp :class: doxyrest-title-code-block void resetBuffer() Reset the internal buffer of the sound. This function is for internal use only, you don't have to use it. It is called by the :ref:`SoundBuffer ` that this sound uses, when it is destroyed in order to prevent the sound from using a dead buffer.