1 /*******************************************************************************
2 * Copyright 2015-2016 Juan Francisco Crespo Galán
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *   http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 ******************************************************************************/
16 
17 #include "fx/VolumeReader.h"
18 
19 #include <cstring>
20 
21 AUD_NAMESPACE_BEGIN
22 
VolumeReader(std::shared_ptr<IReader> reader,std::shared_ptr<VolumeStorage> volumeStorage)23 VolumeReader::VolumeReader(std::shared_ptr<IReader> reader, std::shared_ptr<VolumeStorage> volumeStorage) :
24 	m_reader(reader), m_volumeStorage(volumeStorage)
25 {
26 }
27 
isSeekable() const28 bool VolumeReader::isSeekable() const
29 {
30 	return m_reader->isSeekable();
31 }
32 
seek(int position)33 void VolumeReader::seek(int position)
34 {
35 	m_reader->seek(position);
36 }
37 
getLength() const38 int VolumeReader::getLength() const
39 {
40 	return m_reader->getLength();
41 }
42 
getPosition() const43 int VolumeReader::getPosition() const
44 {
45 	return m_reader->getPosition();
46 }
47 
getSpecs() const48 Specs VolumeReader::getSpecs() const
49 {
50 	return m_reader->getSpecs();
51 }
52 
read(int & length,bool & eos,sample_t * buffer)53 void VolumeReader::read(int& length, bool& eos, sample_t* buffer)
54 {
55 	m_reader->read(length, eos, buffer);
56 	for(int i = 0; i < length * m_reader->getSpecs().channels; i++)
57 		buffer[i] = buffer[i] * m_volumeStorage->getVolume();
58 }
59 
60 AUD_NAMESPACE_END