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#include "qemu/osdep.h"
26#include "qemu/host-utils.h"
27#include "qemu/module.h"
28#include "audio.h"
29#include "qemu/timer.h"
30
31#define AUDIO_CAP "noaudio"
32#include "audio_int.h"
33
34typedef struct NoVoiceOut {
35 HWVoiceOut hw;
36 RateCtl rate;
37} NoVoiceOut;
38
39typedef struct NoVoiceIn {
40 HWVoiceIn hw;
41 RateCtl rate;
42} NoVoiceIn;
43
44static size_t no_write(HWVoiceOut *hw, void *buf, size_t len)
45{
46 NoVoiceOut *no = (NoVoiceOut *) hw;
47 return audio_rate_get_bytes(&hw->info, &no->rate, len);
48}
49
50static int no_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque)
51{
52 NoVoiceOut *no = (NoVoiceOut *) hw;
53
54 audio_pcm_init_info (&hw->info, as);
55 hw->samples = 1024;
56 audio_rate_start(&no->rate);
57 return 0;
58}
59
60static void no_fini_out (HWVoiceOut *hw)
61{
62 (void) hw;
63}
64
65static void no_enable_out(HWVoiceOut *hw, bool enable)
66{
67 NoVoiceOut *no = (NoVoiceOut *) hw;
68
69 if (enable) {
70 audio_rate_start(&no->rate);
71 }
72}
73
74static int no_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
75{
76 NoVoiceIn *no = (NoVoiceIn *) hw;
77
78 audio_pcm_init_info (&hw->info, as);
79 hw->samples = 1024;
80 audio_rate_start(&no->rate);
81 return 0;
82}
83
84static void no_fini_in (HWVoiceIn *hw)
85{
86 (void) hw;
87}
88
89static size_t no_read(HWVoiceIn *hw, void *buf, size_t size)
90{
91 NoVoiceIn *no = (NoVoiceIn *) hw;
92 int64_t bytes = audio_rate_get_bytes(&hw->info, &no->rate, size);
93
94 audio_pcm_info_clear_buf(&hw->info, buf, bytes / hw->info.bytes_per_frame);
95 return bytes;
96}
97
98static void no_enable_in(HWVoiceIn *hw, bool enable)
99{
100 NoVoiceIn *no = (NoVoiceIn *) hw;
101
102 if (enable) {
103 audio_rate_start(&no->rate);
104 }
105}
106
107static void *no_audio_init(Audiodev *dev)
108{
109 return &no_audio_init;
110}
111
112static void no_audio_fini (void *opaque)
113{
114 (void) opaque;
115}
116
117static struct audio_pcm_ops no_pcm_ops = {
118 .init_out = no_init_out,
119 .fini_out = no_fini_out,
120 .write = no_write,
121 .enable_out = no_enable_out,
122
123 .init_in = no_init_in,
124 .fini_in = no_fini_in,
125 .read = no_read,
126 .enable_in = no_enable_in
127};
128
129static struct audio_driver no_audio_driver = {
130 .name = "none",
131 .descr = "Timer based audio emulation",
132 .init = no_audio_init,
133 .fini = no_audio_fini,
134 .pcm_ops = &no_pcm_ops,
135 .can_be_default = 1,
136 .max_voices_out = INT_MAX,
137 .max_voices_in = INT_MAX,
138 .voice_size_out = sizeof (NoVoiceOut),
139 .voice_size_in = sizeof (NoVoiceIn)
140};
141
142static void register_audio_none(void)
143{
144 audio_driver_register(&no_audio_driver);
145}
146type_init(register_audio_none);
147