xref: /haiku/src/add-ons/media/media-add-ons/opensound/OpenSoundDevice.h (revision 08c82102cfa929042c6f33aa2e9b9edab276f5be)
1 /*
2  * Copyright (c) 2002-2007, Jerome Duval (jerome.duval@free.fr)
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #ifndef _OPENSOUNDDEVICE_H
7 #define _OPENSOUNDDEVICE_H
8 
9 #include <OS.h>
10 #include <List.h>
11 #include <MediaFormats.h>
12 #include <Locker.h>
13 #include "soundcard.h"
14 
15 //
16 //#define OSS_PREFIX "/dev/audio/oss/"
17 #define OSS_PREFIX "/dev/oss/"
18 // should be fixed later
19 #define OSS_MIXER_DEV "/dev/mixer"
20 
21 #define MAX_CONTROLS	128
22 #define MAX_CHANNELS	32
23 #define NB_BUFFERS		32
24 
25 #define DEFAULT_BUFFER_SIZE 2048
26 
27 /* define to support encoded audio (AC3, MPEG, ...) when the card supports it */
28 //#define ENABLE_NON_RAW_SUPPORT 1
29 //XXX: make it a BParameter ?
30 
31 #define ENABLE_REC 1
32 
33 // timeout in OpenSoundNode::RunThread()
34 #define MIN_SNOOZING 2000
35 
36 // pretend we don't drift
37 #define DISABLE_DRIFT 1
38 
39 
40 /* bit mask of supported formats for raw_audio */
41 /* also used to mark the raw_audio node input&outputs */
42 //XXX: _OE ?
43 #define AFMT_SUPPORTED_PCM (AFMT_U8|AFMT_S8|\
44 							AFMT_S16_NE|\
45 							AFMT_S24_NE|AFMT_S32_NE|\
46 							AFMT_S16_OE|\
47 							AFMT_S24_OE|AFMT_S32_OE|\
48 							AFMT_FLOAT)
49 
50 
51 extern const int gSupportedFormats[];
52 extern const char *gSupportedFormatsNames[];
53 
54 class OpenSoundDeviceEngine;
55 class OpenSoundDeviceMixer;
56 
57 
58 class OpenSoundDevice
59 {
60 	public:
61 		explicit OpenSoundDevice(oss_card_info *cardinfo);
62 		virtual ~OpenSoundDevice(void);
63 
64 		status_t			InitDriver();
65 		virtual status_t InitCheck(void) const;
66 
67 		status_t			AddEngine(oss_audioinfo *info);
68 		status_t			AddMixer(oss_mixerinfo *info);
69 //		status_t			AddMidi();
70 
71 		int32					CountEngines();
72 		int32					CountMixers();
73 		OpenSoundDeviceEngine	*EngineAt(int32 i);
74 		OpenSoundDeviceMixer	*MixerAt(int32 i);
75 
76 		OpenSoundDeviceEngine	*NextFreeEngineAt(int32 i, bool rec=false);
77 
Locker()78 		BLocker					*Locker() { return &fLocker; };
79 
80 		static float convert_oss_rate_to_media_rate(int rate);
81 		static int convert_media_rate_to_oss_rate(float rate);
82 		static uint32 convert_oss_format_to_media_format(int fmt);
83 		static int convert_oss_format_to_endian(int fmt);
84 		static int16 convert_oss_format_to_valid_bits(int fmt);
85 		static int convert_media_format_to_oss_format(uint32 fmt);
86 		static int select_oss_rate(const oss_audioinfo *info, int rate);
87 		static int select_oss_format(int fmt);
88 
89 		static status_t get_media_format_description_for(int fmt, media_format_description *desc, int count=1);
90 		static status_t register_media_formats();
91 		static status_t get_media_format_for(int fmt, media_format &format);
92 
93 	public:
94 		oss_card_info			fCardInfo;
95 
96 	private:
97 		status_t 				fInitCheckStatus;
98 		BList					fEngines;
99 		BList					fMixers;
100 friend class OpenSoundNode; // ugly
101 friend class OpenSoundDeviceEngine; // ugly
102 		audio_buf_info			fFragments;
103 		BLocker					fLocker;
104 };
105 
106 #endif
107