|
|
|
@@ -119,7 +119,7 @@ ToneProducer::AddOn(int32 *internal_id) const
|
|
|
|
|
//#pragma mark -
|
|
|
|
|
|
|
|
|
|
// BControllable methods
|
|
|
|
|
status_t
|
|
|
|
|
status_t
|
|
|
|
|
ToneProducer::GetParameterValue(int32 id, bigtime_t* last_change, void* value, size_t* ioSize)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::GetParameterValue\n");
|
|
|
|
@@ -161,7 +161,7 @@ ToneProducer::GetParameterValue(int32 id, bigtime_t* last_change, void* value, s
|
|
|
|
|
return B_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::SetParameterValue(int32 id, bigtime_t performance_time, const void* value, size_t size)
|
|
|
|
|
{
|
|
|
|
|
switch (id)
|
|
|
|
@@ -194,14 +194,14 @@ status_t ToneProducer::StartControlPanel(
|
|
|
|
|
if(pMessenger && pMessenger->IsValid()) {
|
|
|
|
|
PRINT(("\tgot valid control panel\n"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//#pragma mark -
|
|
|
|
|
|
|
|
|
|
// BBufferProducer methods
|
|
|
|
|
status_t
|
|
|
|
|
status_t
|
|
|
|
|
ToneProducer::FormatSuggestionRequested(media_type type, int32 /*quality*/, media_format* format)
|
|
|
|
|
{
|
|
|
|
|
// FormatSuggestionRequested() is not necessarily part of the format negotiation
|
|
|
|
@@ -226,7 +226,7 @@ ToneProducer::FormatSuggestionRequested(media_type type, int32 /*quality*/, medi
|
|
|
|
|
else return B_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
|
status_t
|
|
|
|
|
ToneProducer::FormatProposal(const media_source& output, media_format* format)
|
|
|
|
|
{
|
|
|
|
|
// FormatProposal() is the first stage in the BMediaRoster::Connect() process. We hand
|
|
|
|
@@ -242,7 +242,7 @@ ToneProducer::FormatProposal(const media_source& output, media_format* format)
|
|
|
|
|
|
|
|
|
|
// we only support floating-point raw audio, so we always return that, but we
|
|
|
|
|
// supply an error code depending on whether we found the proposal acceptable.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
media_type requestedType = format->type;
|
|
|
|
|
*format = mPreferredFormat;
|
|
|
|
|
if ((requestedType != B_MEDIA_UNKNOWN_TYPE) && (requestedType != B_MEDIA_RAW_AUDIO))
|
|
|
|
@@ -253,7 +253,7 @@ ToneProducer::FormatProposal(const media_source& output, media_format* format)
|
|
|
|
|
else return B_OK; // raw audio or wildcard type, either is okay by us
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
|
status_t
|
|
|
|
|
ToneProducer::FormatChangeRequested(const media_source& source, const media_destination& destination, media_format* io_format, int32* _deprecated_)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::FormatChangeRequested\n");
|
|
|
|
@@ -262,7 +262,7 @@ ToneProducer::FormatChangeRequested(const media_source& source, const media_dest
|
|
|
|
|
return B_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
|
status_t
|
|
|
|
|
ToneProducer::GetNextOutput(int32* cookie, media_output* out_output)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::GetNextOutput\n");
|
|
|
|
@@ -279,7 +279,7 @@ ToneProducer::GetNextOutput(int32* cookie, media_output* out_output)
|
|
|
|
|
else return B_BAD_INDEX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
|
status_t
|
|
|
|
|
ToneProducer::DisposeOutputCookie(int32 cookie)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::DisposeOutputCookie\n");
|
|
|
|
@@ -288,7 +288,7 @@ ToneProducer::DisposeOutputCookie(int32 cookie)
|
|
|
|
|
return B_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
|
status_t
|
|
|
|
|
ToneProducer::SetBufferGroup(const media_source& for_source, BBufferGroup* newGroup)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::SetBufferGroup\n");
|
|
|
|
@@ -323,7 +323,7 @@ ToneProducer::SetBufferGroup(const media_source& for_source, BBufferGroup* newGr
|
|
|
|
|
return B_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
|
status_t
|
|
|
|
|
ToneProducer::GetLatency(bigtime_t* out_latency)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::GetLatency\n");
|
|
|
|
@@ -333,7 +333,7 @@ ToneProducer::GetLatency(bigtime_t* out_latency)
|
|
|
|
|
return B_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
|
status_t
|
|
|
|
|
ToneProducer::PrepareToConnect(const media_source& what, const media_destination& where, media_format* format, media_source* out_source, char* out_name)
|
|
|
|
|
{
|
|
|
|
|
// PrepareToConnect() is the second stage of format negotiations that happens
|
|
|
|
@@ -366,7 +366,7 @@ ToneProducer::PrepareToConnect(const media_source& what, const media_destination
|
|
|
|
|
format->u.raw_audio.channel_count = 2;
|
|
|
|
|
return B_MEDIA_BAD_FORMAT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// !!! validate all other fields except for buffer_size here, because the consumer might have
|
|
|
|
|
// supplied different values from AcceptFormat()?
|
|
|
|
@@ -399,13 +399,13 @@ ToneProducer::PrepareToConnect(const media_source& what, const media_destination
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "\tconsumer suggested buffer_size %lu\n", format->u.raw_audio.buffer_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Now reserve the connection, and return information about it
|
|
|
|
|
mOutput.destination = where;
|
|
|
|
|
mOutput.format = *format;
|
|
|
|
|
*out_source = mOutput.source;
|
|
|
|
|
strncpy(out_name, mOutput.name, B_MEDIA_NAME_LENGTH);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char formatStr[256];
|
|
|
|
|
string_for_format(*format, formatStr, 255);
|
|
|
|
|
FPRINTF(stderr, "\treturning format: %s\n", formatStr);
|
|
|
|
@@ -413,7 +413,7 @@ ToneProducer::PrepareToConnect(const media_source& what, const media_destination
|
|
|
|
|
return B_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::Connect(status_t error, const media_source& source, const media_destination& destination, const media_format& format, char* io_name)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::Connect\n");
|
|
|
|
@@ -440,7 +440,7 @@ ToneProducer::Connect(status_t error, const media_source& source, const media_de
|
|
|
|
|
// FPRINTF(stderr, "\tcorrupted format; falling back to last suggested format\n");
|
|
|
|
|
// format = mOutput.format;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// Okay, the connection has been confirmed. Record the destination and format
|
|
|
|
|
// that we agreed on, and report our connection name again.
|
|
|
|
@@ -476,7 +476,7 @@ ToneProducer::Connect(status_t error, const media_source& source, const media_de
|
|
|
|
|
// reset our buffer duration, etc. to avoid later calculations
|
|
|
|
|
// +++++ e.moon 11jun99: crashes w/ divide-by-zero when connecting to LoggingConsumer
|
|
|
|
|
ASSERT(mOutput.format.u.raw_audio.frame_rate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bigtime_t duration = bigtime_t(1000000) * samplesPerBuffer / bigtime_t(mOutput.format.u.raw_audio.frame_rate);
|
|
|
|
|
SetBufferDuration(duration);
|
|
|
|
|
|
|
|
|
@@ -487,7 +487,7 @@ ToneProducer::Connect(status_t error, const media_source& source, const media_de
|
|
|
|
|
if (!mBufferGroup) AllocateBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::Disconnect(const media_source& what, const media_destination& where)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::Disconnect\n");
|
|
|
|
@@ -508,7 +508,7 @@ ToneProducer::Disconnect(const media_source& what, const media_destination& wher
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::LateNoticeReceived(const media_source& what, bigtime_t how_much, bigtime_t performance_time)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::LateNoticeReceived\n");
|
|
|
|
@@ -552,7 +552,7 @@ ToneProducer::LateNoticeReceived(const media_source& what, bigtime_t how_much, b
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::EnableOutput(const media_source& what, bool enabled, int32* _deprecated_)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::EnableOutput\n");
|
|
|
|
@@ -567,7 +567,7 @@ ToneProducer::EnableOutput(const media_source& what, bool enabled, int32* _depre
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
|
status_t
|
|
|
|
|
ToneProducer::SetPlayRate(int32 numer, int32 denom)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::SetPlayRate\n");
|
|
|
|
@@ -577,7 +577,7 @@ ToneProducer::SetPlayRate(int32 numer, int32 denom)
|
|
|
|
|
return B_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
|
status_t
|
|
|
|
|
ToneProducer::HandleMessage(int32 message, const void* data, size_t size)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::HandleMessage(%" B_PRId32 " = 0x%" B_PRIx32
|
|
|
|
@@ -591,7 +591,7 @@ ToneProducer::HandleMessage(int32 message, const void* data, size_t size)
|
|
|
|
|
return B_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::AdditionalBufferRequested(const media_source& source, media_buffer_id prev_buffer, bigtime_t prev_time, const media_seek_tag* prev_tag)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::AdditionalBufferRequested\n");
|
|
|
|
@@ -600,7 +600,7 @@ ToneProducer::AdditionalBufferRequested(const media_source& source, media_buffer
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::LatencyChanged(
|
|
|
|
|
const media_source& source,
|
|
|
|
|
const media_destination& destination,
|
|
|
|
@@ -624,7 +624,7 @@ ToneProducer::LatencyChanged(
|
|
|
|
|
//#pragma mark -
|
|
|
|
|
|
|
|
|
|
// BMediaEventLooper methods
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::NodeRegistered()
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::NodeRegistered\n");
|
|
|
|
@@ -641,7 +641,7 @@ ToneProducer::NodeRegistered()
|
|
|
|
|
SetParameterWeb(mWeb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::Start(bigtime_t performance_time)
|
|
|
|
|
{
|
|
|
|
|
PRINT(("ToneProducer::Start(%" B_PRIdBIGTIME "): now %" B_PRIdBIGTIME "\n",
|
|
|
|
@@ -656,7 +656,7 @@ ToneProducer::Start(bigtime_t performance_time)
|
|
|
|
|
BMediaEventLooper::Start(performance_time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::Stop(bigtime_t performance_time, bool immediate)
|
|
|
|
|
{
|
|
|
|
|
// send 'data not available' message
|
|
|
|
@@ -671,7 +671,7 @@ ToneProducer::Stop(bigtime_t performance_time, bool immediate)
|
|
|
|
|
BMediaEventLooper::Stop(performance_time, immediate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::SetRunMode(run_mode mode)
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::SetRunMode\n");
|
|
|
|
@@ -684,7 +684,7 @@ ToneProducer::SetRunMode(run_mode mode)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness, bool realTimeEvent)
|
|
|
|
|
{
|
|
|
|
|
// FPRINTF(stderr, "ToneProducer::HandleEvent\n");
|
|
|
|
@@ -813,11 +813,11 @@ ToneProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness, bo
|
|
|
|
|
|
|
|
|
|
//#pragma mark -
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::AllocateBuffers()
|
|
|
|
|
{
|
|
|
|
|
FPRINTF(stderr, "ToneProducer::AllocateBuffers\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// allocate enough buffers to span our downstream latency, plus one
|
|
|
|
|
size_t size = mOutput.format.u.raw_audio.buffer_size;
|
|
|
|
|
int32 count = int32(mLatency / BufferDuration() + 1 + 1);
|
|
|
|
@@ -844,7 +844,7 @@ ToneProducer::FillNextBuffer(bigtime_t event_time)
|
|
|
|
|
|
|
|
|
|
// now fill it with data, continuing where the last buffer left off
|
|
|
|
|
// 20sep99: multichannel support
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t numFrames =
|
|
|
|
|
mOutput.format.u.raw_audio.buffer_size /
|
|
|
|
|
(sizeof(float)*mOutput.format.u.raw_audio.channel_count);
|
|
|
|
@@ -904,7 +904,7 @@ ToneProducer::FillNextBuffer(bigtime_t event_time)
|
|
|
|
|
void
|
|
|
|
|
ToneProducer::FillSineBuffer(float *data, size_t numFrames, bool stereo)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// cover 2pi radians in one period
|
|
|
|
|
double dTheta = 2*M_PI * double(mFrequency) / mOutput.format.u.raw_audio.frame_rate;
|
|
|
|
@@ -918,7 +918,7 @@ ToneProducer::FillSineBuffer(float *data, size_t numFrames, bool stereo)
|
|
|
|
|
++data;
|
|
|
|
|
*data = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mTheta += dTheta;
|
|
|
|
|
if (mTheta > 2*M_PI)
|
|
|
|
|
{
|
|
|
|
@@ -943,7 +943,7 @@ ToneProducer::FillTriangleBuffer(float *data, size_t numFrames, bool stereo)
|
|
|
|
|
++data;
|
|
|
|
|
*data = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mTheta += dTheta;
|
|
|
|
|
if (mTheta >= 1)
|
|
|
|
|
{
|
|
|
|
|