Warning
This page refers to an old version of SFML. Click here to switch to the latest version.
Warning
This page refers to an old version of SFML. Click here to switch to the latest version.
Provide read access to sound files. More...
#include <SFML/Audio/InputSoundFile.hpp>
Public Member Functions | |
| InputSoundFile () | |
| Default constructor. | |
| ~InputSoundFile () | |
| Destructor. | |
| bool | openFromFile (const std::string &filename) |
| Open a sound file from the disk for reading. | |
| bool | openFromMemory (const void *data, std::size_t sizeInBytes) |
| Open a sound file in memory for reading. | |
| bool | openFromStream (InputStream &stream) |
| Open a sound file from a custom stream for reading. | |
| bool | openForWriting (const std::string &filename, unsigned int channelCount, unsigned int sampleRate) |
| Open the sound file from the disk for writing. | |
| Uint64 | getSampleCount () const |
| Get the total number of audio samples in the file. | |
| unsigned int | getChannelCount () const |
| Get the number of channels used by the sound. | |
| unsigned int | getSampleRate () const |
| Get the sample rate of the sound. | |
| Time | getDuration () const |
| Get the total duration of the sound file. | |
| void | seek (Uint64 sampleOffset) |
| Change the current read position to the given sample offset. | |
| void | seek (Time timeOffset) |
| Change the current read position to the given time offset. | |
| Uint64 | read (Int16 *samples, Uint64 maxCount) |
| Read audio samples from the open file. | |
Provide read access to sound files.
This class decodes audio samples from a sound file.
It is used internally by higher-level classes such as sf::SoundBuffer and sf::Music, but can also be useful if you want to process or analyze audio files without playing them, or if you want to implement your own version of sf::Music with more specific features.
Usage example:
Definition at line 46 of file InputSoundFile.hpp.
| sf::InputSoundFile::InputSoundFile | ( | ) |
Default constructor.
| sf::InputSoundFile::~InputSoundFile | ( | ) |
Destructor.
| unsigned int sf::InputSoundFile::getChannelCount | ( | ) | const |
Get the number of channels used by the sound.
| Time sf::InputSoundFile::getDuration | ( | ) | const |
Get the total duration of the sound file.
This function is provided for convenience, the duration is deduced from the other sound file attributes.
| Uint64 sf::InputSoundFile::getSampleCount | ( | ) | const |
Get the total number of audio samples in the file.
| unsigned int sf::InputSoundFile::getSampleRate | ( | ) | const |
Get the sample rate of the sound.
| bool sf::InputSoundFile::openForWriting | ( | const std::string & | filename, |
| unsigned int | channelCount, | ||
| unsigned int | sampleRate ) |
Open the sound file from the disk for writing.
| filename | Path of the sound file to write |
| channelCount | Number of channels in the sound |
| sampleRate | Sample rate of the sound |
| bool sf::InputSoundFile::openFromFile | ( | const std::string & | filename | ) |
Open a sound file from the disk for reading.
The supported audio formats are: WAV, OGG/Vorbis, FLAC.
| filename | Path of the sound file to load |
| bool sf::InputSoundFile::openFromMemory | ( | const void * | data, |
| std::size_t | sizeInBytes ) |
Open a sound file in memory for reading.
The supported audio formats are: WAV, OGG/Vorbis, FLAC.
| data | Pointer to the file data in memory |
| sizeInBytes | Size of the data to load, in bytes |
| bool sf::InputSoundFile::openFromStream | ( | InputStream & | stream | ) |
Open a sound file from a custom stream for reading.
The supported audio formats are: WAV, OGG/Vorbis, FLAC.
| stream | Source stream to read from |
Read audio samples from the open file.
| samples | Pointer to the sample array to fill |
| maxCount | Maximum number of samples to read |
| void sf::InputSoundFile::seek | ( | Time | timeOffset | ) |
Change the current read position to the given time offset.
Using a time offset is handy but imprecise. If you need an accurate result, consider using the overload which takes a sample offset.
If the given time exceeds to total duration, this function jumps to the end of the sound file.
| timeOffset | Time to jump to, relative to the beginning |
| void sf::InputSoundFile::seek | ( | Uint64 | sampleOffset | ) |
Change the current read position to the given sample offset.
This function takes a sample offset to provide maximum precision. If you need to jump to a given time, use the other overload.
If the given offset exceeds to total number of samples, this function jumps to the end of the sound file.
| sampleOffset | Index of the sample to jump to, relative to the beginning |