]>
Commit | Line | Data |
---|---|---|
7372f88d | 1 | /* |
1d14ffa9 FB |
2 | * QEMU Timer based audio emulation |
3 | * | |
4 | * Copyright (c) 2004-2005 Vassili Karpov (malc) | |
5 | * | |
7372f88d FB |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
24 | #include "vl.h" | |
25 | ||
1d14ffa9 FB |
26 | #define AUDIO_CAP "noaudio" |
27 | #include "audio_int.h" | |
7372f88d | 28 | |
1d14ffa9 FB |
29 | typedef struct NoVoiceOut { |
30 | HWVoiceOut hw; | |
7372f88d | 31 | int64_t old_ticks; |
1d14ffa9 | 32 | } NoVoiceOut; |
7372f88d | 33 | |
1d14ffa9 FB |
34 | typedef struct NoVoiceIn { |
35 | HWVoiceIn hw; | |
36 | int64_t old_ticks; | |
37 | } NoVoiceIn; | |
7372f88d | 38 | |
1d14ffa9 | 39 | static int no_run_out (HWVoiceOut *hw) |
7372f88d | 40 | { |
1d14ffa9 FB |
41 | NoVoiceOut *no = (NoVoiceOut *) hw; |
42 | int live, decr, samples; | |
8ead62cf FB |
43 | int64_t now; |
44 | int64_t ticks; | |
45 | int64_t bytes; | |
7372f88d | 46 | |
1d14ffa9 FB |
47 | live = audio_pcm_hw_get_live_out (&no->hw); |
48 | if (!live) { | |
49 | return 0; | |
50 | } | |
7372f88d | 51 | |
8ead62cf FB |
52 | now = qemu_get_clock (vm_clock); |
53 | ticks = now - no->old_ticks; | |
54 | bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec; | |
55 | bytes = audio_MIN (bytes, INT_MAX); | |
56 | samples = bytes >> hw->info.shift; | |
57 | ||
7372f88d FB |
58 | no->old_ticks = now; |
59 | decr = audio_MIN (live, samples); | |
1d14ffa9 FB |
60 | hw->rpos = (hw->rpos + decr) % hw->samples; |
61 | return decr; | |
62 | } | |
7372f88d | 63 | |
1d14ffa9 FB |
64 | static int no_write (SWVoiceOut *sw, void *buf, int len) |
65 | { | |
66 | return audio_pcm_sw_write (sw, buf, len); | |
67 | } | |
7372f88d | 68 | |
c0fe3827 | 69 | static int no_init_out (HWVoiceOut *hw, audsettings_t *as) |
1d14ffa9 | 70 | { |
d929eba5 | 71 | audio_pcm_init_info (&hw->info, as); |
c0fe3827 | 72 | hw->samples = 1024; |
1d14ffa9 FB |
73 | return 0; |
74 | } | |
7372f88d | 75 | |
1d14ffa9 FB |
76 | static void no_fini_out (HWVoiceOut *hw) |
77 | { | |
78 | (void) hw; | |
7372f88d FB |
79 | } |
80 | ||
1d14ffa9 | 81 | static int no_ctl_out (HWVoiceOut *hw, int cmd, ...) |
7372f88d | 82 | { |
1d14ffa9 FB |
83 | (void) hw; |
84 | (void) cmd; | |
85 | return 0; | |
7372f88d FB |
86 | } |
87 | ||
c0fe3827 | 88 | static int no_init_in (HWVoiceIn *hw, audsettings_t *as) |
7372f88d | 89 | { |
d929eba5 | 90 | audio_pcm_init_info (&hw->info, as); |
c0fe3827 | 91 | hw->samples = 1024; |
7372f88d FB |
92 | return 0; |
93 | } | |
94 | ||
1d14ffa9 | 95 | static void no_fini_in (HWVoiceIn *hw) |
7372f88d FB |
96 | { |
97 | (void) hw; | |
98 | } | |
99 | ||
1d14ffa9 FB |
100 | static int no_run_in (HWVoiceIn *hw) |
101 | { | |
102 | NoVoiceIn *no = (NoVoiceIn *) hw; | |
1d14ffa9 FB |
103 | int live = audio_pcm_hw_get_live_in (hw); |
104 | int dead = hw->samples - live; | |
ec36b695 | 105 | int samples = 0; |
1d14ffa9 | 106 | |
8ead62cf FB |
107 | if (dead) { |
108 | int64_t now = qemu_get_clock (vm_clock); | |
109 | int64_t ticks = now - no->old_ticks; | |
110 | int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec; | |
1d14ffa9 | 111 | |
8ead62cf FB |
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 | } | |
1d14ffa9 FB |
117 | return samples; |
118 | } | |
119 | ||
120 | static int no_read (SWVoiceIn *sw, void *buf, int size) | |
121 | { | |
122 | int samples = size >> sw->info.shift; | |
123 | int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired; | |
124 | int to_clear = audio_MIN (samples, total); | |
125 | audio_pcm_info_clear_buf (&sw->info, buf, to_clear); | |
126 | return to_clear; | |
127 | } | |
128 | ||
129 | static int no_ctl_in (HWVoiceIn *hw, int cmd, ...) | |
7372f88d FB |
130 | { |
131 | (void) hw; | |
132 | (void) cmd; | |
133 | return 0; | |
134 | } | |
135 | ||
136 | static void *no_audio_init (void) | |
137 | { | |
138 | return &no_audio_init; | |
139 | } | |
140 | ||
141 | static void no_audio_fini (void *opaque) | |
142 | { | |
1d14ffa9 | 143 | (void) opaque; |
7372f88d FB |
144 | } |
145 | ||
1d14ffa9 FB |
146 | static struct audio_pcm_ops no_pcm_ops = { |
147 | no_init_out, | |
148 | no_fini_out, | |
149 | no_run_out, | |
150 | no_write, | |
151 | no_ctl_out, | |
152 | ||
153 | no_init_in, | |
154 | no_fini_in, | |
155 | no_run_in, | |
156 | no_read, | |
157 | no_ctl_in | |
7372f88d FB |
158 | }; |
159 | ||
1d14ffa9 FB |
160 | struct audio_driver no_audio_driver = { |
161 | INIT_FIELD (name = ) "none", | |
162 | INIT_FIELD (descr = ) "Timer based audio emulation", | |
163 | INIT_FIELD (options = ) NULL, | |
164 | INIT_FIELD (init = ) no_audio_init, | |
165 | INIT_FIELD (fini = ) no_audio_fini, | |
166 | INIT_FIELD (pcm_ops = ) &no_pcm_ops, | |
167 | INIT_FIELD (can_be_default = ) 1, | |
168 | INIT_FIELD (max_voices_out = ) INT_MAX, | |
169 | INIT_FIELD (max_voices_in = ) INT_MAX, | |
170 | INIT_FIELD (voice_size_out = ) sizeof (NoVoiceOut), | |
171 | INIT_FIELD (voice_size_in = ) sizeof (NoVoiceIn) | |
7372f88d | 172 | }; |