1
mirror of https://github.com/mpv-player/mpv synced 2024-11-14 22:48:35 +01:00
mpv/audio
wm4 3f7e1f0492 audio/format: add heuristic to estimate loss on format conversion
The added function af_format_conversion_score() can be used to select
the best sample format to convert to in order to reduce loss and extra
conversion work.

It calculates a "loss" score when going from one format to another, and
for each conversion that needs to be done a certain score is subtracted.
Thus, if you have to convert from one format to a set of other formats,
you can calculate the score for each conversion, and pick the one with
the highest score.

Conversion between int and float is considered the worst case. One odd
consequence is that when converting from s32 to u8 or float, u8 will be
picked.

Test program used to develop this follows:

#define MAX_FMT 200
struct entry {
    const char *name;
    int score;
};

static int compentry(const void *px1, const void *px2)
{
    const struct entry *x1 = px1;
    const struct entry *x2 = px2;
    if (x1->score > x2->score)
        return 1;
    if (x1->score < x2->score)
        return -1;
    return 0;
}

int main(int argc, char *argv[])
{
    for (int n = 0; af_fmtstr_table[n].name; n++) {
        struct entry entry[MAX_FMT];
        int entries = 0;
        for (int i = 0; af_fmtstr_table[i].name; i++) {
            assert(i < MAX_FMT);
            entry[entries].name = af_fmtstr_table[i].name;
            entry[entries].score =
                af_format_conversion_score(af_fmtstr_table[i].format,
                                           af_fmtstr_table[n].format);
            entries++;
        }
        qsort(&entry[0], entries, sizeof(entry[0]), compentry);
        for (int i = 0; i < entries; i++) {
            printf("%s -> %s: %d \n", af_fmtstr_table[n].name,
                   entry[i].name, entry[i].score);
        }
    }
}
2013-11-16 21:46:17 +01:00
..
decode audio: drop "_NE"/"ne" suffix from audio formats 2013-11-15 21:25:05 +01:00
filter audio: drop "_NE"/"ne" suffix from audio formats 2013-11-15 21:25:05 +01:00
out ao_lavc: write the final audio chunks from uninit() 2013-11-16 18:50:07 +01:00
audio_buffer.c audio: add mp_audio_buffer 2013-11-12 23:28:21 +01:00
audio_buffer.h audio: add mp_audio_buffer 2013-11-12 23:28:21 +01:00
audio.c audio: fix audio data memory leak 2013-11-14 19:51:42 +01:00
audio.h mp_audio: use av_malloc (cargo cult for libav*) 2013-11-12 23:35:33 +01:00
chmap_sel.c ao_jack: allow more control about channel layouts 2013-07-07 18:37:55 +02:00
chmap_sel.h audio: add channel map selection function 2013-05-12 21:24:57 +02:00
chmap.c core: move contents to mpvcore (2/2) 2013-08-06 22:52:31 +02:00
chmap.h core: move contents to mpvcore (2/2) 2013-08-06 22:52:31 +02:00
fmt-conversion.c audio: drop "_NE"/"ne" suffix from audio formats 2013-11-15 21:25:05 +01:00
fmt-conversion.h ad_lavc: use fmt-conversion to map sample formats 2013-04-13 04:21:27 +02:00
format.c audio/format: add heuristic to estimate loss on format conversion 2013-11-16 21:46:17 +01:00
format.h audio/format: add heuristic to estimate loss on format conversion 2013-11-16 21:46:17 +01:00
mixer.c af_volume: use only one volume setting for all channels 2013-11-09 23:32:58 +01:00
mixer.h command: don't allow changing volume if no audio initialized 2013-10-12 18:57:02 +02:00
reorder_ch.c ao_lavc: support non-interleaved audio 2013-11-13 20:10:17 +01:00
reorder_ch.h ao_lavc: support non-interleaved audio 2013-11-13 20:10:17 +01:00