root / audio / noaudio.c @ 192c7bd9
History | View | Annotate | Download (3.2 kB)
1 | 7372f88d | bellard | /*
|
---|---|---|---|
2 | 7372f88d | bellard | * QEMU NULL audio output driver
|
3 | 7372f88d | bellard | *
|
4 | 7372f88d | bellard | * Copyright (c) 2004 Vassili Karpov (malc)
|
5 | 7372f88d | 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 | 7372f88d | bellard | #include "audio/audio_int.h" |
27 | 7372f88d | bellard | |
28 | 7372f88d | bellard | typedef struct NoVoice { |
29 | 7372f88d | bellard | HWVoice hw; |
30 | 7372f88d | bellard | int64_t old_ticks; |
31 | 7372f88d | bellard | } NoVoice; |
32 | 7372f88d | bellard | |
33 | 7372f88d | bellard | #define dolog(...) AUD_log ("noaudio", __VA_ARGS__) |
34 | 7372f88d | bellard | #ifdef DEBUG
|
35 | 7372f88d | bellard | #define ldebug(...) dolog (__VA_ARGS__)
|
36 | 7372f88d | bellard | #else
|
37 | 7372f88d | bellard | #define ldebug(...)
|
38 | 7372f88d | bellard | #endif
|
39 | 7372f88d | bellard | |
40 | 7372f88d | bellard | static void no_hw_run (HWVoice *hw) |
41 | 7372f88d | bellard | { |
42 | 7372f88d | bellard | NoVoice *no = (NoVoice *) hw; |
43 | 7372f88d | bellard | int rpos, live, decr, samples;
|
44 | 7372f88d | bellard | st_sample_t *src; |
45 | 7372f88d | bellard | int64_t now = qemu_get_clock (vm_clock); |
46 | 7372f88d | bellard | int64_t ticks = now - no->old_ticks; |
47 | 7372f88d | bellard | int64_t bytes = (ticks * hw->bytes_per_second) / ticks_per_sec; |
48 | 7372f88d | bellard | |
49 | 7372f88d | bellard | if (bytes > INT_MAX)
|
50 | 7372f88d | bellard | samples = INT_MAX >> hw->shift; |
51 | 7372f88d | bellard | else
|
52 | 7372f88d | bellard | samples = bytes >> hw->shift; |
53 | 7372f88d | bellard | |
54 | 7372f88d | bellard | live = pcm_hw_get_live (hw); |
55 | 7372f88d | bellard | if (live <= 0) |
56 | 7372f88d | bellard | return;
|
57 | 7372f88d | bellard | |
58 | 7372f88d | bellard | no->old_ticks = now; |
59 | 7372f88d | bellard | decr = audio_MIN (live, samples); |
60 | 7372f88d | bellard | samples = decr; |
61 | 7372f88d | bellard | rpos = hw->rpos; |
62 | 7372f88d | bellard | while (samples) {
|
63 | 7372f88d | bellard | int left_till_end_samples = hw->samples - rpos;
|
64 | 7372f88d | bellard | int convert_samples = audio_MIN (samples, left_till_end_samples);
|
65 | 7372f88d | bellard | |
66 | 7372f88d | bellard | src = advance (hw->mix_buf, rpos * sizeof (st_sample_t));
|
67 | 7372f88d | bellard | memset (src, 0, convert_samples * sizeof (st_sample_t)); |
68 | 7372f88d | bellard | |
69 | 7372f88d | bellard | rpos = (rpos + convert_samples) % hw->samples; |
70 | 7372f88d | bellard | samples -= convert_samples; |
71 | 7372f88d | bellard | } |
72 | 7372f88d | bellard | |
73 | 7372f88d | bellard | pcm_hw_dec_live (hw, decr); |
74 | 7372f88d | bellard | hw->rpos = rpos; |
75 | 7372f88d | bellard | } |
76 | 7372f88d | bellard | |
77 | 7372f88d | bellard | static int no_hw_write (SWVoice *sw, void *buf, int len) |
78 | 7372f88d | bellard | { |
79 | 7372f88d | bellard | return pcm_hw_write (sw, buf, len);
|
80 | 7372f88d | bellard | } |
81 | 7372f88d | bellard | |
82 | 7372f88d | bellard | static int no_hw_init (HWVoice *hw, int freq, int nchannels, audfmt_e fmt) |
83 | 7372f88d | bellard | { |
84 | 7372f88d | bellard | hw->freq = freq; |
85 | 7372f88d | bellard | hw->nchannels = nchannels; |
86 | 7372f88d | bellard | hw->fmt = fmt; |
87 | 7372f88d | bellard | hw->bufsize = 4096;
|
88 | 7372f88d | bellard | return 0; |
89 | 7372f88d | bellard | } |
90 | 7372f88d | bellard | |
91 | 7372f88d | bellard | static void no_hw_fini (HWVoice *hw) |
92 | 7372f88d | bellard | { |
93 | 7372f88d | bellard | (void) hw;
|
94 | 7372f88d | bellard | } |
95 | 7372f88d | bellard | |
96 | 7372f88d | bellard | static int no_hw_ctl (HWVoice *hw, int cmd, ...) |
97 | 7372f88d | bellard | { |
98 | 7372f88d | bellard | (void) hw;
|
99 | 7372f88d | bellard | (void) cmd;
|
100 | 7372f88d | bellard | return 0; |
101 | 7372f88d | bellard | } |
102 | 7372f88d | bellard | |
103 | 7372f88d | bellard | static void *no_audio_init (void) |
104 | 7372f88d | bellard | { |
105 | 7372f88d | bellard | return &no_audio_init;
|
106 | 7372f88d | bellard | } |
107 | 7372f88d | bellard | |
108 | 7372f88d | bellard | static void no_audio_fini (void *opaque) |
109 | 7372f88d | bellard | { |
110 | 7372f88d | bellard | } |
111 | 7372f88d | bellard | |
112 | 7372f88d | bellard | struct pcm_ops no_pcm_ops = {
|
113 | 7372f88d | bellard | no_hw_init, |
114 | 7372f88d | bellard | no_hw_fini, |
115 | 7372f88d | bellard | no_hw_run, |
116 | 7372f88d | bellard | no_hw_write, |
117 | 7372f88d | bellard | no_hw_ctl |
118 | 7372f88d | bellard | }; |
119 | 7372f88d | bellard | |
120 | 7372f88d | bellard | struct audio_output_driver no_output_driver = {
|
121 | 7372f88d | bellard | "none",
|
122 | 7372f88d | bellard | no_audio_init, |
123 | 7372f88d | bellard | no_audio_fini, |
124 | 7372f88d | bellard | &no_pcm_ops, |
125 | 7372f88d | bellard | 1,
|
126 | 7372f88d | bellard | 1,
|
127 | 7372f88d | bellard | sizeof (NoVoice)
|
128 | 7372f88d | bellard | }; |