1 /* libFLAC++ - Free Lossless Audio Codec library
2 * Copyright (C) 2002 Josh Coalson
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.
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.
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.
20 #include "FLAC++/decoder.h"
21 #include "FLAC/assert.h"
27 decoder_(::FLAC__file_decoder_new())
33 (void) ::FLAC__file_decoder_finish(decoder_);
34 ::FLAC__file_decoder_delete(decoder_);
38 bool File::is_valid() const
43 bool File::set_md5_checking(bool value)
45 FLAC__ASSERT(0 != decoder_);
46 return ::FLAC__file_decoder_set_md5_checking(decoder_, value);
49 bool File::set_filename(const char *value)
51 FLAC__ASSERT(0 != decoder_);
52 return ::FLAC__file_decoder_set_filename(decoder_, value);
55 bool File::set_metadata_respond(::FLAC__MetaDataType type)
57 FLAC__ASSERT(0 != decoder_);
58 return ::FLAC__file_decoder_set_metadata_respond(decoder_, type);
61 bool File::set_metadata_respond_application(const FLAC__byte id[4])
63 FLAC__ASSERT(0 != decoder_);
64 return ::FLAC__file_decoder_set_metadata_respond_application(decoder_, id);
67 bool File::set_metadata_respond_all()
69 FLAC__ASSERT(0 != decoder_);
70 return ::FLAC__file_decoder_set_metadata_respond_all(decoder_);
73 bool File::set_metadata_ignore(::FLAC__MetaDataType type)
75 FLAC__ASSERT(0 != decoder_);
76 return ::FLAC__file_decoder_set_metadata_ignore(decoder_, type);
79 bool File::set_metadata_ignore_application(const FLAC__byte id[4])
81 FLAC__ASSERT(0 != decoder_);
82 return ::FLAC__file_decoder_set_metadata_ignore_application(decoder_, id);
85 bool File::set_metadata_ignore_all()
87 FLAC__ASSERT(0 != decoder_);
88 return ::FLAC__file_decoder_set_metadata_ignore_all(decoder_);
91 File::State File::get_state() const
93 FLAC__ASSERT(0 != decoder_);
94 return State(::FLAC__file_decoder_get_state(decoder_));
97 bool File::get_md5_checking() const
99 FLAC__ASSERT(0 != decoder_);
100 return ::FLAC__file_decoder_get_md5_checking(decoder_);
103 File::State File::init()
105 FLAC__ASSERT(0 != decoder_);
106 ::FLAC__file_decoder_set_write_callback(decoder_, write_callback_);
107 ::FLAC__file_decoder_set_metadata_callback(decoder_, metadata_callback_);
108 ::FLAC__file_decoder_set_error_callback(decoder_, error_callback_);
109 ::FLAC__file_decoder_set_client_data(decoder_, (void*)this);
110 return State(::FLAC__file_decoder_init(decoder_));
115 FLAC__ASSERT(0 != decoder_);
116 return ::FLAC__file_decoder_finish(decoder_);
119 bool File::process_whole_file()
121 FLAC__ASSERT(0 != decoder_);
122 return ::FLAC__file_decoder_process_whole_file(decoder_);
125 bool File::process_metadata()
127 FLAC__ASSERT(0 != decoder_);
128 return ::FLAC__file_decoder_process_metadata(decoder_);
131 bool File::process_one_frame()
133 FLAC__ASSERT(0 != decoder_);
134 return ::FLAC__file_decoder_process_one_frame(decoder_);
137 bool File::process_remaining_frames()
139 FLAC__ASSERT(0 != decoder_);
140 return ::FLAC__file_decoder_process_remaining_frames(decoder_);
143 bool File::seek_absolute(FLAC__uint64 sample)
145 FLAC__ASSERT(0 != decoder_);
146 return ::FLAC__file_decoder_seek_absolute(decoder_, sample);
149 ::FLAC__StreamDecoderWriteStatus File::write_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 *buffer[], void *client_data)
152 FLAC__ASSERT(0 != client_data);
153 File *instance = reinterpret_cast<File *>(client_data);
154 FLAC__ASSERT(0 != instance);
155 return instance->write_callback(frame, buffer);
158 void File::metadata_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__StreamMetaData *metadata, void *client_data)
161 FLAC__ASSERT(0 != client_data);
162 File *instance = reinterpret_cast<File *>(client_data);
163 FLAC__ASSERT(0 != instance);
164 instance->metadata_callback(metadata);
167 void File::error_callback_(const ::FLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data)
170 FLAC__ASSERT(0 != client_data);
171 File *instance = reinterpret_cast<File *>(client_data);
172 FLAC__ASSERT(0 != instance);
173 instance->error_callback(status);