style cleanup
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25177 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -33,13 +33,11 @@ bool FillBuffer(_gs_ramp * ramp, uint8 * data, uint8 * buffer, size_t * bytes)
|
|||||||
{
|
{
|
||||||
int32 samples = *bytes / sizeof(int16);
|
int32 samples = *bytes / sizeof(int16);
|
||||||
|
|
||||||
for(int32 byte = 0; byte < samples; byte++)
|
for (int32 byte = 0; byte < samples; byte++) {
|
||||||
{
|
|
||||||
float gain = *ramp->value;
|
float gain = *ramp->value;
|
||||||
data[byte] = uint8(float(buffer[byte]) * gain);
|
data[byte] = uint8(float(buffer[byte]) * gain);
|
||||||
|
|
||||||
if (ChangeRamp(ramp))
|
if (ChangeRamp(ramp)) {
|
||||||
{
|
|
||||||
*bytes = byte * sizeof(int16);
|
*bytes = byte * sizeof(int16);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -52,13 +50,11 @@ bool FillBuffer(_gs_ramp * ramp, int16 * data, int16 * buffer, size_t * bytes)
|
|||||||
{
|
{
|
||||||
int32 samples = *bytes / sizeof(int16);
|
int32 samples = *bytes / sizeof(int16);
|
||||||
|
|
||||||
for(int32 byte = 0; byte < samples; byte++)
|
for (int32 byte = 0; byte < samples; byte++) {
|
||||||
{
|
|
||||||
float gain = *ramp->value;
|
float gain = *ramp->value;
|
||||||
data[byte] = int16(float(buffer[byte]) * gain);
|
data[byte] = int16(float(buffer[byte]) * gain);
|
||||||
|
|
||||||
if (ChangeRamp(ramp))
|
if (ChangeRamp(ramp)) {
|
||||||
{
|
|
||||||
*bytes = byte * sizeof(int16);
|
*bytes = byte * sizeof(int16);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -72,13 +68,11 @@ bool FillBuffer(_gs_ramp * ramp, int32 * data, int32 * buffer, size_t * bytes)
|
|||||||
size_t byte = 0;
|
size_t byte = 0;
|
||||||
bool bytesAreReady = (*bytes > 0);
|
bool bytesAreReady = (*bytes > 0);
|
||||||
|
|
||||||
while(bytesAreReady)
|
while (bytesAreReady) {
|
||||||
{
|
|
||||||
float gain = *ramp->value;
|
float gain = *ramp->value;
|
||||||
data[byte] = int32(float(buffer[byte]) * gain);
|
data[byte] = int32(float(buffer[byte]) * gain);
|
||||||
|
|
||||||
if (ChangeRamp(ramp))
|
if (ChangeRamp(ramp)) {
|
||||||
{
|
|
||||||
*bytes = byte;
|
*bytes = byte;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -95,13 +89,11 @@ bool FillBuffer(_gs_ramp * ramp, float * data, float * buffer, size_t * bytes)
|
|||||||
size_t byte = 0;
|
size_t byte = 0;
|
||||||
bool bytesAreReady = (*bytes > 0);
|
bool bytesAreReady = (*bytes > 0);
|
||||||
|
|
||||||
while(bytesAreReady)
|
while (bytesAreReady) {
|
||||||
{
|
|
||||||
float gain = *ramp->value;
|
float gain = *ramp->value;
|
||||||
data[byte] = buffer[byte] * gain;
|
data[byte] = buffer[byte] * gain;
|
||||||
|
|
||||||
if (ChangeRamp(ramp))
|
if (ChangeRamp(ramp)) {
|
||||||
{
|
|
||||||
*bytes = byte;
|
*bytes = byte;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -145,8 +137,7 @@ BFileGameSound::BFileGameSound(const char *file,
|
|||||||
fPaused(false),
|
fPaused(false),
|
||||||
fPauseGain(1.0)
|
fPauseGain(1.0)
|
||||||
{
|
{
|
||||||
if (InitCheck() == B_OK)
|
if (InitCheck() == B_OK) {
|
||||||
{
|
|
||||||
entry_ref node;
|
entry_ref node;
|
||||||
|
|
||||||
if (get_ref_for_path(file, &node) != B_OK)
|
if (get_ref_for_path(file, &node) != B_OK)
|
||||||
@@ -159,10 +150,10 @@ BFileGameSound::BFileGameSound(const char *file,
|
|||||||
|
|
||||||
BFileGameSound::~BFileGameSound()
|
BFileGameSound::~BFileGameSound()
|
||||||
{
|
{
|
||||||
if (fReadThread >= 0) kill_thread(fReadThread);
|
if (fReadThread >= 0)
|
||||||
|
kill_thread(fReadThread);
|
||||||
|
|
||||||
if (fAudioStream)
|
if (fAudioStream) {
|
||||||
{
|
|
||||||
if (fAudioStream->stream)
|
if (fAudioStream->stream)
|
||||||
fAudioStream->file->ReleaseTrack(fAudioStream->stream);
|
fAudioStream->file->ReleaseTrack(fAudioStream->stream);
|
||||||
|
|
||||||
@@ -307,16 +298,14 @@ status_t
|
|||||||
BFileGameSound::SetPaused(bool isPaused,
|
BFileGameSound::SetPaused(bool isPaused,
|
||||||
bigtime_t rampTime)
|
bigtime_t rampTime)
|
||||||
{
|
{
|
||||||
if (fPaused != isPaused)
|
if (fPaused != isPaused) {
|
||||||
{
|
|
||||||
Lock();
|
Lock();
|
||||||
|
|
||||||
// Clear any old ramping
|
// Clear any old ramping
|
||||||
delete fPausing;
|
delete fPausing;
|
||||||
fPausing = NULL;
|
fPausing = NULL;
|
||||||
|
|
||||||
if (rampTime > 100000)
|
if (rampTime > 100000) {
|
||||||
{
|
|
||||||
// Setup for ramping
|
// Setup for ramping
|
||||||
if (isPaused)
|
if (isPaused)
|
||||||
fPausing = InitRamp(&fPauseGain, 0.0, Format().frame_rate, rampTime);
|
fPausing = InitRamp(&fPauseGain, 0.0, Format().frame_rate, rampTime);
|
||||||
@@ -335,9 +324,11 @@ BFileGameSound::SetPaused(bool isPaused,
|
|||||||
int32
|
int32
|
||||||
BFileGameSound::IsPaused()
|
BFileGameSound::IsPaused()
|
||||||
{
|
{
|
||||||
if (fPausing) return B_PAUSE_IN_PROGRESS;
|
if (fPausing)
|
||||||
|
return B_PAUSE_IN_PROGRESS;
|
||||||
|
|
||||||
if (fPaused) return B_PAUSED;
|
if (fPaused)
|
||||||
|
return B_PAUSED;
|
||||||
|
|
||||||
return B_NOT_PAUSED;
|
return B_NOT_PAUSED;
|
||||||
}
|
}
|
||||||
@@ -403,7 +394,6 @@ BFileGameSound::Init(const entry_ref* file)
|
|||||||
bool
|
bool
|
||||||
BFileGameSound::Load()
|
BFileGameSound::Load()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fPlayPosition != 0) {
|
if (fPlayPosition != 0) {
|
||||||
if (fBufferSize > fPlayPosition)
|
if (fBufferSize > fPlayPosition)
|
||||||
memcpy(fBuffer, fBuffer + fPlayPosition, fBufferSize - fPlayPosition);
|
memcpy(fBuffer, fBuffer + fPlayPosition, fBufferSize - fPlayPosition);
|
||||||
|
|||||||
@@ -217,13 +217,12 @@ GameProducer::Connect(status_t error, const media_source& source, const media_de
|
|||||||
// If something earlier failed, Connect() might still be called, but with a non-zero
|
// If something earlier failed, Connect() might still be called, but with a non-zero
|
||||||
// error code. When that happens we simply unreserve the connection and do
|
// error code. When that happens we simply unreserve the connection and do
|
||||||
// nothing else.
|
// nothing else.
|
||||||
if (error)
|
if (error) {
|
||||||
{
|
|
||||||
fOutput.destination = media_destination::null;
|
fOutput.destination = media_destination::null;
|
||||||
fOutput.format = fPreferredFormat;
|
fOutput.format = fPreferredFormat;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Okay, the connection has been confirmed. Record the destination and format
|
// Okay, the connection has been confirmed. Record the destination and format
|
||||||
// that we agreed on, and report our connection name again.
|
// that we agreed on, and report our connection name again.
|
||||||
fOutput.destination = destination;
|
fOutput.destination = destination;
|
||||||
@@ -244,14 +243,13 @@ GameProducer::Connect(status_t error, const media_source& source, const media_de
|
|||||||
|
|
||||||
// Second, fill the buffer
|
// Second, fill the buffer
|
||||||
start = ::system_time();
|
start = ::system_time();
|
||||||
for(int32 i = 0; i < frames; i++)
|
for (int32 i = 0; i < frames; i++) {
|
||||||
{
|
|
||||||
data[i*2] = 0.8 * float(i/frames);
|
data[i*2] = 0.8 * float(i/frames);
|
||||||
data[i*2+1] = 0.8 * float(i/frames);
|
data[i*2+1] = 0.8 * float(i/frames);
|
||||||
}
|
}
|
||||||
produceLatency = ::system_time();
|
produceLatency = ::system_time();
|
||||||
|
|
||||||
// Thid, calculate the latency
|
// Third, calculate the latency
|
||||||
fInternalLatency = produceLatency - start;
|
fInternalLatency = produceLatency - start;
|
||||||
SetEventLatency(fLatency + fInternalLatency);
|
SetEventLatency(fLatency + fInternalLatency);
|
||||||
|
|
||||||
@@ -264,22 +262,19 @@ GameProducer::Connect(status_t error, const media_source& source, const media_de
|
|||||||
|
|
||||||
// Set up the buffer group for our connection, as long as nobody handed us a
|
// Set up the buffer group for our connection, as long as nobody handed us a
|
||||||
// buffer group (via SetBufferGroup()) prior to this.
|
// buffer group (via SetBufferGroup()) prior to this.
|
||||||
if (!fBufferGroup)
|
if (!fBufferGroup) {
|
||||||
{
|
|
||||||
size_t size = fOutput.format.u.raw_audio.buffer_size;
|
size_t size = fOutput.format.u.raw_audio.buffer_size;
|
||||||
int32 count = int32(fLatency / BufferDuration() + 2);
|
int32 count = int32(fLatency / BufferDuration() + 2);
|
||||||
fBufferGroup = new BBufferGroup(size, count);
|
fBufferGroup = new BBufferGroup(size, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GameProducer::Disconnect(const media_source& what, const media_destination& where)
|
GameProducer::Disconnect(const media_source& what, const media_destination& where)
|
||||||
{
|
{
|
||||||
// Make sure that our connection is the one being disconnected
|
// Make sure that our connection is the one being disconnected
|
||||||
if ((where == fOutput.destination) && (what == fOutput.source))
|
if ((where == fOutput.destination) && (what == fOutput.source)) {
|
||||||
{
|
|
||||||
fOutput.destination = media_destination::null;
|
fOutput.destination = media_destination::null;
|
||||||
fOutput.format = fPreferredFormat;
|
fOutput.format = fPreferredFormat;
|
||||||
delete fBufferGroup;
|
delete fBufferGroup;
|
||||||
@@ -300,10 +295,12 @@ status_t
|
|||||||
GameProducer::SetBufferGroup(const media_source& for_source, BBufferGroup* newGroup)
|
GameProducer::SetBufferGroup(const media_source& for_source, BBufferGroup* newGroup)
|
||||||
{
|
{
|
||||||
// verify that we didn't get bogus arguments before we proceed
|
// verify that we didn't get bogus arguments before we proceed
|
||||||
if (for_source != fOutput.source) return B_MEDIA_BAD_SOURCE;
|
if (for_source != fOutput.source)
|
||||||
|
return B_MEDIA_BAD_SOURCE;
|
||||||
|
|
||||||
// Are we being passed the buffer group we're already using?
|
// Are we being passed the buffer group we're already using?
|
||||||
if (newGroup == fBufferGroup) return B_OK;
|
if (newGroup == fBufferGroup)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
// Ahh, someone wants us to use a different buffer group. At this point we delete
|
// Ahh, someone wants us to use a different buffer group. At this point we delete
|
||||||
// the one we are using and use the specified one instead. If the specified group is
|
// the one we are using and use the specified one instead. If the specified group is
|
||||||
@@ -312,13 +309,10 @@ GameProducer::SetBufferGroup(const media_source& for_source, BBufferGroup* newGr
|
|||||||
// *before* deleting the buffer group, otherwise we'll deadlock waiting for that
|
// *before* deleting the buffer group, otherwise we'll deadlock waiting for that
|
||||||
// buffer to be recycled!
|
// buffer to be recycled!
|
||||||
delete fBufferGroup; // waits for all buffers to recycle
|
delete fBufferGroup; // waits for all buffers to recycle
|
||||||
if (newGroup != NULL)
|
if (newGroup != NULL) {
|
||||||
{
|
|
||||||
// we were given a valid group; just use that one from now on
|
// we were given a valid group; just use that one from now on
|
||||||
fBufferGroup = newGroup;
|
fBufferGroup = newGroup;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// we were passed a NULL group pointer; that means we construct
|
// we were passed a NULL group pointer; that means we construct
|
||||||
// our own buffer group to use from now on
|
// our own buffer group to use from now on
|
||||||
size_t size = fOutput.format.u.raw_audio.buffer_size;
|
size_t size = fOutput.format.u.raw_audio.buffer_size;
|
||||||
@@ -344,17 +338,13 @@ GameProducer::LateNoticeReceived(const media_source& what, bigtime_t how_much, b
|
|||||||
{
|
{
|
||||||
// If we're late, we need to catch up. Respond in a manner appropriate to our
|
// If we're late, we need to catch up. Respond in a manner appropriate to our
|
||||||
// current run mode.
|
// current run mode.
|
||||||
if (what == fOutput.source)
|
if (what == fOutput.source) {
|
||||||
{
|
if (RunMode() == B_RECORDING) {
|
||||||
if (RunMode() == B_RECORDING)
|
|
||||||
{
|
|
||||||
// A hardware capture node can't adjust; it simply emits buffers at
|
// A hardware capture node can't adjust; it simply emits buffers at
|
||||||
// appropriate points. We (partially) simulate this by not adjusting
|
// appropriate points. We (partially) simulate this by not adjusting
|
||||||
// our behavior upon receiving late notices -- after all, the hardware
|
// our behavior upon receiving late notices -- after all, the hardware
|
||||||
// can't choose to capture "sooner"....
|
// can't choose to capture "sooner"....
|
||||||
}
|
} else if (RunMode() == B_INCREASE_LATENCY) {
|
||||||
else if (RunMode() == B_INCREASE_LATENCY)
|
|
||||||
{
|
|
||||||
// We're late, and our run mode dictates that we try to produce buffers
|
// We're late, and our run mode dictates that we try to produce buffers
|
||||||
// earlier in order to catch up. This argues that the downstream nodes are
|
// earlier in order to catch up. This argues that the downstream nodes are
|
||||||
// not properly reporting their latency, but there's not much we can do about
|
// not properly reporting their latency, but there's not much we can do about
|
||||||
@@ -362,9 +352,7 @@ GameProducer::LateNoticeReceived(const media_source& what, bigtime_t how_much, b
|
|||||||
// compensate.
|
// compensate.
|
||||||
fInternalLatency += how_much;
|
fInternalLatency += how_much;
|
||||||
SetEventLatency(fLatency + fInternalLatency);
|
SetEventLatency(fLatency + fInternalLatency);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// The other run modes dictate various strategies for sacrificing data quality
|
// The other run modes dictate various strategies for sacrificing data quality
|
||||||
// in the interests of timely data delivery. The way *we* do this is to skip
|
// in the interests of timely data delivery. The way *we* do this is to skip
|
||||||
// a buffer, which catches us up in time by one buffer duration.
|
// a buffer, which catches us up in time by one buffer duration.
|
||||||
@@ -382,8 +370,7 @@ GameProducer::LatencyChanged(const media_source& source, const media_destination
|
|||||||
// buffers earlier (or later) than we were previously. Make sure that the
|
// buffers earlier (or later) than we were previously. Make sure that the
|
||||||
// connection that changed is ours, and adjust to the new downstream
|
// connection that changed is ours, and adjust to the new downstream
|
||||||
// latency if so.
|
// latency if so.
|
||||||
if ((source == fOutput.source) && (destination == fOutput.destination))
|
if ((source == fOutput.source) && (destination == fOutput.destination)) {
|
||||||
{
|
|
||||||
fLatency = new_latency;
|
fLatency = new_latency;
|
||||||
SetEventLatency(fLatency + fInternalLatency);
|
SetEventLatency(fLatency + fInternalLatency);
|
||||||
}
|
}
|
||||||
@@ -435,8 +422,7 @@ GameProducer::SetRunMode(run_mode mode)
|
|||||||
{
|
{
|
||||||
// We don't support offline run mode, so broadcast an error if we're set to
|
// We don't support offline run mode, so broadcast an error if we're set to
|
||||||
// B_OFFLINE. Unfortunately, we can't actually reject the mode change...
|
// B_OFFLINE. Unfortunately, we can't actually reject the mode change...
|
||||||
if (B_OFFLINE == mode)
|
if (B_OFFLINE == mode) {
|
||||||
{
|
|
||||||
ReportError(B_NODE_FAILED_SET_RUN_MODE);
|
ReportError(B_NODE_FAILED_SET_RUN_MODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -450,8 +436,7 @@ GameProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness, bo
|
|||||||
{
|
{
|
||||||
case BTimedEventQueue::B_START:
|
case BTimedEventQueue::B_START:
|
||||||
// don't do anything if we're already running
|
// don't do anything if we're already running
|
||||||
if (RunState() != B_STARTED)
|
if (RunState() != B_STARTED) {
|
||||||
{
|
|
||||||
// We are going to start sending buffers so setup the needed bookkeeping
|
// We are going to start sending buffers so setup the needed bookkeeping
|
||||||
fFramesSent = 0;
|
fFramesSent = 0;
|
||||||
fStartTime = event->event_time;
|
fStartTime = event->event_time;
|
||||||
@@ -476,17 +461,16 @@ GameProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness, bo
|
|||||||
case BTimedEventQueue::B_HANDLE_BUFFER:
|
case BTimedEventQueue::B_HANDLE_BUFFER:
|
||||||
{
|
{
|
||||||
// make sure we're both started *and* connected before delivering a buffer
|
// make sure we're both started *and* connected before delivering a buffer
|
||||||
if ((RunState() == BMediaEventLooper::B_STARTED) && (fOutput.destination != media_destination::null))
|
if ((RunState() == BMediaEventLooper::B_STARTED)
|
||||||
{
|
&& (fOutput.destination != media_destination::null)) {
|
||||||
// Get the next buffer of data
|
// Get the next buffer of data
|
||||||
BBuffer* buffer = FillNextBuffer(event->event_time);
|
BBuffer* buffer = FillNextBuffer(event->event_time);
|
||||||
if (buffer)
|
if (buffer) {
|
||||||
{
|
|
||||||
// send the buffer downstream if and only if output is enabled
|
// send the buffer downstream if and only if output is enabled
|
||||||
status_t err = B_ERROR;
|
status_t err = B_ERROR;
|
||||||
if (fOutputEnabled) err = SendBuffer(buffer, fOutput.destination);
|
if (fOutputEnabled)
|
||||||
if (err)
|
err = SendBuffer(buffer, fOutput.destination);
|
||||||
{
|
if (err) {
|
||||||
// we need to recycle the buffer ourselves if output is disabled or
|
// we need to recycle the buffer ourselves if output is disabled or
|
||||||
// if the call to SendBuffer() fails
|
// if the call to SendBuffer() fails
|
||||||
buffer->Recycle();
|
buffer->Recycle();
|
||||||
@@ -511,8 +495,6 @@ GameProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness, bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------
|
|
||||||
// GameProducer
|
|
||||||
BBuffer*
|
BBuffer*
|
||||||
GameProducer::FillNextBuffer(bigtime_t event_time)
|
GameProducer::FillNextBuffer(bigtime_t event_time)
|
||||||
{
|
{
|
||||||
@@ -521,7 +503,8 @@ GameProducer::FillNextBuffer(bigtime_t event_time)
|
|||||||
|
|
||||||
// if we fail to get a buffer (for example, if the request times out), we skip this
|
// if we fail to get a buffer (for example, if the request times out), we skip this
|
||||||
// buffer and go on to the next, to avoid locking up the control thread
|
// buffer and go on to the next, to avoid locking up the control thread
|
||||||
if (!buf) return NULL;
|
if (!buf)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
// we need to discribe the buffer
|
// we need to discribe the buffer
|
||||||
int64 frames = int64(fOutput.format.u.raw_audio.buffer_size / fFrameSize);
|
int64 frames = int64(fOutput.format.u.raw_audio.buffer_size / fFrameSize);
|
||||||
@@ -537,15 +520,12 @@ GameProducer::FillNextBuffer(bigtime_t event_time)
|
|||||||
hdr->time_source = TimeSource()->ID();
|
hdr->time_source = TimeSource()->ID();
|
||||||
|
|
||||||
bigtime_t stamp;
|
bigtime_t stamp;
|
||||||
if (RunMode() == B_RECORDING)
|
if (RunMode() == B_RECORDING) {
|
||||||
{
|
|
||||||
// In B_RECORDING mode, we stamp with the capture time. We're not
|
// In B_RECORDING mode, we stamp with the capture time. We're not
|
||||||
// really a hardware capture node, but we simulate it by using the (precalculated)
|
// really a hardware capture node, but we simulate it by using the (precalculated)
|
||||||
// time at which this buffer "should" have been created.
|
// time at which this buffer "should" have been created.
|
||||||
stamp = event_time;
|
stamp = event_time;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// okay, we're in one of the "live" performance run modes. in these modes, we
|
// okay, we're in one of the "live" performance run modes. in these modes, we
|
||||||
// stamp the buffer with the time at which the buffer should be rendered to the
|
// stamp the buffer with the time at which the buffer should be rendered to the
|
||||||
// output, not with the capture time. fStartTime is the cached value of the
|
// output, not with the capture time. fStartTime is the cached value of the
|
||||||
@@ -559,4 +539,3 @@ GameProducer::FillNextBuffer(bigtime_t event_time)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -93,8 +93,7 @@ GameSoundBuffer::~GameSoundBuffer()
|
|||||||
{
|
{
|
||||||
BMediaRoster* r = BMediaRoster::Roster();
|
BMediaRoster* r = BMediaRoster::Roster();
|
||||||
|
|
||||||
if (fIsConnected)
|
if (fIsConnected) {
|
||||||
{
|
|
||||||
// Ordinarily we'd stop *all* of the nodes in the chain at this point. However,
|
// Ordinarily we'd stop *all* of the nodes in the chain at this point. However,
|
||||||
// one of the nodes is the System Mixer, and stopping the Mixer is a Bad Idea (tm).
|
// one of the nodes is the System Mixer, and stopping the Mixer is a Bad Idea (tm).
|
||||||
// So, we just disconnect from it, and release our references to the nodes that
|
// So, we just disconnect from it, and release our references to the nodes that
|
||||||
@@ -172,24 +171,21 @@ GameSoundBuffer::SetPan(float pan, bigtime_t duration)
|
|||||||
if (pan < -1.0 || pan > 1.0)
|
if (pan < -1.0 || pan > 1.0)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
if (fPanRamp) delete fPanRamp;
|
if (fPanRamp)
|
||||||
|
delete fPanRamp;
|
||||||
|
|
||||||
if (duration < 100000)
|
if (duration < 100000) {
|
||||||
{
|
|
||||||
fPan = pan;
|
fPan = pan;
|
||||||
|
|
||||||
if (fPan < 0.0)
|
if (fPan < 0.0) {
|
||||||
{
|
|
||||||
fPanLeft = 1.0;
|
fPanLeft = 1.0;
|
||||||
fPanRight = 1.0 + fPan;
|
fPanRight = 1.0 + fPan;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
fPanRight = 1.0;
|
fPanRight = 1.0;
|
||||||
fPanLeft = 1.0 - fPan;
|
fPanLeft = 1.0 - fPan;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else fPanRamp = InitRamp(&fPan, pan, fFormat.frame_rate, duration);
|
fPanRamp = InitRamp(&fPan, pan, fFormat.frame_rate, duration);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -199,18 +195,18 @@ status_t
|
|||||||
GameSoundBuffer::GetAttributes(gs_attribute * attributes,
|
GameSoundBuffer::GetAttributes(gs_attribute * attributes,
|
||||||
size_t attributeCount)
|
size_t attributeCount)
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < attributeCount; i++)
|
for (size_t i = 0; i < attributeCount; i++) {
|
||||||
{
|
switch(attributes[i].attribute) {
|
||||||
switch(attributes[i].attribute)
|
|
||||||
{
|
|
||||||
case B_GS_GAIN:
|
case B_GS_GAIN:
|
||||||
attributes[i].value = fGain;
|
attributes[i].value = fGain;
|
||||||
if (fGainRamp) attributes[i].duration = fGainRamp->duration;
|
if (fGainRamp)
|
||||||
|
attributes[i].duration = fGainRamp->duration;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_GS_PAN:
|
case B_GS_PAN:
|
||||||
attributes[i].value = fPan;
|
attributes[i].value = fPan;
|
||||||
if (fPanRamp) attributes[i].duration = fGainRamp->duration;
|
if (fPanRamp)
|
||||||
|
attributes[i].duration = fGainRamp->duration;
|
||||||
|
|
||||||
case B_GS_LOOPING:
|
case B_GS_LOOPING:
|
||||||
attributes[i].value = (fLooping) ? -1.0 : 0.0;
|
attributes[i].value = (fLooping) ? -1.0 : 0.0;
|
||||||
@@ -232,10 +228,8 @@ GameSoundBuffer::SetAttributes(gs_attribute * attributes,
|
|||||||
{
|
{
|
||||||
status_t error = B_OK;
|
status_t error = B_OK;
|
||||||
|
|
||||||
for(size_t i = 0; i < attributeCount; i++)
|
for (size_t i = 0; i < attributeCount; i++) {
|
||||||
{
|
switch(attributes[i].attribute) {
|
||||||
switch(attributes[i].attribute)
|
|
||||||
{
|
|
||||||
case B_GS_GAIN:
|
case B_GS_GAIN:
|
||||||
error = SetGain(attributes[i].value, attributes[i].duration);
|
error = SetGain(attributes[i].value, attributes[i].duration);
|
||||||
break;
|
break;
|
||||||
@@ -264,12 +258,10 @@ GameSoundBuffer::Play(void * data, int64 frames)
|
|||||||
|
|
||||||
FillBuffer(buffer, frames);
|
FillBuffer(buffer, frames);
|
||||||
|
|
||||||
switch(fFormat.format)
|
switch(fFormat.format) {
|
||||||
{
|
|
||||||
case gs_audio_format::B_GS_U8:
|
case gs_audio_format::B_GS_U8:
|
||||||
{
|
{
|
||||||
for(int64 i = 0; i < frames; i++)
|
for (int64 i = 0; i < frames; i++) {
|
||||||
{
|
|
||||||
ApplyMod((uint8*)data, (uint8*)buffer, i, fGain, pan);
|
ApplyMod((uint8*)data, (uint8*)buffer, i, fGain, pan);
|
||||||
UpdateMods();
|
UpdateMods();
|
||||||
}
|
}
|
||||||
@@ -279,8 +271,7 @@ GameSoundBuffer::Play(void * data, int64 frames)
|
|||||||
|
|
||||||
case gs_audio_format::B_GS_S16:
|
case gs_audio_format::B_GS_S16:
|
||||||
{
|
{
|
||||||
for(int64 i = 0; i < frames; i++)
|
for (int64 i = 0; i < frames; i++) {
|
||||||
{
|
|
||||||
ApplyMod((int16*)data, (int16*)buffer, i, fGain, pan);
|
ApplyMod((int16*)data, (int16*)buffer, i, fGain, pan);
|
||||||
UpdateMods();
|
UpdateMods();
|
||||||
}
|
}
|
||||||
@@ -290,8 +281,7 @@ GameSoundBuffer::Play(void * data, int64 frames)
|
|||||||
|
|
||||||
case gs_audio_format::B_GS_S32:
|
case gs_audio_format::B_GS_S32:
|
||||||
{
|
{
|
||||||
for(int64 i = 0; i < frames; i++)
|
for (int64 i = 0; i < frames; i++) {
|
||||||
{
|
|
||||||
ApplyMod((int32*)data, (int32*)buffer, i, fGain, pan);
|
ApplyMod((int32*)data, (int32*)buffer, i, fGain, pan);
|
||||||
UpdateMods();
|
UpdateMods();
|
||||||
}
|
}
|
||||||
@@ -301,8 +291,7 @@ GameSoundBuffer::Play(void * data, int64 frames)
|
|||||||
|
|
||||||
case gs_audio_format::B_GS_F:
|
case gs_audio_format::B_GS_F:
|
||||||
{
|
{
|
||||||
for(int64 i = 0; i < frames; i++)
|
for (int64 i = 0; i < frames; i++) {
|
||||||
{
|
|
||||||
ApplyMod((float*)data, (float*)buffer, i, fGain, pan);
|
ApplyMod((float*)data, (float*)buffer, i, fGain, pan);
|
||||||
UpdateMods();
|
UpdateMods();
|
||||||
}
|
}
|
||||||
@@ -320,32 +309,23 @@ void
|
|||||||
GameSoundBuffer::UpdateMods()
|
GameSoundBuffer::UpdateMods()
|
||||||
{
|
{
|
||||||
// adjust the gain if needed
|
// adjust the gain if needed
|
||||||
if (fGainRamp)
|
if (fGainRamp) {
|
||||||
{
|
if (ChangeRamp(fGainRamp)) {
|
||||||
if (ChangeRamp(fGainRamp))
|
|
||||||
{
|
|
||||||
delete fGainRamp;
|
delete fGainRamp;
|
||||||
fGainRamp = NULL;
|
fGainRamp = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// adjust the ramp if needed
|
// adjust the ramp if needed
|
||||||
if (fPanRamp)
|
if (fPanRamp) {
|
||||||
{
|
if (ChangeRamp(fPanRamp)) {
|
||||||
if (ChangeRamp(fPanRamp))
|
|
||||||
{
|
|
||||||
delete fPanRamp;
|
delete fPanRamp;
|
||||||
fPanRamp = NULL;
|
fPanRamp = NULL;
|
||||||
}
|
} else {
|
||||||
else
|
if (fPan < 0.0) {
|
||||||
{
|
|
||||||
if (fPan < 0.0)
|
|
||||||
{
|
|
||||||
fPanLeft = 1.0;
|
fPanLeft = 1.0;
|
||||||
fPanRight = 1.0 + fPan;
|
fPanRight = 1.0 + fPan;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
fPanRight = 1.0;
|
fPanRight = 1.0;
|
||||||
fPanLeft = 1.0 - fPan;
|
fPanLeft = 1.0 - fPan;
|
||||||
}
|
}
|
||||||
@@ -378,14 +358,16 @@ GameSoundBuffer::Connect(media_node * consumer)
|
|||||||
status_t err;
|
status_t err;
|
||||||
|
|
||||||
err = r->RegisterNode(fNode);
|
err = r->RegisterNode(fNode);
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
// make sure the Media Roster knows that we're using the node
|
// make sure the Media Roster knows that we're using the node
|
||||||
r->GetNodeFor(fNode->Node().node, &fConnection->producer);
|
r->GetNodeFor(fNode->Node().node, &fConnection->producer);
|
||||||
|
|
||||||
// connect to the mixer
|
// connect to the mixer
|
||||||
fConnection->consumer = *consumer;
|
fConnection->consumer = *consumer;
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
// set the producer's time source to be the "default" time source, which
|
// set the producer's time source to be the "default" time source, which
|
||||||
// the Mixer uses too.
|
// the Mixer uses too.
|
||||||
@@ -397,17 +379,20 @@ GameSoundBuffer::Connect(media_node * consumer)
|
|||||||
media_output soundOutput;
|
media_output soundOutput;
|
||||||
int32 count = 1;
|
int32 count = 1;
|
||||||
err = r->GetFreeOutputsFor(fConnection->producer, &soundOutput, 1, &count);
|
err = r->GetFreeOutputsFor(fConnection->producer, &soundOutput, 1, &count);
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
count = 1;
|
count = 1;
|
||||||
err = r->GetFreeInputsFor(fConnection->consumer, &mixerInput, 1, &count);
|
err = r->GetFreeInputsFor(fConnection->consumer, &mixerInput, 1, &count);
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
// got the endpoints; now we connect it!
|
// got the endpoints; now we connect it!
|
||||||
media_format format;
|
media_format format;
|
||||||
format.type = B_MEDIA_RAW_AUDIO;
|
format.type = B_MEDIA_RAW_AUDIO;
|
||||||
format.u.raw_audio = media_raw_audio_format::wildcard;
|
format.u.raw_audio = media_raw_audio_format::wildcard;
|
||||||
err = r->Connect(soundOutput.source, mixerInput.destination, &format, &soundOutput, &mixerInput);
|
err = r->Connect(soundOutput.source, mixerInput.destination, &format, &soundOutput, &mixerInput);
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
// the inputs and outputs might have been reassigned during the
|
// the inputs and outputs might have been reassigned during the
|
||||||
// nodes' negotiation of the Connect(). That's why we wait until
|
// nodes' negotiation of the Connect(). That's why we wait until
|
||||||
@@ -424,7 +409,8 @@ GameSoundBuffer::Connect(media_node * consumer)
|
|||||||
status_t
|
status_t
|
||||||
GameSoundBuffer::StartPlaying()
|
GameSoundBuffer::StartPlaying()
|
||||||
{
|
{
|
||||||
if (fIsPlaying) return EALREADY;
|
if (fIsPlaying)
|
||||||
|
return EALREADY;
|
||||||
|
|
||||||
BMediaRoster* r = BMediaRoster::Roster();
|
BMediaRoster* r = BMediaRoster::Roster();
|
||||||
BTimeSource* ts = r->MakeTimeSourceFor(fConnection->producer);
|
BTimeSource* ts = r->MakeTimeSourceFor(fConnection->producer);
|
||||||
@@ -445,7 +431,8 @@ GameSoundBuffer::StartPlaying()
|
|||||||
status_t
|
status_t
|
||||||
GameSoundBuffer::StopPlaying()
|
GameSoundBuffer::StopPlaying()
|
||||||
{
|
{
|
||||||
if (!fIsPlaying) return EALREADY;
|
if (!fIsPlaying)
|
||||||
|
return EALREADY;
|
||||||
|
|
||||||
BMediaRoster* r = BMediaRoster::Roster();
|
BMediaRoster* r = BMediaRoster::Roster();
|
||||||
r->StopNode(fConnection->producer, 0, true); // synchronous stop
|
r->StopNode(fConnection->producer, 0, true); // synchronous stop
|
||||||
@@ -499,27 +486,22 @@ SimpleSoundBuffer::FillBuffer(void * data, int64 frames)
|
|||||||
char * buffer = (char*)data;
|
char * buffer = (char*)data;
|
||||||
size_t bytes = fFrameSize * frames;
|
size_t bytes = fFrameSize * frames;
|
||||||
|
|
||||||
if (fPosition + bytes >= fBufferSize)
|
if (fPosition + bytes >= fBufferSize) {
|
||||||
{
|
if (fPosition < fBufferSize) {
|
||||||
if (fPosition < fBufferSize)
|
|
||||||
{
|
|
||||||
// copy the remaining frames
|
// copy the remaining frames
|
||||||
size_t remainder = fBufferSize - fPosition;
|
size_t remainder = fBufferSize - fPosition;
|
||||||
memcpy(buffer, &fBuffer[fPosition], remainder);
|
memcpy(buffer, &fBuffer[fPosition], remainder);
|
||||||
|
|
||||||
if (fLooping)
|
if (fLooping) {
|
||||||
{
|
|
||||||
// restart the sound from the begging
|
// restart the sound from the begging
|
||||||
memcpy(&buffer[remainder], fBuffer, bytes - remainder);
|
memcpy(&buffer[remainder], fBuffer, bytes - remainder);
|
||||||
fPosition = bytes - remainder;
|
fPosition = bytes - remainder;
|
||||||
}
|
} else
|
||||||
else fPosition = fBufferSize;
|
fPosition = fBufferSize;
|
||||||
}
|
} else
|
||||||
else memset(data, 0, bytes);
|
memset(data, 0, bytes);
|
||||||
// there is nothing left to play
|
// there is nothing left to play
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
memcpy(buffer, &fBuffer[fPosition], bytes);
|
memcpy(buffer, &fBuffer[fPosition], bytes);
|
||||||
fPosition += bytes;
|
fPosition += bytes;
|
||||||
}
|
}
|
||||||
@@ -549,3 +531,4 @@ StreamingSoundBuffer::FillBuffer(void * buffer,
|
|||||||
size_t bytes = fFrameSize * frames;
|
size_t bytes = fFrameSize * frames;
|
||||||
object->FillBuffer(buffer, bytes);
|
object->FillBuffer(buffer, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,8 +61,7 @@ void ReleaseDevice()
|
|||||||
{
|
{
|
||||||
deviceCount--;
|
deviceCount--;
|
||||||
|
|
||||||
if (deviceCount <= 0)
|
if (deviceCount <= 0) {
|
||||||
{
|
|
||||||
delete theDevice;
|
delete theDevice;
|
||||||
theDevice = NULL;
|
theDevice = NULL;
|
||||||
}
|
}
|
||||||
@@ -89,14 +88,13 @@ BGameSoundDevice::~BGameSoundDevice()
|
|||||||
BMediaRoster* r = BMediaRoster::Roster();
|
BMediaRoster* r = BMediaRoster::Roster();
|
||||||
|
|
||||||
// We need to stop all the sounds before we stop the mixer
|
// We need to stop all the sounds before we stop the mixer
|
||||||
for(int32 i = 0; i < fSoundCount; i++)
|
for (int32 i = 0; i < fSoundCount; i++) {
|
||||||
{
|
if (fSounds[i])
|
||||||
if (fSounds[i]) fSounds[i]->StopPlaying();
|
fSounds[i]->StopPlaying();
|
||||||
delete fSounds[i];
|
delete fSounds[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fIsConnected)
|
if (fIsConnected) {
|
||||||
{
|
|
||||||
// stop the nodes if they are running
|
// stop the nodes if they are running
|
||||||
r->StopNode(fConnection->producer, 0, true); // synchronous stop
|
r->StopNode(fConnection->producer, 0, true); // synchronous stop
|
||||||
|
|
||||||
@@ -150,13 +148,13 @@ BGameSoundDevice::CreateBuffer(gs_id * sound,
|
|||||||
const void * data,
|
const void * data,
|
||||||
int64 frames)
|
int64 frames)
|
||||||
{
|
{
|
||||||
if (frames <= 0 || !sound) return B_BAD_VALUE;
|
if (frames <= 0 || !sound)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
status_t err = B_MEDIA_TOO_MANY_BUFFERS;
|
status_t err = B_MEDIA_TOO_MANY_BUFFERS;
|
||||||
int32 position = AllocateSound();
|
int32 position = AllocateSound();
|
||||||
|
|
||||||
if (position >= 0)
|
if (position >= 0) {
|
||||||
{
|
|
||||||
fSounds[position] = new SimpleSoundBuffer(format, data, frames);
|
fSounds[position] = new SimpleSoundBuffer(format, data, frames);
|
||||||
err = fSounds[position]->Connect(&fConnection->producer);
|
err = fSounds[position]->Connect(&fConnection->producer);
|
||||||
}
|
}
|
||||||
@@ -171,13 +169,13 @@ BGameSoundDevice::CreateBuffer(gs_id * sound,
|
|||||||
const void * object,
|
const void * object,
|
||||||
const gs_audio_format * format)
|
const gs_audio_format * format)
|
||||||
{
|
{
|
||||||
if (!object || !sound) return B_BAD_VALUE;
|
if (!object || !sound)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
status_t err = B_MEDIA_TOO_MANY_BUFFERS;
|
status_t err = B_MEDIA_TOO_MANY_BUFFERS;
|
||||||
int32 position = AllocateSound();
|
int32 position = AllocateSound();
|
||||||
|
|
||||||
if (position >= 0)
|
if (position >= 0) {
|
||||||
{
|
|
||||||
fSounds[position] = new StreamingSoundBuffer(format, object);
|
fSounds[position] = new StreamingSoundBuffer(format, object);
|
||||||
err = fSounds[position]->Connect(&fConnection->producer);
|
err = fSounds[position]->Connect(&fConnection->producer);
|
||||||
}
|
}
|
||||||
@@ -193,8 +191,7 @@ BGameSoundDevice::ReleaseBuffer(gs_id sound)
|
|||||||
if (sound <= 0)
|
if (sound <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fSounds[sound-1])
|
if (fSounds[sound-1]) {
|
||||||
{
|
|
||||||
// We must stop playback befor destroying the sound or else
|
// We must stop playback befor destroying the sound or else
|
||||||
// we may recieve fatel errors.
|
// we may recieve fatel errors.
|
||||||
fSounds[sound-1]->StopPlaying();
|
fSounds[sound-1]->StopPlaying();
|
||||||
@@ -218,8 +215,8 @@ BGameSoundDevice::Buffer(gs_id sound,
|
|||||||
if (fSounds[sound-1]->Data()) {
|
if (fSounds[sound-1]->Data()) {
|
||||||
data = malloc(format->buffer_size);
|
data = malloc(format->buffer_size);
|
||||||
memcpy(data, fSounds[sound-1]->Data(), format->buffer_size);
|
memcpy(data, fSounds[sound-1]->Data(), format->buffer_size);
|
||||||
}
|
} else
|
||||||
else data = NULL;
|
data = NULL;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -270,7 +267,8 @@ BGameSoundDevice::GetAttributes(gs_id sound,
|
|||||||
gs_attribute * attributes,
|
gs_attribute * attributes,
|
||||||
size_t attributeCount)
|
size_t attributeCount)
|
||||||
{
|
{
|
||||||
if (!fSounds[sound-1]) return B_ERROR;
|
if (!fSounds[sound-1])
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
return fSounds[sound-1]->GetAttributes(attributes, attributeCount);
|
return fSounds[sound-1]->GetAttributes(attributes, attributeCount);
|
||||||
}
|
}
|
||||||
@@ -281,7 +279,8 @@ BGameSoundDevice::SetAttributes(gs_id sound,
|
|||||||
gs_attribute * attributes,
|
gs_attribute * attributes,
|
||||||
size_t attributeCount)
|
size_t attributeCount)
|
||||||
{
|
{
|
||||||
if (!fSounds[sound-1]) return B_ERROR;
|
if (!fSounds[sound-1])
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
return fSounds[sound-1]->SetAttributes(attributes, attributeCount);
|
return fSounds[sound-1]->SetAttributes(attributes, attributeCount);
|
||||||
}
|
}
|
||||||
@@ -297,29 +296,35 @@ BGameSoundDevice::Connect()
|
|||||||
dormant_node_info mixer_dormant_info;
|
dormant_node_info mixer_dormant_info;
|
||||||
int32 mixer_count = 1; // for now, we only care about the first we find.
|
int32 mixer_count = 1; // for now, we only care about the first we find.
|
||||||
err = r->GetDormantNodes(&mixer_dormant_info, &mixer_count, 0, 0, 0, B_SYSTEM_MIXER, 0);
|
err = r->GetDormantNodes(&mixer_dormant_info, &mixer_count, 0, 0, 0, B_SYSTEM_MIXER, 0);
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
//fMixer = new media_node;
|
//fMixer = new media_node;
|
||||||
err = r->InstantiateDormantNode(mixer_dormant_info, &fConnection->producer);
|
err = r->InstantiateDormantNode(mixer_dormant_info, &fConnection->producer);
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
// retieve the system's audio mixer
|
// retieve the system's audio mixer
|
||||||
err = r->GetAudioMixer(&fConnection->consumer);
|
err = r->GetAudioMixer(&fConnection->consumer);
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
int32 count = 1;
|
int32 count = 1;
|
||||||
media_input mixerInput;
|
media_input mixerInput;
|
||||||
err = r->GetFreeInputsFor(fConnection->consumer, &mixerInput, 1, &count);
|
err = r->GetFreeInputsFor(fConnection->consumer, &mixerInput, 1, &count);
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
count = 1;
|
count = 1;
|
||||||
media_output mixerOutput;
|
media_output mixerOutput;
|
||||||
err = r->GetFreeOutputsFor(fConnection->producer, &mixerOutput, 1, &count);
|
err = r->GetFreeOutputsFor(fConnection->producer, &mixerOutput, 1, &count);
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
media_format format(mixerOutput.format);
|
media_format format(mixerOutput.format);
|
||||||
err = r->Connect(mixerOutput.source, mixerInput.destination, &format, &mixerOutput, &mixerInput);
|
err = r->Connect(mixerOutput.source, mixerInput.destination, &format, &mixerOutput, &mixerInput);
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
// set the producer's time source to be the "default" time source, which
|
// set the producer's time source to be the "default" time source, which
|
||||||
// the Mixer uses too.
|
// the Mixer uses too.
|
||||||
@@ -329,13 +334,12 @@ BGameSoundDevice::Connect()
|
|||||||
// Start our mixer's time source if need be. Chances are, it won't need to be,
|
// Start our mixer's time source if need be. Chances are, it won't need to be,
|
||||||
// but if we forget to do this, our mixer might not do anything at all.
|
// but if we forget to do this, our mixer might not do anything at all.
|
||||||
BTimeSource* mixerTimeSource = r->MakeTimeSourceFor(fConnection->producer);
|
BTimeSource* mixerTimeSource = r->MakeTimeSourceFor(fConnection->producer);
|
||||||
if (! mixerTimeSource) return B_ERROR;
|
if (!mixerTimeSource)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
if (!mixerTimeSource->IsRunning())
|
if (!mixerTimeSource->IsRunning()) {
|
||||||
{
|
|
||||||
status_t err = r->StartNode(mixerTimeSource->Node(), BTimeSource::RealTime());
|
status_t err = r->StartNode(mixerTimeSource->Node(), BTimeSource::RealTime());
|
||||||
if (err != B_OK)
|
if (err != B_OK) {
|
||||||
{
|
|
||||||
mixerTimeSource->Release();
|
mixerTimeSource->Release();
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -345,7 +349,8 @@ BGameSoundDevice::Connect()
|
|||||||
bigtime_t tpNow = mixerTimeSource->Now();
|
bigtime_t tpNow = mixerTimeSource->Now();
|
||||||
err = r->StartNode(fConnection->producer, tpNow + 10000);
|
err = r->StartNode(fConnection->producer, tpNow + 10000);
|
||||||
mixerTimeSource->Release();
|
mixerTimeSource->Release();
|
||||||
if (err != B_OK) return err;
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
// the inputs and outputs might have been reassigned during the
|
// the inputs and outputs might have been reassigned during the
|
||||||
// nodes' negotiation of the Connect(). That's why we wait until
|
// nodes' negotiation of the Connect(). That's why we wait until
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ _EXPORT BNode& operator<<(BNode& n, const BMessage& m)
|
|||||||
|
|
||||||
for (int32 i = 0;
|
for (int32 i = 0;
|
||||||
m.GetInfo(B_ANY_TYPE, i, &name, &type) == 0;
|
m.GetInfo(B_ANY_TYPE, i, &name, &type) == 0;
|
||||||
i++)
|
i++) {
|
||||||
{
|
|
||||||
m.FindData (name,type,0,&data,&bytes);
|
m.FindData (name,type,0,&data,&bytes);
|
||||||
n.WriteAttr(name,type,0, data, bytes);
|
n.WriteAttr(name,type,0, data, bytes);
|
||||||
}
|
}
|
||||||
@@ -45,8 +44,7 @@ _EXPORT BNode& operator>>(BNode& n, BMessage& m)
|
|||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
|
||||||
n.RewindAttrs();
|
n.RewindAttrs();
|
||||||
while (n.GetNextAttrName(name)==B_OK)
|
while (n.GetNextAttrName(name) == B_OK) {
|
||||||
{
|
|
||||||
if (n.GetAttrInfo(name,&info) != B_OK)
|
if (n.GetAttrInfo(name,&info) != B_OK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -235,9 +235,11 @@ BBitmapStream::WriteAt(off_t pos, const void *data, size_t size)
|
|||||||
fBitmap = new BBitmap(fHeader.bounds, fHeader.colors);
|
fBitmap = new BBitmap(fHeader.bounds, fHeader.colors);
|
||||||
if (!fBitmap)
|
if (!fBitmap)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
if ((uint32)fBitmap->BytesPerRow() != fHeader.rowBytes)
|
if ((uint32)fBitmap->BytesPerRow() != fHeader.rowBytes) {
|
||||||
|
fprintf(stderr, "BitmapStream %ld %ld\n", fBitmap->BytesPerRow(), fHeader.rowBytes);
|
||||||
return B_MISMATCHED_VALUES;
|
return B_MISMATCHED_VALUES;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (fBitmap)
|
if (fBitmap)
|
||||||
fSize = sizeof(TranslatorBitmap) + fBitmap->BitsLength();
|
fSize = sizeof(TranslatorBitmap) + fBitmap->BitsLength();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user