whitespace and style cleanup, no functional changes

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28358 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Maurice Kalinowski
2008-10-28 19:54:43 +00:00
parent 58b80f0913
commit 3feea27945
+108 -100
View File
@@ -1,9 +1,9 @@
/* /*
* Copyright 2001-2007, Haiku Inc. * Copyright 2001-2007, Haiku Inc.
* Authors: * Authors:
* Christopher ML Zumwalt May ([email protected]) * Christopher ML Zumwalt May ([email protected])
* Jérôme Duval * Jérôme Duval
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -32,34 +32,34 @@ struct _gs_media_tracker
bool FillBuffer(_gs_ramp * ramp, uint8 * data, uint8 * buffer, size_t * bytes) 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;
} }
} }
return false; return false;
} }
bool FillBuffer(_gs_ramp * ramp, int16 * data, int16 * buffer, size_t * bytes) 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;
} }
} }
return false; return false;
} }
@@ -71,16 +71,16 @@ bool FillBuffer(_gs_ramp * ramp, int32 * data, int32 * buffer, size_t * bytes)
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;
} }
byte++; byte++;
bytesAreReady = (byte >= *bytes); bytesAreReady = (byte >= *bytes);
} }
return false; return false;
} }
@@ -92,57 +92,57 @@ bool FillBuffer(_gs_ramp * ramp, float * data, float * buffer, size_t * bytes)
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;
} }
byte++; byte++;
bytesAreReady = (byte >= *bytes); bytesAreReady = (byte >= *bytes);
} }
return false; return false;
} }
// BFileGameSound ------------------------------------------------------- // BFileGameSound -------------------------------------------------------
BFileGameSound::BFileGameSound(const entry_ref *file, BFileGameSound::BFileGameSound(const entry_ref *file,
bool looping, bool looping,
BGameSoundDevice *device) BGameSoundDevice *device)
: BStreamingGameSound(device), : BStreamingGameSound(device),
fAudioStream(NULL), fAudioStream(NULL),
fStopping(false), fStopping(false),
fLooping(looping), fLooping(looping),
fBuffer(NULL), fBuffer(NULL),
fPlayPosition(0), fPlayPosition(0),
fPausing(NULL), fPausing(NULL),
fPaused(false), fPaused(false),
fPauseGain(1.0) fPauseGain(1.0)
{ {
if (InitCheck() == B_OK) if (InitCheck() == B_OK)
SetInitError(Init(file)); SetInitError(Init(file));
} }
BFileGameSound::BFileGameSound(const char *file, BFileGameSound::BFileGameSound(const char *file,
bool looping, bool looping,
BGameSoundDevice *device) BGameSoundDevice *device)
: BStreamingGameSound(device), : BStreamingGameSound(device),
fAudioStream(NULL), fAudioStream(NULL),
fStopping(false), fStopping(false),
fLooping(looping), fLooping(looping),
fBuffer(NULL), fBuffer(NULL),
fPlayPosition(0), fPlayPosition(0),
fPausing(NULL), fPausing(NULL),
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)
SetInitError(B_ENTRY_NOT_FOUND); SetInitError(B_ENTRY_NOT_FOUND);
else else
SetInitError(Init(&node)); SetInitError(Init(&node));
} }
} }
@@ -150,17 +150,17 @@ BFileGameSound::BFileGameSound(const char *file,
BFileGameSound::~BFileGameSound() BFileGameSound::~BFileGameSound()
{ {
if (fReadThread >= 0) if (fReadThread >= 0)
kill_thread(fReadThread); kill_thread(fReadThread);
if (fAudioStream) { if (fAudioStream) {
if (fAudioStream->stream) if (fAudioStream->stream)
fAudioStream->file->ReleaseTrack(fAudioStream->stream); fAudioStream->file->ReleaseTrack(fAudioStream->stream);
delete fAudioStream->file; delete fAudioStream->file;
} }
delete [] fBuffer; delete [] fBuffer;
delete fAudioStream; delete fAudioStream;
} }
@@ -176,9 +176,9 @@ status_t
BFileGameSound::StartPlaying() BFileGameSound::StartPlaying()
{ {
// restart playback if needed // restart playback if needed
if (IsPlaying()) if (IsPlaying())
StopPlaying(); StopPlaying();
// start playing the file // start playing the file
return BStreamingGameSound::StartPlaying(); return BStreamingGameSound::StartPlaying();
} }
@@ -188,18 +188,18 @@ status_t
BFileGameSound::StopPlaying() BFileGameSound::StopPlaying()
{ {
status_t error = BStreamingGameSound::StopPlaying(); status_t error = BStreamingGameSound::StopPlaying();
if (!fAudioStream || !fAudioStream->stream) if (!fAudioStream || !fAudioStream->stream)
return B_OK; return B_OK;
// start reading next time from the start of the file // start reading next time from the start of the file
int64 frame = 0; int64 frame = 0;
fAudioStream->stream->SeekToFrame(&frame); fAudioStream->stream->SeekToFrame(&frame);
fStopping = false; fStopping = false;
fAudioStream->position = 0; fAudioStream->position = 0;
fPlayPosition = 0; fPlayPosition = 0;
return error; return error;
} }
@@ -209,7 +209,7 @@ BFileGameSound::Preload()
{ {
if (!IsPlaying()) if (!IsPlaying())
Load(); Load();
return B_OK; return B_OK;
} }
@@ -219,70 +219,76 @@ BFileGameSound::FillBuffer(void *inBuffer,
size_t inByteCount) size_t inByteCount)
{ {
size_t bytes = inByteCount; size_t bytes = inByteCount;
if (!fPaused || fPausing) { if (!fPaused || fPausing) {
if (fPlayPosition == 0 || fPlayPosition + inByteCount >= fBufferSize) { if (fPlayPosition == 0 || fPlayPosition + inByteCount >= fBufferSize) {
Load(); Load();
} }
if (fPlayPosition + bytes > fBufferSize) if (fPlayPosition + bytes > fBufferSize)
bytes = fBufferSize - fPlayPosition; bytes = fBufferSize - fPlayPosition;
if (bytes == 0) if (bytes == 0)
return; return;
if (fPausing) { if (fPausing) {
Lock(); Lock();
bool rampDone = false; bool rampDone = false;
// Fill the requested buffer, stopping if the paused flag is set // Fill the requested buffer, stopping if the paused flag is set
switch(Format().format) { switch(Format().format) {
case gs_audio_format::B_GS_U8: case gs_audio_format::B_GS_U8:
rampDone = ::FillBuffer(fPausing, (uint8*)inBuffer, (uint8*)&fBuffer[fPlayPosition], &bytes); rampDone = ::FillBuffer(fPausing, (uint8*)inBuffer,
(uint8*)&fBuffer[fPlayPosition], &bytes);
break; break;
case gs_audio_format::B_GS_S16: case gs_audio_format::B_GS_S16:
rampDone = ::FillBuffer(fPausing, (int16*)inBuffer, (int16*)&fBuffer[fPlayPosition], &bytes); rampDone = ::FillBuffer(fPausing, (int16*)inBuffer,
(int16*)&fBuffer[fPlayPosition], &bytes);
break; break;
case gs_audio_format::B_GS_S32: case gs_audio_format::B_GS_S32:
rampDone = ::FillBuffer(fPausing, (int32*)inBuffer, (int32*)&fBuffer[fPlayPosition], &bytes); rampDone = ::FillBuffer(fPausing, (int32*)inBuffer,
(int32*)&fBuffer[fPlayPosition], &bytes);
break; break;
case gs_audio_format::B_GS_F: case gs_audio_format::B_GS_F:
rampDone = ::FillBuffer(fPausing, (float*)inBuffer, (float*)&fBuffer[fPlayPosition], &bytes); rampDone = ::FillBuffer(fPausing, (float*)inBuffer,
(float*)&fBuffer[fPlayPosition], &bytes);
break; break;
} }
// We finished ramping // We finished ramping
if (rampDone) { if (rampDone) {
if (bytes < inByteCount && !fPausing) { if (bytes < inByteCount && !fPausing) {
// Since we are resuming play back, we need to copy any remaining samples // Since we are resuming play back,
// we need to copy any remaining samples
char * buffer = (char*)inBuffer; char * buffer = (char*)inBuffer;
memcpy(&buffer[bytes], &fBuffer[fPlayPosition + bytes], inByteCount - bytes); memcpy(&buffer[bytes], &fBuffer[fPlayPosition + bytes],
inByteCount - bytes);
} }
delete fPausing; delete fPausing;
fPausing = NULL; fPausing = NULL;
} }
Unlock(); Unlock();
} else { } else {
size_t byte = 0; size_t byte = 0;
char * buffer = (char*)inBuffer; char * buffer = (char*)inBuffer;
// We need to be able to stop asap when the pause flag is flipped. // We need to be able to stop asap when the pause flag is flipped.
while(byte < bytes && (!fPaused || fPausing)) { while(byte < bytes && (!fPaused || fPausing)) {
buffer[byte] = fBuffer[fPlayPosition + byte]; buffer[byte] = fBuffer[fPlayPosition + byte];
byte++; byte++;
} }
bytes = byte; bytes = byte;
} }
} }
fPlayPosition += bytes; fPlayPosition += bytes;
} }
@@ -300,23 +306,25 @@ BFileGameSound::SetPaused(bool isPaused,
{ {
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);
else else
fPausing = InitRamp(&fPauseGain, 1.0, Format().frame_rate, rampTime); fPausing = InitRamp(&fPauseGain, 1.0,
Format().frame_rate, rampTime);
} }
fPaused = isPaused; fPaused = isPaused;
Unlock(); Unlock();
} }
return B_OK; return B_OK;
} }
@@ -326,10 +334,10 @@ BFileGameSound::IsPaused()
{ {
if (fPausing) if (fPausing)
return B_PAUSE_IN_PROGRESS; return B_PAUSE_IN_PROGRESS;
if (fPaused) if (fPaused)
return B_PAUSED; return B_PAUSED;
return B_NOT_PAUSED; return B_NOT_PAUSED;
} }
@@ -339,54 +347,54 @@ BFileGameSound::Init(const entry_ref* file)
{ {
fAudioStream = new _gs_media_tracker; fAudioStream = new _gs_media_tracker;
memset(fAudioStream, 0, sizeof(_gs_media_tracker)); memset(fAudioStream, 0, sizeof(_gs_media_tracker));
fAudioStream->file = new BMediaFile(file); fAudioStream->file = new BMediaFile(file);
status_t error = fAudioStream->file->InitCheck(); status_t error = fAudioStream->file->InitCheck();
if (error != B_OK) if (error != B_OK)
return error; return error;
fAudioStream->stream = fAudioStream->file->TrackAt(0); fAudioStream->stream = fAudioStream->file->TrackAt(0);
// is this is an audio file? // is this is an audio file?
media_format playFormat; media_format playFormat;
if ((error = fAudioStream->stream->EncodedFormat(&playFormat)) != B_OK) if ((error = fAudioStream->stream->EncodedFormat(&playFormat)) != B_OK)
return error; return error;
if (!playFormat.IsAudio()) if (!playFormat.IsAudio())
return B_MEDIA_BAD_FORMAT; return B_MEDIA_BAD_FORMAT;
gs_audio_format dformat = Device()->Format(); gs_audio_format dformat = Device()->Format();
// request the format we want the sound // request the format we want the sound
memset(&playFormat, 0, sizeof(media_format)); memset(&playFormat, 0, sizeof(media_format));
playFormat.type = B_MEDIA_RAW_AUDIO; playFormat.type = B_MEDIA_RAW_AUDIO;
if (fAudioStream->stream->DecodedFormat(&playFormat) != B_OK) if (fAudioStream->stream->DecodedFormat(&playFormat) != B_OK)
return B_MEDIA_BAD_FORMAT; return B_MEDIA_BAD_FORMAT;
// translate the format into a "GameKit" friendly one // translate the format into a "GameKit" friendly one
gs_audio_format gsformat; gs_audio_format gsformat;
media_to_gs_format(&gsformat, &playFormat.u.raw_audio); media_to_gs_format(&gsformat, &playFormat.u.raw_audio);
// Since the buffer sized read from the file is most likely differnt // Since the buffer sized read from the file is most likely differnt
// then the buffer used by the audio mixer, we must allocate a buffer // then the buffer used by the audio mixer, we must allocate a buffer
// large enough to hold the largest request. // large enough to hold the largest request.
fBufferSize = gsformat.buffer_size; fBufferSize = gsformat.buffer_size;
if (fBufferSize < dformat.buffer_size) if (fBufferSize < dformat.buffer_size)
fBufferSize = dformat.buffer_size; fBufferSize = dformat.buffer_size;
// create the buffer // create the buffer
fBuffer = new char[fBufferSize * 2]; fBuffer = new char[fBufferSize * 2];
memset(fBuffer, 0, fBufferSize * 2); memset(fBuffer, 0, fBufferSize * 2);
fFrameSize = gsformat.channel_count * get_sample_size(gsformat.format); fFrameSize = gsformat.channel_count * get_sample_size(gsformat.format);
fAudioStream->frames = fAudioStream->stream->CountFrames(); fAudioStream->frames = fAudioStream->stream->CountFrames();
// Ask the device to attach our sound to it // Ask the device to attach our sound to it
gs_id sound; gs_id sound;
error = Device()->CreateBuffer(&sound, this, &gsformat); error = Device()->CreateBuffer(&sound, this, &gsformat);
if (error != B_OK) if (error != B_OK)
return error; return error;
return BGameSound::Init(sound); return BGameSound::Init(sound);
} }
@@ -399,13 +407,13 @@ BFileGameSound::Load()
memcpy(fBuffer, fBuffer + fPlayPosition, fBufferSize - fPlayPosition); memcpy(fBuffer, fBuffer + fPlayPosition, fBufferSize - fPlayPosition);
fPlayPosition = fBufferSize - fPlayPosition; fPlayPosition = fBufferSize - fPlayPosition;
} }
// time to read a new buffer // time to read a new buffer
int64 frames = 0; int64 frames = 0;
fAudioStream->stream->ReadFrames(fBuffer + fPlayPosition, &frames); fAudioStream->stream->ReadFrames(fBuffer + fPlayPosition, &frames);
fBufferSize = fPlayPosition + frames * fFrameSize; fBufferSize = fPlayPosition + frames * fFrameSize;
fPlayPosition = 0; fPlayPosition = 0;
if (fBufferSize == 0) { if (fBufferSize == 0) {
if (fLooping) { if (fLooping) {
// start reading next time from the start of the file // start reading next time from the start of the file
@@ -415,7 +423,7 @@ BFileGameSound::Load()
StopPlaying(); StopPlaying();
} }
} }
return true; return true;
} }
@@ -423,17 +431,17 @@ BFileGameSound::Load()
bool bool
BFileGameSound::Read(void * buffer, size_t bytes) BFileGameSound::Read(void * buffer, size_t bytes)
{ {
return false; return false;
} }
/* unimplemented for protection of the user: /* unimplemented for protection of the user:
* *
* BFileGameSound::BFileGameSound() * BFileGameSound::BFileGameSound()
* BFileGameSound::BFileGameSound(const BFileGameSound &) * BFileGameSound::BFileGameSound(const BFileGameSound &)
* BFileGameSound &BFileGameSound::operator=(const BFileGameSound &) * BFileGameSound &BFileGameSound::operator=(const BFileGameSound &)
*/ */
status_t status_t
BFileGameSound::_Reserved_BFileGameSound_0(int32 arg, ...) BFileGameSound::_Reserved_BFileGameSound_0(int32 arg, ...)