.. index:: pair: class; EE::Audio::Music .. _doxid-class_e_e_1_1_audio_1_1_music: class EE::Audio::Music ====================== .. toctree:: :hidden: struct_EE_Audio_Music_Span.rst Overview ~~~~~~~~ Streamed music played from an audio file. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class Music: public :ref:`EE::Audio::SoundStream` { public: // typedefs typedef :ref:`Span`<:ref:`Time`> :target:`TimeSpan`; // structs template struct :ref:`Span`; // construction :target:`~Music`(); // methods static Music* :target:`New`(); bool :ref:`openFromFile`(const std::string& filename); bool :ref:`openFromMemory`(const void* data, std::size_t sizeInBytes); bool :ref:`openFromStream`(:ref:`IOStream`& stream); bool :target:`openFromPack`(:ref:`Pack`* pack, const std::string& filePackPath); :ref:`Time` :ref:`getDuration`() const; :ref:`TimeSpan` :ref:`getLoopPoints`() const; void :ref:`setLoopPoints`(:ref:`TimeSpan` timePoints); }; Inherited Members ----------------- .. ref-code-block:: cpp :class: doxyrest-overview-inherited-code-block public: // enums enum :ref:`Status`; // structs struct :ref:`Chunk`; // 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; virtual void :ref:`play`(); virtual void :ref:`pause`(); virtual void :ref:`stop`(); unsigned int :ref:`getChannelCount`() const; unsigned int :ref:`getSampleRate`() const; virtual :ref:`Status` :ref:`getStatus`() const; void :ref:`setPlayingOffset`(:ref:`Time` timeOffset); :ref:`Time` :ref:`getPlayingOffset`() const; void :ref:`setLoop`(bool loop); bool :ref:`getLoop`() const; .. _details-class_e_e_1_1_audio_1_1_music: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Streamed music played from an audio file. Musics are sounds that are streamed rather than completely loaded in memory. This is especially useful for compressed musics that usually take hundreds of MB when they are uncompressed: by streaming it instead of loading it entirely, you avoid saturating the memory and have almost no loading delay. This implies that the underlying resource (file, stream or memory buffer) must remain valid for the lifetime of the :ref:`Music ` object. Apart from that, a :ref:`Music ` has almost the same features as the :ref:`SoundBuffer ` / :ref:`Sound ` pair: you can play/pause/stop it, request its parameters (channels, sample rate), change the way it is played (pitch, volume, 3D position, ...), etc. As a sound stream, a music is played in its own thread in order not to block the rest of the program. This means that you can leave the music alone after calling :ref:`play() `, it will manage itself very well. Usage example: .. ref-code-block:: cpp // Declare a new music Music music; // Open it from an audio file if (!music.openFromFile("music.ogg")) { // error... } // Change some parameters music.setPosition(0, 1, 10); // change its 3D position music.setPitch(2); // increase the pitch music.setVolume(50); // reduce the volume music.setLoop(true); // make it loop // Play it music.play(); .. rubric:: See also: :ref:`Sound `, :ref:`SoundStream ` Methods ------- .. index:: pair: function; openFromFile .. _doxid-class_e_e_1_1_audio_1_1_music_1afc2b3ce03c01ce0b53f8eaef4e7a1fe5: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool openFromFile(const std::string& filename) Open a music from an audio file. This function doesn't start playing the music (call :ref:`play() ` to do so). See the documentation of :ref:`InputSoundFile ` for the list of supported formats. .. warning:: Since the music is not loaded at once but rather streamed continuously, the file must remain accessible until the :ref:`Music ` object loads a new music or is destroyed. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - filename - Path of the music file to open .. rubric:: Returns: True if loading succeeded, false if it failed .. rubric:: See also: :ref:`openFromMemory `, :ref:`openFromStream ` .. index:: pair: function; openFromMemory .. _doxid-class_e_e_1_1_audio_1_1_music_1aef3a1e05f61b3797d95e94ba39531971: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool openFromMemory(const void* data, std::size_t sizeInBytes) Open a music from an audio file in memory. This function doesn't start playing the music (call :ref:`play() ` to do so). See the documentation of :ref:`InputSoundFile ` for the list of supported formats. .. warning:: Since the music is not loaded at once but rather streamed continuously, the *data* buffer must remain accessible until the :ref:`Music ` object loads a new music or is destroyed. That is, you can't deallocate the buffer right after calling this function. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - data - Pointer to the file data in memory * - sizeInBytes - Size of the data to load, in bytes .. rubric:: Returns: True if loading succeeded, false if it failed .. rubric:: See also: :ref:`openFromFile `, :ref:`openFromStream ` .. index:: pair: function; openFromStream .. _doxid-class_e_e_1_1_audio_1_1_music_1a63ccf554d8e774d741eaf16f52261661: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool openFromStream(:ref:`IOStream`& stream) Open a music from an audio file in a custom stream. This function doesn't start playing the music (call :ref:`play() ` to do so). See the documentation of :ref:`InputSoundFile ` for the list of supported formats. .. warning:: Since the music is not loaded at once but rather streamed continuously, the *stream* must remain accessible until the :ref:`Music ` object loads a new music or is destroyed. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - stream - Source stream to read from .. rubric:: Returns: True if loading succeeded, false if it failed .. rubric:: See also: :ref:`openFromFile `, :ref:`openFromMemory ` .. index:: pair: function; getDuration .. _doxid-class_e_e_1_1_audio_1_1_music_1aafcf87ca769b1b9a428c1c483ceef294: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Time` getDuration() const Get the total duration of the music. .. rubric:: Returns: :ref:`Music ` duration .. index:: pair: function; getLoopPoints .. _doxid-class_e_e_1_1_audio_1_1_music_1a3ef75fc666b6d410d9360610d157de25: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`TimeSpan` getLoopPoints() const Get the positions of the of the sound's looping sequence. .. warning:: Since :ref:`setLoopPoints() ` performs some adjustments on the provided values and rounds them to internal samples, a call to :ref:`getLoopPoints() ` is not guaranteed to return the same times passed into a previous call to :ref:`setLoopPoints() `. However, it is guaranteed to return times that will map to the valid internal samples of this :ref:`Music ` if they are later passed to :ref:`setLoopPoints() `. .. rubric:: Returns: Loop Time position class. .. rubric:: See also: :ref:`setLoopPoints ` .. index:: pair: function; setLoopPoints .. _doxid-class_e_e_1_1_audio_1_1_music_1ab6204b4dcccb3a161d2ffd7c4d9e4d02: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setLoopPoints(:ref:`TimeSpan` timePoints) Sets the beginning and end of the sound's looping sequence using Time. Loop points allow one to specify a pair of positions such that, when the music is enabled for looping, it will seamlessly seek to the beginning whenever it encounters the end. Valid ranges for timePoints.offset and timePoints.length are [0, Dur) and (0, Dur-offset] respectively, where Dur is the value returned by :ref:`getDuration() `. Note that the EOF "loop point" from the end to the beginning of the stream is still honored, in case the caller seeks to a point after the end of the loop range. This function can be safely called at any point after a stream is opened, and will be applied to a playing sound without affecting the current playing offset. .. warning:: Setting the loop points while the stream's status is Paused will set its status to Stopped. The playing offset will be unaffected. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - timePoints - The definition of the loop. Can be any time points within the sound's length .. rubric:: See also: :ref:`getLoopPoints `