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 ()
 
wxString GetPluginFormatDescription ()
 
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 71 of file ImportPCM.cpp.

Constructor & Destructor Documentation

PCMImportPlugin::PCMImportPlugin ( )
inline

Definition at line 74 of file ImportPCM.cpp.

References ImportPlugin::mExtensions, and sf_get_all_extensions().

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

Definition at line 80 of file ImportPCM.cpp.

80 { }

Member Function Documentation

wxString PCMImportPlugin::GetPluginFormatDescription ( )
virtual

Implements ImportPlugin.

Definition at line 122 of file ImportPCM.cpp.

References DESC.

123 {
124  return DESC;
125 }
#define DESC
Definition: ImportPCM.cpp:69
wxString PCMImportPlugin::GetPluginStringID ( )
inlinevirtual

Implements ImportPlugin.

Definition at line 82 of file ImportPCM.cpp.

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

Implements ImportPlugin.

Definition at line 127 of file ImportPCM.cpp.

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

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