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);
|
||||
|
||||
for(int32 byte = 0; byte < samples; byte++)
|
||||
{
|
||||
for (int32 byte = 0; byte < samples; byte++) {
|
||||
float gain = *ramp->value;
|
||||
data[byte] = uint8(float(buffer[byte]) * gain);
|
||||
|
||||
if (ChangeRamp(ramp))
|
||||
{
|
||||
if (ChangeRamp(ramp)) {
|
||||
*bytes = byte * sizeof(int16);
|
||||
return true;
|
||||
}
|
||||
@@ -52,13 +50,11 @@ bool FillBuffer(_gs_ramp * ramp, int16 * data, int16 * buffer, size_t * bytes)
|
||||
{
|
||||
int32 samples = *bytes / sizeof(int16);
|
||||
|
||||
for(int32 byte = 0; byte < samples; byte++)
|
||||
{
|
||||
for (int32 byte = 0; byte < samples; byte++) {
|
||||
float gain = *ramp->value;
|
||||
data[byte] = int16(float(buffer[byte]) * gain);
|
||||
|
||||
if (ChangeRamp(ramp))
|
||||
{
|
||||
if (ChangeRamp(ramp)) {
|
||||
*bytes = byte * sizeof(int16);
|
||||
return true;
|
||||
}
|
||||
@@ -72,13 +68,11 @@ bool FillBuffer(_gs_ramp * ramp, int32 * data, int32 * buffer, size_t * bytes)
|
||||
size_t byte = 0;
|
||||
bool bytesAreReady = (*bytes > 0);
|
||||
|
||||
while(bytesAreReady)
|
||||
{
|
||||
while (bytesAreReady) {
|
||||
float gain = *ramp->value;
|
||||
data[byte] = int32(float(buffer[byte]) * gain);
|
||||
|
||||
if (ChangeRamp(ramp))
|
||||
{
|
||||
if (ChangeRamp(ramp)) {
|
||||
*bytes = byte;
|
||||
return true;
|
||||
}
|
||||
@@ -95,13 +89,11 @@ bool FillBuffer(_gs_ramp * ramp, float * data, float * buffer, size_t * bytes)
|
||||
size_t byte = 0;
|
||||
bool bytesAreReady = (*bytes > 0);
|
||||
|
||||
while(bytesAreReady)
|
||||
{
|
||||
while (bytesAreReady) {
|
||||
float gain = *ramp->value;
|
||||
data[byte] = buffer[byte] * gain;
|
||||
|
||||
if (ChangeRamp(ramp))
|
||||
{
|
||||
if (ChangeRamp(ramp)) {
|
||||
*bytes = byte;
|
||||
return true;
|
||||
}
|
||||
@@ -145,8 +137,7 @@ BFileGameSound::BFileGameSound(const char *file,
|
||||
fPaused(false),
|
||||
fPauseGain(1.0)
|
||||
{
|
||||
if (InitCheck() == B_OK)
|
||||
{
|
||||
if (InitCheck() == B_OK) {
|
||||
entry_ref node;
|
||||
|
||||
if (get_ref_for_path(file, &node) != B_OK)
|
||||
@@ -159,10 +150,10 @@ BFileGameSound::BFileGameSound(const char *file,
|
||||
|
||||
BFileGameSound::~BFileGameSound()
|
||||
{
|
||||
if (fReadThread >= 0) kill_thread(fReadThread);
|
||||
if (fReadThread >= 0)
|
||||
kill_thread(fReadThread);
|
||||
|
||||
if (fAudioStream)
|
||||
{
|
||||
if (fAudioStream) {
|
||||
if (fAudioStream->stream)
|
||||
fAudioStream->file->ReleaseTrack(fAudioStream->stream);
|
||||
|
||||
@@ -307,16 +298,14 @@ status_t
|
||||
BFileGameSound::SetPaused(bool isPaused,
|
||||
bigtime_t rampTime)
|
||||
{
|
||||
if (fPaused != isPaused)
|
||||
{
|
||||
if (fPaused != isPaused) {
|
||||
Lock();
|
||||
|
||||
// Clear any old ramping
|
||||
delete fPausing;
|
||||
fPausing = NULL;
|
||||
|
||||
if (rampTime > 100000)
|
||||
{
|
||||
if (rampTime > 100000) {
|
||||
// Setup for ramping
|
||||
if (isPaused)
|
||||
fPausing = InitRamp(&fPauseGain, 0.0, Format().frame_rate, rampTime);
|
||||
@@ -335,9 +324,11 @@ BFileGameSound::SetPaused(bool isPaused,
|
||||
int32
|
||||
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;
|
||||
}
|
||||
@@ -403,7 +394,6 @@ BFileGameSound::Init(const entry_ref* file)
|
||||
bool
|
||||
BFileGameSound::Load()
|
||||
{
|
||||
|
||||
if (fPlayPosition != 0) {
|
||||
if (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
|
||||
// error code. When that happens we simply unreserve the connection and do
|
||||
// nothing else.
|
||||
if (error)
|
||||
{
|
||||
if (error) {
|
||||
fOutput.destination = media_destination::null;
|
||||
fOutput.format = fPreferredFormat;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// Okay, the connection has been confirmed. Record the destination and format
|
||||
// that we agreed on, and report our connection name again.
|
||||
fOutput.destination = destination;
|
||||
@@ -244,14 +243,13 @@ GameProducer::Connect(status_t error, const media_source& source, const media_de
|
||||
|
||||
// Second, fill the buffer
|
||||
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+1] = 0.8 * float(i/frames);
|
||||
}
|
||||
produceLatency = ::system_time();
|
||||
|
||||
// Thid, calculate the latency
|
||||
// Third, calculate the latency
|
||||
fInternalLatency = produceLatency - start;
|
||||
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
|
||||
// buffer group (via SetBufferGroup()) prior to this.
|
||||
if (!fBufferGroup)
|
||||
{
|
||||
if (!fBufferGroup) {
|
||||
size_t size = fOutput.format.u.raw_audio.buffer_size;
|
||||
int32 count = int32(fLatency / BufferDuration() + 2);
|
||||
fBufferGroup = new BBufferGroup(size, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GameProducer::Disconnect(const media_source& what, const media_destination& where)
|
||||
{
|
||||
// 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.format = fPreferredFormat;
|
||||
delete fBufferGroup;
|
||||
@@ -300,10 +295,12 @@ status_t
|
||||
GameProducer::SetBufferGroup(const media_source& for_source, BBufferGroup* newGroup)
|
||||
{
|
||||
// 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?
|
||||
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
|
||||
// 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
|
||||
// buffer to be recycled!
|
||||
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
|
||||
fBufferGroup = newGroup;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// we were passed a NULL group pointer; that means we construct
|
||||
// our own buffer group to use from now on
|
||||
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
|
||||
// current run mode.
|
||||
if (what == fOutput.source)
|
||||
{
|
||||
if (RunMode() == B_RECORDING)
|
||||
{
|
||||
if (what == fOutput.source) {
|
||||
if (RunMode() == B_RECORDING) {
|
||||
// A hardware capture node can't adjust; it simply emits buffers at
|
||||
// appropriate points. We (partially) simulate this by not adjusting
|
||||
// our behavior upon receiving late notices -- after all, the hardware
|
||||
// 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
|
||||
// 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
|
||||
@@ -362,9 +352,7 @@ GameProducer::LateNoticeReceived(const media_source& what, bigtime_t how_much, b
|
||||
// compensate.
|
||||
fInternalLatency += how_much;
|
||||
SetEventLatency(fLatency + fInternalLatency);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// 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
|
||||
// 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
|
||||
// connection that changed is ours, and adjust to the new downstream
|
||||
// latency if so.
|
||||
if ((source == fOutput.source) && (destination == fOutput.destination))
|
||||
{
|
||||
if ((source == fOutput.source) && (destination == fOutput.destination)) {
|
||||
fLatency = new_latency;
|
||||
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
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
@@ -450,8 +436,7 @@ GameProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness, bo
|
||||
{
|
||||
case BTimedEventQueue::B_START:
|
||||
// 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
|
||||
fFramesSent = 0;
|
||||
fStartTime = event->event_time;
|
||||
@@ -476,17 +461,16 @@ GameProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness, bo
|
||||
case BTimedEventQueue::B_HANDLE_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
|
||||
BBuffer* buffer = FillNextBuffer(event->event_time);
|
||||
if (buffer)
|
||||
{
|
||||
if (buffer) {
|
||||
// send the buffer downstream if and only if output is enabled
|
||||
status_t err = B_ERROR;
|
||||
if (fOutputEnabled) err = SendBuffer(buffer, fOutput.destination);
|
||||
if (err)
|
||||
{
|
||||
if (fOutputEnabled)
|
||||
err = SendBuffer(buffer, fOutput.destination);
|
||||
if (err) {
|
||||
// we need to recycle the buffer ourselves if output is disabled or
|
||||
// if the call to SendBuffer() fails
|
||||
buffer->Recycle();
|
||||
@@ -511,8 +495,6 @@ GameProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness, bo
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------
|
||||
// GameProducer
|
||||
BBuffer*
|
||||
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
|
||||
// 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
|
||||
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();
|
||||
|
||||
bigtime_t stamp;
|
||||
if (RunMode() == B_RECORDING)
|
||||
{
|
||||
if (RunMode() == B_RECORDING) {
|
||||
// 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)
|
||||
// time at which this buffer "should" have been created.
|
||||
stamp = event_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// 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
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -93,8 +93,7 @@ GameSoundBuffer::~GameSoundBuffer()
|
||||
{
|
||||
BMediaRoster* r = BMediaRoster::Roster();
|
||||
|
||||
if (fIsConnected)
|
||||
{
|
||||
if (fIsConnected) {
|
||||
// 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).
|
||||
// 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)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
if (fPanRamp) delete fPanRamp;
|
||||
if (fPanRamp)
|
||||
delete fPanRamp;
|
||||
|
||||
if (duration < 100000)
|
||||
{
|
||||
if (duration < 100000) {
|
||||
fPan = pan;
|
||||
|
||||
if (fPan < 0.0)
|
||||
{
|
||||
if (fPan < 0.0) {
|
||||
fPanLeft = 1.0;
|
||||
fPanRight = 1.0 + fPan;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fPanRight = 1.0;
|
||||
fPanLeft = 1.0 - fPan;
|
||||
}
|
||||
}
|
||||
else fPanRamp = InitRamp(&fPan, pan, fFormat.frame_rate, duration);
|
||||
} else
|
||||
fPanRamp = InitRamp(&fPan, pan, fFormat.frame_rate, duration);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@@ -199,18 +195,18 @@ status_t
|
||||
GameSoundBuffer::GetAttributes(gs_attribute * attributes,
|
||||
size_t attributeCount)
|
||||
{
|
||||
for(size_t i = 0; i < attributeCount; i++)
|
||||
{
|
||||
switch(attributes[i].attribute)
|
||||
{
|
||||
for (size_t i = 0; i < attributeCount; i++) {
|
||||
switch(attributes[i].attribute) {
|
||||
case B_GS_GAIN:
|
||||
attributes[i].value = fGain;
|
||||
if (fGainRamp) attributes[i].duration = fGainRamp->duration;
|
||||
if (fGainRamp)
|
||||
attributes[i].duration = fGainRamp->duration;
|
||||
break;
|
||||
|
||||
case B_GS_PAN:
|
||||
attributes[i].value = fPan;
|
||||
if (fPanRamp) attributes[i].duration = fGainRamp->duration;
|
||||
if (fPanRamp)
|
||||
attributes[i].duration = fGainRamp->duration;
|
||||
|
||||
case B_GS_LOOPING:
|
||||
attributes[i].value = (fLooping) ? -1.0 : 0.0;
|
||||
@@ -232,10 +228,8 @@ GameSoundBuffer::SetAttributes(gs_attribute * attributes,
|
||||
{
|
||||
status_t error = B_OK;
|
||||
|
||||
for(size_t i = 0; i < attributeCount; i++)
|
||||
{
|
||||
switch(attributes[i].attribute)
|
||||
{
|
||||
for (size_t i = 0; i < attributeCount; i++) {
|
||||
switch(attributes[i].attribute) {
|
||||
case B_GS_GAIN:
|
||||
error = SetGain(attributes[i].value, attributes[i].duration);
|
||||
break;
|
||||
@@ -264,12 +258,10 @@ GameSoundBuffer::Play(void * data, int64 frames)
|
||||
|
||||
FillBuffer(buffer, frames);
|
||||
|
||||
switch(fFormat.format)
|
||||
{
|
||||
switch(fFormat.format) {
|
||||
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);
|
||||
UpdateMods();
|
||||
}
|
||||
@@ -279,8 +271,7 @@ GameSoundBuffer::Play(void * data, int64 frames)
|
||||
|
||||
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);
|
||||
UpdateMods();
|
||||
}
|
||||
@@ -290,8 +281,7 @@ GameSoundBuffer::Play(void * data, int64 frames)
|
||||
|
||||
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);
|
||||
UpdateMods();
|
||||
}
|
||||
@@ -301,8 +291,7 @@ GameSoundBuffer::Play(void * data, int64 frames)
|
||||
|
||||
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);
|
||||
UpdateMods();
|
||||
}
|
||||
@@ -320,32 +309,23 @@ void
|
||||
GameSoundBuffer::UpdateMods()
|
||||
{
|
||||
// adjust the gain if needed
|
||||
if (fGainRamp)
|
||||
{
|
||||
if (ChangeRamp(fGainRamp))
|
||||
{
|
||||
if (fGainRamp) {
|
||||
if (ChangeRamp(fGainRamp)) {
|
||||
delete fGainRamp;
|
||||
fGainRamp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// adjust the ramp if needed
|
||||
if (fPanRamp)
|
||||
{
|
||||
if (ChangeRamp(fPanRamp))
|
||||
{
|
||||
if (fPanRamp) {
|
||||
if (ChangeRamp(fPanRamp)) {
|
||||
delete fPanRamp;
|
||||
fPanRamp = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fPan < 0.0)
|
||||
{
|
||||
} else {
|
||||
if (fPan < 0.0) {
|
||||
fPanLeft = 1.0;
|
||||
fPanRight = 1.0 + fPan;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fPanRight = 1.0;
|
||||
fPanLeft = 1.0 - fPan;
|
||||
}
|
||||
@@ -378,14 +358,16 @@ GameSoundBuffer::Connect(media_node * consumer)
|
||||
status_t err;
|
||||
|
||||
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
|
||||
r->GetNodeFor(fNode->Node().node, &fConnection->producer);
|
||||
|
||||
// connect to the mixer
|
||||
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
|
||||
// the Mixer uses too.
|
||||
@@ -397,17 +379,20 @@ GameSoundBuffer::Connect(media_node * consumer)
|
||||
media_output soundOutput;
|
||||
int32 count = 1;
|
||||
err = r->GetFreeOutputsFor(fConnection->producer, &soundOutput, 1, &count);
|
||||
if (err != B_OK) return err;
|
||||
if (err != B_OK)
|
||||
return err;
|
||||
count = 1;
|
||||
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!
|
||||
media_format format;
|
||||
format.type = B_MEDIA_RAW_AUDIO;
|
||||
format.u.raw_audio = media_raw_audio_format::wildcard;
|
||||
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
|
||||
// nodes' negotiation of the Connect(). That's why we wait until
|
||||
@@ -424,7 +409,8 @@ GameSoundBuffer::Connect(media_node * consumer)
|
||||
status_t
|
||||
GameSoundBuffer::StartPlaying()
|
||||
{
|
||||
if (fIsPlaying) return EALREADY;
|
||||
if (fIsPlaying)
|
||||
return EALREADY;
|
||||
|
||||
BMediaRoster* r = BMediaRoster::Roster();
|
||||
BTimeSource* ts = r->MakeTimeSourceFor(fConnection->producer);
|
||||
@@ -445,7 +431,8 @@ GameSoundBuffer::StartPlaying()
|
||||
status_t
|
||||
GameSoundBuffer::StopPlaying()
|
||||
{
|
||||
if (!fIsPlaying) return EALREADY;
|
||||
if (!fIsPlaying)
|
||||
return EALREADY;
|
||||
|
||||
BMediaRoster* r = BMediaRoster::Roster();
|
||||
r->StopNode(fConnection->producer, 0, true); // synchronous stop
|
||||
@@ -499,27 +486,22 @@ SimpleSoundBuffer::FillBuffer(void * data, int64 frames)
|
||||
char * buffer = (char*)data;
|
||||
size_t bytes = fFrameSize * frames;
|
||||
|
||||
if (fPosition + bytes >= fBufferSize)
|
||||
{
|
||||
if (fPosition < fBufferSize)
|
||||
{
|
||||
if (fPosition + bytes >= fBufferSize) {
|
||||
if (fPosition < fBufferSize) {
|
||||
// copy the remaining frames
|
||||
size_t remainder = fBufferSize - fPosition;
|
||||
memcpy(buffer, &fBuffer[fPosition], remainder);
|
||||
|
||||
if (fLooping)
|
||||
{
|
||||
if (fLooping) {
|
||||
// restart the sound from the begging
|
||||
memcpy(&buffer[remainder], fBuffer, bytes - remainder);
|
||||
fPosition = bytes - remainder;
|
||||
}
|
||||
else fPosition = fBufferSize;
|
||||
}
|
||||
else memset(data, 0, bytes);
|
||||
} else
|
||||
fPosition = fBufferSize;
|
||||
} else
|
||||
memset(data, 0, bytes);
|
||||
// there is nothing left to play
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
memcpy(buffer, &fBuffer[fPosition], bytes);
|
||||
fPosition += bytes;
|
||||
}
|
||||
@@ -549,3 +531,4 @@ StreamingSoundBuffer::FillBuffer(void * buffer,
|
||||
size_t bytes = fFrameSize * frames;
|
||||
object->FillBuffer(buffer, bytes);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,7 @@ void ReleaseDevice()
|
||||
{
|
||||
deviceCount--;
|
||||
|
||||
if (deviceCount <= 0)
|
||||
{
|
||||
if (deviceCount <= 0) {
|
||||
delete theDevice;
|
||||
theDevice = NULL;
|
||||
}
|
||||
@@ -89,14 +88,13 @@ BGameSoundDevice::~BGameSoundDevice()
|
||||
BMediaRoster* r = BMediaRoster::Roster();
|
||||
|
||||
// We need to stop all the sounds before we stop the mixer
|
||||
for(int32 i = 0; i < fSoundCount; i++)
|
||||
{
|
||||
if (fSounds[i]) fSounds[i]->StopPlaying();
|
||||
for (int32 i = 0; i < fSoundCount; i++) {
|
||||
if (fSounds[i])
|
||||
fSounds[i]->StopPlaying();
|
||||
delete fSounds[i];
|
||||
}
|
||||
|
||||
if (fIsConnected)
|
||||
{
|
||||
if (fIsConnected) {
|
||||
// stop the nodes if they are running
|
||||
r->StopNode(fConnection->producer, 0, true); // synchronous stop
|
||||
|
||||
@@ -150,13 +148,13 @@ BGameSoundDevice::CreateBuffer(gs_id * sound,
|
||||
const void * data,
|
||||
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;
|
||||
int32 position = AllocateSound();
|
||||
|
||||
if (position >= 0)
|
||||
{
|
||||
if (position >= 0) {
|
||||
fSounds[position] = new SimpleSoundBuffer(format, data, frames);
|
||||
err = fSounds[position]->Connect(&fConnection->producer);
|
||||
}
|
||||
@@ -171,13 +169,13 @@ BGameSoundDevice::CreateBuffer(gs_id * sound,
|
||||
const void * object,
|
||||
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;
|
||||
int32 position = AllocateSound();
|
||||
|
||||
if (position >= 0)
|
||||
{
|
||||
if (position >= 0) {
|
||||
fSounds[position] = new StreamingSoundBuffer(format, object);
|
||||
err = fSounds[position]->Connect(&fConnection->producer);
|
||||
}
|
||||
@@ -193,8 +191,7 @@ BGameSoundDevice::ReleaseBuffer(gs_id sound)
|
||||
if (sound <= 0)
|
||||
return;
|
||||
|
||||
if (fSounds[sound-1])
|
||||
{
|
||||
if (fSounds[sound-1]) {
|
||||
// We must stop playback befor destroying the sound or else
|
||||
// we may recieve fatel errors.
|
||||
fSounds[sound-1]->StopPlaying();
|
||||
@@ -218,8 +215,8 @@ BGameSoundDevice::Buffer(gs_id sound,
|
||||
if (fSounds[sound-1]->Data()) {
|
||||
data = malloc(format->buffer_size);
|
||||
memcpy(data, fSounds[sound-1]->Data(), format->buffer_size);
|
||||
}
|
||||
else data = NULL;
|
||||
} else
|
||||
data = NULL;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@@ -270,7 +267,8 @@ BGameSoundDevice::GetAttributes(gs_id sound,
|
||||
gs_attribute * attributes,
|
||||
size_t attributeCount)
|
||||
{
|
||||
if (!fSounds[sound-1]) return B_ERROR;
|
||||
if (!fSounds[sound-1])
|
||||
return B_ERROR;
|
||||
|
||||
return fSounds[sound-1]->GetAttributes(attributes, attributeCount);
|
||||
}
|
||||
@@ -281,7 +279,8 @@ BGameSoundDevice::SetAttributes(gs_id sound,
|
||||
gs_attribute * attributes,
|
||||
size_t attributeCount)
|
||||
{
|
||||
if (!fSounds[sound-1]) return B_ERROR;
|
||||
if (!fSounds[sound-1])
|
||||
return B_ERROR;
|
||||
|
||||
return fSounds[sound-1]->SetAttributes(attributes, attributeCount);
|
||||
}
|
||||
@@ -297,29 +296,35 @@ BGameSoundDevice::Connect()
|
||||
dormant_node_info mixer_dormant_info;
|
||||
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);
|
||||
if (err != B_OK) return err;
|
||||
if (err != B_OK)
|
||||
return err;
|
||||
|
||||
//fMixer = new media_node;
|
||||
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
|
||||
err = r->GetAudioMixer(&fConnection->consumer);
|
||||
if (err != B_OK) return err;
|
||||
if (err != B_OK)
|
||||
return err;
|
||||
|
||||
int32 count = 1;
|
||||
media_input mixerInput;
|
||||
err = r->GetFreeInputsFor(fConnection->consumer, &mixerInput, 1, &count);
|
||||
if (err != B_OK) return err;
|
||||
if (err != B_OK)
|
||||
return err;
|
||||
|
||||
count = 1;
|
||||
media_output mixerOutput;
|
||||
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);
|
||||
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
|
||||
// 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,
|
||||
// but if we forget to do this, our mixer might not do anything at all.
|
||||
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());
|
||||
if (err != B_OK)
|
||||
{
|
||||
if (err != B_OK) {
|
||||
mixerTimeSource->Release();
|
||||
return err;
|
||||
}
|
||||
@@ -345,7 +349,8 @@ BGameSoundDevice::Connect()
|
||||
bigtime_t tpNow = mixerTimeSource->Now();
|
||||
err = r->StartNode(fConnection->producer, tpNow + 10000);
|
||||
mixerTimeSource->Release();
|
||||
if (err != B_OK) return err;
|
||||
if (err != B_OK)
|
||||
return err;
|
||||
|
||||
// the inputs and outputs might have been reassigned during the
|
||||
// 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;
|
||||
m.GetInfo(B_ANY_TYPE, i, &name, &type) == 0;
|
||||
i++)
|
||||
{
|
||||
i++) {
|
||||
m.FindData (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;
|
||||
|
||||
n.RewindAttrs();
|
||||
while (n.GetNextAttrName(name)==B_OK)
|
||||
{
|
||||
while (n.GetNextAttrName(name) == B_OK) {
|
||||
if (n.GetAttrInfo(name,&info) != B_OK)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -235,9 +235,11 @@ BBitmapStream::WriteAt(off_t pos, const void *data, size_t size)
|
||||
fBitmap = new BBitmap(fHeader.bounds, fHeader.colors);
|
||||
if (!fBitmap)
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (fBitmap)
|
||||
fSize = sizeof(TranslatorBitmap) + fBitmap->BitsLength();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user