Files
fs2open.github.com/code/sound/IAudioFile.h
asarium 2dc2295a59 Make FFmpeg an optional requirement
This does some refactoring to make it possible to cimpile and run FSO
without needing to link to FFmpeg. Since that eliminates support for
cutscenes or sound this is mostly useful for running a standalone server
which has no need for this anyway.

This reduces the image size of the standalone Docker image to only 20MB
and also resolves any licensing issues that might have existed.
2020-02-29 17:24:56 +01:00

78 lines
2.0 KiB
C++

#pragma once
namespace sound {
/**
* @brief Properties of an audio file
*/
struct AudioFileProperties {
int bytes_per_sample = -1;
double duration = -1.0;
int total_samples = -1;
int num_channels = -1;
int sample_rate = -1;
};
struct ResampleProperties {
int num_channels = -1;
};
/**
* @brief An audio file from which decoded audio data can be read
*/
class IAudioFile {
public:
virtual ~IAudioFile() = default;
/**
* @brief Opens the specified file for playback
*
* After this call you can start reading from this file
*
* @param pszFilename The filename
* @param keep_ext @c true if the extension of the specified file name should be kept
* @return @c true if the file was succesfully loaded, @c false otherwise
*/
virtual bool Open(const char* pszFilename, bool keep_ext = true) = 0;
/**
* @brief Prepare file for audio reading
*
* This reset the file poiner to the start of the stream and reset internal data. Future calls to Read start reading
* from the beginning of the file again
*
* @return @c true if succesfull, @c false otherwise
*/
virtual bool Cue() = 0;
/**
* @brief Read audio data into a buffer
*
* Reads up to cbSize bytes of audio data into the buffer. cbSize must be a multiple of the size of one sample
*
* @param pbDest The buffer to write data to
* @param cbSize The size of the buffer
* @return The number of bytes written into the buffer. Can be 0 if no data is available, try a bigger buffer.
* Returns -1 when the end of the stream or an error has been encountered
*/
virtual int Read(uint8_t* pbDest, size_t cbSize) = 0;
/**
* @brief Gets properties related to the audio file
* @return A struct containing various file related members
*/
virtual AudioFileProperties getFileProperties() = 0;
/**
* @brief Sets properties for resampling audio data before returning audio data
* @param resampleProps The properties for resampling
*/
virtual void setResamplingProperties(const ResampleProperties& resampleProps) = 0;
};
} // namespace sound