xref: /haiku/src/add-ons/kernel/drivers/audio/echo/echo.h (revision c9002531707d3f9a185a100dc6393d7b6e75aca3)
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 	ECHOGALS_CAPS	caps;
90 	NUINT		mixer;
91 	PCOsSupport pOSS;
92 
93 	void	*ptb_log_base;
94 	void	*ptb_phy_base;
95 	area_id ptb_area;
96 
97 	sem_id buffer_ready_sem;
98 
99 	LIST_HEAD(, _echo_stream) streams;
100 	LIST_HEAD(, _echo_mem) mems;
101 
102 	echo_stream		*pstream, *pstream2;
103 	echo_stream		*rstream;
104 
105 	/* multi_audio */
106 	multi_dev	multi;
107 } echo_dev;
108 
109 extern int32 num_cards;
110 extern echo_dev cards[NUM_CARDS];
111 
112 #ifdef __cplusplus
113 extern "C" {
114 #endif
115 
116 status_t echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
117 			     uint8 bitsPerSample, uint32 sample_ratei, uint8 index);
118 status_t echo_stream_get_nth_buffer(echo_stream *stream, uint8 chan, uint8 buf,
119 					char** buffer, size_t *stride);
120 void echo_stream_start(echo_stream *stream, void (*inth) (void *), void *inthparam);
121 void echo_stream_halt(echo_stream *stream);
122 echo_stream *echo_stream_new(echo_dev *card, uint8 use, uint32 bufframes, uint8 bufcount);
123 void echo_stream_delete(echo_stream *stream);
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 
130 #endif /* _ECHO_H_ */
131