xref: /titanic_50/usr/src/cmd/audio/include/AudioBuffer.h (revision 0a1278f26ea4b7c8c0285d4f2d6c5b680904aa01)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1992-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _MULTIMEDIA_AUDIOBUFFER_H
28 #define	_MULTIMEDIA_AUDIOBUFFER_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <AudioStream.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 // This is the class describing a mapped buffer of audio data.
39 // In addition to the standard Read and Write methods, the address
40 // of the buffer may be obtained and the data accessed directly.
41 
42 class AudioBuffer : public AudioStream {
43 private:
44 	Double		buflen;			// buffer size, in seconds
45 	int		zflag;			// malloc'd with zmalloc?
46 protected:
47 	size_t		bufsize;		// buffer size, in bytes
48 	void*		bufaddr;		// buffer address
49 
50 	// class AudioStream methods specialized here
51 	virtual Boolean opened() const;			// TRUE, if open
52 	virtual AudioError alloc();			// Allocate buffer
53 
54 public:
55 	// Constructor
56 	AudioBuffer(
57 	    double len = 0.,			// buffer size, in seconds
58 	    const char *name = "(buffer)");	// name
59 	~AudioBuffer();					// Destructor
60 
61 	virtual void* GetAddress() const;		// Get buffer address
62 	virtual void* GetAddress(Double) const;		// Get address at offset
63 	virtual AudioError SetSize(Double len);		// Change buffer size
64 	virtual Double GetSize() const;			// Get buffer size
65 	virtual size_t GetByteCount() const;		// Get size, in bytes
66 
67 	// class AudioStream methods specialized here
68 	// Set header
69 	virtual AudioError SetHeader(
70 	    const AudioHdr& h);			// header to copy
71 
72 	// Set data length
73 	virtual void SetLength(
74 	    Double len);			// new length, in secs
75 
76 	// class Audio methods specialized here
77 
78 	// Read from position
79 	virtual AudioError ReadData(
80 	    void* buf,				// buffer to fill
81 	    size_t& len,			// buffer length (updated)
82 	    Double& pos);			// start position (updated)
83 
84 	// Write at position
85 	virtual AudioError WriteData(
86 	    void* buf,				// buffer to copy
87 	    size_t& len,			// buffer length (updated)
88 	    Double& pos);			// start position (updated)
89 
90 	// Append at position
91 	virtual AudioError AppendData(
92 	    void* buf,				// buffer to copy
93 	    size_t& len,			// buffer length (updated)
94 	    Double& pos);			// start position (updated)
95 
96 	// copy to another audio obj.
97 	virtual AudioError AsyncCopy(
98 	    Audio* to,				// dest audio object
99 	    Double& frompos,
100 	    Double& topos,
101 	    Double& limit);
102 
103 	virtual Boolean isBuffer() const { return (TRUE); }
104 };
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* !_MULTIMEDIA_AUDIOBUFFER_H */
111