1 | /*
|
---|
2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
3 | * Copyright (c) 2011 Jan Vesely
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 | /** @addtogroup drvaudiosb16
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief Sound Blaster Digital Sound Processor (DSP) helper functions.
|
---|
34 | */
|
---|
35 | #ifndef DRV_AUDIO_SB16_DSP_H
|
---|
36 | #define DRV_AUDIO_SB16_DSP_H
|
---|
37 |
|
---|
38 | #include <ddf/driver.h>
|
---|
39 | #include <libarch/ddi.h>
|
---|
40 | #include <errno.h>
|
---|
41 | #include <pcm/sample_format.h>
|
---|
42 | #include <audio_pcm_iface.h>
|
---|
43 |
|
---|
44 | #include "registers.h"
|
---|
45 | typedef enum {
|
---|
46 | DSP_PLAYBACK_ACTIVE_EVENTS,
|
---|
47 | DSP_CAPTURE_ACTIVE_EVENTS,
|
---|
48 | DSP_PLAYBACK_NOEVENTS,
|
---|
49 | DSP_CAPTURE_NOEVENTS,
|
---|
50 | DSP_PLAYBACK_TERMINATE,
|
---|
51 | DSP_CAPTURE_TERMINATE,
|
---|
52 | DSP_READY,
|
---|
53 | DSP_NO_BUFFER,
|
---|
54 | DSP_QUIESCED
|
---|
55 | } dsp_state_t;
|
---|
56 |
|
---|
57 | typedef struct sb_dsp {
|
---|
58 | sb16_regs_t *regs;
|
---|
59 | int dma8_channel;
|
---|
60 | int dma16_channel;
|
---|
61 | struct {
|
---|
62 | uint8_t major;
|
---|
63 | uint8_t minor;
|
---|
64 | } version;
|
---|
65 | struct {
|
---|
66 | uint8_t *data;
|
---|
67 | size_t size;
|
---|
68 | } buffer;
|
---|
69 | struct {
|
---|
70 | uint8_t mode;
|
---|
71 | uint16_t samples;
|
---|
72 | unsigned frame_count;
|
---|
73 | } active;
|
---|
74 | dsp_state_t state;
|
---|
75 | async_sess_t *event_session;
|
---|
76 | async_exch_t *event_exchange;
|
---|
77 | ddf_dev_t *sb_dev;
|
---|
78 | } sb_dsp_t;
|
---|
79 |
|
---|
80 | errno_t sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs, ddf_dev_t *dev,
|
---|
81 | int dma8, int dma16);
|
---|
82 | void sb_dsp_quiesce(sb_dsp_t *dsp);
|
---|
83 | void sb_dsp_interrupt(sb_dsp_t *dsp);
|
---|
84 | unsigned sb_dsp_query_cap(sb_dsp_t *dsp, audio_cap_t cap);
|
---|
85 | errno_t sb_dsp_get_buffer_position(sb_dsp_t *dsp, size_t *size);
|
---|
86 | errno_t sb_dsp_test_format(sb_dsp_t *dsp, unsigned *channels, unsigned *rate,
|
---|
87 | pcm_sample_format_t *format);
|
---|
88 | errno_t sb_dsp_get_buffer(sb_dsp_t *dsp, void **buffer, size_t *size);
|
---|
89 | errno_t sb_dsp_set_event_session(sb_dsp_t *dsp, async_sess_t *session);
|
---|
90 | async_sess_t *sb_dsp_get_event_session(sb_dsp_t *dsp);
|
---|
91 | errno_t sb_dsp_release_buffer(sb_dsp_t *dsp);
|
---|
92 | errno_t sb_dsp_start_playback(sb_dsp_t *dsp, unsigned frames,
|
---|
93 | unsigned channels, unsigned sample_rate, pcm_sample_format_t format);
|
---|
94 | errno_t sb_dsp_stop_playback(sb_dsp_t *dsp, bool immediate);
|
---|
95 | errno_t sb_dsp_start_capture(sb_dsp_t *dsp, unsigned frames,
|
---|
96 | unsigned channels, unsigned sample_rate, pcm_sample_format_t format);
|
---|
97 | errno_t sb_dsp_stop_capture(sb_dsp_t *dsp, bool immediate);
|
---|
98 |
|
---|
99 | #endif
|
---|
100 | /**
|
---|
101 | * @}
|
---|
102 | */
|
---|