[cf083e8] | 1 | /*
|
---|
[a64970e1] | 2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
[cf083e8] | 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
|
---|
[763444e] | 33 | * @brief Sound Blaster Digital Sound Processor (DSP) helper functions.
|
---|
[cf083e8] | 34 | */
|
---|
| 35 | #ifndef DRV_AUDIO_SB16_DSP_H
|
---|
| 36 | #define DRV_AUDIO_SB16_DSP_H
|
---|
| 37 |
|
---|
[c885a21] | 38 | #include <ddf/driver.h>
|
---|
[0687e1b] | 39 | #include <libarch/ddi.h>
|
---|
[763444e] | 40 | #include <errno.h>
|
---|
[ea6c838] | 41 | #include <pcm/sample_format.h>
|
---|
[f0241bda] | 42 | #include <audio_pcm_iface.h>
|
---|
[0687e1b] | 43 |
|
---|
[cf083e8] | 44 | #include "registers.h"
|
---|
[fb6c98f] | 45 | typedef enum {
|
---|
| 46 | DSP_PLAYBACK_ACTIVE_EVENTS,
|
---|
| 47 | DSP_CAPTURE_ACTIVE_EVENTS,
|
---|
| 48 | DSP_PLAYBACK_NOEVENTS,
|
---|
| 49 | DSP_CAPTURE_NOEVENTS,
|
---|
[daed689] | 50 | DSP_PLAYBACK_TERMINATE,
|
---|
| 51 | DSP_CAPTURE_TERMINATE,
|
---|
[fb6c98f] | 52 | DSP_READY,
|
---|
| 53 | DSP_NO_BUFFER,
|
---|
[a64970e1] | 54 | DSP_QUIESCED
|
---|
[fb6c98f] | 55 | } dsp_state_t;
|
---|
[cf083e8] | 56 |
|
---|
[6136393] | 57 | typedef struct sb_dsp {
|
---|
[bf38143] | 58 | sb16_regs_t *regs;
|
---|
[c885a21] | 59 | int dma8_channel;
|
---|
| 60 | int dma16_channel;
|
---|
[bf38143] | 61 | struct {
|
---|
| 62 | uint8_t major;
|
---|
| 63 | uint8_t minor;
|
---|
| 64 | } version;
|
---|
[01aef43] | 65 | struct {
|
---|
[dce7e41] | 66 | uint8_t *data;
|
---|
| 67 | size_t size;
|
---|
[01aef43] | 68 | } buffer;
|
---|
[dce7e41] | 69 | struct {
|
---|
| 70 | uint8_t mode;
|
---|
[c17c872c] | 71 | uint16_t samples;
|
---|
[57e8b3b] | 72 | unsigned frame_count;
|
---|
[a3ab774] | 73 | } active;
|
---|
[fb6c98f] | 74 | dsp_state_t state;
|
---|
[7ca22e5] | 75 | async_sess_t *event_session;
|
---|
| 76 | async_exch_t *event_exchange;
|
---|
[c885a21] | 77 | ddf_dev_t *sb_dev;
|
---|
[bf38143] | 78 | } sb_dsp_t;
|
---|
[cf083e8] | 79 |
|
---|
[b7fd2a0] | 80 | errno_t sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs, ddf_dev_t *dev,
|
---|
[c885a21] | 81 | int dma8, int dma16);
|
---|
[a64970e1] | 82 | void sb_dsp_quiesce(sb_dsp_t *dsp);
|
---|
[f14e6ea] | 83 | void sb_dsp_interrupt(sb_dsp_t *dsp);
|
---|
[f0241bda] | 84 | unsigned sb_dsp_query_cap(sb_dsp_t *dsp, audio_cap_t cap);
|
---|
[b7fd2a0] | 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,
|
---|
[5b0cf63] | 87 | pcm_sample_format_t *format);
|
---|
[b7fd2a0] | 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);
|
---|
[5b0cf63] | 90 | async_sess_t *sb_dsp_get_event_session(sb_dsp_t *dsp);
|
---|
[b7fd2a0] | 91 | errno_t sb_dsp_release_buffer(sb_dsp_t *dsp);
|
---|
| 92 | errno_t sb_dsp_start_playback(sb_dsp_t *dsp, unsigned frames,
|
---|
[346643c] | 93 | unsigned channels, unsigned sample_rate, pcm_sample_format_t format);
|
---|
[b7fd2a0] | 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,
|
---|
[346643c] | 96 | unsigned channels, unsigned sample_rate, pcm_sample_format_t format);
|
---|
[b7fd2a0] | 97 | errno_t sb_dsp_stop_capture(sb_dsp_t *dsp, bool immediate);
|
---|
[43dec08] | 98 |
|
---|
[cf083e8] | 99 | #endif
|
---|
| 100 | /**
|
---|
| 101 | * @}
|
---|
| 102 | */
|
---|