Added the tone producer add-on for testing and demo purposes

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3292 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper
2003-05-23 21:51:47 +00:00
parent 1b14f4182f
commit 11bb5731c8
6 changed files with 1434 additions and 0 deletions
+1
View File
@@ -6,5 +6,6 @@ SubInclude OBOS_TOP src add-ons media media-add-ons writer ;
SubInclude OBOS_TOP src add-ons media media-add-ons legacy ;
SubInclude OBOS_TOP src add-ons media media-add-ons mixer ;
SubInclude OBOS_TOP src add-ons media media-add-ons multi_audio ;
SubInclude OBOS_TOP src add-ons media media-add-ons tone_producer_demo ;
SubInclude OBOS_TOP src add-ons media media-add-ons video_producer_demo ;
@@ -0,0 +1,8 @@
SubDir OBOS_TOP src add-ons media media-add-ons tone_producer_demo ;
Addon tone_producer_demo.media_addon : media :
ToneProducerAddOn.cpp
ToneProducer.cpp
;
LinkSharedOSLibs tone_producer_demo.media_addon : be media ;
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,229 @@
/*
ToneProducer.h
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
NOTES [email protected] 11june99
- this node has some holes in it, but it's pretty useful starting
point for writing producers.
- I've tried to clean up the format negotiation a bit, which didn't
fare too well when faced with an apathetic downstream node
(LoggingConsumer.)
KNOWN BUGS
eamoon 17jun99
* Can't handle 2 channels, but is too polite to refuse.
How embarrassing.
*/
#ifndef ToneProducer_H
#define ToneProducer_H 1
#include <media/BufferProducer.h>
#include <media/MediaEventLooper.h>
#include <media/Controllable.h>
class BMediaAddOn;
// ----------------
// ToneProducer - a node to generate precisely defined digital tones
class ToneProducer : public BBufferProducer, public BControllable, public BMediaEventLooper
{
public:
enum event_t {
// e.moon 2jun99
_PARAMETER_EVENT = BTimedEventQueue::B_USER_EVENT
};
public:
// add-on-friendly ctor
// e.moon [8jun99]
ToneProducer(BMediaAddOn* pAddOn=0);
~ToneProducer();
// BMediaNode methods
BMediaAddOn* AddOn( int32* internal_id) const;
// BControllable methods
status_t GetParameterValue(
int32 id,
bigtime_t* last_change,
void* value,
size_t* ioSize);
void SetParameterValue(
int32 id,
bigtime_t when,
const void* value,
size_t size);
status_t StartControlPanel(
BMessenger* pMessenger);
// BBufferProducer methods
status_t FormatSuggestionRequested(
media_type type,
int32 quality,
media_format* format);
status_t FormatProposal(
const media_source& output,
media_format* format);
/* If the format isn't good, put a good format into *io_format and return error */
/* If format has wildcard, specialize to what you can do (and change). */
/* If you can change the format, return OK. */
/* The request comes from your destination sychronously, so you cannot ask it */
/* whether it likes it -- you should assume it will since it asked. */
status_t FormatChangeRequested(
const media_source& source,
const media_destination& destination,
media_format* io_format,
int32* _deprecated_);
status_t GetNextOutput( /* cookie starts as 0 */
int32* cookie,
media_output* out_output);
status_t DisposeOutputCookie(
int32 cookie);
/* In this function, you should either pass on the group to your upstream guy, */
/* or delete your current group and hang on to this group. Deleting the previous */
/* group (unless you passed it on with the reclaim flag set to false) is very */
/* important, else you will 1) leak memory and 2) block someone who may want */
/* to reclaim the buffers living in that group. */
status_t SetBufferGroup(
const media_source& for_source,
BBufferGroup* group);
/* Iterates over all outputs and maxes the latency found */
status_t GetLatency(
bigtime_t* out_latency);
status_t PrepareToConnect(
const media_source& what,
const media_destination& where,
media_format* format,
media_source* out_source,
char* out_name);
void Connect(
status_t error,
const media_source& source,
const media_destination& destination,
const media_format& format,
char* io_name);
void Disconnect(
const media_source& what,
const media_destination& where);
void LateNoticeReceived(
const media_source& what,
bigtime_t how_much,
bigtime_t performance_time);
void EnableOutput(
const media_source & what,
bool enabled,
int32* _deprecated_);
status_t SetPlayRate(
int32 numer,
int32 denom);
status_t HandleMessage(
int32 message,
const void* data,
size_t size);
void AdditionalBufferRequested(
const media_source& source,
media_buffer_id prev_buffer,
bigtime_t prev_time,
const media_seek_tag* prev_tag); // may be NULL
void LatencyChanged(
const media_source& source,
const media_destination& destination,
bigtime_t new_latency,
uint32 flags);
// BMediaEventLooper methods
void NodeRegistered();
void Start(bigtime_t performance_time);
// Workaround for a Metrowerks PPC compiler bug
void Stop(bigtime_t performance_time, bool immediate);
// Workaround for a Metrowerks PPC compiler bug
void Seek(bigtime_t media_time, bigtime_t performance_time);
// Workaround for a Metrowerks PPC compiler bug
void TimeWarp(bigtime_t at_real_time, bigtime_t to_performance_time);
// Workaround for a Metrowerks PPC compiler bug
status_t AddTimer(bigtime_t at_performance_time, int32 cookie);
void SetRunMode(run_mode mode);
void HandleEvent(
const media_timed_event* event,
bigtime_t lateness,
bool realTimeEvent = false);
/* removed e.moon 2jun99
protected:
// Workaround for a Metrowerks PPC compiler bug
void CleanUpEvent(const media_timed_event *event);
// Workaround for a Metrowerks PPC compiler bug
bigtime_t OfflineTime();
// Workaround for a Metrowerks PPC compiler bug
void ControlLoop();
// Workaround for a Metrowerks PPC compiler bug
status_t DeleteHook(BMediaNode* node);
*/
private:
void AllocateBuffers();
BBuffer* FillNextBuffer(bigtime_t event_time);
// 20sep99 e.moon: stereo support
void FillSineBuffer(float* data, size_t numFrames, bool stereo);
void FillTriangleBuffer(float* data, size_t numFrames, bool stereo);
void FillSawtoothBuffer(float* data, size_t numFrames, bool stereo);
BParameterWeb* mWeb;
BBufferGroup* mBufferGroup;
bigtime_t mLatency, mInternalLatency;
media_output mOutput;
bool mOutputEnabled;
media_format mPreferredFormat;
// These next attributes are related to tone buffer generation
double mTheta; // generic parameter used by all generators
bool mWaveAscending; // used by the triangle-wave generator
float mFrequency; // can be anything, in Hertz
float mGain; // should be in the range [0,1]
int32 mWaveform;
uint64 mFramesSent;
bigtime_t mStartTime;
// more parameter handling
bigtime_t mGainLastChanged;
bigtime_t mFreqLastChanged;
bigtime_t mWaveLastChanged;
// host addon
// [8jun99] e.moon
BMediaAddOn* m_pAddOn;
};
#endif
@@ -0,0 +1,85 @@
/* Written by Eric Moon, from the Cortex Source code archive.
* Distributed under the terms of the Be Sample Code License
*/
// ToneProducerAddOn.cpp
// e.moon 4jun99
#include "ToneProducer.h"
#include "ToneProducerAddOn.h"
#include <cstring>
#include <cstdlib>
// instantiation function
extern "C" _EXPORT BMediaAddOn* make_media_addon(image_id image) {
return new ToneProducerAddOn(image);
}
// -------------------------------------------------------- //
// ctor/dtor
// -------------------------------------------------------- //
ToneProducerAddOn::~ToneProducerAddOn() {}
ToneProducerAddOn::ToneProducerAddOn(image_id image) :
BMediaAddOn(image) {}
// -------------------------------------------------------- //
// BMediaAddOn impl
// -------------------------------------------------------- //
status_t ToneProducerAddOn::InitCheck(
const char** out_failure_text) {
return B_OK;
}
int32 ToneProducerAddOn::CountFlavors() {
return 1;
}
status_t ToneProducerAddOn::GetFlavorAt(
int32 n,
const flavor_info** out_info) {
if(n)
return B_ERROR;
flavor_info* pInfo = new flavor_info;
pInfo->internal_id = n;
pInfo->name = "ToneProducer";
pInfo->info =
"An add-on version of the ToneProducer node.\n"
"See the Be Developer Newsletter: 2 June, 1999\n"
"adapted by Eric Moon (4 June, 1999)";
pInfo->kinds = B_BUFFER_PRODUCER | B_CONTROLLABLE;
pInfo->flavor_flags = 0;
pInfo->possible_count = 0;
pInfo->in_format_count = 0;
pInfo->in_formats = 0;
pInfo->out_format_count = 1;
media_format* pFormat = new media_format;
pFormat->type = B_MEDIA_RAW_AUDIO;
pFormat->u.raw_audio = media_raw_audio_format::wildcard;
pInfo->out_formats = pFormat;
*out_info = pInfo;
return B_OK;
}
BMediaNode* ToneProducerAddOn::InstantiateNodeFor(
const flavor_info* info,
BMessage* config,
status_t* out_error) {
return new ToneProducer(this);
}
status_t ToneProducerAddOn::GetConfigurationFor(
BMediaNode* your_node,
BMessage* into_message) {
// no config yet
return B_OK;
}
// END -- ToneProducerAddOn.cpp
@@ -0,0 +1,50 @@
/* Written by Eric Moon, from the Cortex Source code archive.
* Distributed under the terms of the Be Sample Code License
*/
// ToneProducerAddOn.h
// e.moon 4jun99
//
// PURPOSE
// Quickie AddOn class for the ToneProducer node.
//
#ifndef __ToneProducerAddOn_H__
#define __ToneProducerAddOn_H__
#include <MediaAddOn.h>
// -------------------------------------------------------- //
class ToneProducerAddOn :
public BMediaAddOn {
typedef BMediaAddOn _inherited;
public: // ctor/dtor
virtual ~ToneProducerAddOn();
explicit ToneProducerAddOn(image_id image);
public: // BMediaAddOn impl
virtual status_t InitCheck(
const char** out_failure_text);
virtual int32 CountFlavors();
virtual status_t GetFlavorAt(
int32 n,
const flavor_info ** out_info);
virtual BMediaNode * InstantiateNodeFor(
const flavor_info * info,
BMessage * config,
status_t * out_error);
virtual status_t GetConfigurationFor(
BMediaNode * your_node,
BMessage * into_message);
virtual bool WantsAutoStart() { return false; }
virtual status_t AutoStart(
int in_count,
BMediaNode ** out_node,
int32 * out_internal_id,
bool * out_has_more) { return B_OK; }
};
#endif /*__ToneProducerAddOn_H__*/