Audacity  2.2.2
ODDecodeFlacTask.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ODDecodeFlacTask.h
6 
7  Created by Michael Chinen (mchinen) on 8/11/08.
8  Audacity(R) is copyright (c) 1999-2008 Audacity Team.
9  License: GPL v2. See License.txt.
10 
11 ******************************************************************//*******************************************************************/
24 
25 
26 
27 
28 #ifndef __AUDACITY_ODDecodeFLACTask__
29 #define __AUDACITY_ODDecodeFLACTask__
30 
31 #include <vector>
32 #include "ODDecodeTask.h"
33 #include "ODTaskThread.h"
34 
35 #include "FLAC++/decoder.h"
36 
37 class ODDecodeBlockFile;
38 class WaveTrack;
39 class ODFileDecoder;
40 
41 class ODFlacDecoder;
42 class ODFLACFile;
43 
45 class ODDecodeFlacTask final : public ODDecodeTask
46 {
47  public:
48 
51  virtual ~ODDecodeFlacTask();
52 
53 
54  std::unique_ptr<ODTask> Clone() const override;
56  ODFileDecoder* CreateFileDecoder(const wxString & fileName) override;
57 
60  unsigned int GetODType() override { return eODFLAC; }
61 };
62 
63 
64 class ODFLACFile final : public FLAC::Decoder::File
65 {
66  public:
67  ODFLACFile(ODFlacDecoder *decoder) : mDecoder(decoder)
68  {
69  mWasError = false;
70  set_metadata_ignore_all();
71  set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT);
72  set_metadata_respond(FLAC__METADATA_TYPE_STREAMINFO);
73  }
74 
75  bool get_was_error() const
76  {
77  return mWasError;
78  }
79  private:
80  friend class ODFlacDecoder;
82  bool mWasError;
83  wxArrayString mComments;
84 
85  protected:
86  FLAC__StreamDecoderWriteStatus write_callback(const FLAC__Frame *frame,
87  const FLAC__int32 * const buffer[]) override;
88  void metadata_callback(const FLAC__StreamMetadata *metadata) override;
89  void error_callback(FLAC__StreamDecoderErrorStatus status) override;
90 };
91 
92 
94 class ODFlacDecoder final : public ODFileDecoder
95 {
96  friend class ODFLACFile;
97 public:
99  ODFlacDecoder(const wxString & fileName):ODFileDecoder(fileName),mSamplesDone(0){mFile=NULL;}
100  virtual ~ODFlacDecoder();
101 
109  int Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, size_t len, unsigned int channel) override;
110 
111 
114  bool ReadHeader() override;
115 
118 
119 private:
120  friend class FLACImportFileHandle;
122  std::unique_ptr<ODFLACFile> mFile;
123  ODLock mFlacFileLock;//for mFile;
124  wxFFile mHandle;
125  unsigned long mSampleRate;
126  unsigned long mNumChannels;
127  unsigned long mBitsPerSample;
128  FLAC__uint64 mNumSamples;
129  FLAC__uint64 mSamplesDone;
134  unsigned int mTargetChannel;
136  unsigned int mDecodeBufferLen;
138 };
139 
140 #endif
141 
142 
143 
ODFlacDecoder(const wxString &fileName)
This should handle unicode converted to UTF-8 on mac/linux, but OD TODO:check on windows.
std::unique_ptr< ODTask > Clone() const override
ODFileDecoder * CreateFileDecoder(const wxString &fileName) override
Creates an ODFileDecoder that decodes a file of filetype the subclass handles.
ODFLACFile * GetFlacFile()
FLAC specific file (inherited from FLAC::Decoder::File)
ODFLACFile(ODFlacDecoder *decoder)
unsigned int mDecodeBufferWritePosition
FLAC__StreamDecoderWriteStatus write_callback(const FLAC__Frame *frame, const FLAC__int32 *const buffer[]) override
class to decode a particular file (one per file). Saves info such as filename and length (after the h...
Definition: ODDecodeTask.h:100
An AliasBlockFile that references uncompressed data in an existing file.
sampleFormat mFormat
unsigned long mNumChannels
unsigned long mSampleRate
A class representing a modular task to be used with the On-Demand structures.
virtual ~ODDecodeFlacTask()
unsigned int GetODType() override
unsigned int mTargetChannel
int format
Definition: ExportPCM.cpp:56
bool ReadHeader() override
An ImportFileHandle for FLAC data.
sampleFormat
Definition: Types.h:188
void error_callback(FLAC__StreamDecoderErrorStatus status) override
char * samplePtr
Definition: Types.h:203
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
bool get_was_error() const
void metadata_callback(const FLAC__StreamMetadata *metadata) override
ODDecodeFlacTask()
Constructs an ODTask.
unsigned long mBitsPerSample
std::unique_ptr< ODFLACFile > mFile
WaveTrack ** mChannels
int Decode(SampleBuffer &data, sampleFormat &format, sampleCount start, size_t len, unsigned int channel) override
unsigned int mDecodeBufferLen
class to decode a particular file (one per file). Saves info such as filename and length (after the h...
A class representing a modular task to be used with the On-Demand structures.
Definition: ODDecodeTask.h:41
FLAC__uint64 mSamplesDone
samplePtr mDecodeBuffer
FLAC__uint64 mNumSamples
wxArrayString mComments
virtual ~ODFlacDecoder()
ODFlacDecoder * mDecoder
sampleCount mLastDecodeStartSample