Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 539680
Collapse All | Expand All

(-)alsa-plugins-1.0.28/configure.ac (-2 / +18 lines)
Lines 66-72 if test "$use_maemo_rm" = "yes"; then Link Here
66
fi
66
fi
67
67
68
AC_ARG_ENABLE([avcodec],
68
AC_ARG_ENABLE([avcodec],
69
      AS_HELP_STRING([--disable-avcodec], [Don't build plugins depending on avcodec (a52)]))
69
      AS_HELP_STRING([--disable-avcodec], [Do not build plugins depending on avcodec (a52)]))
70
70
71
if test "x$enable_avcodec" != "xno"; then
71
if test "x$enable_avcodec" != "xno"; then
72
  PKG_CHECK_MODULES(AVCODEC, [libavcodec libavutil], [HAVE_AVCODEC=yes], [HAVE_AVCODEC=no])
72
  PKG_CHECK_MODULES(AVCODEC, [libavcodec libavutil], [HAVE_AVCODEC=yes], [HAVE_AVCODEC=no])
Lines 101-106 if test $HAVE_AVCODEC = yes; then Link Here
101
  if test -z "$AVCODEC_HEADER"; then
101
  if test -z "$AVCODEC_HEADER"; then
102
    HAVE_AVCODEC=no
102
    HAVE_AVCODEC=no
103
  fi
103
  fi
104
  SAVE_LIBS=$LIBS
105
  LIBS="$LIBS $AVCODEC_LIBS"
106
  AC_CHECK_FUNCS([av_resample_init])
107
  LIBS=$SAVE_LIBS
104
fi
108
fi
105
109
106
AM_CONDITIONAL(HAVE_AVCODEC, test x$HAVE_AVCODEC = xyes)
110
AM_CONDITIONAL(HAVE_AVCODEC, test x$HAVE_AVCODEC = xyes)
Lines 108-113 AC_SUBST(AVCODEC_CFLAGS) Link Here
108
AC_SUBST(AVCODEC_LIBS)
112
AC_SUBST(AVCODEC_LIBS)
109
AC_SUBST(AVCODEC_HEADER)
113
AC_SUBST(AVCODEC_HEADER)
110
114
115
AC_ARG_ENABLE([avresample],
116
      AS_HELP_STRING([--disable-avresample], [Do not build plugins depending on avcodec (lavrate)]))
117
118
if test "x$enable_avresample" != "xno"; then
119
  PKG_CHECK_MODULES(AVRESAMPLE, [libavresample libavutil], [HAVE_AVRESAMPLE=yes], [HAVE_AVRESAMPLE=no])
120
fi
121
122
AM_CONDITIONAL(HAVE_AVRESAMPLE, test x$HAVE_AVCODEC = xyes)
123
AC_SUBST(AVRESAMPLE_CFLAGS)
124
AC_SUBST(AVRESAMPLE_LIBS)
125
AC_SUBST(AVRESAMPLE_HEADER)
126
111
PKG_CHECK_MODULES(speexdsp, [speexdsp >= 1.2], [HAVE_SPEEXDSP="yes"], [HAVE_SPEEXDSP=""])
127
PKG_CHECK_MODULES(speexdsp, [speexdsp >= 1.2], [HAVE_SPEEXDSP="yes"], [HAVE_SPEEXDSP=""])
112
AM_CONDITIONAL(HAVE_SPEEXDSP, test "$HAVE_SPEEXDSP" = "yes")
128
AM_CONDITIONAL(HAVE_SPEEXDSP, test "$HAVE_SPEEXDSP" = "yes")
113
129
Lines 181-187 AC_OUTPUT([ Link Here
181
	mix/Makefile
197
	mix/Makefile
182
	rate/Makefile
198
	rate/Makefile
183
	a52/Makefile
199
	a52/Makefile
184
	rate-lavc/Makefile
200
	rate-lavr/Makefile
185
	maemo/Makefile
201
	maemo/Makefile
186
	doc/Makefile
202
	doc/Makefile
187
	usb_stream/Makefile
203
	usb_stream/Makefile
(-)alsa-plugins-1.0.28/Makefile.am (+6 lines)
Lines 9-16 if HAVE_SAMPLERATE Link Here
9
SUBDIRS += rate
9
SUBDIRS += rate
10
endif
10
endif
11
if HAVE_AVCODEC
11
if HAVE_AVCODEC
12
SUBDIRS += a52
13
if !HAVE_AVRESAMPLE
12
SUBDIRS += a52 rate-lavc
14
SUBDIRS += a52 rate-lavc
13
endif
15
endif
16
endif
17
if HAVE_AVRESAMPLE
18
SUBDIRS += rate-lavr
19
endif
14
if HAVE_MAEMO_PLUGIN
20
if HAVE_MAEMO_PLUGIN
15
SUBDIRS += maemo
21
SUBDIRS += maemo
16
endif
22
endif
(-)alsa-plugins-1.0.28/rate-lavr/Makefile.am (+22 lines)
Line 0 Link Here
1
asound_module_rate_lavr_LTLIBRARIES = libasound_module_rate_lavr.la
2
3
asound_module_rate_lavrdir = @ALSA_PLUGIN_DIR@
4
5
AM_CFLAGS = -Wall -g @ALSA_CFLAGS@ @AVRESAMPLE_CFLAGS@
6
AM_LDFLAGS = -module -avoid-version -export-dynamic -no-undefined $(LDFLAGS_NOUNDEFINED)
7
8
libasound_module_rate_lavr_la_SOURCES = rate_lavr.c
9
libasound_module_rate_lavr_la_LIBADD = @ALSA_LIBS@ @AVRESAMPLE_LIBS@
10
11
12
install-exec-hook:
13
	rm -f $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate*.so
14
	$(LN_S) libasound_module_rate_lavr.so $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate.so
15
	$(LN_S) libasound_module_rate_lavr.so $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate_higher.so
16
	$(LN_S) libasound_module_rate_lavr.so $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate_high.so
17
	$(LN_S) libasound_module_rate_lavr.so $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate_fast.so
18
	$(LN_S) libasound_module_rate_lavr.so $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate_faster.so
19
20
uninstall-hook:
21
	rm -f $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate*.so
22
	rm -f $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavr*.so
(-)alsa-plugins-1.0.28/rate-lavr/rate_lavr.c (+227 lines)
Line 0 Link Here
1
/*
2
 * Rate converter plugin using libavresample
3
 * Copyright (c) 2014 by Anton Khirnov
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 */
15
16
#include <stdio.h>
17
#include <alsa/asoundlib.h>
18
#include <alsa/pcm_rate.h>
19
20
#include <libavresample/avresample.h>
21
#include <libavutil/channel_layout.h>
22
#include <libavutil/opt.h>
23
#include <libavutil/mathematics.h>
24
#include <libavutil/samplefmt.h>
25
26
27
static int filter_size = 16;
28
static int phase_shift = 10; /* auto-adjusts */
29
static double cutoff = 0; /* auto-adjusts */
30
31
struct rate_src {
32
	AVAudioResampleContext *avr;
33
34
	int in_rate;
35
	int out_rate;
36
	unsigned int channels;
37
};
38
39
static snd_pcm_uframes_t input_frames(void *obj, snd_pcm_uframes_t frames)
40
{
41
	return frames;
42
}
43
44
static snd_pcm_uframes_t output_frames(void *obj, snd_pcm_uframes_t frames)
45
{
46
	return frames;
47
}
48
49
static void pcm_src_free(void *obj)
50
{
51
	struct rate_src *rate = obj;
52
	avresample_free(&rate->avr);
53
}
54
55
static int pcm_src_init(void *obj, snd_pcm_rate_info_t *info)
56
{
57
	struct rate_src *rate = obj;
58
	int i, ir, or;
59
60
	if (!rate->avr || rate->channels != info->channels) {
61
		int ret;
62
63
		pcm_src_free(rate);
64
		rate->channels = info->channels;
65
		ir = rate->in_rate = info->in.rate;
66
		or = rate->out_rate = info->out.rate;
67
		i = av_gcd(or, ir);
68
		if (or > ir) {
69
			phase_shift = or/i;
70
		} else {
71
			phase_shift = ir/i;
72
		}
73
		if (cutoff <= 0.0) {
74
			cutoff = 1.0 - 1.0/filter_size;
75
			if (cutoff < 0.80)
76
				cutoff = 0.80;
77
		}
78
79
		rate->avr = avresample_alloc_context();
80
		if (!rate->avr)
81
			return -ENOMEM;
82
83
		av_opt_set_int(rate->avr, "in_sample_rate",     info->in.rate,  0);
84
		av_opt_set_int(rate->avr, "out_sample_rate",    info->out.rate, 0);
85
		av_opt_set_int(rate->avr, "in_sample_format",   AV_SAMPLE_FMT_S16, 0);
86
		av_opt_set_int(rate->avr, "out_sample_format",  AV_SAMPLE_FMT_S16, 0);
87
		av_opt_set_int(rate->avr, "in_channel_layout",  av_get_default_channel_layout(rate->channels), 0);
88
		av_opt_set_int(rate->avr, "out_channel_layout", av_get_default_channel_layout(rate->channels), 0);
89
90
		av_opt_set_int(rate->avr, "filter_size",        filter_size, 0);
91
		av_opt_set_int(rate->avr, "phase_shift",        phase_shift, 0);
92
		av_opt_set_double(rate->avr, "cutoff",          cutoff,      0);
93
94
		ret = avresample_open(rate->avr);
95
		if (ret < 0) {
96
			avresample_free(&rate->avr);
97
			return -EINVAL;
98
		}
99
	}
100
101
	return 0;
102
}
103
104
static int pcm_src_adjust_pitch(void *obj, snd_pcm_rate_info_t *info)
105
{
106
	struct rate_src *rate = obj;
107
108
	if (info->out.rate != rate->out_rate || info->in.rate != rate->in_rate)
109
		pcm_src_init(obj, info);
110
	return 0;
111
}
112
113
static void pcm_src_reset(void *obj)
114
{
115
	struct rate_src *rate = obj;
116
117
	if (rate->avr) {
118
		avresample_close(rate->avr);
119
		avresample_open(rate->avr);
120
	}
121
}
122
123
static void pcm_src_convert_s16(void *obj, int16_t *dst, unsigned int
124
	dst_frames, const int16_t *src, unsigned int src_frames)
125
{
126
	struct rate_src *rate = obj;
127
	int consumed = 0, chans=rate->channels, ret=0, i;
128
	int total_in = avresample_get_delay(rate->avr) + src_frames;
129
130
	ret = avresample_convert(rate->avr, &dst, dst_frames * chans * 2, dst_frames,
131
	                         &src, src_frames * chans * 2, src_frames);
132
133
	avresample_set_compensation(rate->avr,
134
                                    total_in - src_frames > filter_size ? 0 : 1, src_frames);
135
}
136
137
static void pcm_src_close(void *obj)
138
{
139
	pcm_src_free(obj);
140
}
141
142
#if SND_PCM_RATE_PLUGIN_VERSION >= 0x010002
143
static int get_supported_rates(void *obj, unsigned int *rate_min,
144
			       unsigned int *rate_max)
145
{
146
	*rate_min = *rate_max = 0; /* both unlimited */
147
	return 0;
148
}
149
150
static void dump(void *obj, snd_output_t *out)
151
{
152
	snd_output_printf(out, "Converter: libavr\n");
153
}
154
#endif
155
156
static snd_pcm_rate_ops_t pcm_src_ops = {
157
	.close = pcm_src_close,
158
	.init = pcm_src_init,
159
	.free = pcm_src_free,
160
	.adjust_pitch = pcm_src_adjust_pitch,
161
	.convert_s16 = pcm_src_convert_s16,
162
	.input_frames = input_frames,
163
	.output_frames = output_frames,
164
#if SND_PCM_RATE_PLUGIN_VERSION >= 0x010002
165
	.version = SND_PCM_RATE_PLUGIN_VERSION,
166
	.get_supported_rates = get_supported_rates,
167
	.dump = dump,
168
#endif
169
};
170
171
int pcm_src_open(unsigned int version, void **objp, snd_pcm_rate_ops_t *ops)
172
173
{
174
	struct rate_src *rate;
175
176
#if SND_PCM_RATE_PLUGIN_VERSION < 0x010002
177
	if (version != SND_PCM_RATE_PLUGIN_VERSION) {
178
		fprintf(stderr, "Invalid rate plugin version %x\n", version);
179
		return -EINVAL;
180
	}
181
#endif
182
	rate = calloc(1, sizeof(*rate));
183
	if (!rate)
184
		return -ENOMEM;
185
186
	*objp = rate;
187
	rate->avr = NULL;
188
#if SND_PCM_RATE_PLUGIN_VERSION >= 0x010002
189
	if (version == 0x010001)
190
		memcpy(ops, &pcm_src_ops, sizeof(snd_pcm_rate_old_ops_t));
191
	else
192
#endif
193
		*ops = pcm_src_ops;
194
	return 0;
195
}
196
197
int SND_PCM_RATE_PLUGIN_ENTRY(lavcrate)(unsigned int version, void **objp,
198
			snd_pcm_rate_ops_t *ops)
199
{
200
	return pcm_src_open(version, objp, ops);
201
}
202
int SND_PCM_RATE_PLUGIN_ENTRY(lavcrate_higher)(unsigned int version,
203
			void **objp, snd_pcm_rate_ops_t *ops)
204
{
205
	filter_size = 64;
206
	return pcm_src_open(version, objp, ops);
207
}
208
int SND_PCM_RATE_PLUGIN_ENTRY(lavcrate_high)(unsigned int version,
209
			void **objp, snd_pcm_rate_ops_t *ops)
210
{
211
	filter_size = 32;
212
	return pcm_src_open(version, objp, ops);
213
}
214
int SND_PCM_RATE_PLUGIN_ENTRY(lavcrate_fast)(unsigned int version,
215
			void **objp, snd_pcm_rate_ops_t *ops)
216
{
217
	filter_size = 8;
218
	return pcm_src_open(version, objp, ops);
219
}
220
int SND_PCM_RATE_PLUGIN_ENTRY(lavcrate_faster)(unsigned int version,
221
			void **objp, snd_pcm_rate_ops_t *ops)
222
{
223
	filter_size = 4;
224
	return pcm_src_open(version, objp, ops);
225
}
226
227

Return to bug 539680