Audacity 3.2.0
Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes | Friends | List of all members
MyFLACFile Class Referencefinal
Inheritance diagram for MyFLACFile:
[legend]
Collaboration diagram for MyFLACFile:
[legend]

Public Member Functions

 MyFLACFile (FLACImportFileHandle *handle)
 
bool get_was_error () const
 

Public Attributes

ImportProgressListenermImportProgressListener {nullptr}
 

Protected Member Functions

FLAC__StreamDecoderWriteStatus write_callback (const FLAC__Frame *frame, const FLAC__int32 *const buffer[]) override
 
void metadata_callback (const FLAC__StreamMetadata *metadata) override
 
void error_callback (FLAC__StreamDecoderErrorStatus status) override
 

Private Attributes

FLACImportFileHandlemFile
 
bool mWasError
 
wxArrayString mComments
 

Friends

class FLACImportFileHandle
 

Detailed Description

Definition at line 67 of file ImportFLAC.cpp.

Constructor & Destructor Documentation

◆ MyFLACFile()

MyFLACFile::MyFLACFile ( FLACImportFileHandle handle)
inline

Definition at line 70 of file ImportFLAC.cpp.

70 : mFile(handle)
71 {
72 mWasError = false;
73 set_metadata_ignore_all();
74 set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT);
75 set_metadata_respond(FLAC__METADATA_TYPE_STREAMINFO);
76 }
FLACImportFileHandle * mFile
Definition: ImportFLAC.cpp:87
bool mWasError
Definition: ImportFLAC.cpp:88

References mWasError.

Member Function Documentation

◆ error_callback()

void MyFLACFile::error_callback ( FLAC__StreamDecoderErrorStatus  status)
overrideprotected

Definition at line 197 of file ImportFLAC.cpp.

198{
199 mWasError = true;
200
201 /*
202 switch (status)
203 {
204 case FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC:
205 wxPrintf(wxT("Flac Error: Lost sync\n"));
206 break;
207 case FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH:
208 wxPrintf(wxT("Flac Error: Crc mismatch\n"));
209 break;
210 case FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER:
211 wxPrintf(wxT("Flac Error: Bad Header\n"));
212 break;
213 default:
214 wxPrintf(wxT("Flac Error: Unknown error code\n"));
215 break;
216 }*/
217}

References mWasError.

◆ get_was_error()

bool MyFLACFile::get_was_error ( ) const
inline

Definition at line 78 of file ImportFLAC.cpp.

79 {
80 return mWasError;
81 }

References mWasError.

◆ metadata_callback()

void MyFLACFile::metadata_callback ( const FLAC__StreamMetadata *  metadata)
overrideprotected

Definition at line 156 of file ImportFLAC.cpp.

157{
158 switch (metadata->type)
159 {
160 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
161 for (FLAC__uint32 i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
162 mComments.push_back(UTF8CTOWX((char *)metadata->data.vorbis_comment.comments[i].entry));
163 }
164 break;
165
166 case FLAC__METADATA_TYPE_STREAMINFO:
167 mFile->mSampleRate=metadata->data.stream_info.sample_rate;
168 mFile->mNumChannels=metadata->data.stream_info.channels;
169 mFile->mBitsPerSample=metadata->data.stream_info.bits_per_sample;
170 mFile->mNumSamples=metadata->data.stream_info.total_samples;
171
172 // Widen mFormat after examining the file header
173 if (mFile->mBitsPerSample<=16) {
175 } else if (mFile->mBitsPerSample<=24) {
177 } else {
179 }
181 break;
182 // handle the other types we do nothing with to avoid a warning
183 case FLAC__METADATA_TYPE_PADDING: // do nothing with padding
184 case FLAC__METADATA_TYPE_APPLICATION: // no idea what to do with this
185 case FLAC__METADATA_TYPE_SEEKTABLE: // don't need a seektable here
186 case FLAC__METADATA_TYPE_CUESHEET: // convert this to labels?
187 case FLAC__METADATA_TYPE_PICTURE: // ignore pictures
188 case FLAC__METADATA_TYPE_UNDEFINED: // do nothing with this either
189
190 // FIXME: not declared when compiling on Ubuntu.
191 //case FLAC__MAX_METADATA_TYPE: // quiet compiler warning with this line
192 default:
193 break;
194 }
195}
#define UTF8CTOWX(X)
Definition: Internat.h:157
FLAC__uint64 mNumSamples
Definition: ImportFLAC.cpp:149
unsigned long mBitsPerSample
Definition: ImportFLAC.cpp:148
unsigned long mNumChannels
Definition: ImportFLAC.cpp:147
unsigned long mSampleRate
Definition: ImportFLAC.cpp:146
sampleFormat mFormat
Definition: ImportFLAC.cpp:143
wxArrayString mComments
Definition: ImportFLAC.cpp:89

References floatSample, int16Sample, int24Sample, FLACImportFileHandle::mBitsPerSample, mComments, mFile, FLACImportFileHandle::mFormat, FLACImportFileHandle::mNumChannels, FLACImportFileHandle::mNumSamples, FLACImportFileHandle::mSampleRate, FLACImportFileHandle::mStreamInfoDone, and UTF8CTOWX.

◆ write_callback()

FLAC__StreamDecoderWriteStatus MyFLACFile::write_callback ( const FLAC__Frame *  frame,
const FLAC__int32 *const  buffer[] 
)
overrideprotected

Definition at line 219 of file ImportFLAC.cpp.

221{
222 // Don't let C++ exceptions propagate through libflac
223 return GuardedCall< FLAC__StreamDecoderWriteStatus > ( [&] {
224 auto tmp = ArrayOf< short >{ frame->header.blocksize };
225
226 unsigned chn = 0;
227 ImportUtils::ForEachChannel(*mFile->mTrack, [&](auto& channel)
228 {
229 if (frame->header.bits_per_sample <= 16) {
230 if (frame->header.bits_per_sample == 8) {
231 for (unsigned int s = 0; s < frame->header.blocksize; s++) {
232 tmp[s] = buffer[chn][s] << 8;
233 }
234 } else /* if (frame->header.bits_per_sample == 16) */ {
235 for (unsigned int s = 0; s < frame->header.blocksize; s++) {
236 tmp[s] = buffer[chn][s];
237 }
238 }
239
240 channel.AppendBuffer((samplePtr)tmp.get(),
241 int16Sample,
242 frame->header.blocksize, 1,
243 int16Sample);
244 }
245 else {
246 channel.AppendBuffer((samplePtr)buffer[chn],
247 int24Sample,
248 frame->header.blocksize, 1,
249 int24Sample);
250 }
251 ++chn;
252 });
253
254 mFile->mSamplesDone += frame->header.blocksize;
255
256 if(mFile->mNumSamples > 0)
258 static_cast<double>(mFile->mNumSamples));
259
260 if (mFile->IsCancelled() || mFile->IsStopped())
261 {
262 return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
263 }
264
265 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
266 }, MakeSimpleGuard(FLAC__STREAM_DECODER_WRITE_STATUS_ABORT) );
267}
SimpleGuard< R > MakeSimpleGuard(R value) noexcept(noexcept(SimpleGuard< R >{ value }))
Convert a value to a handler function returning that value, suitable for GuardedCall<R>
This simplifies arrays of arrays, each array separately allocated with NEW[] But it might be better t...
Definition: MemoryX.h:29
WaveTrack::Holder mTrack
Definition: ImportFLAC.cpp:152
FLAC__uint64 mSamplesDone
Definition: ImportFLAC.cpp:150
bool IsStopped() const noexcept
bool IsCancelled() const noexcept
virtual void OnImportProgress(double progress)=0
static void ForEachChannel(TrackList &trackList, const std::function< void(WaveChannel &)> &op)
Iterates over channels in each wave track from the list.
Definition: ImportUtils.cpp:73
ImportProgressListener * mImportProgressListener
Definition: ImportFLAC.cpp:83

References ImportUtils::ForEachChannel(), ImportFileHandleEx::IsCancelled(), ImportFileHandleEx::IsStopped(), mFile, mImportProgressListener, FLACImportFileHandle::mNumSamples, FLACImportFileHandle::mSamplesDone, FLACImportFileHandle::mTrack, and ImportProgressListener::OnImportProgress().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ FLACImportFileHandle

friend class FLACImportFileHandle
friend

Definition at line 86 of file ImportFLAC.cpp.

Member Data Documentation

◆ mComments

wxArrayString MyFLACFile::mComments
private

Definition at line 89 of file ImportFLAC.cpp.

Referenced by metadata_callback().

◆ mFile

FLACImportFileHandle* MyFLACFile::mFile
private

Definition at line 87 of file ImportFLAC.cpp.

Referenced by metadata_callback(), and write_callback().

◆ mImportProgressListener

ImportProgressListener* MyFLACFile::mImportProgressListener {nullptr}

Definition at line 83 of file ImportFLAC.cpp.

Referenced by write_callback().

◆ mWasError

bool MyFLACFile::mWasError
private

Definition at line 88 of file ImportFLAC.cpp.

Referenced by error_callback(), get_was_error(), and MyFLACFile().


The documentation for this class was generated from the following file: