Audacity  3.0.3
Public Member Functions | 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
 

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 92 of file ImportFLAC.cpp.

Constructor & Destructor Documentation

◆ MyFLACFile()

MyFLACFile::MyFLACFile ( FLACImportFileHandle handle)
inline

Definition at line 95 of file ImportFLAC.cpp.

95  : mFile(handle)
96  {
97  mWasError = false;
98  set_metadata_ignore_all();
99  set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT);
100  set_metadata_respond(FLAC__METADATA_TYPE_STREAMINFO);
101  }

References mWasError.

Member Function Documentation

◆ error_callback()

void MyFLACFile::error_callback ( FLAC__StreamDecoderErrorStatus  status)
overrideprotected

Definition at line 218 of file ImportFLAC.cpp.

219 {
220  mWasError = true;
221 
222  /*
223  switch (status)
224  {
225  case FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC:
226  wxPrintf(wxT("Flac Error: Lost sync\n"));
227  break;
228  case FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH:
229  wxPrintf(wxT("Flac Error: Crc mismatch\n"));
230  break;
231  case FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER:
232  wxPrintf(wxT("Flac Error: Bad Header\n"));
233  break;
234  default:
235  wxPrintf(wxT("Flac Error: Unknown error code\n"));
236  break;
237  }*/
238 }

References mWasError.

◆ get_was_error()

bool MyFLACFile::get_was_error ( ) const
inline

Definition at line 103 of file ImportFLAC.cpp.

104  {
105  return mWasError;
106  }

References mWasError.

◆ metadata_callback()

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

Definition at line 177 of file ImportFLAC.cpp.

178 {
179  switch (metadata->type)
180  {
181  case FLAC__METADATA_TYPE_VORBIS_COMMENT:
182  for (FLAC__uint32 i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
183  mComments.push_back(UTF8CTOWX((char *)metadata->data.vorbis_comment.comments[i].entry));
184  }
185  break;
186 
187  case FLAC__METADATA_TYPE_STREAMINFO:
188  mFile->mSampleRate=metadata->data.stream_info.sample_rate;
189  mFile->mNumChannels=metadata->data.stream_info.channels;
190  mFile->mBitsPerSample=metadata->data.stream_info.bits_per_sample;
191  mFile->mNumSamples=metadata->data.stream_info.total_samples;
192 
193  // Widen mFormat after examining the file header
194  if (mFile->mBitsPerSample<=16) {
196  } else if (mFile->mBitsPerSample<=24) {
198  } else {
200  }
201  mFile->mStreamInfoDone=true;
202  break;
203  // handle the other types we do nothing with to avoid a warning
204  case FLAC__METADATA_TYPE_PADDING: // do nothing with padding
205  case FLAC__METADATA_TYPE_APPLICATION: // no idea what to do with this
206  case FLAC__METADATA_TYPE_SEEKTABLE: // don't need a seektable here
207  case FLAC__METADATA_TYPE_CUESHEET: // convert this to labels?
208  case FLAC__METADATA_TYPE_PICTURE: // ignore pictures
209  case FLAC__METADATA_TYPE_UNDEFINED: // do nothing with this either
210 
211  // FIXME: not declared when compiling on Ubuntu.
212  //case FLAC__MAX_METADATA_TYPE: // quiet compiler warning with this line
213  default:
214  break;
215  }
216 }

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 240 of file ImportFLAC.cpp.

242 {
243  // Don't let C++ exceptions propagate through libflac
244  return GuardedCall< FLAC__StreamDecoderWriteStatus > ( [&] {
245  auto tmp = ArrayOf< short >{ frame->header.blocksize };
246 
247  auto iter = mFile->mChannels.begin();
248  for (unsigned int chn=0; chn<mFile->mNumChannels; ++iter, ++chn) {
249  if (frame->header.bits_per_sample <= 16) {
250  if (frame->header.bits_per_sample == 8) {
251  for (unsigned int s = 0; s < frame->header.blocksize; s++) {
252  tmp[s] = buffer[chn][s] << 8;
253  }
254  } else /* if (frame->header.bits_per_sample == 16) */ {
255  for (unsigned int s = 0; s < frame->header.blocksize; s++) {
256  tmp[s] = buffer[chn][s];
257  }
258  }
259 
260  iter->get()->Append((samplePtr)tmp.get(),
261  int16Sample,
262  frame->header.blocksize);
263  }
264  else {
265  iter->get()->Append((samplePtr)buffer[chn],
266  int24Sample,
267  frame->header.blocksize);
268  }
269  }
270 
271  mFile->mSamplesDone += frame->header.blocksize;
272 
273  mFile->mUpdateResult = mFile->mProgress->Update((wxULongLong_t) mFile->mSamplesDone, mFile->mNumSamples != 0 ? (wxULongLong_t)mFile->mNumSamples : 1);
275  {
276  return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
277  }
278 
279  return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
280  }, MakeSimpleGuard(FLAC__STREAM_DECODER_WRITE_STATUS_ABORT) );
281 }

References Append(), int16Sample, int24Sample, FLACImportFileHandle::mChannels, mFile, and FLACImportFileHandle::mNumChannels.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ FLACImportFileHandle

friend class FLACImportFileHandle
friend

Definition at line 108 of file ImportFLAC.cpp.

Member Data Documentation

◆ mComments

wxArrayString MyFLACFile::mComments
private

Definition at line 111 of file ImportFLAC.cpp.

Referenced by metadata_callback().

◆ mFile

FLACImportFileHandle* MyFLACFile::mFile
private

Definition at line 109 of file ImportFLAC.cpp.

Referenced by metadata_callback(), and write_callback().

◆ mWasError

bool MyFLACFile::mWasError
private

Definition at line 110 of file ImportFLAC.cpp.

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


The documentation for this class was generated from the following file:
MyFLACFile::mComments
wxArrayString mComments
Definition: ImportFLAC.cpp:111
MyFLACFile::mFile
FLACImportFileHandle * mFile
Definition: ImportFLAC.cpp:109
BasicUI::ProgressResult::Success
@ Success
FLACImportFileHandle::mChannels
NewChannelGroup mChannels
Definition: ImportFLAC.cpp:173
MakeSimpleGuard
SimpleGuard< R > MakeSimpleGuard(R value)
Convert a value to a handler function returning that value, suitable for GuardedCall<R>
Definition: AudacityException.h:167
int24Sample
@ int24Sample
Definition: SampleFormat.h:33
FLACImportFileHandle::mStreamInfoDone
bool mStreamInfoDone
Definition: ImportFLAC.cpp:171
FLACImportFileHandle::mFormat
sampleFormat mFormat
Definition: ImportFLAC.cpp:163
ImportFileHandle::mProgress
std::unique_ptr< ProgressDialog > mProgress
Definition: ImportPlugin.h:159
floatSample
@ floatSample
Definition: SampleFormat.h:34
int16Sample
@ int16Sample
Definition: SampleFormat.h:32
FLACImportFileHandle::mNumChannels
unsigned long mNumChannels
Definition: ImportFLAC.cpp:167
Append
Append([](My &table) -> Registry::BaseItemPtr { if(WaveTrackSubViews::slots() > 1) return std::make_unique< Entry >("MultiView", Entry::CheckItem, OnMultiViewID, XXO("&Multi-view"), POPUP_MENU_FN(OnMultiView), table, [](PopupMenuHandler &handler, wxMenu &menu, int id){ auto &table=static_cast< WaveTrackMenuTable & >(handler);auto &track=table.FindWaveTrack();const auto &view=WaveTrackView::Get(track);menu.Check(id, view.GetMultiView());});else return nullptr;})
UTF8CTOWX
#define UTF8CTOWX(X)
Definition: Internat.h:159
FLACImportFileHandle::mUpdateResult
ProgressResult mUpdateResult
Definition: ImportFLAC.cpp:172
FLACImportFileHandle::mBitsPerSample
unsigned long mBitsPerSample
Definition: ImportFLAC.cpp:168
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
FLACImportFileHandle::mNumSamples
FLAC__uint64 mNumSamples
Definition: ImportFLAC.cpp:169
FLACImportFileHandle::mSampleRate
unsigned long mSampleRate
Definition: ImportFLAC.cpp:166
MyFLACFile::mWasError
bool mWasError
Definition: ImportFLAC.cpp:110
ArrayOf
Memory.h template class for making an array of float, bool, etc.
Definition: MemoryX.h:27
FLACImportFileHandle::mSamplesDone
FLAC__uint64 mSamplesDone
Definition: ImportFLAC.cpp:170