SFML 3.0.2
Loading...
Searching...
No Matches
Public Member Functions | List of all members
sf::OutputSoundFile Class Reference
Audio module

Provide write access to sound files. More...

`#include <SFML/Audio/OutputSoundFile.hpp>`

## Public Member Functions
| OutputSoundFile ()=default
| Default constructor.
| OutputSoundFile (const std::filesystem::path &filename, unsigned int sampleRate, unsigned int channelCount, const std::vector< SoundChannel > &channelMap)
| Construct the sound file from the disk for writing.
bool | openFromFile (const std::filesystem::path &filename, unsigned int sampleRate, unsigned int channelCount, const std::vector< SoundChannel > &channelMap)
| Open the sound file from the disk for writing.
void | write (const std::int16_t *samples, std::uint64_t count)
| Write audio samples to the file.
void | close ()
| Close the current file.

## Detailed Description

Provide write access to sound files.

This class encodes audio samples to a sound file.

It is used internally by higher-level classes such as sf::SoundBuffer, but can also be useful if you want to create audio files from custom data sources, like generated audio samples.

Usage example:

// Create a sound file, ogg/vorbis format, 44100 Hz, stereo
sf::OutputSoundFile file("music.ogg", 44100, 2, {sf::SoundChannel::FrontLeft, sf::SoundChannel::FrontRight});
while (...)
{
// Read or generate audio samples from your custom source
std::vector<std::int16_t> samples = ...;
// Write them to the file
file.write(samples.data(), samples.size());
}
sf::OutputSoundFile
Provide write access to sound files.
Definition OutputSoundFile.hpp:49
sf::SoundChannel::FrontRight
@ FrontRight
Definition SoundChannel.hpp:46
sf::SoundChannel::FrontLeft
@ FrontLeft
Definition SoundChannel.hpp:45

See also
  sf::SoundFileWriter, sf::InputSoundFile

Definition at line 48 of file OutputSoundFile.hpp.

## Constructor & Destructor Documentation

## ◆ OutputSoundFile() [1/2]

sf::OutputSoundFile::OutputSoundFile | ( |  | ) |
| default

Default constructor.

Construct an output sound file that is not associated with a file to write.

## ◆ OutputSoundFile() [2/2]

sf::OutputSoundFile::OutputSoundFile | ( | const std::filesystem::path & | filename,
|  | unsigned int | sampleRate,
|  | unsigned int | channelCount,
|  | const std::vector< SoundChannel > & | channelMap )

Construct the sound file from the disk for writing.

The supported audio formats are: WAV, OGG/Vorbis, FLAC.

Parameters

  filename | Path of the sound file to write
  sampleRate | Sample rate of the sound
  channelCount | Number of channels in the sound
  channelMap | Map of position in sample frame to sound channel

Exceptions

  sf::Exception | if the file could not be opened successfully

## Member Function Documentation

## ◆ close()

void sf::OutputSoundFile::close | ( |  | ) |

Close the current file.

## ◆ openFromFile()

bool sf::OutputSoundFile::openFromFile | ( | const std::filesystem::path & | filename,
|  | unsigned int | sampleRate,
|  | unsigned int | channelCount,
|  | const std::vector< SoundChannel > & | channelMap )
| nodiscard

Open the sound file from the disk for writing.

The supported audio formats are: WAV, OGG/Vorbis, FLAC.

Parameters

  filename | Path of the sound file to write
  sampleRate | Sample rate of the sound
  channelCount | Number of channels in the sound
  channelMap | Map of position in sample frame to sound channel

Returns
  true if the file was successfully opened

## ◆ write()

void sf::OutputSoundFile::write | ( | const std::int16_t * | samples,
|  | std::uint64_t | count )

Write audio samples to the file.

Parameters

  samples | Pointer to the sample array to write
  count | Number of samples to write

The documentation for this class was generated from the following file:

- OutputSoundFile.hpp