···11+/*****************************************************************************
22+ * pce *
33+ *****************************************************************************/
44+55+/*****************************************************************************
66+ * File name: src/devices/speaker.h *
77+ * Created: 2022-02-08 by Hampa Hug <hampa@hampa.ch> *
88+ * Copyright: (C) 2022-2024 Hampa Hug <hampa@hampa.ch> *
99+ *****************************************************************************/
1010+1111+/*****************************************************************************
1212+ * This program is free software. You can redistribute it and / or modify it *
1313+ * under the terms of the GNU General Public License version 2 as published *
1414+ * by the Free Software Foundation. *
1515+ * *
1616+ * This program is distributed in the hope that it will be useful, but *
1717+ * WITHOUT ANY WARRANTY, without even the implied warranty of *
1818+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
1919+ * Public License for more details. *
2020+ *****************************************************************************/
2121+2222+2323+#ifndef PCE_DEVICES_SPEAKER_H
2424+#define PCE_DEVICES_SPEAKER_H 1
2525+2626+2727+#include <drivers/sound/sound.h>
2828+2929+3030+#define SPEAKER_BUF 1024
3131+3232+3333+typedef struct {
3434+ sound_drv_t *drv;
3535+3636+ unsigned long srate;
3737+ unsigned long input_clock;
3838+ unsigned speed_mul;
3939+4040+ char enabled;
4141+4242+ int speaker_inp;
4343+ uint16_t speaker_val;
4444+ uint16_t sample_acc;
4545+4646+ uint16_t val_n;
4747+ uint16_t val_p;
4848+4949+ uint16_t timeout_val;
5050+ unsigned long timeout_clk;
5151+ unsigned long timeout_max;
5252+5353+ unsigned long clk;
5454+ unsigned long rem;
5555+5656+ unsigned long lowpass_freq;
5757+ sound_iir2_t iir;
5858+5959+ unsigned buf_cnt;
6060+ uint16_t buf[SPEAKER_BUF];
6161+6262+ void *get_clock_ext;
6363+ unsigned long (*get_clock) (void *ext);
6464+} speaker_t;
6565+6666+6767+void spk_init (speaker_t *spk, int level);
6868+void spk_free (speaker_t *spk);
6969+7070+speaker_t *_spk_new (int level);
7171+void spk_del (speaker_t *spk);
7272+7373+void spk_set_clock_fct (speaker_t *spk, void *ext, void *fct);
7474+7575+void spk_set_input_clock (speaker_t *spk, unsigned long clk);
7676+7777+int spk_set_driver (speaker_t *spk, const char *driver, unsigned long srate);
7878+7979+void spk_set_lowpass (speaker_t *spk, unsigned long freq);
8080+8181+void spk_set_volume (speaker_t *spk, unsigned vol);
8282+8383+void spk_set_input (speaker_t *spk, int val);
8484+8585+void spk_check (speaker_t *spk);
8686+8787+8888+#endif