1 /*
2 BStone: A Source port of
3 Blake Stone: Aliens of Gold and Blake Stone: Planet Strike
4 
5 Copyright (c) 1992-2013 Apogee Entertainment, LLC
6 Copyright (c) 2013-2015 Boris I. Bendovsky (bibendovsky@hotmail.com)
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
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 this program; if not, write to the
20 Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23 
24 
25 //
26 // Base class for audio decoding.
27 //
28 
29 
30 #include "bstone_audio_decoder.h"
31 #include <cstddef>
32 
33 
34 namespace bstone {
35 
36 
AudioDecoder()37 AudioDecoder::AudioDecoder() :
38         is_initialized_(),
39         raw_data_(),
40         raw_size_(),
41         dst_rate_(),
42         dst_length_in_samples_()
43 {
44 }
45 
46 // (virtual)
~AudioDecoder()47 AudioDecoder::~AudioDecoder()
48 {
49 }
50 
51 // (virtual)
initialize(const void * raw_data,int raw_size,int dst_rate)52 bool AudioDecoder::initialize(
53     const void* raw_data,
54     int raw_size,
55     int dst_rate)
56 {
57     uninitialize();
58 
59     if (!raw_data) {
60         return false;
61     }
62 
63     if (raw_size < 0) {
64         return false;
65     }
66 
67     if (dst_rate < 1) {
68         return false;
69     }
70 
71     raw_data_ = raw_data;
72     raw_size_ = raw_size;
73     dst_rate_ = dst_rate;
74     dst_length_in_samples_ = 0;
75 
76     return true;
77 }
78 
uninitialize()79 void AudioDecoder::uninitialize()
80 {
81     dst_length_in_samples_ = 0;
82     raw_data_ = nullptr;
83     raw_size_ = 0;
84     dst_rate_ = 0;
85     set_is_initialized(false);
86 }
87 
is_initialized() const88 bool AudioDecoder::is_initialized() const
89 {
90     return is_initialized_;
91 }
92 
get_dst_rate() const93 int AudioDecoder::get_dst_rate() const
94 {
95     return dst_rate_;
96 }
97 
get_dst_length_in_samples() const98 int AudioDecoder::get_dst_length_in_samples() const
99 {
100     return dst_length_in_samples_;
101 }
102 
get_raw_data() const103 const void* AudioDecoder::get_raw_data() const
104 {
105     return raw_data_;
106 }
107 
set_is_initialized(bool value)108 void AudioDecoder::set_is_initialized(
109     bool value)
110 {
111     is_initialized_ = value;
112 }
113 
get_raw_size() const114 int AudioDecoder::get_raw_size() const
115 {
116     return raw_size_;
117 }
118 
set_dst_length_in_samples(int value)119 void AudioDecoder::set_dst_length_in_samples(
120     int value)
121 {
122     dst_length_in_samples_ = value;
123 }
124 
125 
126 } // bstone
127