aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/sfx/pcm_device/audiobuf.h
blob: b2019aec17a2526ea4fec0ad7850c737aa482b93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/***************************************************************************
 audiobuf.h Copyright (C) 2003 Christoph Reichenbach


 This program may be modified and copied freely according to the terms of
 the GNU general public license (GPL), as long as the above copyright
 notice and the licensing information contained herein are preserved.

 Please refer to www.gnu.org for licensing details.

 This work is provided AS IS, without warranty of any kind, expressed or
 implied, including but not limited to the warranties of merchantibility,
 noninfringement, and fitness for a specific purpose. The author will not
 be held liable for any damage caused by this work or derivatives of it.

 By using this source code, you agree to the licensing terms as stated
 above.


 Please contact the maintainer for bug reports or inquiries.

 Current Maintainer:

    Christoph Reichenbach (CR) <jameson@linuxgames.com>

***************************************************************************/

/* Auxiliary audio buffer for PCM devices
** Polled PCM devices must store data written to them until it is explicitly
** requiested. This is facilitated by the structures and functions defined
** here.
**   This is generic for all PCM devices; it implies no specific requirements.
**
** Usage: Introduce an sfx_audio_buf_t into your state and make sure to use
** each of the functions provided here at least once in the appropriate
** places.
*/


#ifndef _AUDIOBUF_H_
#define _AUDIOBUF_H_

#include <resource.h>
#include <sfx_time.h>
#include <sci_memory.h>
#include <sfx_pcm.h>


#define SFX_AUDIO_BUF_SIZE 8192	/* Must be multiple of framesize */
#define SFX_AUDIO_MAX_FRAME 8	/* Max. individual frame size */

typedef struct _sfx_audio_buf_chunk {
	unsigned char data[SFX_AUDIO_BUF_SIZE];
	int used;
	struct _sfx_audio_buf_chunk *prev;
	struct _sfx_audio_buf_chunk *next;
} sfx_audio_buf_chunk_t;

typedef struct {
	int read_offset;
	sfx_audio_buf_chunk_t *first; /* Next to read-- can be = last */
	sfx_audio_buf_chunk_t *last; /* Next to write-- can be = first */
	sfx_audio_buf_chunk_t *unused; /* Unused chunk list, can be NULL */
	unsigned char last_frame[SFX_AUDIO_MAX_FRAME];
	/* Contains the last frame successfully read; used for buffer
	** underruns to avoid crack before silance  */
	sfx_timestamp_t read_timestamp; /* Timestamp for reading */
	int frames_nr; /* Total number of frames currently in between reading and writing */
	int framesize;
} sfx_audio_buf_t;


void
sfx_audbuf_init(sfx_audio_buf_t *buf, sfx_pcm_config_t conf);
/* Initialises an audio buffer
** Parameters: (sfx_audio_buf_t *) buf: The buffer to initialise
**             (sfx_pcm_config_t) conf: The configuration for which the buffer should
**                                      be set up
** Modifies  : (sfx_audio_buf_t) *buf
*/

void
sfx_audbuf_free(sfx_audio_buf_t *buf);
/* Frees all memory associated with an audio buffer
** Parameters: (sfx_audio_buf_t *) buf: The buffer whose associated memory
**					should be freed
** Modifies  : (sfx_audio_buf_t) *buf
*/

void
sfx_audbuf_write(sfx_audio_buf_t *buf, unsigned char *src, int frames);
/* Store data in an audion buffer
** Parameters: (sfx_audio_buf_t *) buf: The buffer to write to
**             (unsigned char *) src: Pointer to the data that should be
**                                    written
**             (int) frames: Number of frames to write
** Modifies  : (sfx_audio_buf_t) *buf
*/


void
sfx_audbuf_write_timestamp(sfx_audio_buf_t *buf, sfx_timestamp_t ts);
/* Sets the most recently written timestamp for the buffer
** Parameters: (sfx_audio_buf_t *) buf: The buffer to operate on
**             (sfx_timestamp_t) ts: The timestamp to set
** If a timestamp is already set, 'ts' is checked for consistency and
** 'silent' frames are introduced as padding for future writes.
*/


int
sfx_audbuf_read_timestamp(sfx_audio_buf_t *buf, sfx_timestamp_t *ts);
/* Reads the timestamp describing the time right before the next frame being read
** Parameters: (sfx_audio_buf_t *) buf: The buffer to read from
** Returns   : (sfx_timestamp_t) *ts: The requested timestamp, or nothing
**             (int) zero on success, nonzero if no timestamp is known
*/


int
sfx_audbuf_read(sfx_audio_buf_t *buf, unsigned char *dest, int frames);
/* Read data from audio buffer
** Parameters: (sfx_audio_buf_t *) buf: The buffer to write to
**             (unsigned char *) dest: Pointer to the place the read data
**                                     should be written to
**             (int) frames: Number of frames to write
** Returns   : (int) Number of frames actually read
** Affects   : (sfx_audio_buf_t) *buf
**             (unsigned char ) *dest
**             global error stream
** If the returned number of frames is smaller than the number of frames
** requested to be written, this function will issue a buffer underrun
** warning and fill up the remaining space with the last frame it en--
** countered, or a block of '0' if no such frame is known.
*/




#endif /* !_AUDIOBUF_H_ */