tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / game / GSUtility.cpp
blobee0dd8650cf59835c1e6b0ea3f9dbd43f4367cae
1 /*
2 * Copyright 2001-2012 Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Christopher ML Zumwalt May (zummy@users.sf.net)
7 */
10 #include "GSUtility.h"
12 #include <GameSoundDefs.h>
13 #include <MediaDefs.h>
15 #include <new>
18 _gs_ramp*
19 InitRamp(float* value, float set, float frames, bigtime_t duration)
21 float diff = (set > *value) ? set - *value : *value - set;
22 bigtime_t sec = bigtime_t(duration / 1000000.0);
23 float inc = diff * 200;
25 _gs_ramp* ramp = new (std::nothrow) _gs_ramp;
26 if (ramp != NULL) {
27 ramp->value = value;
29 ramp->frame_total = frames * sec;
30 ramp->frame_inc = int(ramp->frame_total / inc);
32 ramp->inc = (set - *value) / inc;
34 ramp->frame_count = 0;
35 ramp->frame_inc_count = 0;
37 ramp->duration = duration;
39 return ramp;
43 bool
44 ChangeRamp(_gs_ramp* ramp)
46 if (ramp->frame_count > ramp->frame_total)
47 return true;
49 if (ramp->frame_inc_count >= ramp->frame_inc) {
50 ramp->frame_inc_count = 0;
51 *ramp->value += ramp->inc;
52 } else
53 ramp->frame_inc_count++;
55 ramp->frame_count++;
56 return false;
60 size_t
61 get_sample_size(int32 format)
63 size_t sample;
65 switch(format) {
66 case media_raw_audio_format::B_AUDIO_CHAR:
67 sample = sizeof(char);
68 break;
70 case gs_audio_format::B_GS_U8:
71 sample = sizeof(uint8);
72 break;
74 case gs_audio_format::B_GS_S16:
75 sample = sizeof(int16);
76 break;
78 case gs_audio_format::B_GS_S32:
79 sample = sizeof(int32);
80 break;
82 case gs_audio_format::B_GS_F:
83 sample = sizeof(float);
84 break;
86 default:
87 sample = 0;
88 break;
91 return sample;
95 void
96 media_to_gs_format(gs_audio_format* dest, media_raw_audio_format* source)
98 dest->format = source->format;
99 dest->frame_rate = source->frame_rate;
100 dest->channel_count = source->channel_count;
101 dest->byte_order = source->byte_order;
102 dest->buffer_size = source->buffer_size;