~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to intern/audaspace/FX/AUD_DelayReader.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: AUD_DelayReader.cpp 25643 2010-01-01 05:09:30Z nexyon $
3
 
 *
4
 
 * ***** BEGIN LGPL LICENSE BLOCK *****
5
 
 *
6
 
 * Copyright 2009 Jörg Hermann Müller
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
4
 * Copyright 2009-2011 Jörg Hermann Müller
7
5
 *
8
6
 * This file is part of AudaSpace.
9
7
 *
10
 
 * AudaSpace is free software: you can redistribute it and/or modify
11
 
 * it under the terms of the GNU Lesser General Public License as published by
12
 
 * the Free Software Foundation, either version 3 of the License, or
 
8
 * Audaspace is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
13
11
 * (at your option) any later version.
14
12
 *
15
13
 * AudaSpace is distributed in the hope that it will be useful,
16
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
 * GNU Lesser General Public License for more details.
19
 
 *
20
 
 * You should have received a copy of the GNU Lesser General Public License
21
 
 * along with AudaSpace.  If not, see <http://www.gnu.org/licenses/>.
22
 
 *
23
 
 * ***** END LGPL LICENSE BLOCK *****
24
 
 */
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with Audaspace; if not, write to the Free Software Foundation,
 
20
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
21
 *
 
22
 * ***** END GPL LICENSE BLOCK *****
 
23
 */
 
24
 
 
25
/** \file audaspace/FX/AUD_DelayReader.cpp
 
26
 *  \ingroup audfx
 
27
 */
 
28
 
25
29
 
26
30
#include "AUD_DelayReader.h"
27
 
#include "AUD_Buffer.h"
28
31
 
29
32
#include <cstring>
30
33
 
31
 
AUD_DelayReader::AUD_DelayReader(AUD_IReader* reader, float delay) :
32
 
                AUD_EffectReader(reader)
33
 
{
34
 
        m_delay = (int)(delay * reader->getSpecs().rate);
35
 
        m_remdelay = m_delay;
36
 
        m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
37
 
}
38
 
 
39
 
AUD_DelayReader::~AUD_DelayReader()
40
 
{
41
 
        delete m_buffer; AUD_DELETE("buffer")
 
34
AUD_DelayReader::AUD_DelayReader(AUD_Reference<AUD_IReader> reader, float delay) :
 
35
                AUD_EffectReader(reader),
 
36
                m_delay(int(delay * reader->getSpecs().rate)),
 
37
                m_remdelay(int(delay * reader->getSpecs().rate))
 
38
{
42
39
}
43
40
 
44
41
void AUD_DelayReader::seek(int position)
45
42
{
46
 
        if(position < 0)
47
 
                return;
48
 
 
49
43
        if(position < m_delay)
50
44
        {
51
45
                m_remdelay = m_delay - position;
58
52
        }
59
53
}
60
54
 
61
 
int AUD_DelayReader::getLength()
 
55
int AUD_DelayReader::getLength() const
62
56
{
63
57
        int len = m_reader->getLength();
64
58
        if(len < 0)
65
59
                return len;
66
 
        return len+m_delay;
 
60
        return len + m_delay;
67
61
}
68
62
 
69
 
int AUD_DelayReader::getPosition()
 
63
int AUD_DelayReader::getPosition() const
70
64
{
71
65
        if(m_remdelay > 0)
72
 
                return m_delay-m_remdelay;
 
66
                return m_delay - m_remdelay;
73
67
        return m_reader->getPosition() + m_delay;
74
68
}
75
69
 
76
 
void AUD_DelayReader::read(int & length, sample_t* & buffer)
 
70
void AUD_DelayReader::read(int& length, bool& eos, sample_t* buffer)
77
71
{
78
72
        if(m_remdelay > 0)
79
73
        {
80
74
                AUD_Specs specs = m_reader->getSpecs();
81
75
                int samplesize = AUD_SAMPLE_SIZE(specs);
82
76
 
83
 
                if(m_buffer->getSize() < length * samplesize)
84
 
                        m_buffer->resize(length * samplesize);
85
 
 
86
77
                if(length > m_remdelay)
87
78
                {
88
 
                        memset(m_buffer->getBuffer(), 0, m_remdelay * samplesize);
 
79
                        memset(buffer, 0, m_remdelay * samplesize);
 
80
 
89
81
                        int len = length - m_remdelay;
90
 
                        m_reader->read(len, buffer);
91
 
                        memcpy(m_buffer->getBuffer() + m_remdelay * specs.channels,
92
 
                                   buffer, len * samplesize);
93
 
                        if(len < length-m_remdelay)
94
 
                                length = m_remdelay + len;
 
82
                        m_reader->read(len, eos, buffer + m_remdelay * specs.channels);
 
83
 
 
84
                        length = m_remdelay + len;
 
85
 
95
86
                        m_remdelay = 0;
96
87
                }
97
88
                else
98
89
                {
99
 
                        memset(m_buffer->getBuffer(), 0, length * samplesize);
 
90
                        memset(buffer, 0, length * samplesize);
100
91
                        m_remdelay -= length;
101
92
                }
102
 
                buffer = m_buffer->getBuffer();
103
93
        }
104
94
        else
105
 
                m_reader->read(length, buffer);
 
95
                m_reader->read(length, eos, buffer);
106
96
}