Statistics
| Branch: | Revision:

root / audio / noaudio.c @ 26a76461

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 7372f88d bellard
    int64_t now = qemu_get_clock (vm_clock);
44 7372f88d bellard
    int64_t ticks = now - no->old_ticks;
45 1d14ffa9 bellard
    int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
46 7372f88d bellard
47 1d14ffa9 bellard
    if (bytes > INT_MAX) {
48 1d14ffa9 bellard
        samples = INT_MAX >> hw->info.shift;
49 1d14ffa9 bellard
    }
50 1d14ffa9 bellard
    else {
51 1d14ffa9 bellard
        samples = bytes >> hw->info.shift;
52 1d14ffa9 bellard
    }
53 7372f88d bellard
54 1d14ffa9 bellard
    live = audio_pcm_hw_get_live_out (&no->hw);
55 1d14ffa9 bellard
    if (!live) {
56 1d14ffa9 bellard
        return 0;
57 1d14ffa9 bellard
    }
58 7372f88d bellard
59 7372f88d bellard
    no->old_ticks = now;
60 7372f88d bellard
    decr = audio_MIN (live, samples);
61 1d14ffa9 bellard
    hw->rpos = (hw->rpos + decr) % hw->samples;
62 1d14ffa9 bellard
    return decr;
63 1d14ffa9 bellard
}
64 7372f88d bellard
65 1d14ffa9 bellard
static int no_write (SWVoiceOut *sw, void *buf, int len)
66 1d14ffa9 bellard
{
67 1d14ffa9 bellard
    return audio_pcm_sw_write (sw, buf, len);
68 1d14ffa9 bellard
}
69 7372f88d bellard
70 c0fe3827 bellard
static int no_init_out (HWVoiceOut *hw, audsettings_t *as)
71 1d14ffa9 bellard
{
72 c0fe3827 bellard
    audio_pcm_init_info (&hw->info, as, 0);
73 c0fe3827 bellard
    hw->samples = 1024;
74 1d14ffa9 bellard
    return 0;
75 1d14ffa9 bellard
}
76 7372f88d bellard
77 1d14ffa9 bellard
static void no_fini_out (HWVoiceOut *hw)
78 1d14ffa9 bellard
{
79 1d14ffa9 bellard
    (void) hw;
80 7372f88d bellard
}
81 7372f88d bellard
82 1d14ffa9 bellard
static int no_ctl_out (HWVoiceOut *hw, int cmd, ...)
83 7372f88d bellard
{
84 1d14ffa9 bellard
    (void) hw;
85 1d14ffa9 bellard
    (void) cmd;
86 1d14ffa9 bellard
    return 0;
87 7372f88d bellard
}
88 7372f88d bellard
89 c0fe3827 bellard
static int no_init_in (HWVoiceIn *hw, audsettings_t *as)
90 7372f88d bellard
{
91 c0fe3827 bellard
    audio_pcm_init_info (&hw->info, as, 0);
92 c0fe3827 bellard
    hw->samples = 1024;
93 7372f88d bellard
    return 0;
94 7372f88d bellard
}
95 7372f88d bellard
96 1d14ffa9 bellard
static void no_fini_in (HWVoiceIn *hw)
97 7372f88d bellard
{
98 7372f88d bellard
    (void) hw;
99 7372f88d bellard
}
100 7372f88d bellard
101 1d14ffa9 bellard
static int no_run_in (HWVoiceIn *hw)
102 1d14ffa9 bellard
{
103 1d14ffa9 bellard
    NoVoiceIn *no = (NoVoiceIn *) hw;
104 1d14ffa9 bellard
    int64_t now = qemu_get_clock (vm_clock);
105 1d14ffa9 bellard
    int64_t ticks = now - no->old_ticks;
106 1d14ffa9 bellard
    int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
107 1d14ffa9 bellard
    int live = audio_pcm_hw_get_live_in (hw);
108 1d14ffa9 bellard
    int dead = hw->samples - live;
109 1d14ffa9 bellard
    int samples;
110 1d14ffa9 bellard
111 1d14ffa9 bellard
    bytes = audio_MIN (bytes, INT_MAX);
112 1d14ffa9 bellard
    samples = bytes >> hw->info.shift;
113 1d14ffa9 bellard
    samples = audio_MIN (samples, dead);
114 1d14ffa9 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 1d14ffa9 bellard
static struct audio_pcm_ops no_pcm_ops = {
145 1d14ffa9 bellard
    no_init_out,
146 1d14ffa9 bellard
    no_fini_out,
147 1d14ffa9 bellard
    no_run_out,
148 1d14ffa9 bellard
    no_write,
149 1d14ffa9 bellard
    no_ctl_out,
150 1d14ffa9 bellard
151 1d14ffa9 bellard
    no_init_in,
152 1d14ffa9 bellard
    no_fini_in,
153 1d14ffa9 bellard
    no_run_in,
154 1d14ffa9 bellard
    no_read,
155 1d14ffa9 bellard
    no_ctl_in
156 7372f88d bellard
};
157 7372f88d bellard
158 1d14ffa9 bellard
struct audio_driver no_audio_driver = {
159 1d14ffa9 bellard
    INIT_FIELD (name           = ) "none",
160 1d14ffa9 bellard
    INIT_FIELD (descr          = ) "Timer based audio emulation",
161 1d14ffa9 bellard
    INIT_FIELD (options        = ) NULL,
162 1d14ffa9 bellard
    INIT_FIELD (init           = ) no_audio_init,
163 1d14ffa9 bellard
    INIT_FIELD (fini           = ) no_audio_fini,
164 1d14ffa9 bellard
    INIT_FIELD (pcm_ops        = ) &no_pcm_ops,
165 1d14ffa9 bellard
    INIT_FIELD (can_be_default = ) 1,
166 1d14ffa9 bellard
    INIT_FIELD (max_voices_out = ) INT_MAX,
167 1d14ffa9 bellard
    INIT_FIELD (max_voices_in  = ) INT_MAX,
168 1d14ffa9 bellard
    INIT_FIELD (voice_size_out = ) sizeof (NoVoiceOut),
169 1d14ffa9 bellard
    INIT_FIELD (voice_size_in  = ) sizeof (NoVoiceIn)
170 7372f88d bellard
};