| 1 | /* |
| 2 | * QEMU Timer based audio emulation |
| 3 | * |
| 4 | * Copyright (c) 2004-2005 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 | |
| 25 | #include "qemu/osdep.h" |
| 26 | #include "qemu/module.h" |
| 27 | #include "qemu/audio.h" |
| 28 | #include "qom/object.h" |
| 29 | |
| 30 | #include "audio_int.h" |
| 31 | |
| 32 | #define TYPE_AUDIO_NONE "audio-none" |
| 33 | OBJECT_DECLARE_SIMPLE_TYPE(AudioNone, AUDIO_NONE) |
| 34 | |
| 35 | struct AudioNone { |
| 36 | AudioMixengBackend parent_obj; |
| 37 | }; |
| 38 | |
| 39 | typedef struct NoVoiceOut { |
| 40 | HWVoiceOut hw; |
| 41 | RateCtl rate; |
| 42 | } NoVoiceOut; |
| 43 | |
| 44 | typedef struct NoVoiceIn { |
| 45 | HWVoiceIn hw; |
| 46 | RateCtl rate; |
| 47 | } NoVoiceIn; |
| 48 | |
| 49 | static size_t no_write(HWVoiceOut *hw, void *buf, size_t len) |
| 50 | { |
| 51 | NoVoiceOut *no = (NoVoiceOut *) hw; |
| 52 | return audio_rate_get_bytes(&no->rate, &hw->info, len); |
| 53 | } |
| 54 | |
| 55 | static int no_init_out(HWVoiceOut *hw, struct audsettings *as) |
| 56 | { |
| 57 | NoVoiceOut *no = (NoVoiceOut *) hw; |
| 58 | |
| 59 | audio_pcm_init_info (&hw->info, as); |
| 60 | hw->samples = 1024; |
| 61 | audio_rate_start(&no->rate); |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static void no_fini_out (HWVoiceOut *hw) |
| 66 | { |
| 67 | (void) hw; |
| 68 | } |
| 69 | |
| 70 | static void no_enable_out(HWVoiceOut *hw, bool enable) |
| 71 | { |
| 72 | NoVoiceOut *no = (NoVoiceOut *) hw; |
| 73 | |
| 74 | if (enable) { |
| 75 | audio_rate_start(&no->rate); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | static int no_init_in(HWVoiceIn *hw, struct audsettings *as) |
| 80 | { |
| 81 | NoVoiceIn *no = (NoVoiceIn *) hw; |
| 82 | |
| 83 | audio_pcm_init_info (&hw->info, as); |
| 84 | hw->samples = 1024; |
| 85 | audio_rate_start(&no->rate); |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | static void no_fini_in (HWVoiceIn *hw) |
| 90 | { |
| 91 | (void) hw; |
| 92 | } |
| 93 | |
| 94 | static size_t no_read(HWVoiceIn *hw, void *buf, size_t size) |
| 95 | { |
| 96 | NoVoiceIn *no = (NoVoiceIn *) hw; |
| 97 | int64_t bytes = audio_rate_get_bytes(&no->rate, &hw->info, size); |
| 98 | |
| 99 | audio_pcm_info_clear_buf(&hw->info, buf, bytes / hw->info.bytes_per_frame); |
| 100 | return bytes; |
| 101 | } |
| 102 | |
| 103 | static void no_enable_in(HWVoiceIn *hw, bool enable) |
| 104 | { |
| 105 | NoVoiceIn *no = (NoVoiceIn *) hw; |
| 106 | |
| 107 | if (enable) { |
| 108 | audio_rate_start(&no->rate); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | static void audio_none_class_init(ObjectClass *klass, const void *data) |
| 113 | { |
| 114 | AudioMixengBackendClass *k = AUDIO_MIXENG_BACKEND_CLASS(klass); |
| 115 | |
| 116 | k->max_voices_out = INT_MAX; |
| 117 | k->max_voices_in = INT_MAX; |
| 118 | k->voice_size_out = sizeof(NoVoiceOut); |
| 119 | k->voice_size_in = sizeof(NoVoiceIn); |
| 120 | |
| 121 | k->init_out = no_init_out; |
| 122 | k->fini_out = no_fini_out; |
| 123 | k->write = no_write; |
| 124 | k->buffer_get_free = audio_generic_buffer_get_free; |
| 125 | k->run_buffer_out = audio_generic_run_buffer_out; |
| 126 | k->enable_out = no_enable_out; |
| 127 | |
| 128 | k->init_in = no_init_in; |
| 129 | k->fini_in = no_fini_in; |
| 130 | k->read = no_read; |
| 131 | k->run_buffer_in = audio_generic_run_buffer_in; |
| 132 | k->enable_in = no_enable_in; |
| 133 | } |
| 134 | |
| 135 | static const TypeInfo audio_types[] = { |
| 136 | { |
| 137 | .name = TYPE_AUDIO_NONE, |
| 138 | .parent = TYPE_AUDIO_MIXENG_BACKEND, |
| 139 | .instance_size = sizeof(AudioNone), |
| 140 | .class_init = audio_none_class_init, |
| 141 | }, |
| 142 | }; |
| 143 | |
| 144 | DEFINE_TYPES(audio_types) |
| 145 | module_obj(TYPE_AUDIO_NONE); |