19
19
#ifndef AVUTIL_SAMPLEFMT_H
20
20
#define AVUTIL_SAMPLEFMT_H
22
24
#include "avutil.h"
25
#include "attributes.h"
25
* all in native-endian format
28
* Audio Sample Formats
31
* The data described by the sample format is always in native-endian order.
32
* Sample values can be expressed by native C types, hence the lack of a signed
33
* 24-bit sample format even though it is a common raw audio data format.
36
* The floating-point formats are based on full volume being in the range
37
* [-1.0, 1.0]. Any values outside this range are beyond full volume level.
40
* The data layout as used in av_samples_fill_arrays() and elsewhere in Libav
41
* (such as AVFrame in libavcodec) is as follows:
43
* For planar sample formats, each audio channel is in a separate data plane,
44
* and linesize is the buffer size, in bytes, for a single plane. All data
45
* planes must be the same size. For packed sample formats, only the first data
46
* plane is used, and samples for each channel are interleaved. In this case,
47
* linesize is the buffer size, in bytes, for the 1 plane.
27
49
enum AVSampleFormat {
28
50
AV_SAMPLE_FMT_NONE = -1,
54
76
enum AVSampleFormat av_get_sample_fmt(const char *name);
79
* Get the packed alternative form of the given sample format.
81
* If the passed sample_fmt is already in packed format, the format returned is
82
* the same as the input.
84
* @return the packed alternative form of the given sample format or
85
AV_SAMPLE_FMT_NONE on error.
87
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt);
90
* Get the planar alternative form of the given sample format.
92
* If the passed sample_fmt is already in planar format, the format returned is
93
* the same as the input.
95
* @return the planar alternative form of the given sample format or
96
AV_SAMPLE_FMT_NONE on error.
98
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt);
57
101
* Generate a string corresponding to the sample format with
58
102
* sample_fmt, or a header if sample_fmt is negative.
68
112
char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt);
70
#if FF_API_GET_BITS_PER_SAMPLE_FMT
72
* @deprecated Use av_get_bytes_per_sample() instead.
75
int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
79
115
* Return number of bytes per sample.
99
135
* @param nb_channels the number of channels
100
136
* @param nb_samples the number of samples in a single channel
101
137
* @param sample_fmt the sample format
138
* @param align buffer size alignment (0 = default, 1 = no alignment)
102
139
* @return required buffer size, or negative error code on failure
104
141
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
116
153
* buffer for planar layout, or the aligned size of the buffer for all channels
117
154
* for packed layout.
156
* @see enum AVSampleFormat
157
* The documentation for AVSampleFormat describes the data layout.
119
159
* @param[out] audio_data array to be filled with the pointer for each channel
120
* @param[out] linesize calculated linesize
160
* @param[out] linesize calculated linesize, may be NULL
121
161
* @param buf the pointer to a buffer containing the samples
122
162
* @param nb_channels the number of channels
123
163
* @param nb_samples the number of samples in a single channel
124
164
* @param sample_fmt the sample format
125
* @param align buffer size alignment (1 = no alignment required)
165
* @param align buffer size alignment (0 = default, 1 = no alignment)
126
166
* @return 0 on success or a negative error code on failure
128
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, uint8_t *buf,
168
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
129
170
int nb_channels, int nb_samples,
130
171
enum AVSampleFormat sample_fmt, int align);
133
174
* Allocate a samples buffer for nb_samples samples, and fill data pointers and
134
175
* linesize accordingly.
135
176
* The allocated samples buffer can be freed by using av_freep(&audio_data[0])
177
* Allocated data will be initialized to silence.
179
* @see enum AVSampleFormat
180
* The documentation for AVSampleFormat describes the data layout.
137
182
* @param[out] audio_data array to be filled with the pointer for each channel
138
* @param[out] linesize aligned size for audio buffer(s)
183
* @param[out] linesize aligned size for audio buffer(s), may be NULL
139
184
* @param nb_channels number of audio channels
140
185
* @param nb_samples number of samples per channel
141
* @param align buffer size alignment (1 = no alignment required)
186
* @param align buffer size alignment (0 = default, 1 = no alignment)
142
187
* @return 0 on success or a negative error code on failure
143
188
* @see av_samples_fill_arrays()
145
190
int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
146
191
int nb_samples, enum AVSampleFormat sample_fmt, int align);
194
* Copy samples from src to dst.
196
* @param dst destination array of pointers to data planes
197
* @param src source array of pointers to data planes
198
* @param dst_offset offset in samples at which the data will be written to dst
199
* @param src_offset offset in samples at which the data will be read from src
200
* @param nb_samples number of samples to be copied
201
* @param nb_channels number of audio channels
202
* @param sample_fmt audio sample format
204
int av_samples_copy(uint8_t **dst, uint8_t * const *src, int dst_offset,
205
int src_offset, int nb_samples, int nb_channels,
206
enum AVSampleFormat sample_fmt);
209
* Fill an audio buffer with silence.
211
* @param audio_data array of pointers to data planes
212
* @param offset offset in samples at which to start filling
213
* @param nb_samples number of samples to fill
214
* @param nb_channels number of audio channels
215
* @param sample_fmt audio sample format
217
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples,
218
int nb_channels, enum AVSampleFormat sample_fmt);
148
220
#endif /* AVUTIL_SAMPLEFMT_H */