1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "qemu/osdep.h"
25#include "qemu-common.h"
26#include "qemu/host-utils.h"
27#include "audio.h"
28#include "qemu/timer.h"
29
30#define AUDIO_CAP "noaudio"
31#include "audio_int.h"
32
33typedef struct NoVoiceOut {
34 HWVoiceOut hw;
35 int64_t old_ticks;
36} NoVoiceOut;
37
38typedef struct NoVoiceIn {
39 HWVoiceIn hw;
40 int64_t old_ticks;
41} NoVoiceIn;
42
43static int no_run_out (HWVoiceOut *hw, int live)
44{
45 NoVoiceOut *no = (NoVoiceOut *) hw;
46 int decr, samples;
47 int64_t now;
48 int64_t ticks;
49 int64_t bytes;
50
51 now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
52 ticks = now - no->old_ticks;
53 bytes = muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);
54 bytes = audio_MIN(bytes, INT_MAX);
55 samples = bytes >> hw->info.shift;
56
57 no->old_ticks = now;
58 decr = audio_MIN (live, samples);
59 hw->rpos = (hw->rpos + decr) % hw->samples;
60 return decr;
61}
62
63static int no_write (SWVoiceOut *sw, void *buf, int len)
64{
65 return audio_pcm_sw_write(sw, buf, len);
66}
67
68static int no_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque)
69{
70 audio_pcm_init_info (&hw->info, as);
71 hw->samples = 1024;
72 return 0;
73}
74
75static void no_fini_out (HWVoiceOut *hw)
76{
77 (void) hw;
78}
79
80static int no_ctl_out (HWVoiceOut *hw, int cmd, ...)
81{
82 (void) hw;
83 (void) cmd;
84 return 0;
85}
86
87static int no_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
88{
89 audio_pcm_init_info (&hw->info, as);
90 hw->samples = 1024;
91 return 0;
92}
93
94static void no_fini_in (HWVoiceIn *hw)
95{
96 (void) hw;
97}
98
99static int no_run_in (HWVoiceIn *hw)
100{
101 NoVoiceIn *no = (NoVoiceIn *) hw;
102 int live = audio_pcm_hw_get_live_in (hw);
103 int dead = hw->samples - live;
104 int samples = 0;
105
106 if (dead) {
107 int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
108 int64_t ticks = now - no->old_ticks;
109 int64_t bytes =
110 muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);
111
112 no->old_ticks = now;
113 bytes = audio_MIN (bytes, INT_MAX);
114 samples = bytes >> hw->info.shift;
115 samples = audio_MIN (samples, dead);
116 }
117 return samples;
118}
119
120static int no_read (SWVoiceIn *sw, void *buf, int size)
121{
122
123
124 int samples = size >> sw->info.shift;
125 int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
126 int to_clear = audio_MIN (samples, total);
127 sw->total_hw_samples_acquired += total;
128 audio_pcm_info_clear_buf (&sw->info, buf, to_clear);
129 return to_clear << sw->info.shift;
130}
131
132static int no_ctl_in (HWVoiceIn *hw, int cmd, ...)
133{
134 (void) hw;
135 (void) cmd;
136 return 0;
137}
138
139static void *no_audio_init (void)
140{
141 return &no_audio_init;
142}
143
144static void no_audio_fini (void *opaque)
145{
146 (void) opaque;
147}
148
149static struct audio_pcm_ops no_pcm_ops = {
150 .init_out = no_init_out,
151 .fini_out = no_fini_out,
152 .run_out = no_run_out,
153 .write = no_write,
154 .ctl_out = no_ctl_out,
155
156 .init_in = no_init_in,
157 .fini_in = no_fini_in,
158 .run_in = no_run_in,
159 .read = no_read,
160 .ctl_in = no_ctl_in
161};
162
163struct audio_driver no_audio_driver = {
164 .name = "none",
165 .descr = "Timer based audio emulation",
166 .options = NULL,
167 .init = no_audio_init,
168 .fini = no_audio_fini,
169 .pcm_ops = &no_pcm_ops,
170 .can_be_default = 1,
171 .max_voices_out = INT_MAX,
172 .max_voices_in = INT_MAX,
173 .voice_size_out = sizeof (NoVoiceOut),
174 .voice_size_in = sizeof (NoVoiceIn)
175};
176