2 * Copyright 2001-2012 Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Christopher ML Zumwalt May (zummy@users.sf.net)
10 #include "GSUtility.h"
12 #include <GameSoundDefs.h>
13 #include <MediaDefs.h>
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
;
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
;
44 ChangeRamp(_gs_ramp
* ramp
)
46 if (ramp
->frame_count
> ramp
->frame_total
)
49 if (ramp
->frame_inc_count
>= ramp
->frame_inc
) {
50 ramp
->frame_inc_count
= 0;
51 *ramp
->value
+= ramp
->inc
;
53 ramp
->frame_inc_count
++;
61 get_sample_size(int32 format
)
66 case media_raw_audio_format::B_AUDIO_CHAR
:
67 sample
= sizeof(char);
70 case gs_audio_format::B_GS_U8
:
71 sample
= sizeof(uint8
);
74 case gs_audio_format::B_GS_S16
:
75 sample
= sizeof(int16
);
78 case gs_audio_format::B_GS_S32
:
79 sample
= sizeof(int32
);
82 case gs_audio_format::B_GS_F
:
83 sample
= sizeof(float);
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
;