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