]> git.proxmox.com Git - qemu.git/blame - audio/audio.h
fixed big endian host support
[qemu.git] / audio / audio.h
CommitLineData
85571bc7
FB
1/*
2 * QEMU Audio subsystem header
1d14ffa9
FB
3 *
4 * Copyright (c) 2003-2005 Vassili Karpov (malc)
5 *
85571bc7
FB
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#ifndef QEMU_AUDIO_H
25#define QEMU_AUDIO_H
26
c0fe3827
FB
27#include "sys-queue.h"
28
1d14ffa9 29typedef void (*audio_callback_fn_t) (void *opaque, int avail);
85571bc7 30
85571bc7 31typedef enum {
c0fe3827
FB
32 AUD_FMT_U8,
33 AUD_FMT_S8,
34 AUD_FMT_U16,
35 AUD_FMT_S16
85571bc7
FB
36} audfmt_e;
37
c0fe3827
FB
38typedef struct {
39 int freq;
40 int nchannels;
41 audfmt_e fmt;
42} audsettings_t;
43
44typedef struct AudioState AudioState;
1d14ffa9
FB
45typedef struct SWVoiceOut SWVoiceOut;
46typedef struct SWVoiceIn SWVoiceIn;
47
c0fe3827
FB
48typedef struct QEMUSoundCard {
49 AudioState *audio;
50 char *name;
51 LIST_ENTRY (QEMUSoundCard) entries;
52} QEMUSoundCard;
53
1d14ffa9
FB
54typedef struct QEMUAudioTimeStamp {
55 uint64_t old_ts;
56} QEMUAudioTimeStamp;
57
58void AUD_vlog (const char *cap, const char *fmt, va_list ap);
59void AUD_log (const char *cap, const char *fmt, ...)
60#ifdef __GNUC__
61 __attribute__ ((__format__ (__printf__, 2, 3)))
62#endif
63 ;
85571bc7 64
c0fe3827 65AudioState *AUD_init (void);
1d14ffa9 66void AUD_help (void);
c0fe3827
FB
67void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card);
68void AUD_remove_card (QEMUSoundCard *card);
1d14ffa9 69
c0fe3827
FB
70SWVoiceOut *AUD_open_out (
71 QEMUSoundCard *card,
1d14ffa9
FB
72 SWVoiceOut *sw,
73 const char *name,
74 void *callback_opaque,
75 audio_callback_fn_t callback_fn,
571ec3d6
FB
76 audsettings_t *settings,
77 int sw_endian
1d14ffa9 78 );
c0fe3827
FB
79
80void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
81int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
82int AUD_get_buffer_size_out (SWVoiceOut *sw);
83void AUD_set_active_out (SWVoiceOut *sw, int on);
84int AUD_is_active_out (SWVoiceOut *sw);
85
86void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
87uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
88
89SWVoiceIn *AUD_open_in (
90 QEMUSoundCard *card,
1d14ffa9
FB
91 SWVoiceIn *sw,
92 const char *name,
93 void *callback_opaque,
94 audio_callback_fn_t callback_fn,
571ec3d6
FB
95 audsettings_t *settings,
96 int sw_endian
1d14ffa9 97 );
c0fe3827
FB
98
99void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
100int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
101void AUD_set_active_in (SWVoiceIn *sw, int on);
102int AUD_is_active_in (SWVoiceIn *sw);
103
104void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
105uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
85571bc7
FB
106
107static inline void *advance (void *p, int incr)
108{
109 uint8_t *d = p;
110 return (d + incr);
111}
112
113uint32_t popcount (uint32_t u);
114inline uint32_t lsbindex (uint32_t u);
115
1d14ffa9
FB
116#ifdef __GNUC__
117#define audio_MIN(a, b) ( __extension__ ({ \
118 __typeof (a) ta = a; \
119 __typeof (b) tb = b; \
120 ((ta)>(tb)?(tb):(ta)); \
121}))
122
123#define audio_MAX(a, b) ( __extension__ ({ \
124 __typeof (a) ta = a; \
125 __typeof (b) tb = b; \
126 ((ta)<(tb)?(tb):(ta)); \
127}))
128#else
85571bc7
FB
129#define audio_MIN(a, b) ((a)>(b)?(b):(a))
130#define audio_MAX(a, b) ((a)<(b)?(b):(a))
1d14ffa9 131#endif
85571bc7
FB
132
133#endif /* audio.h */