1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: util_buffers.h
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // Ananya Misra (amisra@cs.princeton.edu)
33 // Summer 2005 - allow multiple readers
34 //-----------------------------------------------------------------------------
35 #ifndef __UTIL_BUFFERS_H__
36 #define __UTIL_BUFFERS_H__
39 #include "util_thread.h"
43 #define DWORD__ unsigned long
45 #define UINT__ DWORD__
46 #define BOOL__ DWORD__
47 #define BYTE__ unsigned char
55 //-----------------------------------------------------------------------------
56 // name: class CBufferAdvance
57 // desc: circular buffer
58 //-----------------------------------------------------------------------------
66 BOOL__
initialize( UINT__ num_elem
, UINT__ width
);
70 UINT__
get( void * data
, UINT__ num_elem
, UINT__ read_offset_index
);
71 void put( void * data
, UINT__ num_elem
);
72 BOOL__
empty( UINT__ read_offset_index
);
73 UINT__
join( Chuck_Event
* event
= NULL
);
74 void resign( UINT__ read_offset_index
);
79 //UINT__ m_read_offset;
81 // this holds the offset allocated by join(), paired with an optional
82 // Chuck_Event to notify when things are put in the buffer
87 ReadOffset( SINT__ ro
, Chuck_Event
* e
= NULL
)
88 { read_offset
= ro
; event
= e
; }
90 std::vector
<ReadOffset
> m_read_offsets
;
91 std::queue
<UINT__
> m_free
;
93 SINT__ m_write_offset
;
102 //-----------------------------------------------------------------------------
103 // name: class CBufferSimple
104 // desc: circular buffer - one reader one writer
105 //-----------------------------------------------------------------------------
113 BOOL__
initialize( UINT__ num_elem
, UINT__ width
);
117 UINT__
get( void * data
, UINT__ num_elem
);
118 void put( void * data
, UINT__ num_elem
);
123 UINT__ m_read_offset
;
124 UINT__ m_write_offset
;
131 //-----------------------------------------------------------------------------
132 // name: class AccumBuffer
133 // desc: circular buffer for sample accumulation
134 //-----------------------------------------------------------------------------
142 t_CKINT
resize( t_CKINT new_size
);
146 void put( SAMPLE next
);
147 void get( SAMPLE
* buffer
, t_CKINT num_elem
);
151 t_CKUINT m_write_offset
;
158 //-----------------------------------------------------------------------------
159 // name: class DeccumBuffer
160 // desc: circular buffer for sample deccumulation
161 //-----------------------------------------------------------------------------
169 t_CKINT
resize( t_CKINT new_size
);
173 void put( SAMPLE
* next
, t_CKINT num_elem
);
174 void get( SAMPLE
* out
);
175 void get( SAMPLE
* buffer
, t_CKINT num_elem
);
179 t_CKUINT m_read_offset
;