style cleanup

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25177 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2008-04-26 12:16:53 +00:00
parent 5b89ed13fd
commit fc1ca2da5c
10 changed files with 212 additions and 255 deletions

View File

@ -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);

View File

@ -217,59 +217,55 @@ 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;
fOutput.format = format;
strncpy(io_name, fOutput.name, B_MEDIA_NAME_LENGTH);
// Now that we're connected, we can determine our downstream latency.
// Do so, then make sure we get our events early enough.
media_node_id id;
FindLatencyFor(fOutput.destination, &fLatency, &id);
// Okay, the connection has been confirmed. Record the destination and format
// that we agreed on, and report our connection name again.
fOutput.destination = destination;
fOutput.format = format;
strncpy(io_name, fOutput.name, B_MEDIA_NAME_LENGTH);
// Use a dry run to see how long it takes me to fill a buffer of data
// Now that we're connected, we can determine our downstream latency.
// Do so, then make sure we get our events early enough.
media_node_id id;
FindLatencyFor(fOutput.destination, &fLatency, &id);
// Use a dry run to see how long it takes me to fill a buffer of data
// The first step to setup the buffer
bigtime_t start, produceLatency;
int32 frames = int32(fOutput.format.u.raw_audio.buffer_size / fFrameSize);
float* data = new float[frames * 2];
// The first step to setup the buffer
bigtime_t start, produceLatency;
int32 frames = int32(fOutput.format.u.raw_audio.buffer_size / fFrameSize);
float* data = new float[frames * 2];
// Second, fill the buffer
start = ::system_time();
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();
// Second, fill the buffer
start = ::system_time();
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
fInternalLatency = produceLatency - start;
SetEventLatency(fLatency + fInternalLatency);
// Third, calculate the latency
fInternalLatency = produceLatency - start;
SetEventLatency(fLatency + fInternalLatency);
// Finaily, clean up
delete [] data;
// Finaily, clean up
delete [] data;
// reset our buffer duration, etc. to avoid later calculations
bigtime_t duration = bigtime_t(1000000) * frames / bigtime_t(fOutput.format.u.raw_audio.frame_rate);
SetBufferDuration(duration);
// reset our buffer duration, etc. to avoid later calculations
bigtime_t duration = bigtime_t(1000000) * frames / bigtime_t(fOutput.format.u.raw_audio.frame_rate);
SetBufferDuration(duration);
// Set up the buffer group for our connection, as long as nobody handed us a
// buffer group (via SetBufferGroup()) prior to this.
if (!fBufferGroup)
{
size_t size = fOutput.format.u.raw_audio.buffer_size;
int32 count = int32(fLatency / BufferDuration() + 2);
fBufferGroup = new BBufferGroup(size, count);
}
// Set up the buffer group for our connection, as long as nobody handed us a
// buffer group (via SetBufferGroup()) prior to this.
if (!fBufferGroup) {
size_t size = fOutput.format.u.raw_audio.buffer_size;
int32 count = int32(fLatency / BufferDuration() + 2);
fBufferGroup = new BBufferGroup(size, count);
}
}
@ -278,8 +274,7 @@ 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;
}

View File

@ -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);
}

View File

@ -61,8 +61,7 @@ void ReleaseDevice()
{
deviceCount--;
if (deviceCount <= 0)
{
if (deviceCount <= 0) {
delete theDevice;
theDevice = NULL;
}
@ -79,7 +78,7 @@ BGameSoundDevice::BGameSoundDevice()
fInitError = Connect();
fSounds = new GameSoundBuffer*[kInitSoundCount];
for(int32 i = 0; i < kInitSoundCount; i++)
for (int32 i = 0; i < kInitSoundCount; i++)
fSounds[i] = 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
@ -366,16 +371,16 @@ BGameSoundDevice::Connect()
int32
BGameSoundDevice::AllocateSound()
{
for(int32 i = 0; i < fSoundCount; i++)
for (int32 i = 0; i < fSoundCount; i++)
if (!fSounds[i])
return i;
// we need to allocate new space for the sound
GameSoundBuffer ** sounds = new GameSoundBuffer*[fSoundCount + kGrowth];
for(int32 i = 0; i < fSoundCount; i++)
for (int32 i = 0; i < fSoundCount; i++)
sounds[i] = fSounds[i];
for(int32 i = fSoundCount; i < fSoundCount + kGrowth; i++)
for (int32 i = fSoundCount; i < fSoundCount + kGrowth; i++)
sounds[i] = NULL;
// replace the old list

View File

@ -27,10 +27,9 @@ _EXPORT BNode& operator<<(BNode& n, const BMessage& m)
ssize_t bytes;
const void *data;
for(int32 i = 0;
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;

View File

@ -37,7 +37,7 @@ BMediaFiles::RewindTypes()
server_rewindtypes_request request;
server_rewindtypes_reply reply;
for(int32 i = 0; i < m_types.CountItems(); i++)
for (int32 i = 0; i < m_types.CountItems(); i++)
delete (BString*)m_types.ItemAt(i);
m_types.MakeEmpty();
@ -97,7 +97,7 @@ BMediaFiles::RewindRefs(const char *type)
server_rewindrefs_request request;
server_rewindrefs_reply reply;
for(int32 i = 0; i < m_items.CountItems(); i++)
for (int32 i = 0; i < m_items.CountItems(); i++)
delete (BString*)m_items.ItemAt(i);
m_items.MakeEmpty();

View File

@ -344,7 +344,7 @@ BParameterWeb::~BParameterWeb()
CALLED();
if (mGroups != NULL) {
for(int32 i = mGroups->CountItems(); i-- > 0;) {
for (int32 i = mGroups->CountItems(); i-- > 0;) {
delete static_cast<BParameterGroup *>(mGroups->ItemAt(i));
}
@ -1097,7 +1097,7 @@ BParameterGroup::Unflatten(type_code code, const void *buffer, ssize_t size)
//Clear all existing parameters/subgroups
int i;
if (mControls != NULL) {
for(i = 0; i < mControls->CountItems(); i++) {
for (i = 0; i < mControls->CountItems(); i++) {
BParameter *CurrentItem = static_cast<BParameter *>(mControls->ItemAt(i));
if (CurrentItem != NULL) {
delete CurrentItem;
@ -2135,7 +2135,7 @@ BDiscreteParameter::MakeItemsFromInputs()
ASSERT(mInputs != NULL);
int32 count = mInputs->CountItems();
for(int32 i = 0; i < count; i++) {
for (int32 i = 0; i < count; i++) {
BParameter *parameter = static_cast<BParameter *>(mInputs->ItemAt(i));
AddItem(i, parameter->Name());
}
@ -2153,7 +2153,7 @@ BDiscreteParameter::MakeItemsFromOutputs()
ASSERT(mOutputs != NULL);
int32 count = mOutputs->CountItems();
for(int32 i = 0; i < count; i++) {
for (int32 i = 0; i < count; i++) {
BParameter *parameter = static_cast<BParameter *>(mOutputs->ItemAt(i));
AddItem(i, parameter->Name());
}
@ -2174,7 +2174,7 @@ BDiscreteParameter::MakeEmpty()
}
mValues->MakeEmpty();
for(int32 i = mSelections->CountItems(); i-- > 0;) {
for (int32 i = mSelections->CountItems(); i-- > 0;) {
free(static_cast<char *>(mSelections->ItemAt(i)));
}
mSelections->MakeEmpty();

View File

@ -54,7 +54,7 @@ void
BCommandPipe::FlushArgs()
{
// Delete all arguments from the list
for(int32 i = 0; i < fArgList.CountItems(); i++)
for (int32 i = 0; i < fArgList.CountItems(); i++)
free(fArgList.RemoveItem(0L));
fArgList.MakeEmpty();

View File

@ -35,7 +35,7 @@ AddOnMonitorHandler::AddDirectory(const node_ref * nref)
{
// ignore directories added twice
std::list<add_on_directory_info>::iterator diter = directories.begin();
for( ; diter != directories.end() ; diter++) {
for (; diter != directories.end() ; diter++) {
if (diter->nref == *nref) {
return B_OK;
}
@ -147,10 +147,10 @@ AddOnMonitorHandler::EntryRemoved(ino_t directory, dev_t device, ino_t node)
// find the entry's info, and the entry's directory info
std::list<add_on_directory_info>::iterator diter = directories.begin();
for( ; diter != directories.end() ; diter++) {
for (; diter != directories.end() ; diter++) {
if (diter->nref == dir_nref) {
std::list<add_on_entry_info>::iterator eiter = diter->entries.begin();
for( ; eiter != diter->entries.end() ; eiter++) {
for (; eiter != diter->entries.end() ; eiter++) {
info = *eiter;
if (eiter->nref == entry_nref) {
info = *eiter;
@ -172,9 +172,9 @@ AddOnMonitorHandler::EntryRemoved(ino_t directory, dev_t device, ino_t node)
// the old add_on was not enabled. So we deallocate the old
// add_on and return.
std::list<add_on_directory_info>::iterator diter2 = directories.begin();
for( ; diter2 != diter ; diter2++) {
for (; diter2 != diter ; diter2++) {
std::list<add_on_entry_info>::iterator eiter = diter2->entries.begin();
for( ; eiter != diter2->entries.end() ; eiter++) {
for (; eiter != diter2->entries.end() ; eiter++) {
if (strcmp(eiter->name, info.name) == 0) {
AddOnRemoved(&info);
return;
@ -191,7 +191,7 @@ AddOnMonitorHandler::EntryRemoved(ino_t directory, dev_t device, ino_t node)
// with the same name, we must enable it.
for (diter++ ; diter != directories.end() ; diter++) {
std::list<add_on_entry_info>::iterator eiter = diter->entries.begin();
for( ; eiter != diter->entries.end() ; eiter++) {
for (; eiter != diter->entries.end() ; eiter++) {
if (strcmp(eiter->name, info.name) == 0) {
AddOnEnabled(&*eiter);
return;
@ -235,7 +235,7 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
if (to_iter == directories.end()) {
// moved out of our view
std::list<add_on_entry_info>::iterator eiter = from_iter->entries.begin();
for( ; eiter != from_iter->entries.end() ; eiter++) {
for (; eiter != from_iter->entries.end() ; eiter++) {
if (entry_nref == eiter->nref) {
// save the info and remove the entry
info = *eiter;
@ -259,9 +259,9 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
// If we find a add_on with the same name then the moved add_on
// was not enabled. So we are done.
std::list<add_on_directory_info>::iterator diter = directories.begin();
for( ; diter != from_iter ; diter++) {
for (; diter != from_iter ; diter++) {
std::list<add_on_entry_info>::iterator eiter2 = diter->entries.begin();
for( ; eiter2 != diter->entries.end() ; eiter2++) {
for (; eiter2 != diter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) {
return;
}
@ -275,7 +275,7 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
// with the same name, we must enable it.
for (from_iter++ ; from_iter != directories.end() ; from_iter++) {
std::list<add_on_entry_info>::iterator eiter2 = from_iter->entries.begin();
for( ; eiter2 != from_iter->entries.end() ; eiter2++) {
for (; eiter2 != from_iter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) {
AddOnEnabled(&*eiter2);
return;
@ -295,7 +295,7 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
if (from_iter == directories.end()) {
// moved into our view
std::list<add_on_entry_info>::iterator eiter = former_entries.begin();
for( ; eiter != former_entries.end() ; eiter++) {
for (; eiter != former_entries.end() ; eiter++) {
if (entry_nref == eiter->nref) {
// save the info and remove the entry
info = *eiter;
@ -325,9 +325,9 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
// If we find a add_on with the same name then the moved add_on
// is not to be enabled. So we are done.
std::list<add_on_directory_info>::iterator diter = directories.begin();
for( ; diter != to_iter ; diter++) {
for (; diter != to_iter ; diter++) {
std::list<add_on_entry_info>::iterator eiter2 = diter->entries.begin();
for( ; eiter2 != diter->entries.end() ; eiter2++) {
for (; eiter2 != diter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) {
return;
}
@ -339,7 +339,7 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
bool shadowing = false;
for (diter++ ; diter != directories.end() ; diter++) {
std::list<add_on_entry_info>::iterator eiter2 = diter->entries.begin();
for( ; eiter2 != diter->entries.end() ; eiter2++) {
for (; eiter2 != diter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) {
AddOnDisabled(&*eiter2);
shadowing = true;
@ -362,7 +362,7 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
}
std::list<add_on_entry_info>::iterator eiter = from_iter->entries.begin();
for( ; eiter != from_iter->entries.end() ; eiter++) {
for (; eiter != from_iter->entries.end() ; eiter++) {
if (entry_nref == eiter->nref) {
// save the old info and remove the entry
info = *eiter;
@ -378,9 +378,9 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
// check to see if it was formerly enabled
bool was_enabled = true;
std::list<add_on_directory_info>::iterator old_iter = directories.begin();
for( ; old_iter != from_iter ; old_iter++) {
for (; old_iter != from_iter ; old_iter++) {
std::list<add_on_entry_info>::iterator eiter2 = old_iter->entries.begin();
for( ; eiter2 != old_iter->entries.end() ; eiter2++) {
for (; eiter2 != old_iter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) {
was_enabled = false;
break;
@ -395,9 +395,9 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
if (was_enabled) {
AddOnDisabled(&info);
bool done = false;
for( ; old_iter != directories.end() ; old_iter++) {
for (; old_iter != directories.end() ; old_iter++) {
std::list<add_on_entry_info>::iterator eiter2 = old_iter->entries.begin();
for( ; eiter2 != old_iter->entries.end() ; eiter2++) {
for (; eiter2 != old_iter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) {
AddOnEnabled(&*eiter2);
done = true;
@ -423,9 +423,9 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
// check to see if we are newly enabled
bool is_enabled = true;
std::list<add_on_directory_info>::iterator new_iter = directories.begin();
for( ; new_iter != to_iter ; new_iter++) {
for (; new_iter != to_iter ; new_iter++) {
std::list<add_on_entry_info>::iterator eiter2 = new_iter->entries.begin();
for( ; eiter2 != new_iter->entries.end() ; eiter2++) {
for (; eiter2 != new_iter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) {
is_enabled = false;
break;
@ -439,9 +439,9 @@ AddOnMonitorHandler::EntryMoved(const char *name, ino_t from_directory,
// if it is newly enabled, check under us for an enabled one, and disable that first
if (is_enabled) {
bool done = false;
for( ; new_iter != directories.end() ; new_iter++) {
for (; new_iter != directories.end() ; new_iter++) {
std::list<add_on_entry_info>::iterator eiter2 = new_iter->entries.begin();
for( ; eiter2 != new_iter->entries.end() ; eiter2++) {
for (; eiter2 != new_iter->entries.end() ; eiter2++) {
if (strcmp(eiter2->name, info.name) == 0) {
AddOnDisabled(&*eiter2);
done = true;
@ -503,7 +503,7 @@ AddOnMonitorHandler::HandlePulse()
// put the new entry into the directory info
std::list<add_on_directory_info>::iterator diter = directories.begin();
for( ; diter != directories.end() ; diter++) {
for (; diter != directories.end() ; diter++) {
if (diter->nref == dir_nref) {
diter->entries.push_back(info);
break;
@ -518,9 +518,9 @@ AddOnMonitorHandler::HandlePulse()
// the new add_on should not be enabled.
bool enabled = true;
std::list<add_on_directory_info>::iterator diter2 = directories.begin();
for( ; diter2 != diter ; diter2++) {
for (; diter2 != diter ; diter2++) {
std::list<add_on_entry_info>::iterator eiter = diter2->entries.begin();
for( ; eiter != diter2->entries.end() ; eiter++) {
for (; eiter != diter2->entries.end() ; eiter++) {
if (strcmp(eiter->name, info.name) == 0) {
enabled = false;
break;
@ -540,7 +540,7 @@ AddOnMonitorHandler::HandlePulse()
bool shadowing = false;
for (diter++ ; diter != directories.end() ; diter++) {
std::list<add_on_entry_info>::iterator eiter = diter->entries.begin();
for( ; eiter != diter->entries.end() ; eiter++) {
for (; eiter != diter->entries.end() ; eiter++) {
if (strcmp(eiter->name, info.name) == 0) {
AddOnDisabled(&*eiter);
shadowing = true;

View File

@ -235,8 +235,10 @@ 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();