xref: /haiku/src/add-ons/kernel/drivers/audio/echo/echo.h (revision c2ddc71cc54397447f60bda00ea1ceca5c80bead)
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 #define	ECHO_USE_PLAY		(1 << 0)
39 #define	ECHO_USE_RECORD	(1 << 1)
40 #define ECHO_STATE_STARTED	(1 << 0)
41 
42 /*
43  * Streams
44  */
45 
46 typedef struct _echo_stream {
47 	struct _echo_dev 	*card;
48 	uint8        		use;
49 	uint8        		state;
50 	uint8        		bitsPerSample;
51 	uint32       		sample_rate;
52 	uint8				channels;
53 	uint32 				bufframes;
54 	uint8 				bufcount;
55 
56 	WORD				pipe;
57 	PDWORD				position;
58 
59 	LIST_ENTRY(_echo_stream)	next;
60 
61 	void            	(*inth) (void *);
62 	void           		*inthparam;
63 
64 	echo_mem 	*buffer;
65 	uint16       blksize;	/* in samples */
66 	uint16       trigblk;	/* blk on which to trigger inth */
67 	uint16       blkmod;	/* Modulo value to wrap trigblk */
68 
69 	/* multi_audio */
70 	volatile int64	frames_count;	// for play or record
71 	volatile bigtime_t real_time;	// for play or record
72 	volatile int32	buffer_cycle;	// for play or record
73 	int32 first_channel;
74 	bool update_needed;
75 } echo_stream;
76 
77 
78 typedef struct _echo_dev {
79 	char		name[DEVNAME];	/* used for resources */
80 	pci_info	info;
81 
82 	uint32	bmbar;
83 	void *	log_bmbar;
84 	area_id area_bmbar;
85 	uint32	irq;
86 	uint16	type;
87 
88 	PCEchoGals	pEG;
89 	PCOsSupport pOSS;
90 
91 	void	*ptb_log_base;
92 	void	*ptb_phy_base;
93 	area_id ptb_area;
94 
95 	sem_id buffer_ready_sem;
96 
97 	LIST_HEAD(, _echo_stream) streams;
98 	LIST_HEAD(, _echo_mem) mems;
99 
100 	echo_stream		*pstream;
101 	echo_stream		*rstream;
102 
103 	/* multi_audio */
104 	multi_dev	multi;
105 } echo_dev;
106 
107 extern int32 num_cards;
108 extern echo_dev cards[NUM_CARDS];
109 
110 #ifdef __cplusplus
111 extern "C" {
112 #endif
113 
114 status_t echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
115 			     uint8 bitsPerSample, uint32 sample_rate);
116 status_t echo_stream_get_nth_buffer(echo_stream *stream, uint8 chan, uint8 buf,
117 					char** buffer, size_t *stride);
118 void echo_stream_start(echo_stream *stream, void (*inth) (void *), void *inthparam);
119 void echo_stream_halt(echo_stream *stream);
120 echo_stream *echo_stream_new(echo_dev *card, uint8 use, uint32 bufframes, uint8 bufcount);
121 void echo_stream_delete(echo_stream *stream);
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 
128 #endif /* _ECHO_H_ */
129