1*11bb5731Sbeveloper /* 2*11bb5731Sbeveloper ToneProducer.h 3*11bb5731Sbeveloper 4*11bb5731Sbeveloper Copyright 1999, Be Incorporated. All Rights Reserved. 5*11bb5731Sbeveloper This file may be used under the terms of the Be Sample Code License. 6*11bb5731Sbeveloper 7*11bb5731Sbeveloper NOTES eamoon@meadgroup.com 11june99 8*11bb5731Sbeveloper - this node has some holes in it, but it's pretty useful starting 9*11bb5731Sbeveloper point for writing producers. 10*11bb5731Sbeveloper - I've tried to clean up the format negotiation a bit, which didn't 11*11bb5731Sbeveloper fare too well when faced with an apathetic downstream node 12*11bb5731Sbeveloper (LoggingConsumer.) 13*11bb5731Sbeveloper 14*11bb5731Sbeveloper KNOWN BUGS 15*11bb5731Sbeveloper eamoon 17jun99 16*11bb5731Sbeveloper * Can't handle 2 channels, but is too polite to refuse. 17*11bb5731Sbeveloper How embarrassing. 18*11bb5731Sbeveloper 19*11bb5731Sbeveloper */ 20*11bb5731Sbeveloper 21*11bb5731Sbeveloper #ifndef ToneProducer_H 22*11bb5731Sbeveloper #define ToneProducer_H 1 23*11bb5731Sbeveloper 24*11bb5731Sbeveloper #include <media/BufferProducer.h> 25*11bb5731Sbeveloper #include <media/MediaEventLooper.h> 26*11bb5731Sbeveloper #include <media/Controllable.h> 27*11bb5731Sbeveloper 28*11bb5731Sbeveloper class BMediaAddOn; 29*11bb5731Sbeveloper 30*11bb5731Sbeveloper // ---------------- 31*11bb5731Sbeveloper // ToneProducer - a node to generate precisely defined digital tones 32*11bb5731Sbeveloper class ToneProducer : public BBufferProducer, public BControllable, public BMediaEventLooper 33*11bb5731Sbeveloper { 34*11bb5731Sbeveloper public: 35*11bb5731Sbeveloper enum event_t { 36*11bb5731Sbeveloper // e.moon 2jun99 37*11bb5731Sbeveloper _PARAMETER_EVENT = BTimedEventQueue::B_USER_EVENT 38*11bb5731Sbeveloper }; 39*11bb5731Sbeveloper 40*11bb5731Sbeveloper public: 41*11bb5731Sbeveloper // add-on-friendly ctor 42*11bb5731Sbeveloper // e.moon [8jun99] 43*11bb5731Sbeveloper ToneProducer(BMediaAddOn* pAddOn=0); 44*11bb5731Sbeveloper ~ToneProducer(); 45*11bb5731Sbeveloper 46*11bb5731Sbeveloper // BMediaNode methods 47*11bb5731Sbeveloper BMediaAddOn* AddOn( int32* internal_id) const; 48*11bb5731Sbeveloper 49*11bb5731Sbeveloper // BControllable methods 50*11bb5731Sbeveloper status_t GetParameterValue( 51*11bb5731Sbeveloper int32 id, 52*11bb5731Sbeveloper bigtime_t* last_change, 53*11bb5731Sbeveloper void* value, 54*11bb5731Sbeveloper size_t* ioSize); 55*11bb5731Sbeveloper 56*11bb5731Sbeveloper void SetParameterValue( 57*11bb5731Sbeveloper int32 id, 58*11bb5731Sbeveloper bigtime_t when, 59*11bb5731Sbeveloper const void* value, 60*11bb5731Sbeveloper size_t size); 61*11bb5731Sbeveloper 62*11bb5731Sbeveloper status_t StartControlPanel( 63*11bb5731Sbeveloper BMessenger* pMessenger); 64*11bb5731Sbeveloper 65*11bb5731Sbeveloper // BBufferProducer methods 66*11bb5731Sbeveloper status_t FormatSuggestionRequested( 67*11bb5731Sbeveloper media_type type, 68*11bb5731Sbeveloper int32 quality, 69*11bb5731Sbeveloper media_format* format); 70*11bb5731Sbeveloper 71*11bb5731Sbeveloper status_t FormatProposal( 72*11bb5731Sbeveloper const media_source& output, 73*11bb5731Sbeveloper media_format* format); 74*11bb5731Sbeveloper 75*11bb5731Sbeveloper /* If the format isn't good, put a good format into *io_format and return error */ 76*11bb5731Sbeveloper /* If format has wildcard, specialize to what you can do (and change). */ 77*11bb5731Sbeveloper /* If you can change the format, return OK. */ 78*11bb5731Sbeveloper /* The request comes from your destination sychronously, so you cannot ask it */ 79*11bb5731Sbeveloper /* whether it likes it -- you should assume it will since it asked. */ 80*11bb5731Sbeveloper status_t FormatChangeRequested( 81*11bb5731Sbeveloper const media_source& source, 82*11bb5731Sbeveloper const media_destination& destination, 83*11bb5731Sbeveloper media_format* io_format, 84*11bb5731Sbeveloper int32* _deprecated_); 85*11bb5731Sbeveloper 86*11bb5731Sbeveloper status_t GetNextOutput( /* cookie starts as 0 */ 87*11bb5731Sbeveloper int32* cookie, 88*11bb5731Sbeveloper media_output* out_output); 89*11bb5731Sbeveloper 90*11bb5731Sbeveloper status_t DisposeOutputCookie( 91*11bb5731Sbeveloper int32 cookie); 92*11bb5731Sbeveloper 93*11bb5731Sbeveloper /* In this function, you should either pass on the group to your upstream guy, */ 94*11bb5731Sbeveloper /* or delete your current group and hang on to this group. Deleting the previous */ 95*11bb5731Sbeveloper /* group (unless you passed it on with the reclaim flag set to false) is very */ 96*11bb5731Sbeveloper /* important, else you will 1) leak memory and 2) block someone who may want */ 97*11bb5731Sbeveloper /* to reclaim the buffers living in that group. */ 98*11bb5731Sbeveloper status_t SetBufferGroup( 99*11bb5731Sbeveloper const media_source& for_source, 100*11bb5731Sbeveloper BBufferGroup* group); 101*11bb5731Sbeveloper 102*11bb5731Sbeveloper /* Iterates over all outputs and maxes the latency found */ 103*11bb5731Sbeveloper status_t GetLatency( 104*11bb5731Sbeveloper bigtime_t* out_latency); 105*11bb5731Sbeveloper 106*11bb5731Sbeveloper status_t PrepareToConnect( 107*11bb5731Sbeveloper const media_source& what, 108*11bb5731Sbeveloper const media_destination& where, 109*11bb5731Sbeveloper media_format* format, 110*11bb5731Sbeveloper media_source* out_source, 111*11bb5731Sbeveloper char* out_name); 112*11bb5731Sbeveloper 113*11bb5731Sbeveloper void Connect( 114*11bb5731Sbeveloper status_t error, 115*11bb5731Sbeveloper const media_source& source, 116*11bb5731Sbeveloper const media_destination& destination, 117*11bb5731Sbeveloper const media_format& format, 118*11bb5731Sbeveloper char* io_name); 119*11bb5731Sbeveloper 120*11bb5731Sbeveloper void Disconnect( 121*11bb5731Sbeveloper const media_source& what, 122*11bb5731Sbeveloper const media_destination& where); 123*11bb5731Sbeveloper 124*11bb5731Sbeveloper void LateNoticeReceived( 125*11bb5731Sbeveloper const media_source& what, 126*11bb5731Sbeveloper bigtime_t how_much, 127*11bb5731Sbeveloper bigtime_t performance_time); 128*11bb5731Sbeveloper 129*11bb5731Sbeveloper void EnableOutput( 130*11bb5731Sbeveloper const media_source & what, 131*11bb5731Sbeveloper bool enabled, 132*11bb5731Sbeveloper int32* _deprecated_); 133*11bb5731Sbeveloper 134*11bb5731Sbeveloper status_t SetPlayRate( 135*11bb5731Sbeveloper int32 numer, 136*11bb5731Sbeveloper int32 denom); 137*11bb5731Sbeveloper 138*11bb5731Sbeveloper status_t HandleMessage( 139*11bb5731Sbeveloper int32 message, 140*11bb5731Sbeveloper const void* data, 141*11bb5731Sbeveloper size_t size); 142*11bb5731Sbeveloper 143*11bb5731Sbeveloper void AdditionalBufferRequested( 144*11bb5731Sbeveloper const media_source& source, 145*11bb5731Sbeveloper media_buffer_id prev_buffer, 146*11bb5731Sbeveloper bigtime_t prev_time, 147*11bb5731Sbeveloper const media_seek_tag* prev_tag); // may be NULL 148*11bb5731Sbeveloper 149*11bb5731Sbeveloper void LatencyChanged( 150*11bb5731Sbeveloper const media_source& source, 151*11bb5731Sbeveloper const media_destination& destination, 152*11bb5731Sbeveloper bigtime_t new_latency, 153*11bb5731Sbeveloper uint32 flags); 154*11bb5731Sbeveloper 155*11bb5731Sbeveloper // BMediaEventLooper methods 156*11bb5731Sbeveloper void NodeRegistered(); 157*11bb5731Sbeveloper 158*11bb5731Sbeveloper void Start(bigtime_t performance_time); 159*11bb5731Sbeveloper 160*11bb5731Sbeveloper // Workaround for a Metrowerks PPC compiler bug 161*11bb5731Sbeveloper void Stop(bigtime_t performance_time, bool immediate); 162*11bb5731Sbeveloper 163*11bb5731Sbeveloper void SetRunMode(run_mode mode); 164*11bb5731Sbeveloper 165*11bb5731Sbeveloper void HandleEvent( 166*11bb5731Sbeveloper const media_timed_event* event, 167*11bb5731Sbeveloper bigtime_t lateness, 168*11bb5731Sbeveloper bool realTimeEvent = false); 169*11bb5731Sbeveloper 170*11bb5731Sbeveloper private: 171*11bb5731Sbeveloper void AllocateBuffers(); 172*11bb5731Sbeveloper BBuffer* FillNextBuffer(bigtime_t event_time); 173*11bb5731Sbeveloper 174*11bb5731Sbeveloper // 20sep99 e.moon: stereo support 175*11bb5731Sbeveloper void FillSineBuffer(float* data, size_t numFrames, bool stereo); 176*11bb5731Sbeveloper void FillTriangleBuffer(float* data, size_t numFrames, bool stereo); 177*11bb5731Sbeveloper void FillSawtoothBuffer(float* data, size_t numFrames, bool stereo); 178*11bb5731Sbeveloper 179*11bb5731Sbeveloper BParameterWeb* mWeb; 180*11bb5731Sbeveloper BBufferGroup* mBufferGroup; 181*11bb5731Sbeveloper bigtime_t mLatency, mInternalLatency; 182*11bb5731Sbeveloper media_output mOutput; 183*11bb5731Sbeveloper bool mOutputEnabled; 184*11bb5731Sbeveloper media_format mPreferredFormat; 185*11bb5731Sbeveloper 186*11bb5731Sbeveloper // These next attributes are related to tone buffer generation 187*11bb5731Sbeveloper double mTheta; // generic parameter used by all generators 188*11bb5731Sbeveloper bool mWaveAscending; // used by the triangle-wave generator 189*11bb5731Sbeveloper float mFrequency; // can be anything, in Hertz 190*11bb5731Sbeveloper float mGain; // should be in the range [0,1] 191*11bb5731Sbeveloper int32 mWaveform; 192*11bb5731Sbeveloper uint64 mFramesSent; 193*11bb5731Sbeveloper bigtime_t mStartTime; 194*11bb5731Sbeveloper 195*11bb5731Sbeveloper // more parameter handling 196*11bb5731Sbeveloper bigtime_t mGainLastChanged; 197*11bb5731Sbeveloper bigtime_t mFreqLastChanged; 198*11bb5731Sbeveloper bigtime_t mWaveLastChanged; 199*11bb5731Sbeveloper 200*11bb5731Sbeveloper // host addon 201*11bb5731Sbeveloper // [8jun99] e.moon 202*11bb5731Sbeveloper BMediaAddOn* m_pAddOn; 203*11bb5731Sbeveloper }; 204*11bb5731Sbeveloper 205*11bb5731Sbeveloper #endif 206