summaryrefslogtreecommitdiff
path: root/gst/legacyresample/resample.h
blob: ba14983b6dd05bc8dc3696ef412fe33aa7ff62bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* Resampling library
 * Copyright (C) <2001> David Schleef <ds@schleef.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#ifndef __RESAMPLE_H__
#define __RESAMPLE_H__

#include "functable.h"
#include "buffer.h"

#ifndef M_PI
#define M_PI  3.14159265358979323846
#endif

#ifdef WIN32
#define rint(x) (floor((x)+0.5))  
#endif 

typedef enum {
        RESAMPLE_FORMAT_S16 = 0,
        RESAMPLE_FORMAT_S32,
        RESAMPLE_FORMAT_F32,
        RESAMPLE_FORMAT_F64
} ResampleFormat;

typedef void (*ResampleCallback) (void *);

typedef struct _ResampleState ResampleState;

struct _ResampleState {
        /* parameters */

        int n_channels;
        ResampleFormat format;

        int filter_length;

        double i_rate;
        double o_rate;

        int method;

        /* internal parameters */

        int need_reinit;

        double halftaps;

        /* filter state */

        unsigned char *o_buf;
        int o_size;

        AudioresampleBufferQueue *queue;
        int eos;
        int started;

        int sample_size;

        unsigned char *buffer;
        int buffer_len;
        int buffer_filled;

        double i_start;
        double o_start;

        double i_inc;
        double o_inc;

        double sinc_scale;

        double i_end;
        double o_end;

        int i_samples;
        int o_samples;

        //void *i_buf;

        Functable *ft;

        double *out_tmp;
};

void resample_init (void);
void resample_cleanup (void);

ResampleState *resample_new (void);
void resample_free (ResampleState *state);

void resample_add_input_data (ResampleState * r, void *data, int size,
    ResampleCallback free_func, void *closure);
void resample_input_eos (ResampleState *r);
void resample_input_flush (ResampleState *r);
void resample_input_pushthrough (ResampleState *r);

int resample_get_output_size_for_input (ResampleState * r, int size);
int resample_get_input_size_for_output (ResampleState * r, int size);

int resample_get_output_size (ResampleState *r);
int resample_get_output_data (ResampleState *r, void *data, int size);

void resample_set_filter_length (ResampleState *r, int length);
void resample_set_input_rate (ResampleState *r, double rate);
void resample_set_output_rate (ResampleState *r, double rate);
void resample_set_n_channels (ResampleState *r, int n_channels);
void resample_set_format (ResampleState *r, ResampleFormat format);
void resample_set_method (ResampleState *r, int method);
int resample_format_size (ResampleFormat format);

void resample_scale_ref (ResampleState * r);
void resample_scale_functable (ResampleState * r);

#endif /* __RESAMPLE_H__ */