SFML - Simple and Fast Multimedia Library

SFML 2.5.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
sf::OutputSoundFile Class Reference
Audio module

Provide write access to sound files. More...

`#include <OutputSoundFile.hpp>`

Inheritance diagram for sf::OutputSoundFile:

## Public Member Functions
| OutputSoundFile ()
| Default constructor. More...
| ~OutputSoundFile ()
| Destructor. More...
bool | openFromFile (const std::string &filename, unsigned int sampleRate, unsigned int channelCount)
| Open the sound file from the disk for writing. More...
void | write (const Int16 *samples, Uint64 count)
| Write audio samples to the file. More...

## 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;
if (!file.openFromFile("music.ogg", 44100, 2))
/* error */;
while (...)
{
// Read or generate audio samples from your custom source
std::vector<sf::Int16> samples = ...;
// Write them to the file
file.write(samples.data(), samples.size());
}
sf::OutputSoundFile
Provide write access to sound files.
Definition: OutputSoundFile.hpp:45
sf::OutputSoundFile::write
void write(const Int16 *samples, Uint64 count)
Write audio samples to the file.
sf::OutputSoundFile::openFromFile
bool openFromFile(const std::string &filename, unsigned int sampleRate, unsigned int channelCount)
Open the sound file from the disk for writing.

See also
  sf::SoundFileWriter, sf::InputSoundFile

Definition at line 44 of file OutputSoundFile.hpp.

## Constructor & Destructor Documentation

## ◆ OutputSoundFile()

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

Default constructor.

## ◆ ~OutputSoundFile()

sf::OutputSoundFile::~OutputSoundFile | ( |  | ) |

Destructor.

Closes the file if it was still open.

## Member Function Documentation

## ◆ openFromFile()

bool sf::OutputSoundFile::openFromFile | ( | const std::string & | filename,
|  | unsigned int | sampleRate,
|  | unsigned int | channelCount
| ) |  |

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

Returns
  True if the file was successfully opened

## ◆ write()

void sf::OutputSoundFile::write | ( | const Int16 * | samples,
|  | Uint64 | 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