• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***
2   This file is part of PulseAudio.
3 
4   PulseAudio is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as published
6   by the Free Software Foundation; either version 2.1 of the License,
7   or (at your option) any later version.
8 
9   PulseAudio is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   General Public License for more details.
13 
14   You should have received a copy of the GNU Lesser General Public License
15   along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
16 ***/
17 
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21 
22 #include <stdio.h>
23 
24 #include <pulse/sample.h>
25 
26 #include <pulsecore/resampler.h>
27 #include <pulsecore/macro.h>
28 #include <pulsecore/memblock.h>
29 
30 struct resample_flags {
31     const char *str;
32     pa_resample_flags_t value;
33 };
34 
35 /* Call like this to get an initializer for struct resample_flags:
36  *     RESAMPLE_FLAGS(PA_RESAMPLER_PRODUCE_LFE)
37  */
38 #define RESAMPLE_FLAGS(flags) { .str = #flags, .value = (flags) }
39 
40 
main(int argc,char * argv[])41 int main(int argc, char *argv[]) {
42 
43     static const pa_channel_map maps[] = {
44         { 1, { PA_CHANNEL_POSITION_MONO } },
45         { 2, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT } },
46         { 3, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_CENTER } },
47         { 3, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_LFE } },
48         { 3, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_CENTER } },
49         { 4, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_CENTER, PA_CHANNEL_POSITION_LFE } },
50         { 4, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_CENTER, PA_CHANNEL_POSITION_REAR_CENTER } },
51         { 4, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT } },
52         { 5, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT, PA_CHANNEL_POSITION_CENTER } },
53         { 5, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT, PA_CHANNEL_POSITION_LFE } },
54         { 6, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT, PA_CHANNEL_POSITION_LFE, PA_CHANNEL_POSITION_CENTER } },
55         { 8, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT, PA_CHANNEL_POSITION_LFE, PA_CHANNEL_POSITION_CENTER, PA_CHANNEL_POSITION_SIDE_LEFT, PA_CHANNEL_POSITION_SIDE_RIGHT } },
56         { 0, { 0 } }
57     };
58 
59     static const struct resample_flags flag_sets[] = {
60         RESAMPLE_FLAGS(0),
61         RESAMPLE_FLAGS(PA_RESAMPLER_NO_REMAP),
62         RESAMPLE_FLAGS(PA_RESAMPLER_NO_REMIX),
63         RESAMPLE_FLAGS(PA_RESAMPLER_PRODUCE_LFE),
64         RESAMPLE_FLAGS(PA_RESAMPLER_NO_FILL_SINK),
65         RESAMPLE_FLAGS(PA_RESAMPLER_PRODUCE_LFE | PA_RESAMPLER_NO_FILL_SINK),
66         RESAMPLE_FLAGS(PA_RESAMPLER_CONSUME_LFE),
67         RESAMPLE_FLAGS(PA_RESAMPLER_CONSUME_LFE | PA_RESAMPLER_NO_FILL_SINK),
68         RESAMPLE_FLAGS(PA_RESAMPLER_PRODUCE_LFE | PA_RESAMPLER_CONSUME_LFE),
69         RESAMPLE_FLAGS(PA_RESAMPLER_PRODUCE_LFE | PA_RESAMPLER_CONSUME_LFE | PA_RESAMPLER_NO_FILL_SINK),
70         { .str = NULL, .value = 0 },
71     };
72 
73     unsigned i, j, k;
74     pa_mempool *pool;
75     unsigned crossover_freq = 120;
76 
77     pa_log_set_level(PA_LOG_DEBUG);
78 
79     pa_assert_se(pool = pa_mempool_new(PA_MEM_TYPE_PRIVATE, 0, true));
80 
81     for (i = 0; maps[i].channels > 0; i++)
82         for (j = 0; maps[j].channels > 0; j++) {
83             char a[PA_CHANNEL_MAP_SNPRINT_MAX], b[PA_CHANNEL_MAP_SNPRINT_MAX];
84             pa_resampler *r;
85             pa_sample_spec ss1, ss2;
86 
87             ss1.channels = maps[i].channels;
88             ss2.channels = maps[j].channels;
89 
90             ss1.rate = ss2.rate = 44100;
91             ss1.format = ss2.format = PA_SAMPLE_S16NE;
92 
93             for (k = 0; flag_sets[k].str; k++) {
94                 pa_log_info("Converting from '%s' to '%s' with flags %s.", pa_channel_map_snprint(a, sizeof(a), &maps[i]),
95                             pa_channel_map_snprint(b, sizeof(b), &maps[j]), flag_sets[k].str);
96 
97                 r = pa_resampler_new(pool, &ss1, &maps[i], &ss2, &maps[j], crossover_freq, PA_RESAMPLER_AUTO,
98                                      flag_sets[k].value);
99 
100                 /* We don't really care for the resampler. We just want to
101                  * see the remixing debug output. */
102 
103                 pa_resampler_free(r);
104             }
105         }
106 
107     pa_mempool_unref(pool);
108 
109     return 0;
110 }
111