Update NTK.
[nondaw.git] / timeline / src / Engine / Audio_Sequence.C
blob3949aafa0019713071d398ac25647556165986f0
2 /*******************************************************************************/
3 /* Copyright (C) 2008 Jonathan Moore Liles                                     */
4 /*                                                                             */
5 /* This program is free software; you can redistribute it and/or modify it     */
6 /* under the terms of the GNU General Public License as published by the       */
7 /* Free Software Foundation; either version 2 of the License, or (at your      */
8 /* option) any later version.                                                  */
9 /*                                                                             */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       */
12 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   */
13 /* more details.                                                               */
14 /*                                                                             */
15 /* You should have received a copy of the GNU General Public License along     */
16 /* with This program; see the file COPYING.  If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18 /*******************************************************************************/
20 #include "../Audio_Sequence.H"
22 #include "dsp.h"
24 #include "const.h"
25 #include "debug.h"
26 #include "Thread.H"
28 using namespace std;
32 /**********/
33 /* Engine */
34 /**********/
36 /** determine region coverage and fill /buf/ with interleaved samples
37  * from /frame/ to /nframes/ for exactly /channels/ channels. */
38 nframes_t
39 Audio_Sequence::play ( sample_t *buf, nframes_t frame, nframes_t nframes, int channels )
41     THREAD_ASSERT( Playback );
43     sample_t *cbuf = new sample_t[ nframes ];
45     memset( cbuf, 0, nframes * sizeof( sample_t ) );
47     /* quick and dirty--let the regions figure out coverage for themselves */
48     for ( list <Sequence_Widget *>::const_iterator i = _widgets.begin();
49           i != _widgets.end(); ++i )
50     {
51         const Audio_Region *r = (Audio_Region*)(*i);
53         for ( int i = channels; i--;  )
54         {
55             int nfr;
57             if ( ! ( nfr = r->read( cbuf, frame, nframes, i ) ) )
58                 /* error ? */
59                 continue;
61             if ( channels == 1 )
62                 buffer_mix( buf, cbuf, nframes );
63             else
64                 buffer_interleave_one_channel_and_mix( buf, cbuf, i, channels, nframes );
65         }
66     }
68     delete[] cbuf;
70     /* FIXME: bogus */
71     return nframes;