Developer World
Spresense SDK Library v3.3.0-375c679
al_audiodrv.h
1/****************************************************************************
2 * modules/include/audiolite/al_audiodrv.h
3 *
4 * Copyright 2023 Sony Semiconductor Solutions Corporation
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 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17 * the names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
35
36#ifndef __INCLUDE_AUDIOLITE_AUDIODRV_H
37#define __INCLUDE_AUDIOLITE_AUDIODRV_H
38
39/****************************************************************************
40 * Included Files
41 ****************************************************************************/
42
43#include <nuttx/config.h>
44
45#include <errno.h>
46#include <mqueue.h>
47#include <mossfw/mossfw_lock.h>
48
49/****************************************************************************
50 * Pre-processor Definitions
51 ****************************************************************************/
52
53#define ALDRV_MODE_OUTPUT (1)
54#define ALDRV_MODE_INPUT (2)
55
56/****************************************************************************
57 * Class Definitions
58 ****************************************************************************/
59
60/****************************************************************************
61 * class: audiolite_drvlistener
62 ****************************************************************************/
63
65{
66 public:
67 virtual ~audiolite_drvlistener(){};
68 virtual void on_pusheddata(FAR struct ap_buffer_s *apb) = 0;
69 virtual void on_popeddata(FAR struct ap_buffer_s *apb) = 0;
70 virtual void on_stopped(void) = 0;
71 virtual void on_overflowed(void) = 0;
72 virtual void on_underflowed(void) = 0;
73};
74
75/****************************************************************************
76 * class: audiolite_driver
77 ****************************************************************************/
78
80{
81 protected:
82 int _fd;
83 int _mode;
84 int _volume;
85 mqd_t _mq;
86 mossfw_thread_t _tid;
87 audiolite_drvlistener *_listener;
88 mossfw_lock_t _lock;
89
90 int _fs;
91 int _bps;
92 int _chnum;
93 int _maxch;
94 const char *_devpath;
95 const char *_mqpath;
96 int _is_started;
97
98 void cleanup_messageq();
99 int update_audioparam();
100 int stop_thread(void);
101 int setup_driver();
102 int set_volume_nolock(int vol);
103 int single_ioctl(int ioc);
104 int set_audioparam(int fs, int bps, int chnum);
105
106 public:
107 audiolite_driver(int mode, const char *devpath,
108 const char *mqpath, int maxch);
110
111 void set_listener(audiolite_drvlistener *l){ _listener = l; };
112 int set_volume(int vol);
113
114 int enqueue_buffer(FAR struct ap_buffer_s *apb);
115 int start(int fs, int bps, int chnum);
116 int stop(void);
117 int pause(void);
118 int resume(void);
119
120 void reset(void);
121
122 static void *message_thread(void *arg);
123};
124
125#endif /* __INCLUDE_AUDIOLITE_AUDIODRV_H */
Definition: al_audiodrv.h:80
Definition: al_audiodrv.h:65