summaryrefslogtreecommitdiffstats
path: root/converter.h
blob: 5be03dce952611771831a00c06f826a206ab2b3b (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
#ifndef foosydneyconverterhfoo
#define foosydneyconverterhfoo

#include "sydney.h"
#include "volscale.h"
#include "byteswap.h"
#include "zero.h"
#include "add.h"
#include "bbuffer.h"
#include "resample.h"
#include "format.h"
#include "common.h"
#include "interleave.h"

typedef struct converter converter_t;

struct converter {
    sa_pcm_format_t from_pcm_format, to_pcm_format;
    unsigned from_nchannels, to_nchannels;
    unsigned from_rate, to_rate;

    int sum_required;
    int remap_required;
    
    sa_pcm_format_t work_pcm_format;
    
    size_t from_sample_size, work_sample_size, to_sample_size;

    byteswap_func_t pre_byteswap_func, post_byteswap_func;
    format_func_t pre_format_func, post_format_func;
    volscale_func_t volscale_func;
    zero_func_t zero_func;
    add_func_t add_func;
    resample_func_t resample_func;
    interleave_func_t interleave_func;

    SpeexResamplerState *speex;

    bbuffer_t bb_pre_byteswap,
        bb_pre_format,
        bb_volscale,
        bb_remap,
        bb_resample,
        bb_post_format,
        bb_post_byteswap,
        bb_interleave,
        bb_tmp;

    void **from_process_data, **to_process_data;
    size_t *from_stride, *to_stride;

    int32_t *volume_factor, *volume_divisor;
    int no_volume;

    int *channel_map_table;

    void *zero_buffer;
    size_t zero_size;
};

int converter_init(converter_t *c, const pcm_attrs_t *from, const pcm_attrs_t *to, int dynamic_rate_enabled);
void converter_done(converter_t *c);

int converter_go(
        converter_t *c,
        const void *const src[], const size_t sstr[], int sinterleave,
        const void **dst[], size_t *dstr[], int dinterleave,
        size_t *size);

int converter_go_interleaved(
        converter_t *c,
        const void *const data, 
        const void **dst[], size_t *dstr[], int dinterleave,
        size_t *size);

void converter_set_volume(converter_t *c, int vol[]);

void converter_set_ratio(converter_t *c, unsigned rate1, unsigned rate2);


#endif