summaryrefslogtreecommitdiffstats
path: root/libhb/audio_resample.h
diff options
context:
space:
mode:
authorRodeo <[email protected]>2012-07-15 16:40:46 +0000
committerRodeo <[email protected]>2012-07-15 16:40:46 +0000
commitebe7a46debf25f8c6b84320f69dd00d83a5a0b45 (patch)
tree74e1656d9dd884e96f0e4b5f8d0072dcf89ad515 /libhb/audio_resample.h
parent8dafff9bfd96dcbbd10247b0ef7eee4cfddfaa6e (diff)
hb_audio_resample: libvaresample wrapper.
Avoids having code that's mostly identical in multiple files. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4838 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/audio_resample.h')
-rw-r--r--libhb/audio_resample.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/libhb/audio_resample.h b/libhb/audio_resample.h
new file mode 100644
index 000000000..5982905e6
--- /dev/null
+++ b/libhb/audio_resample.h
@@ -0,0 +1,81 @@
+/* audio_resample.h
+ *
+ * Copyright (c) 2003-2012 HandBrake Team
+ * This file is part of the HandBrake source code
+ * Homepage: <http://handbrake.fr/>
+ * It may be used under the terms of the GNU General Public License v2.
+ * For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
+ */
+
+/* Implements a libavresample wrapper for convenience.
+ *
+ * Supports sample_fmt and channel_layout conversion.
+ *
+ * sample_rate conversion will come later (libavresample doesn't support
+ * sample_rate conversion with float samples yet). */
+
+#ifndef AUDIO_RESAMPLE_H
+#define AUDIO_RESAMPLE_H
+
+#include <stdint.h>
+#include "libavutil/audioconvert.h"
+#include "libavresample/avresample.h"
+
+typedef struct
+{
+ int resample_needed;
+ AVAudioResampleContext *avresample;
+
+ struct
+ {
+ int channels;
+ int linesize;
+ uint64_t channel_layout;
+ enum AVSampleFormat sample_fmt;
+ } in;
+
+ struct
+ {
+ int channels;
+ int linesize;
+ int sample_size;
+ uint64_t channel_layout;
+ enum AVSampleFormat sample_fmt;
+ enum AVMatrixEncoding matrix_encoding;
+ } out;
+} hb_audio_resample_t;
+
+/* Initialize an hb_audio_resample_t to convert audio to the requested
+ * sample_fmt and channel_layout, using the specified matrix_encoding.
+ *
+ * Input characteristics are set via hb_audio_resample_update().
+ */
+hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat output_sample_fmt,
+ uint64_t output_channel_layout,
+ enum AVMatrixEncoding matrix_encoding);
+
+/* Update an hb_audio_resample_t, setting the input sample characteristics.
+ *
+ * Can be called whenever the input type may change.
+ *
+ * new_channel_layout is sanitized automatically.
+ */
+int hb_audio_resample_update(hb_audio_resample_t *resample,
+ enum AVSampleFormat new_sample_fmt,
+ uint64_t new_channel_layout,
+ int new_channels);
+
+/* Free an hb_audio_remsample_t. */
+void hb_audio_resample_free(hb_audio_resample_t *resample);
+
+/* Convert input samples to the requested output characteristics
+ * (sample_fmt and channel_layout + matrix_encoding).
+ *
+ * Returns an hb_buffer_t with the converted output.
+ *
+ * resampling is only done when necessary.
+ */
+hb_buffer_t* hb_audio_resample(hb_audio_resample_t *resample,
+ void *samples, int nsamples);
+
+#endif /* AUDIO_RESAMPLE_H */