root / audio / noaudio.c @ beb811bd
History | View | Annotate | Download (4.4 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 | 7372f88d | bellard | #include "vl.h" |
25 | 7372f88d | bellard | |
26 | 1d14ffa9 | bellard | #define AUDIO_CAP "noaudio" |
27 | 1d14ffa9 | bellard | #include "audio_int.h" |
28 | 7372f88d | bellard | |
29 | 1d14ffa9 | bellard | typedef struct NoVoiceOut { |
30 | 1d14ffa9 | bellard | HWVoiceOut hw; |
31 | 7372f88d | bellard | int64_t old_ticks; |
32 | 1d14ffa9 | bellard | } NoVoiceOut; |
33 | 7372f88d | bellard | |
34 | 1d14ffa9 | bellard | typedef struct NoVoiceIn { |
35 | 1d14ffa9 | bellard | HWVoiceIn hw; |
36 | 1d14ffa9 | bellard | int64_t old_ticks; |
37 | 1d14ffa9 | bellard | } NoVoiceIn; |
38 | 7372f88d | bellard | |
39 | 1d14ffa9 | bellard | static int no_run_out (HWVoiceOut *hw) |
40 | 7372f88d | bellard | { |
41 | 1d14ffa9 | bellard | NoVoiceOut *no = (NoVoiceOut *) hw; |
42 | 1d14ffa9 | bellard | int live, decr, samples;
|
43 | 8ead62cf | bellard | int64_t now; |
44 | 8ead62cf | bellard | int64_t ticks; |
45 | 8ead62cf | bellard | int64_t bytes; |
46 | 7372f88d | bellard | |
47 | 1d14ffa9 | bellard | live = audio_pcm_hw_get_live_out (&no->hw); |
48 | 1d14ffa9 | bellard | if (!live) {
|
49 | 1d14ffa9 | bellard | return 0; |
50 | 1d14ffa9 | bellard | } |
51 | 7372f88d | bellard | |
52 | 8ead62cf | bellard | now = qemu_get_clock (vm_clock); |
53 | 8ead62cf | bellard | ticks = now - no->old_ticks; |
54 | 8ead62cf | bellard | bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec; |
55 | 8ead62cf | bellard | bytes = audio_MIN (bytes, INT_MAX); |
56 | 8ead62cf | bellard | samples = bytes >> hw->info.shift; |
57 | 8ead62cf | bellard | |
58 | 7372f88d | bellard | no->old_ticks = now; |
59 | 7372f88d | bellard | decr = audio_MIN (live, samples); |
60 | 1d14ffa9 | bellard | hw->rpos = (hw->rpos + decr) % hw->samples; |
61 | 1d14ffa9 | bellard | return decr;
|
62 | 1d14ffa9 | bellard | } |
63 | 7372f88d | bellard | |
64 | 1d14ffa9 | bellard | static int no_write (SWVoiceOut *sw, void *buf, int len) |
65 | 1d14ffa9 | bellard | { |
66 | 1d14ffa9 | bellard | return audio_pcm_sw_write (sw, buf, len);
|
67 | 1d14ffa9 | bellard | } |
68 | 7372f88d | bellard | |
69 | c0fe3827 | bellard | static int no_init_out (HWVoiceOut *hw, audsettings_t *as) |
70 | 1d14ffa9 | bellard | { |
71 | d929eba5 | bellard | audio_pcm_init_info (&hw->info, as); |
72 | c0fe3827 | bellard | hw->samples = 1024;
|
73 | 1d14ffa9 | bellard | return 0; |
74 | 1d14ffa9 | bellard | } |
75 | 7372f88d | bellard | |
76 | 1d14ffa9 | bellard | static void no_fini_out (HWVoiceOut *hw) |
77 | 1d14ffa9 | bellard | { |
78 | 1d14ffa9 | bellard | (void) hw;
|
79 | 7372f88d | bellard | } |
80 | 7372f88d | bellard | |
81 | 1d14ffa9 | bellard | static int no_ctl_out (HWVoiceOut *hw, int cmd, ...) |
82 | 7372f88d | bellard | { |
83 | 1d14ffa9 | bellard | (void) hw;
|
84 | 1d14ffa9 | bellard | (void) cmd;
|
85 | 1d14ffa9 | bellard | return 0; |
86 | 7372f88d | bellard | } |
87 | 7372f88d | bellard | |
88 | c0fe3827 | bellard | static int no_init_in (HWVoiceIn *hw, audsettings_t *as) |
89 | 7372f88d | bellard | { |
90 | d929eba5 | bellard | audio_pcm_init_info (&hw->info, as); |
91 | c0fe3827 | bellard | hw->samples = 1024;
|
92 | 7372f88d | bellard | return 0; |
93 | 7372f88d | bellard | } |
94 | 7372f88d | bellard | |
95 | 1d14ffa9 | bellard | static void no_fini_in (HWVoiceIn *hw) |
96 | 7372f88d | bellard | { |
97 | 7372f88d | bellard | (void) hw;
|
98 | 7372f88d | bellard | } |
99 | 7372f88d | bellard | |
100 | 1d14ffa9 | bellard | static int no_run_in (HWVoiceIn *hw) |
101 | 1d14ffa9 | bellard | { |
102 | 1d14ffa9 | bellard | NoVoiceIn *no = (NoVoiceIn *) hw; |
103 | 1d14ffa9 | bellard | int live = audio_pcm_hw_get_live_in (hw);
|
104 | 1d14ffa9 | bellard | int dead = hw->samples - live;
|
105 | ec36b695 | bellard | int samples = 0; |
106 | 1d14ffa9 | bellard | |
107 | 8ead62cf | bellard | if (dead) {
|
108 | 8ead62cf | bellard | int64_t now = qemu_get_clock (vm_clock); |
109 | 8ead62cf | bellard | int64_t ticks = now - no->old_ticks; |
110 | 8ead62cf | bellard | int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec; |
111 | 1d14ffa9 | bellard | |
112 | 8ead62cf | bellard | no->old_ticks = now; |
113 | 8ead62cf | bellard | bytes = audio_MIN (bytes, INT_MAX); |
114 | 8ead62cf | bellard | samples = bytes >> hw->info.shift; |
115 | 8ead62cf | bellard | samples = audio_MIN (samples, dead); |
116 | 8ead62cf | bellard | } |
117 | 1d14ffa9 | bellard | return samples;
|
118 | 1d14ffa9 | bellard | } |
119 | 1d14ffa9 | bellard | |
120 | 1d14ffa9 | bellard | static int no_read (SWVoiceIn *sw, void *buf, int size) |
121 | 1d14ffa9 | bellard | { |
122 | 1d14ffa9 | bellard | int samples = size >> sw->info.shift;
|
123 | 1d14ffa9 | bellard | int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
|
124 | 1d14ffa9 | bellard | int to_clear = audio_MIN (samples, total);
|
125 | 1d14ffa9 | bellard | audio_pcm_info_clear_buf (&sw->info, buf, to_clear); |
126 | 1d14ffa9 | bellard | return to_clear;
|
127 | 1d14ffa9 | bellard | } |
128 | 1d14ffa9 | bellard | |
129 | 1d14ffa9 | bellard | static int no_ctl_in (HWVoiceIn *hw, int cmd, ...) |
130 | 7372f88d | bellard | { |
131 | 7372f88d | bellard | (void) hw;
|
132 | 7372f88d | bellard | (void) cmd;
|
133 | 7372f88d | bellard | return 0; |
134 | 7372f88d | bellard | } |
135 | 7372f88d | bellard | |
136 | 7372f88d | bellard | static void *no_audio_init (void) |
137 | 7372f88d | bellard | { |
138 | 7372f88d | bellard | return &no_audio_init;
|
139 | 7372f88d | bellard | } |
140 | 7372f88d | bellard | |
141 | 7372f88d | bellard | static void no_audio_fini (void *opaque) |
142 | 7372f88d | bellard | { |
143 | 1d14ffa9 | bellard | (void) opaque;
|
144 | 7372f88d | bellard | } |
145 | 7372f88d | bellard | |
146 | 1d14ffa9 | bellard | static struct audio_pcm_ops no_pcm_ops = { |
147 | 1d14ffa9 | bellard | no_init_out, |
148 | 1d14ffa9 | bellard | no_fini_out, |
149 | 1d14ffa9 | bellard | no_run_out, |
150 | 1d14ffa9 | bellard | no_write, |
151 | 1d14ffa9 | bellard | no_ctl_out, |
152 | 1d14ffa9 | bellard | |
153 | 1d14ffa9 | bellard | no_init_in, |
154 | 1d14ffa9 | bellard | no_fini_in, |
155 | 1d14ffa9 | bellard | no_run_in, |
156 | 1d14ffa9 | bellard | no_read, |
157 | 1d14ffa9 | bellard | no_ctl_in |
158 | 7372f88d | bellard | }; |
159 | 7372f88d | bellard | |
160 | 1d14ffa9 | bellard | struct audio_driver no_audio_driver = {
|
161 | 1d14ffa9 | bellard | INIT_FIELD (name = ) "none",
|
162 | 1d14ffa9 | bellard | INIT_FIELD (descr = ) "Timer based audio emulation",
|
163 | 1d14ffa9 | bellard | INIT_FIELD (options = ) NULL,
|
164 | 1d14ffa9 | bellard | INIT_FIELD (init = ) no_audio_init, |
165 | 1d14ffa9 | bellard | INIT_FIELD (fini = ) no_audio_fini, |
166 | 1d14ffa9 | bellard | INIT_FIELD (pcm_ops = ) &no_pcm_ops, |
167 | 1d14ffa9 | bellard | INIT_FIELD (can_be_default = ) 1,
|
168 | 1d14ffa9 | bellard | INIT_FIELD (max_voices_out = ) INT_MAX, |
169 | 1d14ffa9 | bellard | INIT_FIELD (max_voices_in = ) INT_MAX, |
170 | 1d14ffa9 | bellard | INIT_FIELD (voice_size_out = ) sizeof (NoVoiceOut),
|
171 | 1d14ffa9 | bellard | INIT_FIELD (voice_size_in = ) sizeof (NoVoiceIn)
|
172 | 7372f88d | bellard | }; |