]> icculus.org git repositories - taylor/freespace2.git/blob - include/oal.h
rendering functions mostly done; more complete shader setup
[taylor/freespace2.git] / include / oal.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 #ifndef __OAL_H__
10 #define __OAL_H__
11
12 #include "al.h"
13 #include "alc.h"
14
15 #include "pstypes.h"
16
17
18 #ifndef WAVE_FORMAT_PCM
19 #define WAVE_FORMAT_PCM         1
20 #endif
21
22 #ifndef WAVE_FORMAT_ADPCM
23 #define WAVE_FORMAT_ADPCM       2
24 #endif
25
26 typedef struct WAVE_chunk {
27         short code;
28         ushort num_channels;
29         uint sample_rate;
30         uint bytes_per_second;
31         ushort block_align;
32         ushort bits_per_sample;
33
34         ushort extra_size;
35         ubyte *extra_data;
36
37         WAVE_chunk() : code(0), num_channels(0), sample_rate(0), bytes_per_second(0),
38                         block_align(0), bits_per_sample(0), extra_size(0), extra_data(NULL)
39         {
40         }
41 } WAVE_chunk;
42
43 typedef struct sound_channel {
44         int             sig;            // uniquely identifies the sound playing on the channel
45         int             snd_id;         // identifies which kind of sound is playing
46         ALuint  source_id;      // OpenAL source id
47         int             buf_idx;                // currently bound buffer index (-1 if none)
48         int             flags;          // looping, voice_msg, 3d, ...
49         float   vol;
50         int             priority;               // implementation dependant priority
51         ALint   last_position;
52
53         sound_channel() : sig(0), snd_id(0), source_id(0), buf_idx(-1), flags(0),
54                         vol(1.0f), priority(0), last_position(0)
55         {
56         }
57 } sound_channel;
58
59 typedef struct sound_info {
60         int format;             // WAVE_FORMAT_* defines
61         uint size;
62         int sample_rate;
63         int avg_bytes_per_sec;
64         int n_block_align;
65         int bits;
66         int n_channels;
67         int duration;   // time in ms for duration of sound
68         ubyte *data;
69 } sound_info;
70
71
72 int oal_init();
73 void oal_close();
74
75 int oal_is_initted();
76
77 int oal_get_channel(int sig);
78 int oal_get_number_channels();
79
80 int oal_get_buffer_size(int sid, int *size);
81 int oal_get_channel_size(int channel);
82
83 void oal_stop_buffer(int sid);
84 void oal_stop_channel(int channel);
85 void oal_stop_channel_all();
86
87 void oal_set_volume(int channel, float volume);
88 void oal_set_pan(int channel, float pan);
89 void oal_set_pitch(int channel, float pitch);
90 void oal_set_play_position(int channel, int position);
91
92 float oal_get_pitch(int channel);
93 int oal_get_play_position(int channel);
94
95 int oal_is_channel_playing(int channel);
96
97 void oal_chg_loop_status(int channel, int loop);
98
99 int oal_parse_wave(const char *filename, ubyte **dest, uint *dest_size, WAVE_chunk **header);
100
101 int oal_load_buffer(int *sid, int *final_size, WAVE_chunk *header, sound_info *si, int flags);
102 void oal_unload_buffer(int sid);
103
104 int oal_create_buffer(int frequency, int bits_per_sample, int nchannels, int nseconds);
105 int oal_lock_data(int sid, ubyte *data, int size);
106
107 sound_channel *oal_get_free_channel(float volume, int snd_id, int priority);
108
109 void oal_do_frame();
110
111 int oal_update_source(int channel, int min, int max, vector *pos, vector *vel);
112 int oal_update_listener(vector *pos, vector *vel, matrix *orient);
113
114 int oal_play(int sid, int snd_id, int priority, float volume, float pan, int flags);
115 int oal_play_3d( int sid, int snd_id, vector *pos, vector *vel, int min, int max, int looping, float max_volume, float estimated_vol, int priority);
116
117 bool oal_check_for_errors(const char *location);
118
119 #endif // __OAL_H__