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