cocoa tiny fixes
[qemu/qemu_0_9_1_stable.git] / audio / noaudio.c
bloba192885a72a3b3d38db9863c36231408d715853c
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 #include "vl.h"
26 #include "audio/audio_int.h"
28 typedef struct NoVoice {
29 HWVoice hw;
30 int64_t old_ticks;
31 } NoVoice;
33 #define dolog(...) AUD_log ("noaudio", __VA_ARGS__)
34 #ifdef DEBUG
35 #define ldebug(...) dolog (__VA_ARGS__)
36 #else
37 #define ldebug(...)
38 #endif
40 static void no_hw_run (HWVoice *hw)
42 NoVoice *no = (NoVoice *) hw;
43 int rpos, live, decr, samples;
44 st_sample_t *src;
45 int64_t now = qemu_get_clock (vm_clock);
46 int64_t ticks = now - no->old_ticks;
47 int64_t bytes = (ticks * hw->bytes_per_second) / ticks_per_sec;
49 if (bytes > INT_MAX)
50 samples = INT_MAX >> hw->shift;
51 else
52 samples = bytes >> hw->shift;
54 live = pcm_hw_get_live (hw);
55 if (live <= 0)
56 return;
58 no->old_ticks = now;
59 decr = audio_MIN (live, samples);
60 samples = decr;
61 rpos = hw->rpos;
62 while (samples) {
63 int left_till_end_samples = hw->samples - rpos;
64 int convert_samples = audio_MIN (samples, left_till_end_samples);
66 src = advance (hw->mix_buf, rpos * sizeof (st_sample_t));
67 memset (src, 0, convert_samples * sizeof (st_sample_t));
69 rpos = (rpos + convert_samples) % hw->samples;
70 samples -= convert_samples;
73 pcm_hw_dec_live (hw, decr);
74 hw->rpos = rpos;
77 static int no_hw_write (SWVoice *sw, void *buf, int len)
79 return pcm_hw_write (sw, buf, len);
82 static int no_hw_init (HWVoice *hw, int freq, int nchannels, audfmt_e fmt)
84 hw->freq = freq;
85 hw->nchannels = nchannels;
86 hw->fmt = fmt;
87 hw->bufsize = 4096;
88 return 0;
91 static void no_hw_fini (HWVoice *hw)
93 (void) hw;
96 static int no_hw_ctl (HWVoice *hw, int cmd, ...)
98 (void) hw;
99 (void) cmd;
100 return 0;
103 static void *no_audio_init (void)
105 return &no_audio_init;
108 static void no_audio_fini (void *opaque)
112 struct pcm_ops no_pcm_ops = {
113 no_hw_init,
114 no_hw_fini,
115 no_hw_run,
116 no_hw_write,
117 no_hw_ctl
120 struct audio_output_driver no_output_driver = {
121 "none",
122 no_audio_init,
123 no_audio_fini,
124 &no_pcm_ops,
127 sizeof (NoVoice)