rename (FLAC__format_is_valid_sample_rate() to FLAC__format_sample_rate_is_valid()
[flac.git] / src / libFLAC++ / file_decoder.cc
1 /* libFLAC++ - Free Lossless Audio Codec library
2  * Copyright (C) 2002  Josh Coalson
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA  02111-1307, USA.
18  */
19
20 #include "FLAC++/decoder.h"
21 #include "FLAC/assert.h"
22
23 namespace FLAC {
24         namespace Decoder {
25
26                 File::File():
27                 decoder_(::FLAC__file_decoder_new())
28                 { }
29
30                 File::~File()
31                 {
32                         if(0 != decoder_) {
33                                 (void) ::FLAC__file_decoder_finish(decoder_);
34                                 ::FLAC__file_decoder_delete(decoder_);
35                         }
36                 }
37
38                 bool File::is_valid() const
39                 {
40                         return 0 != decoder_;
41                 }
42
43                 bool File::set_md5_checking(bool value)
44                 {
45                         FLAC__ASSERT(0 != decoder_);
46                         return (bool)::FLAC__file_decoder_set_md5_checking(decoder_, value);
47                 }
48
49                 bool File::set_filename(const char *value)
50                 {
51                         FLAC__ASSERT(0 != decoder_);
52                         return (bool)::FLAC__file_decoder_set_filename(decoder_, value);
53                 }
54
55                 bool File::set_metadata_respond(::FLAC__MetadataType type)
56                 {
57                         FLAC__ASSERT(0 != decoder_);
58                         return (bool)::FLAC__file_decoder_set_metadata_respond(decoder_, type);
59                 }
60
61                 bool File::set_metadata_respond_application(const FLAC__byte id[4])
62                 {
63                         FLAC__ASSERT(0 != decoder_);
64                         return (bool)::FLAC__file_decoder_set_metadata_respond_application(decoder_, id);
65                 }
66
67                 bool File::set_metadata_respond_all()
68                 {
69                         FLAC__ASSERT(0 != decoder_);
70                         return (bool)::FLAC__file_decoder_set_metadata_respond_all(decoder_);
71                 }
72
73                 bool File::set_metadata_ignore(::FLAC__MetadataType type)
74                 {
75                         FLAC__ASSERT(0 != decoder_);
76                         return (bool)::FLAC__file_decoder_set_metadata_ignore(decoder_, type);
77                 }
78
79                 bool File::set_metadata_ignore_application(const FLAC__byte id[4])
80                 {
81                         FLAC__ASSERT(0 != decoder_);
82                         return (bool)::FLAC__file_decoder_set_metadata_ignore_application(decoder_, id);
83                 }
84
85                 bool File::set_metadata_ignore_all()
86                 {
87                         FLAC__ASSERT(0 != decoder_);
88                         return (bool)::FLAC__file_decoder_set_metadata_ignore_all(decoder_);
89                 }
90
91                 File::State File::get_state() const
92                 {
93                         FLAC__ASSERT(0 != decoder_);
94                         return State(::FLAC__file_decoder_get_state(decoder_));
95                 }
96
97                 bool File::get_md5_checking() const
98                 {
99                         FLAC__ASSERT(0 != decoder_);
100                         return (bool)::FLAC__file_decoder_get_md5_checking(decoder_);
101                 }
102
103                 unsigned File::get_channels() const
104                 {
105                         FLAC__ASSERT(is_valid());
106                         return ::FLAC__file_decoder_get_channels(decoder_);
107                 }
108
109                 ::FLAC__ChannelAssignment File::get_channel_assignment() const
110                 {
111                         FLAC__ASSERT(is_valid());
112                         return ::FLAC__file_decoder_get_channel_assignment(decoder_);
113                 }
114
115                 unsigned File::get_bits_per_sample() const
116                 {
117                         FLAC__ASSERT(is_valid());
118                         return ::FLAC__file_decoder_get_bits_per_sample(decoder_);
119                 }
120
121                 unsigned File::get_sample_rate() const
122                 {
123                         FLAC__ASSERT(is_valid());
124                         return ::FLAC__file_decoder_get_sample_rate(decoder_);
125                 }
126
127                 unsigned File::get_blocksize() const
128                 {
129                         FLAC__ASSERT(is_valid());
130                         return ::FLAC__file_decoder_get_blocksize(decoder_);
131                 }
132
133                 File::State File::init()
134                 {
135                         FLAC__ASSERT(0 != decoder_);
136                         ::FLAC__file_decoder_set_write_callback(decoder_, write_callback_);
137                         ::FLAC__file_decoder_set_metadata_callback(decoder_, metadata_callback_);
138                         ::FLAC__file_decoder_set_error_callback(decoder_, error_callback_);
139                         ::FLAC__file_decoder_set_client_data(decoder_, (void*)this);
140                         return State(::FLAC__file_decoder_init(decoder_));
141                 }
142
143                 bool File::finish()
144                 {
145                         FLAC__ASSERT(0 != decoder_);
146                         return (bool)::FLAC__file_decoder_finish(decoder_);
147                 }
148
149                 bool File::process_whole_file()
150                 {
151                         FLAC__ASSERT(0 != decoder_);
152                         return (bool)::FLAC__file_decoder_process_whole_file(decoder_);
153                 }
154
155                 bool File::process_metadata()
156                 {
157                         FLAC__ASSERT(0 != decoder_);
158                         return (bool)::FLAC__file_decoder_process_metadata(decoder_);
159                 }
160
161                 bool File::process_one_frame()
162                 {
163                         FLAC__ASSERT(0 != decoder_);
164                         return (bool)::FLAC__file_decoder_process_one_frame(decoder_);
165                 }
166
167                 bool File::process_remaining_frames()
168                 {
169                         FLAC__ASSERT(0 != decoder_);
170                         return (bool)::FLAC__file_decoder_process_remaining_frames(decoder_);
171                 }
172
173                 bool File::seek_absolute(FLAC__uint64 sample)
174                 {
175                         FLAC__ASSERT(0 != decoder_);
176                         return (bool)::FLAC__file_decoder_seek_absolute(decoder_, sample);
177                 }
178
179                 ::FLAC__StreamDecoderWriteStatus File::write_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
180                 {
181                         (void) decoder;
182                         FLAC__ASSERT(0 != client_data);
183                         File *instance = reinterpret_cast<File *>(client_data);
184                         FLAC__ASSERT(0 != instance);
185                         return instance->write_callback(frame, buffer);
186                 }
187
188                 void File::metadata_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data)
189                 {
190                         (void) decoder;
191                         FLAC__ASSERT(0 != client_data);
192                         File *instance = reinterpret_cast<File *>(client_data);
193                         FLAC__ASSERT(0 != instance);
194                         instance->metadata_callback(metadata);
195                 }
196
197                 void File::error_callback_(const ::FLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data)
198                 {
199                         (void) decoder;
200                         FLAC__ASSERT(0 != client_data);
201                         File *instance = reinterpret_cast<File *>(client_data);
202                         FLAC__ASSERT(0 != instance);
203                         instance->error_callback(status);
204                 }
205
206         };
207 };