xref: /haiku/src/apps/cortex/addons/common/IAudioOp.h (revision c90684742e7361651849be4116d0e5de3a817194)
1 // IAudioOp.h
2 // * PURPOSE
3 //   Abstract audio-operation interface.  Each implementation
4 //   of IAudioOp represents an algorithm for processing
5 //   streaming media.
6 //
7 //   IAudioOp instances are returned by implementations of
8 //   IAudioOpFactory, responsible for finding the
9 //   appropriate algorithm for a given format combination.
10 //
11 // * NOTES
12 //   7sep99:
13 //   +++++ moving back towards a raw interface approach; the host node
14 //         can provide the state/parameter/event-queue access.
15 //         See IAudioOpHost for the operations that the host node needs
16 //         to provide.
17 //
18 // * HISTORY
19 //   e.moon		26aug99		Begun
20 
21 #ifndef __IAudioOp_H__
22 #define __IAudioOp_H__
23 
24 #include "AudioBuffer.h"
25 
26 class IAudioOpHost;
27 class ParameterSet;
28 
29 class IAudioOp {
30 
31 public:											// *** HOST (NODE)
32 	IAudioOpHost* const				host;
33 
34 public:											// *** ctor/dtor
35 	IAudioOp(
36 		IAudioOpHost*						_host) : host(_host) {}
37 
38 	virtual ~IAudioOp() {}
39 
40 public:											// *** REQUIRED INTERFACE
41 
42 	// Process a given source buffer to produce framesRequired
43 	// frames of output (this may differ from the number of frames
44 	// read from input if this is a resampling operation,
45 	// or if the operation requires some amount of 'lookahead'.)
46 	// The time at which the first destination frame should reach
47 	// its destination is given by performanceTime (this should help
48 	// wrt/ accurate parameter-change response.)
49 	//
50 	// Return the number of frames produced (if insufficient source
51 	// frames were available, this may be less than framesRequired;
52 	// it must never be greater.)
53 	// NOTE
54 	//   If the formats are identical, source and destination
55 	//   may reference the same buffer.
56 	//
57 	// ANOTHER NOTE
58 	//   This method may well be called multiple times in response to
59 	//   a single call to the functor method (operator()) if one or
60 	//   more events occur midway through the buffer.
61 	//
62 	virtual uint32 process(
63 		const AudioBuffer&			source,
64 		AudioBuffer&						destination,
65 		double&									sourceFrame,
66 		uint32&									destinationFrame,
67 		uint32									framesRequired,
68 		bigtime_t								performanceTime) =0;
69 
70 	// Replace the given filter operation (responsibility for deleting
71 	// it is yours, in case you want to keep it around for a while.)
72 	//
73 	virtual void replace(
74 		IAudioOp*								oldOp) =0;
75 
76 public:											// *** OPTIONAL INTERFACE
77 
78 	// Called when the host node is started, before any calls to
79 	// process().
80 
81 	virtual void init() {}
82 
83 	// Return the number of input frames required before an output
84 	// frame can be produced.
85 
86 	virtual uint32 bufferLatency() const { return 0; }
87 
88 };
89 
90 #endif /*__IAudioOp_H__*/
91