mirror of
https://github.com/mpv-player/mpv
synced 2024-08-04 14:59:58 +02:00
audio/format: add some helper functions
This commit is contained in:
parent
bb5fe4d874
commit
33707c6d63
@ -42,6 +42,27 @@ int af_fmt2bits(int format)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bits_to_mask(int bits)
|
||||
{
|
||||
switch (bits) {
|
||||
case 8: return AF_FORMAT_8BIT;
|
||||
case 16: return AF_FORMAT_16BIT;
|
||||
case 24: return AF_FORMAT_24BIT;
|
||||
case 32: return AF_FORMAT_32BIT;
|
||||
case 64: return AF_FORMAT_64BIT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int af_fmt_change_bits(int format, int bits)
|
||||
{
|
||||
if (!af_fmt_is_valid(format) || (format & AF_FORMAT_SPECIAL_MASK))
|
||||
return 0;
|
||||
int mask = bits_to_mask(bits);
|
||||
format = (format & ~AF_FORMAT_BITS_MASK) | mask;
|
||||
return af_fmt_is_valid(format) ? format : 0;
|
||||
}
|
||||
|
||||
/* Convert format to str input str is a buffer for the
|
||||
converted string, size is the size of the buffer */
|
||||
char* af_fmt2str(int format, char* str, int size)
|
||||
@ -90,6 +111,15 @@ const struct af_fmt_entry af_fmtstr_table[] = {
|
||||
{0}
|
||||
};
|
||||
|
||||
bool af_fmt_is_valid(int format)
|
||||
{
|
||||
for (int i = 0; af_fmtstr_table[i].name; i++) {
|
||||
if (af_fmtstr_table[i].format == format)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *af_fmt2str_short(int format)
|
||||
{
|
||||
int i;
|
||||
|
@ -131,6 +131,7 @@ extern const struct af_fmt_entry af_fmtstr_table[];
|
||||
|
||||
int af_str2fmt_short(bstr str);
|
||||
int af_fmt2bits(int format);
|
||||
int af_fmt_change_bits(int format, int bits);
|
||||
|
||||
// Amount of bytes that contain audio of the given duration, aligned to frames.
|
||||
int af_fmt_seconds_to_bytes(int format, float seconds, int channels, int samplerate);
|
||||
@ -138,4 +139,6 @@ int af_fmt_seconds_to_bytes(int format, float seconds, int channels, int sampler
|
||||
char* af_fmt2str(int format, char* str, int size);
|
||||
const char* af_fmt2str_short(int format);
|
||||
|
||||
bool af_fmt_is_valid(int format);
|
||||
|
||||
#endif /* MPLAYER_AF_FORMAT_H */
|
||||
|
Loading…
Reference in New Issue
Block a user