1
/* $Id: resample.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJMEDIA_RESAMPLE_H__
21
#define __PJMEDIA_RESAMPLE_H__
27
* @brief Sample rate converter.
29
#include <pjmedia/types.h>
30
#include <pjmedia/port.h>
33
* @defgroup PJMEDIA_RESAMPLE Resampling Algorithm
34
* @ingroup PJMEDIA_FRAME_OP
35
* @brief Sample rate conversion algorithm
38
* This section describes the base resampling functions. In addition to this,
39
* application can use the @ref PJMEDIA_RESAMPLE_PORT which provides
40
* media port abstraction for the base resampling algorithm.
46
* This file declares two types of API:
48
* Application can use #pjmedia_resample_create() and #pjmedia_resample_run()
49
* to convert a frame from source rate to destination rate. The inpuit frame
50
* must have a constant length.
52
* Alternatively, application can create a resampling port with
53
* #pjmedia_resample_port_create() and connect the port to other ports to
54
* change the sampling rate of the samples.
59
* Opaque resample session.
61
typedef struct pjmedia_resample pjmedia_resample;
64
* Create a frame based resample session.
66
* @param pool Pool to allocate the structure and buffers.
67
* @param high_quality If true, then high quality conversion will be
68
* used, at the expense of more CPU and memory,
69
* because temporary buffer needs to be created.
70
* @param large_filter If true, large filter size will be used.
71
* @param channel_count Number of channels.
72
* @param rate_in Clock rate of the input samples.
73
* @param rate_out Clock rate of the output samples.
74
* @param samples_per_frame Number of samples per frame in the input.
75
* @param p_resample Pointer to receive the resample session.
77
* @return PJ_SUCCESS on success.
79
PJ_DECL(pj_status_t) pjmedia_resample_create(pj_pool_t *pool,
80
pj_bool_t high_quality,
81
pj_bool_t large_filter,
82
unsigned channel_count,
85
unsigned samples_per_frame,
86
pjmedia_resample **p_resample);
90
* Use the resample session to resample a frame. The frame must have the
91
* same size and settings as the resample session, or otherwise the
92
* behavior is undefined.
94
* @param resample The resample session.
95
* @param input Buffer containing the input samples.
96
* @param output Buffer to store the output samples.
98
PJ_DECL(void) pjmedia_resample_run( pjmedia_resample *resample,
99
const pj_int16_t *input,
100
pj_int16_t *output );
104
* Get the input frame size of a resample session.
106
* @param resample The resample session.
108
* @return The frame size, in number of samples.
110
PJ_DECL(unsigned) pjmedia_resample_get_input_size(pjmedia_resample *resample);
114
* Destroy the resample.
116
* @param resample The resample session.
118
PJ_DECL(void) pjmedia_resample_destroy(pjmedia_resample *resample);
125
* @defgroup PJMEDIA_RESAMPLE_PORT Resample Port
126
* @ingroup PJMEDIA_PORT
127
* @brief Audio sample rate conversion
130
* This section describes media port abstraction for @ref PJMEDIA_RESAMPLE.
135
* Option flags that can be specified when creating resample port.
137
enum pjmedia_resample_port_options
140
* Do not use high quality resampling algorithm, but use linear
143
PJMEDIA_RESAMPLE_USE_LINEAR = 1,
146
* Use small filter workspace when high quality resampling is
149
PJMEDIA_RESAMPLE_USE_SMALL_FILTER = 2,
152
* Do not destroy downstream port when resample port is destroyed.
154
PJMEDIA_RESAMPLE_DONT_DESTROY_DN = 4
160
* Create a resample port. This creates a bidirectional resample session,
161
* which will resample frames when the port's get_frame() and put_frame()
164
* When the resample port's get_frame() is called, this port will get
165
* a frame from the downstream port and resample the frame to the target
166
* clock rate before returning it to the caller.
168
* When the resample port's put_frame() is called, this port will resample
169
* the frame to the downstream port's clock rate before giving the frame
170
* to the downstream port.
172
* @param pool Pool to allocate the structure and buffers.
173
* @param dn_port The downstream port, which clock rate is to
174
* be converted to the target clock rate.
175
* @param clock_rate Target clock rate.
176
* @param options Flags from #pjmedia_resample_port_options.
177
* When this flag is zero, the default behavior
178
* is to use high quality resampling with
179
* large filter, and to destroy downstream port
180
* when resample port is destroyed.
181
* @param p_port Pointer to receive the resample port instance.
183
* @return PJ_SUCCESS on success.
185
PJ_DECL(pj_status_t) pjmedia_resample_port_create( pj_pool_t *pool,
186
pjmedia_port *dn_port,
189
pjmedia_port **p_port );
199
#endif /* __PJMEDIA_RESAMPLE_H__ */