|
|
1.1 ! root 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: 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; ! 48: ! 49: if (bytes > INT_MAX) ! 50: samples = INT_MAX >> hw->shift; ! 51: else ! 52: samples = bytes >> hw->shift; ! 53: ! 54: live = pcm_hw_get_live (hw); ! 55: if (live <= 0) ! 56: return; ! 57: ! 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); ! 65: ! 66: src = advance (hw->mix_buf, rpos * sizeof (st_sample_t)); ! 67: memset (src, 0, convert_samples * sizeof (st_sample_t)); ! 68: ! 69: rpos = (rpos + convert_samples) % hw->samples; ! 70: samples -= convert_samples; ! 71: } ! 72: ! 73: pcm_hw_dec_live (hw, decr); ! 74: hw->rpos = rpos; ! 75: } ! 76: ! 77: static int no_hw_write (SWVoice *sw, void *buf, int len) ! 78: { ! 79: return pcm_hw_write (sw, buf, len); ! 80: } ! 81: ! 82: static int no_hw_init (HWVoice *hw, int freq, int nchannels, audfmt_e fmt) ! 83: { ! 84: hw->freq = freq; ! 85: hw->nchannels = nchannels; ! 86: hw->fmt = fmt; ! 87: hw->bufsize = 4096; ! 88: return 0; ! 89: } ! 90: ! 91: static void no_hw_fini (HWVoice *hw) ! 92: { ! 93: (void) hw; ! 94: } ! 95: ! 96: static int no_hw_ctl (HWVoice *hw, int cmd, ...) ! 97: { ! 98: (void) hw; ! 99: (void) cmd; ! 100: return 0; ! 101: } ! 102: ! 103: static void *no_audio_init (void) ! 104: { ! 105: return &no_audio_init; ! 106: } ! 107: ! 108: static void no_audio_fini (void *opaque) ! 109: { ! 110: } ! 111: ! 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 ! 118: }; ! 119: ! 120: struct audio_output_driver no_output_driver = { ! 121: "none", ! 122: no_audio_init, ! 123: no_audio_fini, ! 124: &no_pcm_ops, ! 125: 1, ! 126: 1, ! 127: sizeof (NoVoice) ! 128: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.