File: IAudioFile.h

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (89 lines) | stat: -rw-r--r-- 2,380 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once

#include "globalincs/vmallocator.h"

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 Sets up the given in-memory "soundfile"
	 *
	 * @param snddata The sound
 	 * @param snd_len The sound's length
	 * @return @c true if the sound was succesfully loaded, @c false otherwise
	 */
	virtual bool OpenMem(const uint8_t* snddata, size_t snd_len) = 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