2 * QEMU NULL audio output driver
4 * Copyright (c) 2004 Vassili Karpov (malc)
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
26 #include "audio/audio_int.h"
28 typedef struct NoVoice
{
33 #define dolog(...) AUD_log ("noaudio", __VA_ARGS__)
35 #define ldebug(...) dolog (__VA_ARGS__)
40 static void no_hw_run (HWVoice
*hw
)
42 NoVoice
*no
= (NoVoice
*) hw
;
43 int rpos
, live
, decr
, samples
;
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
;
50 samples
= INT_MAX
>> hw
->shift
;
52 samples
= bytes
>> hw
->shift
;
54 live
= pcm_hw_get_live (hw
);
59 decr
= audio_MIN (live
, 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
);
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
)
85 hw
->nchannels
= nchannels
;
91 static void no_hw_fini (HWVoice
*hw
)
96 static int no_hw_ctl (HWVoice
*hw
, int cmd
, ...)
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
= {
120 struct audio_output_driver no_output_driver
= {