Annotation of qemu/audio/noaudio.c, revision 1.1.1.2

1.1       root        1: /*
1.1.1.2 ! root        2:  * QEMU Timer based audio emulation
        !             3:  *
        !             4:  * Copyright (c) 2004-2005 Vassili Karpov (malc)
        !             5:  *
1.1       root        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: 
1.1.1.2 ! root       26: #define AUDIO_CAP "noaudio"
        !            27: #include "audio_int.h"
        !            28: 
        !            29: typedef struct NoVoiceOut {
        !            30:     HWVoiceOut hw;
        !            31:     int64_t old_ticks;
        !            32: } NoVoiceOut;
1.1       root       33: 
1.1.1.2 ! root       34: typedef struct NoVoiceIn {
        !            35:     HWVoiceIn hw;
1.1       root       36:     int64_t old_ticks;
1.1.1.2 ! root       37: } NoVoiceIn;
1.1       root       38: 
1.1.1.2 ! root       39: static int no_run_out (HWVoiceOut *hw)
        !            40: {
        !            41:     NoVoiceOut *no = (NoVoiceOut *) hw;
        !            42:     int live, decr, samples;
1.1       root       43:     int64_t now = qemu_get_clock (vm_clock);
                     44:     int64_t ticks = now - no->old_ticks;
1.1.1.2 ! root       45:     int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
        !            46: 
        !            47:     if (bytes > INT_MAX) {
        !            48:         samples = INT_MAX >> hw->info.shift;
        !            49:     }
        !            50:     else {
        !            51:         samples = bytes >> hw->info.shift;
        !            52:     }
1.1       root       53: 
1.1.1.2 ! root       54:     live = audio_pcm_hw_get_live_out (&no->hw);
        !            55:     if (!live) {
        !            56:         return 0;
        !            57:     }
1.1       root       58: 
                     59:     no->old_ticks = now;
                     60:     decr = audio_MIN (live, samples);
1.1.1.2 ! root       61:     hw->rpos = (hw->rpos + decr) % hw->samples;
        !            62:     return decr;
        !            63: }
1.1       root       64: 
1.1.1.2 ! root       65: static int no_write (SWVoiceOut *sw, void *buf, int len)
        !            66: {
        !            67:     return audio_pcm_sw_write (sw, buf, len);
        !            68: }
1.1       root       69: 
1.1.1.2 ! root       70: static int no_init_out (HWVoiceOut *hw, audsettings_t *as)
        !            71: {
        !            72:     audio_pcm_init_info (&hw->info, as, 0);
        !            73:     hw->samples = 1024;
        !            74:     return 0;
        !            75: }
1.1       root       76: 
1.1.1.2 ! root       77: static void no_fini_out (HWVoiceOut *hw)
        !            78: {
        !            79:     (void) hw;
1.1       root       80: }
                     81: 
1.1.1.2 ! root       82: static int no_ctl_out (HWVoiceOut *hw, int cmd, ...)
1.1       root       83: {
1.1.1.2 ! root       84:     (void) hw;
        !            85:     (void) cmd;
        !            86:     return 0;
1.1       root       87: }
                     88: 
1.1.1.2 ! root       89: static int no_init_in (HWVoiceIn *hw, audsettings_t *as)
1.1       root       90: {
1.1.1.2 ! root       91:     audio_pcm_init_info (&hw->info, as, 0);
        !            92:     hw->samples = 1024;
1.1       root       93:     return 0;
                     94: }
                     95: 
1.1.1.2 ! root       96: static void no_fini_in (HWVoiceIn *hw)
1.1       root       97: {
                     98:     (void) hw;
                     99: }
                    100: 
1.1.1.2 ! root      101: static int no_run_in (HWVoiceIn *hw)
        !           102: {
        !           103:     NoVoiceIn *no = (NoVoiceIn *) hw;
        !           104:     int64_t now = qemu_get_clock (vm_clock);
        !           105:     int64_t ticks = now - no->old_ticks;
        !           106:     int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
        !           107:     int live = audio_pcm_hw_get_live_in (hw);
        !           108:     int dead = hw->samples - live;
        !           109:     int samples;
        !           110: 
        !           111:     bytes = audio_MIN (bytes, INT_MAX);
        !           112:     samples = bytes >> hw->info.shift;
        !           113:     samples = audio_MIN (samples, dead);
        !           114: 
        !           115:     return samples;
        !           116: }
        !           117: 
        !           118: static int no_read (SWVoiceIn *sw, void *buf, int size)
        !           119: {
        !           120:     int samples = size >> sw->info.shift;
        !           121:     int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
        !           122:     int to_clear = audio_MIN (samples, total);
        !           123:     audio_pcm_info_clear_buf (&sw->info, buf, to_clear);
        !           124:     return to_clear;
        !           125: }
        !           126: 
        !           127: static int no_ctl_in (HWVoiceIn *hw, int cmd, ...)
1.1       root      128: {
                    129:     (void) hw;
                    130:     (void) cmd;
                    131:     return 0;
                    132: }
                    133: 
                    134: static void *no_audio_init (void)
                    135: {
                    136:     return &no_audio_init;
                    137: }
                    138: 
                    139: static void no_audio_fini (void *opaque)
                    140: {
1.1.1.2 ! root      141:     (void) opaque;
1.1       root      142: }
                    143: 
1.1.1.2 ! root      144: static struct audio_pcm_ops no_pcm_ops = {
        !           145:     no_init_out,
        !           146:     no_fini_out,
        !           147:     no_run_out,
        !           148:     no_write,
        !           149:     no_ctl_out,
        !           150: 
        !           151:     no_init_in,
        !           152:     no_fini_in,
        !           153:     no_run_in,
        !           154:     no_read,
        !           155:     no_ctl_in
1.1       root      156: };
                    157: 
1.1.1.2 ! root      158: struct audio_driver no_audio_driver = {
        !           159:     INIT_FIELD (name           = ) "none",
        !           160:     INIT_FIELD (descr          = ) "Timer based audio emulation",
        !           161:     INIT_FIELD (options        = ) NULL,
        !           162:     INIT_FIELD (init           = ) no_audio_init,
        !           163:     INIT_FIELD (fini           = ) no_audio_fini,
        !           164:     INIT_FIELD (pcm_ops        = ) &no_pcm_ops,
        !           165:     INIT_FIELD (can_be_default = ) 1,
        !           166:     INIT_FIELD (max_voices_out = ) INT_MAX,
        !           167:     INIT_FIELD (max_voices_in  = ) INT_MAX,
        !           168:     INIT_FIELD (voice_size_out = ) sizeof (NoVoiceOut),
        !           169:     INIT_FIELD (voice_size_in  = ) sizeof (NoVoiceIn)
1.1       root      170: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.