xref: /haiku/src/kits/media/legacy/OldAudioModule.h (revision 2cad94c1c30b6223ad8c08710b26e071d32e9979)
1 /* ================
2 
3    FILE:  AudioModule.h
4    REVS:  $Revision: 1.1 $
5    NAME:  marc
6 
7    Copyright (c) 1997 by Be Incorporated.  All Rights Reserved.
8 
9 ================ */
10 
11 #ifndef _AUDIO_MODULE_H
12 #define _AUDIO_MODULE_H
13 
14 #include <File.h>
15 
16 #include "OldMediaModule.h"
17 #include "OldMediaDefs.h"
18 
19 class BADCStream;
20 class BDACStream;
21 class BSubscriber;
22 
23 class BAudioEvent : public BMediaEvent {
24 public:
25   BAudioEvent(int32 frames, bool stereo, float* samples = NULL);
26   ~BAudioEvent();
27 
28   virtual mk_time		Start();
29   virtual void			SetStart(mk_time);
30   virtual mk_time		Duration();
31   virtual int32			Frames();
32   virtual float*		Samples();
33   virtual int32			ChannelCount();
34   virtual float			Gain();
35   virtual void			SetGain(float);
36   virtual int32			Destination();
37   virtual void			SetDestination(int32);
38   virtual bool			MixIn (float* dst, int32 frames, mk_time time);
39   virtual BMediaEvent*	Clone();
40   virtual bigtime_t		CaptureTime();
41   virtual void			SetCaptureTime(bigtime_t);
42 
43 private:
44   mk_time	fStart;
45   int32		fFrames;
46   float*	fSamples;
47   float		fGain;
48   int32		fDestination;
49   bigtime_t	fCaptureTime;
50   bool		fStereo;
51   bool		fFreeHuey;
52 };
53 
54 
55 class BDACRenderer : public BMediaRenderer {
56 public:
57   BDACRenderer(const char* name = NULL);
58   ~BDACRenderer();
59 
60   mk_rate		Units();
61   mk_time		Latency();
62   mk_time		Start();
63   mk_time		Duration();
64   BTimeBase*	TimeBase();
65   void			Open();
66   void			Close();
67   void			Wakeup();
68   void			TransportChanged(mk_time time, mk_rate rate,
69 								 transport_status status);
70   void			StreamChanged();
71 
72   virtual BMediaChannel*	Channel();
73 
74 private:
75   static bool	_WriteDAC(void* arg, char* buf, uint32 bytes, void* header);
76   bool			WriteDAC(short* buf, int32 frames, audio_buffer_header* header);
77   bool			MixActiveSegments(mk_time start);
78   void			MixOutput(short* dst);
79 
80   BMediaChannel*	fChannel;
81   BDACStream*		fDACStream;
82   BSubscriber*		fSubscriber;
83   float*			fBuffer;
84   int32				fBufferFrames;
85   BList				fActiveSegments;
86   mk_time			fLatency;
87   mk_time			fNextTime;
88   bool				fRunning;
89   BTimeBase			fDACTimeBase;
90 };
91 
92 
93 class BAudioFileStream : public BEventStream {
94 public:
95   BAudioFileStream(BMediaChannel* channel, BFile* file,
96 				   mk_time start = B_UNDEFINED_MK_TIME);
97   ~BAudioFileStream();
98 
99   BMediaEvent*				GetEvent(BMediaChannel* channel);
100   BMediaEvent*				PeekEvent(BMediaChannel* channel, mk_time asap = 0);
101   status_t					SeekToTime(BMediaChannel* channel, mk_time time);
102   void						SetStart(mk_time start);
103 
104   virtual bigtime_t 		CaptureTime();
105   virtual BMediaChannel*	Channel();
106 
107 private:
108   BMediaChannel*	fChannel;
109   BFile*			fFile;
110   mk_time			fTime;
111   BAudioEvent*		fCurrentEvent;
112   short*			fBuffer;
113 };
114 
115 
116 class BADCSource : public BEventStream {
117 public:
118   BADCSource(BMediaChannel* channel, mk_time start = 0);
119   ~BADCSource();
120 
121   BMediaEvent*				GetEvent(BMediaChannel* channel);
122   BMediaEvent*				PeekEvent(BMediaChannel* channel, mk_time asap = 0);
123   status_t					SeekToTime(BMediaChannel* channel, mk_time time);
124   void						SetStart(mk_time start);
125 
126   virtual BMediaChannel*	Channel();
127 
128 private:
129   static bool	_ReadADC(void* arg, char* buf, uint32 bytes, void* header);
130   void			ReadADC(short* buf, int32 frames, audio_buffer_header* header);
131 
132   BMediaChannel*	fChannel;
133   BFile*			fFile;
134   mk_time			fTime;
135   BAudioEvent*		fCurrentEvent;
136   BAudioEvent*		fNextEvent;
137   BLocker			fEventLock;
138   BADCStream*		fADCStream;
139   BSubscriber*		fSubscriber;
140 };
141 
142 
143 #endif
144