summaryrefslogtreecommitdiffstats
path: root/lib/rbcodec/dsp/dsp_sample_io.h
blob: 095aea3f3a31cf691e5359321d5a0e123aa9e00f (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
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2012 Michael Sevakis
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#ifndef DSP_SAMPLE_IO_H
#define DSP_SAMPLE_IO_H

/* 16-bit samples are scaled based on these constants. The shift should be
 * no more than 15.
 */
#define WORD_SHIFT      12
#define WORD_FRACBITS   27
#define NATIVE_DEPTH    16

struct sample_io_data;

/* DSP initial buffer input function call prototype */
typedef void (*sample_input_fn_type)(struct sample_io_data *this,
                                     struct dsp_buffer **buf_p);

/* DSP final buffer output function call prototype */
typedef void (*sample_output_fn_type)(struct sample_io_data *this,
                                      struct dsp_buffer *src,
                                      struct dsp_buffer *dst);

/* This becomes part of the DSP aggregate */
struct sample_io_data
{
    int outcount;                 /* 00h: Output count */
    struct sample_format format;  /* Format for next dsp_process call */
    int sample_depth;             /* Codec-specified sample depth */           
    int stereo_mode;              /* Codec-specified channel format */
    sample_input_fn_type input_samples; /* Initial input function */
    struct dsp_buffer sample_buf; /* Buffer descriptor for converted samples */
    int32_t *sample_buf_p[2];     /* Internal format buffer pointers */
    sample_output_fn_type output_samples; /* Final output function */
    unsigned int output_sampr;    /* Master output samplerate */
    uint8_t format_dirty;         /* Format change set, avoids superfluous
                                     increments before carrying it out */
    uint8_t output_version;       /* Format version of src buffer at output */
};

void dsp_sample_input_init(struct sample_io_data *this, unsigned int dsp_id) INIT_ATTR;
void dsp_sample_input_flush(struct sample_io_data *this);
void dsp_sample_input_format_change(struct sample_io_data *this,
                                    struct sample_format *format);

void dsp_sample_output_init(struct sample_io_data *this) INIT_ATTR;
void dsp_sample_output_flush(struct sample_io_data *this);
void dsp_sample_output_format_change(struct sample_io_data *this,
                                     struct sample_format *format);

/* Sample IO watches the format setting from the codec */
void dsp_sample_io_init(struct sample_io_data *this, unsigned int dsp_id) INIT_ATTR;
bool dsp_sample_io_configure(struct sample_io_data *this,
                             unsigned int setting,
                             intptr_t *value_p);

#endif /* DSP_SAMPLE_IO_H */