Audacity  2.2.0
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  movable_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;
121  sampleFormat mFormat;
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;
137  samplePtr mDecodeBuffer;
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.
Definition: ODDecodeFlacTask.h:99
ODFileDecoder * CreateFileDecoder(const wxString &fileName) override
Creates an ODFileDecoder that decodes a file of filetype the subclass handles.
Definition: ODDecodeFlacTask.cpp:280
movable_ptr< ODTask > Clone() const override
Definition: ODDecodeFlacTask.cpp:36
std::unique_ptr< T > movable_ptr
Definition: MemoryX.h:683
ODFLACFile * GetFlacFile()
FLAC specific file (inherited from FLAC::Decoder::File)
Definition: ODDecodeFlacTask.cpp:267
ODFLACFile(ODFlacDecoder *decoder)
Definition: ODDecodeFlacTask.h:67
Definition: ODDecodeFlacTask.h:64
unsigned int mDecodeBufferWritePosition
Definition: ODDecodeFlacTask.h:135
FLAC__StreamDecoderWriteStatus write_callback(const FLAC__Frame *frame, const FLAC__int32 *const buffer[]) override
Definition: ODDecodeFlacTask.cpp:115
bool mWasError
Definition: ODDecodeFlacTask.h:82
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.
Definition: ODDecodeBlockFile.h:39
sampleFormat mFormat
Definition: ODDecodeFlacTask.h:121
ODLock mFlacFileLock
Definition: ODDecodeFlacTask.h:123
unsigned long mNumChannels
Definition: ODDecodeFlacTask.h:126
unsigned long mSampleRate
Definition: ODDecodeFlacTask.h:125
A class representing a modular task to be used with the On-Demand structures.
Definition: ODDecodeFlacTask.h:45
virtual ~ODDecodeFlacTask()
Definition: ODDecodeFlacTask.cpp:31
unsigned int GetODType() override
Definition: ODDecodeFlacTask.h:60
unsigned int mTargetChannel
Definition: ODDecodeFlacTask.h:134
int format
Definition: ExportPCM.cpp:56
bool ReadHeader() override
Definition: ODDecodeFlacTask.cpp:224
Definition: SampleFormat.h:52
An ImportFileHandle for FLAC data.
void error_callback(FLAC__StreamDecoderErrorStatus status) override
Definition: ODDecodeFlacTask.cpp:91
bool mStreamInfoDone
Definition: ODDecodeFlacTask.h:131
A Track that contains audio waveform data.
Definition: WaveTrack.h:76
bool get_was_error() const
Definition: ODDecodeFlacTask.h:75
void metadata_callback(const FLAC__StreamMetadata *metadata) override
Definition: ODDecodeFlacTask.cpp:47
ODDecodeFlacTask()
Constructs an ODTask.
Definition: ODDecodeFlacTask.h:50
unsigned long mBitsPerSample
Definition: ODDecodeFlacTask.h:127
std::unique_ptr< ODFLACFile > mFile
Definition: ODDecodeFlacTask.h:122
Definition: ODTask.h:44
int mUpdateResult
Definition: ODDecodeFlacTask.h:132
WaveTrack ** mChannels
Definition: ODDecodeFlacTask.h:133
wxFFile mHandle
Definition: ODDecodeFlacTask.h:124
int Decode(SampleBuffer &data, sampleFormat &format, sampleCount start, size_t len, unsigned int channel) override
Definition: ODDecodeFlacTask.cpp:173
Definition: ODTaskThread.h:150
unsigned int mDecodeBufferLen
Definition: ODDecodeFlacTask.h:136
class to decode a particular file (one per file). Saves info such as filename and length (after the h...
Definition: ODDecodeFlacTask.h:94
A class representing a modular task to be used with the On-Demand structures.
Definition: ODDecodeTask.h:41
FLAC__uint64 mSamplesDone
Definition: ODDecodeFlacTask.h:129
samplePtr mDecodeBuffer
Definition: ODDecodeFlacTask.h:137
FLAC__uint64 mNumSamples
Definition: ODDecodeFlacTask.h:128
wxArrayString mComments
Definition: ODDecodeFlacTask.h:83
virtual ~ODFlacDecoder()
Definition: ODDecodeFlacTask.cpp:272
ODFlacDecoder * mDecoder
Definition: ODDecodeFlacTask.h:81
sampleCount mLastDecodeStartSample
Definition: ODDecodeFlacTask.h:130