Audacity  2.2.2
Public Member Functions | List of all members
PCMImportPlugin Class Referencefinal

An ImportPlugin for PCM data. More...

Inheritance diagram for PCMImportPlugin:
ImportPlugin

Public Member Functions

 PCMImportPlugin ()
 
 ~PCMImportPlugin ()
 
wxString GetPluginStringID () override
 
wxString GetPluginFormatDescription () override
 
std::unique_ptr< ImportFileHandleOpen (const wxString &Filename) override
 
- Public Member Functions inherited from ImportPlugin
virtual wxArrayString GetSupportedExtensions ()
 
bool SupportsExtension (const wxString &extension)
 
virtual ~ImportPlugin ()
 

Additional Inherited Members

- Protected Member Functions inherited from ImportPlugin
 ImportPlugin (wxArrayString supportedExtensions)
 
- Protected Attributes inherited from ImportPlugin
wxArrayString mExtensions
 

Detailed Description

An ImportPlugin for PCM data.

Definition at line 72 of file ImportPCM.cpp.

Constructor & Destructor Documentation

PCMImportPlugin::PCMImportPlugin ( )
inline

Definition at line 75 of file ImportPCM.cpp.

References ImportPlugin::mExtensions, and sf_get_all_extensions().

76  : ImportPlugin(wxArrayString())
77  {
79  }
ImportPlugin(wxArrayString supportedExtensions)
Definition: ImportPlugin.h:110
wxArrayString sf_get_all_extensions()
wxArrayString mExtensions
Definition: ImportPlugin.h:115
PCMImportPlugin::~PCMImportPlugin ( )
inline

Definition at line 81 of file ImportPCM.cpp.

81 { }

Member Function Documentation

wxString PCMImportPlugin::GetPluginFormatDescription ( )
overridevirtual

Implements ImportPlugin.

Definition at line 123 of file ImportPCM.cpp.

References DESC.

124 {
125  return DESC;
126 }
#define DESC
Definition: ImportPCM.cpp:70
wxString PCMImportPlugin::GetPluginStringID ( )
inlineoverridevirtual

Implements ImportPlugin.

Definition at line 83 of file ImportPCM.cpp.

83 { return wxT("libsndfile"); }
std::unique_ptr< ImportFileHandle > PCMImportPlugin::Open ( const wxString &  Filename)
overridevirtual

Implements ImportPlugin.

Definition at line 128 of file ImportPCM.cpp.

129 {
130  SF_INFO info;
131  wxFile f; // will be closed when it goes out of scope
132  SFFile file;
133 
134  memset(&info, 0, sizeof(info));
135 
136 
137 #ifdef __WXGTK__
138  if (filename.Lower().EndsWith(wxT("mp3"))) {
139  // There is a bug in libsndfile where mp3s with duplicated metadata tags
140  // will crash libsndfile and thus audacity.
141  // We have patched the lib-src version of libsndfile, but
142  // for linux the user can build against the system libsndfile which
143  // still has this bug.
144  // This happens in sf_open_fd, which is the very first point of
145  // interaction with libsndfile, so the only workaround is to hardcode
146  // ImportPCM to not handle .mp3. Of couse, this will still fail for mp3s
147  // that are mislabeled with a .wav or other extension.
148  // So, in the future we may want to write a simple parser to detect mp3s here.
149  return NULL;
150  }
151 #endif
152 
153 
154  if (f.Open(filename)) {
155  // Even though there is an sf_open() that takes a filename, use the one that
156  // takes a file descriptor since wxWidgets can open a file with a Unicode name and
157  // libsndfile can't (under Windows).
158  file.reset(SFCall<SNDFILE*>(sf_open_fd, f.fd(), SFM_READ, &info, TRUE));
159  }
160 
161  // The file descriptor is now owned by "file", so we must tell "f" to leave
162  // it alone. The file descriptor is closed by the destructor of file even if an error
163  // occurs.
164  f.Detach();
165 
166  if (!file) {
167  // TODO: Handle error
168  //char str[1000];
169  //sf_error_str((SNDFILE *)NULL, str, 1000);
170 
171  return nullptr;
172  } else if (file &&
173  (info.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_OGG) {
174  // mchinen 15.1.2012 - disallowing libsndfile to handle
175  // ogg files because seeking is broken at this date (very slow,
176  // seeks from beginning of file each seek).
177  // This was said by Erik (libsndfile maintainer).
178  // Note that this won't apply to our local libsndfile, so only
179  // linux builds that use --with-libsndfile=system are affected,
180  // as our local libsndfile doesn't do OGG.
181  // In particular ubuntu 10.10 and 11.04 are known to be affected
182  // When the bug is fixed, we can check version to avoid only
183  // the broken builds.
184 
185  return nullptr;
186  }
187 
188  // Success, so now transfer the duty to close the file from "file".
189  return std::make_unique<PCMImportFileHandle>(filename, std::move(file), info);
190 }

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