xref: /haiku/src/add-ons/media/media-add-ons/opensound/OpenSoundDevice.h (revision de6be214a057eaff48008ca30a411a868aedad19)
1*de6be214SFrançois Revol /*
2*de6be214SFrançois Revol  * Copyright (c) 2002-2007, Jerome Duval (jerome.duval@free.fr)
3*de6be214SFrançois Revol  * Distributed under the terms of the MIT License.
4*de6be214SFrançois Revol  */
5*de6be214SFrançois Revol 
6*de6be214SFrançois Revol #ifndef _OPENSOUNDDEVICE_H
7*de6be214SFrançois Revol #define _OPENSOUNDDEVICE_H
8*de6be214SFrançois Revol 
9*de6be214SFrançois Revol #include <OS.h>
10*de6be214SFrançois Revol #include <List.h>
11*de6be214SFrançois Revol #include <MediaFormats.h>
12*de6be214SFrançois Revol #include <Locker.h>
13*de6be214SFrançois Revol #include "soundcard.h"
14*de6be214SFrançois Revol 
15*de6be214SFrançois Revol //
16*de6be214SFrançois Revol //#define OSS_PREFIX "/dev/audio/oss/"
17*de6be214SFrançois Revol #define OSS_PREFIX "/dev/oss/"
18*de6be214SFrançois Revol // should be fixed later
19*de6be214SFrançois Revol #define OSS_MIXER_DEV "/dev/mixer"
20*de6be214SFrançois Revol 
21*de6be214SFrançois Revol #define MAX_CONTROLS	128
22*de6be214SFrançois Revol #define MAX_CHANNELS	32
23*de6be214SFrançois Revol #define NB_BUFFERS		32
24*de6be214SFrançois Revol 
25*de6be214SFrançois Revol //#define DEFAULT_BUFFER_SIZE 2048
26*de6be214SFrançois Revol //#define DEFAULT_BUFFER_SIZE (32*1024)
27*de6be214SFrançois Revol #define DEFAULT_BUFFER_SIZE (16*1024)
28*de6be214SFrançois Revol //#define DEFAULT_BUFFER_SIZE (2*1024)
29*de6be214SFrançois Revol 
30*de6be214SFrançois Revol /* define to support encoded audio (AC3, MPEG, ...) when the card supports it */
31*de6be214SFrançois Revol //#define ENABLE_NON_RAW_SUPPORT 1
32*de6be214SFrançois Revol //XXX: make it a BParameter ?
33*de6be214SFrançois Revol 
34*de6be214SFrançois Revol #define ENABLE_REC 1
35*de6be214SFrançois Revol 
36*de6be214SFrançois Revol /* bit mask of supported formats for raw_audio */
37*de6be214SFrançois Revol /* also used to mark the raw_audio node input&outputs */
38*de6be214SFrançois Revol //XXX: _OE ?
39*de6be214SFrançois Revol #define AFMT_SUPPORTED_PCM (AFMT_U8|AFMT_S8|\
40*de6be214SFrançois Revol 							AFMT_S16_NE|\
41*de6be214SFrançois Revol 							AFMT_S24_NE|AFMT_S32_NE|\
42*de6be214SFrançois Revol 							AFMT_S16_OE|\
43*de6be214SFrançois Revol 							AFMT_S24_OE|AFMT_S32_OE|\
44*de6be214SFrançois Revol 							AFMT_FLOAT)
45*de6be214SFrançois Revol 
46*de6be214SFrançois Revol 
47*de6be214SFrançois Revol extern const int gSupportedFormats[];
48*de6be214SFrançois Revol extern const char *gSupportedFormatsNames[];
49*de6be214SFrançois Revol 
50*de6be214SFrançois Revol class OpenSoundDeviceEngine;
51*de6be214SFrançois Revol class OpenSoundDeviceMixer;
52*de6be214SFrançois Revol 
53*de6be214SFrançois Revol 
54*de6be214SFrançois Revol class OpenSoundDevice
55*de6be214SFrançois Revol {
56*de6be214SFrançois Revol 	public:
57*de6be214SFrançois Revol 		explicit OpenSoundDevice(oss_card_info *cardinfo);
58*de6be214SFrançois Revol 		virtual ~OpenSoundDevice(void);
59*de6be214SFrançois Revol 
60*de6be214SFrançois Revol 		status_t			InitDriver();
61*de6be214SFrançois Revol 		virtual status_t InitCheck(void) const;
62*de6be214SFrançois Revol 
63*de6be214SFrançois Revol 		status_t			AddEngine(oss_audioinfo *info);
64*de6be214SFrançois Revol 		status_t			AddMixer(oss_mixerinfo *info);
65*de6be214SFrançois Revol //		status_t			AddMidi();
66*de6be214SFrançois Revol 
67*de6be214SFrançois Revol 		int32					CountEngines();
68*de6be214SFrançois Revol 		int32					CountMixers();
69*de6be214SFrançois Revol 		OpenSoundDeviceEngine	*EngineAt(int32 i);
70*de6be214SFrançois Revol 		OpenSoundDeviceMixer	*MixerAt(int32 i);
71*de6be214SFrançois Revol 
72*de6be214SFrançois Revol 		OpenSoundDeviceEngine	*NextFreeEngineAt(int32 i, bool rec=false);
73*de6be214SFrançois Revol 
74*de6be214SFrançois Revol 		BLocker					*Locker() { return &fLocker; };
75*de6be214SFrançois Revol 
76*de6be214SFrançois Revol 		static float convert_oss_rate_to_media_rate(int rate);
77*de6be214SFrançois Revol 		static int convert_media_rate_to_oss_rate(float rate);
78*de6be214SFrançois Revol 		static uint32 convert_oss_format_to_media_format(int fmt);
79*de6be214SFrançois Revol 		static int convert_oss_format_to_endian(int fmt);
80*de6be214SFrançois Revol 		static int16 convert_oss_format_to_valid_bits(int fmt);
81*de6be214SFrançois Revol 		static int convert_media_format_to_oss_format(uint32 fmt);
82*de6be214SFrançois Revol 		static int select_oss_rate(const oss_audioinfo *info, int rate);
83*de6be214SFrançois Revol 		static int select_oss_format(int fmt);
84*de6be214SFrançois Revol 
85*de6be214SFrançois Revol 		static status_t get_media_format_description_for(int fmt, media_format_description *desc, int count=1);
86*de6be214SFrançois Revol 		static status_t register_media_formats();
87*de6be214SFrançois Revol 		static status_t get_media_format_for(int fmt, media_format &format);
88*de6be214SFrançois Revol #if MA
89*de6be214SFrançois Revol 		static float convert_oss_rate_to_media_rate(uint32 rate);
90*de6be214SFrançois Revol 		static uint32 convert_media_rate_to_oss_rate(float rate);
91*de6be214SFrançois Revol 		static uint32 convert_oss_format_to_media_format(uint32 fmt);
92*de6be214SFrançois Revol 		static int16 convert_oss_format_to_valid_bits(uint32 fmt);
93*de6be214SFrançois Revol 		static uint32 convert_media_format_to_oss_format(uint32 fmt);
94*de6be214SFrançois Revol 		static uint32 select_oss_rate(uint32 rate);
95*de6be214SFrançois Revol 		static uint32 select_oss_format(uint32 fmt);
96*de6be214SFrançois Revol 
97*de6be214SFrançois Revol 		int DoBufferExchange(multi_buffer_info *MBI);
98*de6be214SFrançois Revol 		int DoSetMix(multi_mix_value_info *MMVI);
99*de6be214SFrançois Revol 		int DoGetMix(multi_mix_value_info *MMVI);
100*de6be214SFrançois Revol #endif
101*de6be214SFrançois Revol 
102*de6be214SFrançois Revol 	private:
103*de6be214SFrançois Revol 
104*de6be214SFrançois Revol 		char					fDevice_name[32];
105*de6be214SFrançois Revol 		char					fDevice_path[32];
106*de6be214SFrançois Revol 		int						fMixFD;
107*de6be214SFrançois Revol 		int						fPcmFDs[MAX_CHANNELS];
108*de6be214SFrançois Revol 		int						fSpdifFDs[MAX_CHANNELS];
109*de6be214SFrançois Revol #if MA
110*de6be214SFrançois Revol 		int						fd; 			//file descriptor for hw driver
111*de6be214SFrançois Revol #endif
112*de6be214SFrançois Revol 
113*de6be214SFrançois Revol 	public:
114*de6be214SFrançois Revol 		oss_card_info			fCardInfo;
115*de6be214SFrançois Revol #if MA
116*de6be214SFrançois Revol 		multi_description		MD;
117*de6be214SFrançois Revol 		multi_channel_info		MCI[MAX_CHANNELS];
118*de6be214SFrançois Revol 		multi_format_info 		MFI;
119*de6be214SFrançois Revol 		multi_buffer_list 		MBL;
120*de6be214SFrançois Revol 
121*de6be214SFrançois Revol 		multi_mix_control_info 	MMCI;
122*de6be214SFrançois Revol 		multi_mix_control		MMC[MAX_CONTROLS];
123*de6be214SFrançois Revol 
124*de6be214SFrançois Revol 		buffer_desc		play_buffer_list[NB_BUFFERS * MAX_CHANNELS];
125*de6be214SFrançois Revol 		buffer_desc		record_buffer_list[NB_BUFFERS * MAX_CHANNELS];
126*de6be214SFrançois Revol 		buffer_desc 	*play_buffer_desc[NB_BUFFERS];
127*de6be214SFrançois Revol 		buffer_desc 	*record_buffer_desc[NB_BUFFERS];
128*de6be214SFrançois Revol #endif
129*de6be214SFrançois Revol 
130*de6be214SFrançois Revol 	private:
131*de6be214SFrançois Revol 		status_t 				fInitCheckStatus;
132*de6be214SFrançois Revol 		BList					fEngines;
133*de6be214SFrançois Revol 		BList					fMixers;
134*de6be214SFrançois Revol friend class OpenSoundNode; // ugly
135*de6be214SFrançois Revol friend class OpenSoundDeviceEngine; // ugly
136*de6be214SFrançois Revol 		audio_buf_info			fFragments;
137*de6be214SFrançois Revol 		BLocker					fLocker;
138*de6be214SFrançois Revol };
139*de6be214SFrançois Revol 
140*de6be214SFrançois Revol #endif
141