Audacity  3.0.3
Public Member Functions | Private Attributes | Friends | List of all members
ODFlacDecoder Class Referencefinal

class to decode a particular file (one per file). Saves info such as filename and length (after the header is read.) More...

#include <ODDecodeFlacTask.h>

Inheritance diagram for ODFlacDecoder:
[legend]
Collaboration diagram for ODFlacDecoder:
[legend]

Public Member Functions

 ODFlacDecoder (const wxString &fileName)
 This should handle unicode converted to UTF-8 on mac/linux, but OD TODO:check on windows. More...
 
virtual ~ODFlacDecoder ()
 
int Decode (SampleBuffer &data, sampleFormat &format, sampleCount start, size_t len, unsigned int channel) override
 
bool ReadHeader () override
 
ODFLACFileGetFlacFile ()
 FLAC specific file (inherited from FLAC::Decoder::File) More...
 
- Public Member Functions inherited from ODFileDecoder
 ODFileDecoder (const wxString &fName)
 This should handle unicode converted to UTF-8 on mac/linux, but OD TODO:check on windows. More...
 
virtual ~ODFileDecoder ()
 
virtual bool Init ()
 
virtual bool SeekingAllowed ()
 
const wxString & GetFileName ()
 
bool IsInitialized ()
 

Private Attributes

sampleFormat mFormat
 
std::unique_ptr< ODFLACFilemFile
 
ODLock mFlacFileLock
 
wxFFile mHandle
 
unsigned long mSampleRate
 
unsigned long mNumChannels
 
unsigned long mBitsPerSample
 
FLAC__uint64 mNumSamples
 
FLAC__uint64 mSamplesDone
 
sampleCount mLastDecodeStartSample
 
bool mStreamInfoDone
 
int mUpdateResult
 
WaveTrack ** mChannels
 
unsigned int mTargetChannel
 
unsigned int mDecodeBufferWritePosition
 
unsigned int mDecodeBufferLen
 
samplePtr mDecodeBuffer
 

Friends

class ODFLACFile
 
class FLACImportFileHandle
 

Additional Inherited Members

- Protected Member Functions inherited from ODFileDecoder
void MarkInitialized ()
 Derived classes should call this after they have parsed the header. More...
 
- Protected Attributes inherited from ODFileDecoder
bool mInited
 
ODLock mInitedLock
 
const wxString mFName
 
unsigned int mSampleRate
 
unsigned int mNumSamples
 
unsigned int mNumChannels
 

Detailed Description

class to decode a particular file (one per file). Saves info such as filename and length (after the header is read.)

Definition at line 96 of file ODDecodeFlacTask.h.

Constructor & Destructor Documentation

◆ ODFlacDecoder()

ODFlacDecoder::ODFlacDecoder ( const wxString &  fileName)
inline

This should handle unicode converted to UTF-8 on mac/linux, but OD TODO:check on windows.

Definition at line 101 of file ODDecodeFlacTask.h.

101 :ODFileDecoder(fileName),mSamplesDone(0){mFile=NULL;}

References mFile.

◆ ~ODFlacDecoder()

ODFlacDecoder::~ODFlacDecoder ( )
virtual

Definition at line 270 of file ODDecodeFlacTask.cpp.

270  {
271  if(mFile)
272  mFile->finish();
273 }

References mFile.

Member Function Documentation

◆ Decode()

int ODFlacDecoder::Decode ( SampleBuffer data,
sampleFormat format,
sampleCount  start,
size_t  len,
unsigned int  channel 
)
overridevirtual

Decodes the samples for this blockfile from the real file into a float buffer. This is file specific, so subclasses must implement this only. the buffer was defined like samplePtr sampleData = NewSamples(mLen, floatSample); this->ReadData(sampleData, floatSample, 0, mLen); This class should call ReadHeader() first, so it knows the length, and can prepare the file object if it needs to.

Implements ODFileDecoder.

Definition at line 172 of file ODDecodeFlacTask.cpp.

173 {
174 
175  //we need to lock this so the target stays fixed over the seek/write callback.
176  mFlacFileLock.Lock();
177 
178  bool usingCache=mLastDecodeStartSample==start;
179  if(usingCache)
180  {
181  //we've just decoded this, so lets use a cache. (often so for
182  }
183 
184 
186  mDecodeBufferLen = len;
187 
188  data.Allocate(len, mFormat);
189  mDecodeBuffer = data.ptr();
190  format = mFormat;
191 
192  mTargetChannel=channel;
193 
194  // Third party library has its own type alias, check it
195  static_assert(sizeof(sampleCount::type) <=
196  sizeof(FLAC__int64),
197  "Type FLAC__int64 is too narrow to hold a sampleCount");
198  if(!mFile->seek_absolute(static_cast<FLAC__int64>( start.as_long_long() )))
199  {
200  mFlacFileLock.Unlock();
201  return -1;
202  }
203 
205  mFile->process_single();
206 
207  mFlacFileLock.Unlock();
208  if(!usingCache)
209  {
211  }
212  //insert into blockfile and
213  //calculate summary happen in ODDecodeBlockFile::WriteODDecodeBlockFile, where this method is also called.
214  return 1;
215 }

References SampleBuffer::Allocate(), sampleCount::as_long_long(), format, mDecodeBuffer, mDecodeBufferLen, mDecodeBufferWritePosition, mFile, mFlacFileLock, mFormat, mLastDecodeStartSample, mTargetChannel, and SampleBuffer::ptr().

Here is the call graph for this function:

◆ GetFlacFile()

ODFLACFile * ODFlacDecoder::GetFlacFile ( )

FLAC specific file (inherited from FLAC::Decoder::File)

Definition at line 265 of file ODDecodeFlacTask.cpp.

266 {
267  return mFile.get();
268 }

References mFile.

◆ ReadHeader()

bool ODFlacDecoder::ReadHeader ( )
overridevirtual

Read header. Subclasses must override. Probably should save the info somewhere. Ideally called once per decoding of a file. This complicates the task because

Read header. Subclasses must override. Probably should save the info somewhere. Ideally called once per decoding of a file. This complicates the task because returns true if the file exists and the header was read alright.

Implements ODFileDecoder.

Definition at line 223 of file ODDecodeFlacTask.cpp.

224 {
225  mFormat = int16Sample;//start with the smallest and move up in the metadata_callback.
226  //we want to use the native flac type for quick conversion.
227  /* QualityPrefs::SampleFormatChoice(); */
228  mFile = std::make_unique<ODFLACFile>(this);
229 
230 
231  if (!mHandle.Open(mFName, wxT("rb"))) {
232  return false;
233  }
234 
235  // Even though there is an init() method that takes a filename, use the one that
236  // takes a file handle because wxWidgets can open a file with a Unicode name and
237  // libflac can't (under Windows).
238  //
239  // Responsibility for closing the file is passed to libflac.
240  // (it happens when mFile->finish() is called)
241  bool result = mFile->init(mHandle.fp())?true:false;
242  mHandle.Detach();
243 
244  if (result != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
245  return false;
246  }
247 
248  //this will call the metadata_callback when it is done
249  mFile->process_until_end_of_metadata();
250  // not necessary to check state, error callback will catch errors, but here's how:
251  if (mFile->get_state() > FLAC__STREAM_DECODER_READ_FRAME) {
252  return false;
253  }
254 
255  if (!mFile->is_valid() || mFile->get_was_error()) {
256  // This probably is not a FLAC file at all
257  return false;
258  }
259 
260  MarkInitialized();
261  return true;
262 
263 }

References int16Sample, ODFileDecoder::MarkInitialized(), mFile, ODFileDecoder::mFName, mFormat, and mHandle.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ FLACImportFileHandle

friend class FLACImportFileHandle
friend

Definition at line 122 of file ODDecodeFlacTask.h.

◆ ODFLACFile

friend class ODFLACFile
friend

Definition at line 98 of file ODDecodeFlacTask.h.

Member Data Documentation

◆ mBitsPerSample

unsigned long ODFlacDecoder::mBitsPerSample
private

Definition at line 129 of file ODDecodeFlacTask.h.

Referenced by ODFLACFile::metadata_callback().

◆ mChannels

WaveTrack** ODFlacDecoder::mChannels
private

Definition at line 135 of file ODDecodeFlacTask.h.

◆ mDecodeBuffer

samplePtr ODFlacDecoder::mDecodeBuffer
private

Definition at line 139 of file ODDecodeFlacTask.h.

Referenced by Decode(), and ODFLACFile::write_callback().

◆ mDecodeBufferLen

unsigned int ODFlacDecoder::mDecodeBufferLen
private

Definition at line 138 of file ODDecodeFlacTask.h.

Referenced by Decode(), and ODFLACFile::write_callback().

◆ mDecodeBufferWritePosition

unsigned int ODFlacDecoder::mDecodeBufferWritePosition
private

Definition at line 137 of file ODDecodeFlacTask.h.

Referenced by Decode(), and ODFLACFile::write_callback().

◆ mFile

std::unique_ptr<ODFLACFile> ODFlacDecoder::mFile
private

Definition at line 124 of file ODDecodeFlacTask.h.

Referenced by Decode(), GetFlacFile(), ODFlacDecoder(), ReadHeader(), and ~ODFlacDecoder().

◆ mFlacFileLock

ODLock ODFlacDecoder::mFlacFileLock
private

Definition at line 125 of file ODDecodeFlacTask.h.

Referenced by Decode().

◆ mFormat

sampleFormat ODFlacDecoder::mFormat
private

◆ mHandle

wxFFile ODFlacDecoder::mHandle
private

Definition at line 126 of file ODDecodeFlacTask.h.

Referenced by ReadHeader().

◆ mLastDecodeStartSample

sampleCount ODFlacDecoder::mLastDecodeStartSample
private

Definition at line 132 of file ODDecodeFlacTask.h.

Referenced by Decode().

◆ mNumChannels

unsigned long ODFlacDecoder::mNumChannels
private

Definition at line 128 of file ODDecodeFlacTask.h.

Referenced by ODFLACFile::metadata_callback().

◆ mNumSamples

FLAC__uint64 ODFlacDecoder::mNumSamples
private

Definition at line 130 of file ODDecodeFlacTask.h.

Referenced by ODFLACFile::metadata_callback().

◆ mSampleRate

unsigned long ODFlacDecoder::mSampleRate
private

Definition at line 127 of file ODDecodeFlacTask.h.

Referenced by ODFLACFile::metadata_callback().

◆ mSamplesDone

FLAC__uint64 ODFlacDecoder::mSamplesDone
private

Definition at line 131 of file ODDecodeFlacTask.h.

Referenced by ODFLACFile::write_callback().

◆ mStreamInfoDone

bool ODFlacDecoder::mStreamInfoDone
private

Definition at line 133 of file ODDecodeFlacTask.h.

Referenced by ODFLACFile::metadata_callback().

◆ mTargetChannel

unsigned int ODFlacDecoder::mTargetChannel
private

Definition at line 136 of file ODDecodeFlacTask.h.

Referenced by Decode(), and ODFLACFile::write_callback().

◆ mUpdateResult

int ODFlacDecoder::mUpdateResult
private

Definition at line 134 of file ODDecodeFlacTask.h.


The documentation for this class was generated from the following files:
SampleBuffer::Allocate
SampleBuffer & Allocate(size_t count, sampleFormat format)
Definition: SampleFormat.h:84
ODFlacDecoder::mDecodeBufferWritePosition
unsigned int mDecodeBufferWritePosition
Definition: ODDecodeFlacTask.h:137
ODFlacDecoder::mFlacFileLock
ODLock mFlacFileLock
Definition: ODDecodeFlacTask.h:125
ODFlacDecoder::mFormat
sampleFormat mFormat
Definition: ODDecodeFlacTask.h:123
ODFileDecoder::MarkInitialized
void MarkInitialized()
Derived classes should call this after they have parsed the header.
Definition: ODDecodeBlockFile.cpp:558
ODFlacDecoder::mTargetChannel
unsigned int mTargetChannel
Definition: ODDecodeFlacTask.h:136
sampleCount::as_long_long
long long as_long_long() const
Definition: SampleCount.h:47
int16Sample
@ int16Sample
Definition: SampleFormat.h:32
ODFileDecoder::ODFileDecoder
ODFileDecoder(const wxString &fName)
This should handle unicode converted to UTF-8 on mac/linux, but OD TODO:check on windows.
Definition: ODDecodeBlockFile.cpp:538
format
int format
Definition: ExportPCM.cpp:56
sampleCount::type
long long type
Definition: SampleCount.h:20
ODFlacDecoder::mFile
std::unique_ptr< ODFLACFile > mFile
Definition: ODDecodeFlacTask.h:124
ODFlacDecoder::mHandle
wxFFile mHandle
Definition: ODDecodeFlacTask.h:126
ODFlacDecoder::mDecodeBufferLen
unsigned int mDecodeBufferLen
Definition: ODDecodeFlacTask.h:138
ODFlacDecoder::mSamplesDone
FLAC__uint64 mSamplesDone
Definition: ODDecodeFlacTask.h:131
ODFlacDecoder::mDecodeBuffer
samplePtr mDecodeBuffer
Definition: ODDecodeFlacTask.h:139
ODFileDecoder::mFName
const wxString mFName
Definition: ODDecodeBlockFile.h:227
ODFlacDecoder::mLastDecodeStartSample
sampleCount mLastDecodeStartSample
Definition: ODDecodeFlacTask.h:132
SampleBuffer::ptr
samplePtr ptr() const
Definition: SampleFormat.h:98