1 /* 2 * MOC - music on console 3 * Copyright (C) 2004 Damian Pietras <daper@daper.net> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 */ 11 12 /* Fake output device - only for testing. */ 13 14 #ifdef HAVE_CONFIG_H 15 # include "config.h" 16 #endif 17 18 /* _XOPEN_SOURCE is known to break compilation under OpenBSD. */ 19 #ifndef OPENBSD 20 # define _XOPEN_SOURCE 500 /* for usleep() */ 21 #endif 22 23 #include <unistd.h> 24 25 #include "common.h" 26 #include "audio.h" 27 28 static struct sound_params params = { 0, 0, 0 }; 29 null_open(struct sound_params * sound_params)30static int null_open (struct sound_params *sound_params) 31 { 32 params = *sound_params; 33 return 1; 34 } 35 null_close()36static void null_close () 37 { 38 params.rate = 0; 39 } 40 null_play(const char * buff ATTR_UNUSED,const size_t size)41static int null_play (const char *buff ATTR_UNUSED, const size_t size) 42 { 43 usleep (size * 1000000.0 / audio_get_bps ()); 44 return size; 45 } 46 null_read_mixer()47static int null_read_mixer () 48 { 49 return 100; 50 } 51 null_set_mixer(int vol ATTR_UNUSED)52static void null_set_mixer (int vol ATTR_UNUSED) 53 { 54 } 55 null_get_buff_fill()56static int null_get_buff_fill () 57 { 58 return 0; 59 } 60 null_reset()61static int null_reset () 62 { 63 return 1; 64 } 65 null_init(struct output_driver_caps * caps)66static int null_init (struct output_driver_caps *caps) 67 { 68 caps->formats = SFMT_S8 | SFMT_S16 | SFMT_LE; 69 caps->min_channels = 1; 70 caps->max_channels = 2; 71 72 return 1; 73 } 74 null_get_rate()75static int null_get_rate () 76 { 77 return params.rate; 78 } 79 null_toggle_mixer_channel()80static void null_toggle_mixer_channel () 81 { 82 } 83 null_get_mixer_channel_name()84static char *null_get_mixer_channel_name () 85 { 86 return xstrdup ("FakeMixer"); 87 } 88 null_funcs(struct hw_funcs * funcs)89void null_funcs (struct hw_funcs *funcs) 90 { 91 funcs->init = null_init; 92 funcs->open = null_open; 93 funcs->close = null_close; 94 funcs->play = null_play; 95 funcs->read_mixer = null_read_mixer; 96 funcs->set_mixer = null_set_mixer; 97 funcs->get_buff_fill = null_get_buff_fill; 98 funcs->reset = null_reset; 99 funcs->get_rate = null_get_rate; 100 funcs->toggle_mixer_channel = null_toggle_mixer_channel; 101 funcs->get_mixer_channel_name = null_get_mixer_channel_name; 102 } 103