xref: /haiku/src/add-ons/kernel/drivers/audio/echo/echo.h (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
1 //------------------------------------------------------------------------------
2 //	EchoGals/Echo24 BeOS Driver for Echo audio cards
3 //
4 //  Copyright (c) 2003, Jérôme Duval
5 //
6 //	Permission is hereby granted, free of charge, to any person obtaining a
7 //	copy of this software and associated documentation files (the "Software"),
8 //	to deal in the Software without restriction, including without limitation
9 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 //	and/or sell copies of the Software, and to permit persons to whom the
11 //	Software is 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 THE
19 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 //	DEALINGS IN THE SOFTWARE.
23 
24 #ifndef _ECHO_H_
25 #define _ECHO_H_
26 
27 #include <PCI.h>
28 #include "OsSupportBeOS.h"
29 #include "CEchoGals.h"
30 #include "multi_audio.h"
31 #include "multi.h"
32 #include "queue.h"
33 
34 #define AUTHOR "Jérôme Duval"
35 #define DEVNAME 32
36 #define NUM_CARDS 3
37 
38 
39 /*
40  * Echo midi
41  */
42 
43 typedef struct _midi_dev {
44 	int32		count;
45 	char		name[64];
46 	sem_id 		midi_ready_sem;
47 	ECHOGALS_MIDI_IN_CONTEXT	context;
48 } midi_dev;
49 
50 #define	ECHO_USE_PLAY		(1 << 0)
51 #define	ECHO_USE_RECORD	(1 << 1)
52 #define ECHO_STATE_STARTED	(1 << 0)
53 
54 /*
55  * Streams
56  */
57 
58 typedef struct _echo_stream {
59 	struct _echo_dev 	*card;
60 	uint8        		use;
61 	uint8        		state;
62 	uint8        		bitsPerSample;
63 	uint32       		sample_rate;
64 	uint8				channels;
65 	uint32 				bufframes;
66 	uint8 				bufcount;
67 
68 	WORD				pipe;
69 	PDWORD				position;
70 
71 	LIST_ENTRY(_echo_stream)	next;
72 
73 	void            	(*inth) (void *);
74 	void           		*inthparam;
75 
76 	echo_mem 	*buffer;
77 	uint16       blksize;	/* in samples */
78 	uint16       trigblk;	/* blk on which to trigger inth */
79 	uint16       blkmod;	/* Modulo value to wrap trigblk */
80 
81 	/* multi_audio */
82 	volatile int64	frames_count;	// for play or record
83 	volatile bigtime_t real_time;	// for play or record
84 	volatile int32	buffer_cycle;	// for play or record
85 	int32 first_channel;
86 	bool update_needed;
87 } echo_stream;
88 
89 
90 typedef struct _echo_dev {
91 	char		name[DEVNAME];	/* used for resources */
92 	pci_info	info;
93 
94 	uint32	bmbar;
95 	void *	log_bmbar;
96 	area_id area_bmbar;
97 	uint32	irq;
98 	uint16	type;
99 
100 	PCEchoGals	pEG;
101 	ECHOGALS_CAPS	caps;
102 	NUINT		mixer;
103 	PCOsSupport pOSS;
104 
105 	void	*ptb_log_base;
106 	void	*ptb_phy_base;
107 	area_id ptb_area;
108 
109 	sem_id buffer_ready_sem;
110 
111 	LIST_HEAD(, _echo_stream) streams;
112 	LIST_HEAD(, _echo_mem) mems;
113 
114 	echo_stream		*pstream;
115 	echo_stream		*rstream;
116 
117 	/* multi_audio */
118 	multi_dev	multi;
119 #ifdef MIDI_SUPPORT
120 	midi_dev 	midi;
121 #endif
122 } echo_dev;
123 
124 extern int32 num_cards;
125 extern echo_dev cards[NUM_CARDS];
126 
127 #ifdef __cplusplus
128 extern "C" {
129 #endif
130 
131 status_t echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
132 			     uint8 bitsPerSample, uint32 sample_ratei, uint8 index);
133 status_t echo_stream_get_nth_buffer(echo_stream *stream, uint8 chan, uint8 buf,
134 					char** buffer, size_t *stride);
135 void echo_stream_start(echo_stream *stream, void (*inth) (void *), void *inthparam);
136 void echo_stream_halt(echo_stream *stream);
137 echo_stream *echo_stream_new(echo_dev *card, uint8 use, uint32 bufframes, uint8 bufcount);
138 void echo_stream_delete(echo_stream *stream);
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 
145 #endif /* _ECHO_H_ */
146