update license headers, code style

In BPushGameSound, SetParameter and SetStreamHook return B_UNSUPPORTED while Perform calls the parent class.
Moved code to the constructor.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20682 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2007-04-14 13:35:39 +00:00
parent 49f3c71e21
commit ea4f253fd6
6 changed files with 73 additions and 182 deletions
+8 -25
View File
@@ -1,28 +1,11 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2007, Haiku Inc.
// * Authors:
// Permission is hereby granted, free of charge, to any person obtaining a * Christopher ML Zumwalt May ([email protected])
// copy of this software and associated documentation files (the "Software"), * Jérôme Duval
// to deal in the Software without restriction, including without limitation *
// the rights to use, copy, modify, merge, publish, distribute, sublicense, * Distributed under the terms of the MIT License.
// and/or sell copies of the Software, and to permit persons to whom the */
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: FileGameSound.cpp
// Author: Christopher ML Zumwalt May ([email protected])
// Description: BFileGameSound is a class that streams data out of a file.
//------------------------------------------------------------------------------
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
+25 -44
View File
@@ -1,44 +1,19 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2002, Haiku Inc.
// * Authors:
// Permission is hereby granted, free of charge, to any person obtaining a * Christopher ML Zumwalt May ([email protected])
// copy of this software and associated documentation files (the "Software"), *
// to deal in the Software without restriction, including without limitation * Distributed under the terms of the MIT License.
// the rights to use, copy, modify, merge, publish, distribute, sublicense, */
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: GameSoundDevice.h
// Author: Christopher ML Zumwalt May ([email protected])
// Description: Utility functions used by sound system
//------------------------------------------------------------------------------
// Standard Includes ----------------------------------------------------------- #include <GameSoundDefs.h>
// System Includes -------------------------------------------------------------
#include <MediaDefs.h> #include <MediaDefs.h>
// Project Includes ------------------------------------------------------------
#include <GameSoundDefs.h>
// Local Includes --------------------------------------------------------------
#include "GSUtility.h" #include "GSUtility.h"
// Local Defines ---------------------------------------------------------------
// Utility functions ----------------------------------------------------------- _gs_ramp*
_gs_ramp* InitRamp(float* value, float set, float frames, bigtime_t duration) InitRamp(float* value, float set, float frames, bigtime_t duration)
{ {
float diff = (set > *value) ? set - *value : *value - set; float diff = (set > *value) ? set - *value : *value - set;
bigtime_t sec = bigtime_t(duration / 1000000.0); bigtime_t sec = bigtime_t(duration / 1000000.0);
@@ -60,27 +35,31 @@ _gs_ramp* InitRamp(float* value, float set, float frames, bigtime_t duration)
return ramp; return ramp;
} }
bool ChangeRamp(_gs_ramp* ramp)
bool
ChangeRamp(_gs_ramp* ramp)
{ {
if (ramp->frame_count > ramp->frame_total) return true; if (ramp->frame_count > ramp->frame_total)
return true;
if (ramp->frame_inc_count >= ramp->frame_inc) if (ramp->frame_inc_count >= ramp->frame_inc) {
{
ramp->frame_inc_count = 0; ramp->frame_inc_count = 0;
*ramp->value += ramp->inc; *ramp->value += ramp->inc;
} }
else ramp->frame_inc_count++; else
ramp->frame_inc_count++;
ramp->frame_count++; ramp->frame_count++;
return false; return false;
} }
size_t get_sample_size(int32 format)
size_t
get_sample_size(int32 format)
{ {
size_t sample; size_t sample;
switch(format) switch(format) {
{
case media_raw_audio_format::B_AUDIO_CHAR: case media_raw_audio_format::B_AUDIO_CHAR:
sample = sizeof(char); sample = sizeof(char);
break; break;
@@ -107,7 +86,9 @@ size_t get_sample_size(int32 format)
return sample; return sample;
} }
void media_to_gs_format(gs_audio_format* dest, media_raw_audio_format* source)
void
media_to_gs_format(gs_audio_format* dest, media_raw_audio_format* source)
{ {
dest->format = source->format; dest->format = source->format;
dest->frame_rate = source->frame_rate; dest->frame_rate = source->frame_rate;
+7 -26
View File
@@ -1,29 +1,10 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2002, Haiku Inc.
// * Authors:
// Permission is hereby granted, free of charge, to any person obtaining a * Christopher ML Zumwalt May ([email protected])
// copy of this software and associated documentation files (the "Software"), *
// to deal in the Software without restriction, including without limitation * Distributed under the terms of the MIT License.
// the rights to use, copy, modify, merge, publish, distribute, sublicense, */
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: GameSound.cpp
// Author: Christopher ML Zumwalt May ([email protected])
// Description: Provides much of interfaces with BGameSoundDevice on behalf
// of the rest of it's childern.
//------------------------------------------------------------------------------
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
+24 -51
View File
@@ -1,28 +1,11 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2007, Haiku Inc.
// * Authors:
// Permission is hereby granted, free of charge, to any person obtaining a * Christopher ML Zumwalt May ([email protected])
// copy of this software and associated documentation files (the "Software"), * Jérôme Duval
// to deal in the Software without restriction, including without limitation *
// the rights to use, copy, modify, merge, publish, distribute, sublicense, * Distributed under the terms of the MIT License.
// and/or sell copies of the Software, and to permit persons to whom the */
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: GameSound.cpp
// Author: Christopher ML Zumwalt May ([email protected])
// Description: BPushGameSound class
//------------------------------------------------------------------------------
#include <string.h> #include <string.h>
@@ -36,14 +19,15 @@ BPushGameSound::BPushGameSound(size_t inBufferFrameCount, const gs_audio_format
size_t inBufferCount, BGameSoundDevice *device) size_t inBufferCount, BGameSoundDevice *device)
: BStreamingGameSound(inBufferFrameCount, format, inBufferCount, device) : BStreamingGameSound(inBufferFrameCount, format, inBufferCount, device)
{ {
if (InitCheck() != B_OK) fPageLocked = new BList;
return;
size_t frameSize = get_sample_size(format->format) * format->channel_count;
status_t error = SetParameters(inBufferFrameCount, format, inBufferCount); fPageCount = inBufferCount;
if (error == B_OK) fPageSize = frameSize * inBufferFrameCount;
fPageLocked = new BList; fBufferSize = fPageSize * fPageCount;
else
SetInitError(error); fBuffer = new char[fBufferSize];
} }
@@ -58,7 +42,8 @@ BPushGameSound::BPushGameSound(BGameSoundDevice * device)
{ {
fPageLocked = new BList; fPageLocked = new BList;
} }
BPushGameSound::~BPushGameSound() BPushGameSound::~BPushGameSound()
{ {
delete [] fBuffer; delete [] fBuffer;
@@ -70,12 +55,12 @@ BPushGameSound::lock_status
BPushGameSound::LockNextPage(void **out_pagePtr, size_t *out_pageSize) BPushGameSound::LockNextPage(void **out_pagePtr, size_t *out_pageSize)
{ {
// the user can not lock every page // the user can not lock every page
if (fPageLocked->CountItems() > fPageCount - 3) if (fPageLocked->CountItems() > fPageCount - 3)
return lock_failed; return lock_failed;
// the user cann't lock a page being played // the user cann't lock a page being played
if (fLockPos < fPlayPos if (fLockPos < fPlayPos
&& fLockPos + fPageSize > fPlayPos) && fLockPos + fPageSize > fPlayPos)
return lock_failed; return lock_failed;
// lock the page // lock the page
@@ -84,7 +69,7 @@ BPushGameSound::LockNextPage(void **out_pagePtr, size_t *out_pageSize)
// move the locker to the next page // move the locker to the next page
fLockPos += fPageSize; fLockPos += fPageSize;
if (fLockPos > fBufferSize) if (fLockPos > fBufferSize)
fLockPos = 0; fLockPos = 0;
*out_pagePtr = lockPage; *out_pagePtr = lockPage;
@@ -138,7 +123,7 @@ BPushGameSound::Clone() const
status_t status_t
BPushGameSound::Perform(int32 selector, void *data) BPushGameSound::Perform(int32 selector, void *data)
{ {
return B_ERROR; return BStreamingGameSound::Perform(selector, data);
} }
@@ -147,19 +132,7 @@ BPushGameSound::SetParameters(size_t inBufferFrameCount,
const gs_audio_format *format, const gs_audio_format *format,
size_t inBufferCount) size_t inBufferCount)
{ {
status_t error = BStreamingGameSound::SetParameters(inBufferFrameCount, format, inBufferCount); return B_UNSUPPORTED;
if (error != B_OK)
return error;
size_t frameSize = get_sample_size(format->format) * format->channel_count;
fPageCount = inBufferCount;
fPageSize = frameSize * inBufferFrameCount;
fBufferSize = fPageSize * fPageCount;
fBuffer = new char[fBufferSize];
return B_OK;
} }
@@ -167,7 +140,7 @@ status_t
BPushGameSound::SetStreamHook(void (*hook)(void * inCookie, void * inBuffer, size_t inByteCount, BStreamingGameSound * me), BPushGameSound::SetStreamHook(void (*hook)(void * inCookie, void * inBuffer, size_t inByteCount, BStreamingGameSound * me),
void * cookie) void * cookie)
{ {
return B_ERROR; return B_UNSUPPORTED;
} }
+7 -26
View File
@@ -1,29 +1,10 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2005, Haiku * Copyright 2001-2005, Haiku Inc.
// * Authors:
// Permission is hereby granted, free of charge, to any person obtaining a * Christopher ML Zumwalt May ([email protected])
// copy of this software and associated documentation files (the "Software"), *
// to deal in the Software without restriction, including without limitation * Distributed under the terms of the MIT License.
// the rights to use, copy, modify, merge, publish, distribute, sublicense, */
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: SimpleGameSound.h
// Author: Christopher ML Zumwalt May ([email protected])
// Description: BSimpleGameSound is a class for sound effects that are
// short, and consists of non-changing samples in memory.
//------------------------------------------------------------------------------
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
+2 -10
View File
@@ -25,17 +25,10 @@
// (data not known beforehand) game sounds. // (data not known beforehand) game sounds.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
// Project Includes ------------------------------------------------------------
#include "GameSoundDevice.h" #include "GameSoundDevice.h"
// Local Includes --------------------------------------------------------------
#include "StreamingGameSound.h" #include "StreamingGameSound.h"
// Local Defines ---------------------------------------------------------------
BStreamingGameSound::BStreamingGameSound(size_t inBufferFrameCount, BStreamingGameSound::BStreamingGameSound(size_t inBufferFrameCount,
const gs_audio_format *format, const gs_audio_format *format,
size_t inBufferCount, size_t inBufferCount,
@@ -44,8 +37,7 @@ BStreamingGameSound::BStreamingGameSound(size_t inBufferFrameCount,
fStreamHook(NULL), fStreamHook(NULL),
fStreamCookie(NULL) fStreamCookie(NULL)
{ {
if (InitCheck() == B_OK) if (InitCheck() == B_OK) {
{
status_t error = SetParameters(inBufferFrameCount, format, inBufferCount); status_t error = SetParameters(inBufferFrameCount, format, inBufferCount);
SetInitError(error); SetInitError(error);
} }