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