Game Kit: rewrite GameSound and GameSoundDefs headers

Change-Id: I5efee795a73a9637f34ed8ffa4fbeeda09eb7a88
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2104
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Zotyamester
2020-01-25 11:43:02 +00:00
committed by Adrien Destugues
parent e9d6c3150e
commit edad811b96
2 changed files with 35 additions and 58 deletions
+7 -19
View File
@@ -1,22 +1,17 @@
/* /*
* Copyright 2001-2002, Haiku Inc. All Rights Reserved. * Copyright 2020, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*
* Author:
* Christopher ML Zumwalt May ([email protected])
*/ */
#ifndef _GAMESOUND_H #ifndef _GAMESOUND_H
#define _GAMESOUND_H #define _GAMESOUND_H
#include <GameSoundDefs.h> #include <GameSoundDefs.h>
#include <new> #include <new>
class BGameSoundDevice; class BGameSoundDevice;
class BGameSound { class BGameSound {
public: public:
BGameSound(BGameSoundDevice* device = NULL); BGameSound(BGameSoundDevice* device = NULL);
@@ -25,22 +20,16 @@ public:
virtual BGameSound* Clone() const = 0; virtual BGameSound* Clone() const = 0;
status_t InitCheck() const; status_t InitCheck() const;
// BGameSound attributes
BGameSoundDevice* Device() const; BGameSoundDevice* Device() const;
gs_id ID() const; gs_id ID() const;
const gs_audio_format& Format() const; const gs_audio_format& Format() const;
// only valid after Init()
// Playing sounds
virtual status_t StartPlaying(); virtual status_t StartPlaying();
virtual bool IsPlaying(); virtual bool IsPlaying();
virtual status_t StopPlaying(); virtual status_t StopPlaying();
// Modifing the playback
status_t SetGain(float gain, bigtime_t duration = 0); status_t SetGain(float gain, bigtime_t duration = 0);
// ramp duration in seconds
status_t SetPan(float pan, bigtime_t duration = 0); status_t SetPan(float pan, bigtime_t duration = 0);
// ramp duration in seconds
float Gain(); float Gain();
float Pan(); float Pan();
@@ -54,14 +43,14 @@ public:
void* operator new(size_t size, void* operator new(size_t size,
const std::nothrow_t&) throw(); const std::nothrow_t&) throw();
void operator delete(void* ptr); void operator delete(void* ptr);
void operator delete(void* ptr, void operator delete(void* ptr,
const std::nothrow_t&) throw(); const std::nothrow_t&) throw();
static status_t SetMemoryPoolSize(size_t poolSize); static status_t SetMemoryPoolSize(size_t poolSize);
static status_t LockMemoryPool(bool lockInCore); static status_t LockMemoryPool(bool lockInCore);
static int32 SetMaxSoundCount(int32 maxCount); static int32 SetMaxSoundCount(int32 maxCount);
virtual status_t Perform(int32 selector, void* data); virtual status_t Perform(int32 selector, void* data);
protected: protected:
status_t SetInitError(status_t initError); status_t SetInitError(status_t initError);
@@ -72,7 +61,6 @@ protected:
private: private:
BGameSound(); BGameSound();
// not implemented
virtual status_t _Reserved_BGameSound_0(int32 arg, ...); virtual status_t _Reserved_BGameSound_0(int32 arg, ...);
virtual status_t _Reserved_BGameSound_1(int32 arg, ...); virtual status_t _Reserved_BGameSound_1(int32 arg, ...);
@@ -126,12 +114,12 @@ private:
private: private:
BGameSoundDevice* fDevice; BGameSoundDevice* fDevice;
status_t fInitError; status_t fInitError;
gs_audio_format fFormat; gs_audio_format fFormat;
gs_id fSound; gs_id fSound;
uint32 _reserved[16]; uint32 _reserved[16];
}; };
#endif // _GAME_SOUND_H #endif
+28 -39
View File
@@ -1,9 +1,6 @@
/* /*
* Copyright 2001-2002, Haiku Inc. All Rights Reserved. * Copyright 2020, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*
* Author:
* Christopher ML Zumwalt May ([email protected])
*/ */
#ifndef _GAME_SOUND_DEFS_H #ifndef _GAME_SOUND_DEFS_H
#define _GAME_SOUND_DEFS_H #define _GAME_SOUND_DEFS_H
@@ -16,11 +13,7 @@ typedef int32 gs_id;
#define B_GS_CUR_API_VERSION B_BEOS_VERSION #define B_GS_CUR_API_VERSION B_BEOS_VERSION
#define B_GS_MIN_API_VERSION 0x100 #define B_GS_MIN_API_VERSION 0x100
// invalid sound handle
#define B_GS_INVALID_SOUND ((gs_id)-1) #define B_GS_INVALID_SOUND ((gs_id)-1)
// gs_id for the main mix buffer
#define B_GS_MAIN_SOUND ((gs_id)-2) #define B_GS_MAIN_SOUND ((gs_id)-2)
@@ -33,52 +26,48 @@ enum {
}; };
struct gs_audio_format { struct gs_audio_format {
// same as media_raw_audio_format enum format {
enum format { // for "format" B_GS_U8 = 0x11,
B_GS_U8 = 0x11, // 128 == mid, 1 == bottom, 255 == top B_GS_S16 = 0x2,
B_GS_S16 = 0x2, // 0 == mid, -32767 == bottom, +32767 == top B_GS_F = 0x24,
B_GS_F = 0x24, // 0 == mid, -1.0 == bottom, 1.0 == top B_GS_S32 = 0x4
B_GS_S32 = 0x4 // 0 == mid, 0x80000001 == bottom,
// 0x7fffffff == top
}; };
float frame_rate; float frame_rate;
uint32 channel_count; // 1 or 2, mostly uint32 channel_count;
uint32 format; // for compressed formats, go to uint32 format;
// media_encoded_audio_format uint32 byte_order;
uint32 byte_order; // 2 for little endian, 1 for big endian size_t buffer_size;
size_t buffer_size; // size of each buffer -- NOT GUARANTEED
}; };
enum gs_attributes { enum gs_attributes {
B_GS_NO_ATTRIBUTE = 0, // when there is no attribute B_GS_NO_ATTRIBUTE = 0,
B_GS_MAIN_GAIN = 1, // 0 == 0 dB, -6.0 == -6 dB (gs_id ignored) B_GS_MAIN_GAIN = 1,
B_GS_CD_THROUGH_GAIN, // 0 == 0 dB, -12.0 == -12 dB (gs_id ignored) B_GS_CD_THROUGH_GAIN,
// but which CD? B_GS_GAIN = 128,
B_GS_GAIN = 128, // 0 == 0 dB, -1.0 == -1 dB, +10.0 == +10 dB B_GS_PAN,
B_GS_PAN, // 0 == middle, -1.0 == left, +1.0 == right B_GS_SAMPLING_RATE,
B_GS_SAMPLING_RATE, // 44100.0 == 44.1 kHz B_GS_LOOPING,
B_GS_LOOPING, // 0 == no
B_GS_FIRST_PRIVATE_ATTRIBUTE = 90000, B_GS_FIRST_PRIVATE_ATTRIBUTE = 90000,
B_GS_FIRST_USER_ATTRIBUTE = 100000 B_GS_FIRST_USER_ATTRIBUTE = 100000
}; };
struct gs_attribute { struct gs_attribute {
int32 attribute; // which attribute int32 attribute;
bigtime_t duration; // how long of time to ramp over for the change bigtime_t duration;
float value; // where the value stops changing float value;
uint32 flags; // whatever flags are for the attribute uint32 flags;
}; };
struct gs_attribute_info { struct gs_attribute_info {
int32 attribute; int32 attribute;
float granularity; float granularity;
float minimum; float minimum;
float maximum; float maximum;
}; };
#endif // _GAME_SOUND_DEFS_H #endif