Audacity  2.2.2
Classes | Functions | Variables
FileFormats.h File Reference
#include <wx/list.h>
#include <wx/arrstr.h>
#include <wx/string.h>
#include "Audacity.h"
#include "sndfile.h"
#include "MemoryX.h"
#include "ondemand/ODTaskThread.h"

Go to the source code of this file.

Classes

struct  SFFileCloser
 
struct  SFFile
 

Functions

int sf_num_headers ()
 Get the number of container formats supported by libsndfile. More...
 
wxString sf_header_index_name (int format_num)
 Get the name of a container format from libsndfile. More...
 
unsigned int sf_header_index_to_type (int format_num)
 
int sf_num_encodings ()
 Get the number of data encodings libsndfile supports (in any container or none. More...
 
wxString sf_encoding_index_name (int encoding_num)
 Get the string name of the data encoding of the requested format. More...
 
unsigned int sf_encoding_index_to_subtype (int encoding_num)
 
wxString sf_header_name (int format)
 Get the string name of the specified container format. More...
 
wxString sf_header_shortname (int format)
 Get an abbreviated form of the string name of the specified format. More...
 
wxString sf_header_extension (int format)
 Get the most common file extension for the given format. More...
 
wxString sf_encoding_name (int encoding_num)
 Get the string name of the specified data encoding. More...
 
int sf_num_simple_formats ()
 
SF_FORMAT_INFO * sf_simple_format (int i)
 
bool sf_subtype_more_than_16_bits (unsigned int format)
 
bool sf_subtype_is_integer (unsigned int format)
 
wxArrayString sf_get_all_extensions ()
 
wxString sf_normalize_name (const char *name)
 
template<typename R , typename F , typename... Args>
SFCall (F fun, Args &&...args)
 

Variables

ODLock libSndFileMutex
 

Function Documentation

wxString sf_encoding_index_name ( int  encoding_num)

Get the string name of the data encoding of the requested format.

uses SFC_GET_FORMAT_SUBTYPE

Definition at line 84 of file FileFormats.cpp.

References sf_normalize_name().

Referenced by ExportPCMOptions::ExportPCMOptions(), ImportRawDialog::ImportRawDialog(), and ExportPCMOptions::OnHeaderChoice().

85 {
86  SF_FORMAT_INFO format_info ;
87 
88  memset(&format_info, 0, sizeof(format_info));
89  format_info.format = i;
90  sf_command (NULL, SFC_GET_FORMAT_SUBTYPE,
91  &format_info, sizeof (format_info));
92  return sf_normalize_name(format_info.name);
93 }
wxString sf_normalize_name(const char *name)
unsigned int sf_encoding_index_to_subtype ( int  encoding_num)

Definition at line 95 of file FileFormats.cpp.

Referenced by ExportPCMOptions::ExportPCMOptions(), ImportRawDialog::ImportRawDialog(), and ExportPCMOptions::OnHeaderChoice().

96 {
97  SF_FORMAT_INFO format_info ;
98 
99  memset(&format_info, 0, sizeof(format_info));
100  format_info.format = i;
101  sf_command (NULL, SFC_GET_FORMAT_SUBTYPE,
102  &format_info, sizeof (format_info));
103 
104  return format_info.format & SF_FORMAT_SUBMASK;
105 }
wxString sf_encoding_name ( int  encoding_num)

Get the string name of the specified data encoding.

AND encoding_num with SF_FORMAT_SUBMASK to get only the data encoding and then use SFC_GET_FORMAT_INFO to get the description

Parameters
encoding_numthe libsndfile encoding to get the name for (only the data encoding is used)

Definition at line 157 of file FileFormats.cpp.

References sf_normalize_name().

158 {
159  SF_FORMAT_INFO format_info;
160 
161  memset(&format_info, 0, sizeof(format_info));
162  format_info.format = (encoding & SF_FORMAT_SUBMASK);
163  sf_command(NULL, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info));
164 
165  return sf_normalize_name(format_info.name);
166 }
wxString sf_normalize_name(const char *name)
wxArrayString sf_get_all_extensions ( )

Definition at line 207 of file FileFormats.cpp.

References exts, and LAT1CTOWX.

Referenced by ExportPCM::ExportPCM(), and PCMImportPlugin::PCMImportPlugin().

208 {
209  wxArrayString exts;
210  SF_FORMAT_INFO format_info;
211  int count, k;
212 
213  memset(&format_info, 0, sizeof(format_info));
214 
215  sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT,
216  &count, sizeof(count));
217 
218  for(k=0; k<count; k++) {
219  format_info.format = k;
220  sf_command(NULL, SFC_GET_FORMAT_MAJOR,
221  &format_info, sizeof (format_info)) ;
222 
223  exts.Add(LAT1CTOWX(format_info.extension));
224  }
225 
226  // Some other extensions that are often sound files
227  // but aren't included by libsndfile
228 
229  exts.Add(wxT("aif")); // AIFF file with a DOS-style extension
230  exts.Add(wxT("ircam"));
231  exts.Add(wxT("snd"));
232  exts.Add(wxT("svx"));
233  exts.Add(wxT("svx8"));
234  exts.Add(wxT("sv16"));
235 
236  return exts;
237 }
static const wxChar * exts[]
Definition: ImportFLAC.cpp:53
#define LAT1CTOWX(X)
Definition: Internat.h:180
wxString sf_header_extension ( int  format)

Get the most common file extension for the given format.

AND the given format with SF_FORMAT_TYPEMASK to get just the container format, then retreive the most common extension using SFC_GET_FORMAT_INFO.

Parameters
formatthe libsndfile format to get the name for (only the container part is used)

Definition at line 146 of file FileFormats.cpp.

References LAT1CTOWX.

Referenced by ExportPCM::ExportPCM(), and ExportPCM::GetExtension().

147 {
148  SF_FORMAT_INFO format_info;
149 
150  memset(&format_info, 0, sizeof(format_info));
151  format_info.format = (format & SF_FORMAT_TYPEMASK);
152  sf_command(NULL, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info));
153 
154  return LAT1CTOWX(format_info.extension);
155 }
int format
Definition: ExportPCM.cpp:56
#define LAT1CTOWX(X)
Definition: Internat.h:180
wxString sf_header_index_name ( int  format_num)

Get the name of a container format from libsndfile.

Uses SFC_GET_FORMAT_MAJOR in the sf_command() interface. Resulting C string from libsndfile is converted to a wxString

Parameters
format_numThe libsndfile format number for the container format required

Definition at line 47 of file FileFormats.cpp.

References format, and LAT1CTOWX.

Referenced by ExportPCMOptions::ExportPCMOptions().

48 {
49  SF_FORMAT_INFO format_info;
50 
51  memset(&format_info, 0, sizeof(format_info));
52  format_info.format = format;
53  sf_command(NULL, SFC_GET_FORMAT_MAJOR,
54  &format_info, sizeof (format_info)) ;
55 
56  return LAT1CTOWX(format_info.name);
57 }
int format
Definition: ExportPCM.cpp:56
#define LAT1CTOWX(X)
Definition: Internat.h:180
unsigned int sf_header_index_to_type ( int  format_num)

Definition at line 59 of file FileFormats.cpp.

Referenced by ExportPCMOptions::ExportPCMOptions(), ExportPCMOptions::GetFormat(), and ExportPCMOptions::OnHeaderChoice().

60 {
61  SF_FORMAT_INFO format_info ;
62 
63  memset(&format_info, 0, sizeof(format_info));
64  format_info.format = i;
65  sf_command (NULL, SFC_GET_FORMAT_MAJOR,
66  &format_info, sizeof (format_info));
67 
68  return format_info.format & SF_FORMAT_TYPEMASK;
69 }
wxString sf_header_name ( int  format)

Get the string name of the specified container format.

AND format with SF_FORMAT_TYPEMASK to get only the container format and then use SFC_GET_FORMAT_INFO to get the description

Parameters
formatthe libsndfile format to get the name for (only the container part is used)

Definition at line 111 of file FileFormats.cpp.

References LAT1CTOWX.

Referenced by ExportPCM::Export(), and PCMImportFileHandle::GetFileDescription().

112 {
113  SF_FORMAT_INFO format_info;
114 
115  memset(&format_info, 0, sizeof(format_info));
116  format_info.format = (format & SF_FORMAT_TYPEMASK);
117  sf_command(NULL, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info));
118 
119  return LAT1CTOWX(format_info.name);
120 }
int format
Definition: ExportPCM.cpp:56
#define LAT1CTOWX(X)
Definition: Internat.h:180
wxString sf_header_shortname ( int  format)

Get an abbreviated form of the string name of the specified format.

Do sf_header_name() then truncate the string at the first space in the name to get just the first word of the format name.

Parameters
formatthe libsndfile format to get the name for (only the container part is used)

Definition at line 122 of file FileFormats.cpp.

References LAT1CTOWX.

123 {
124  SF_FORMAT_INFO format_info;
125  int i;
126  wxString s;
127 
128  memset(&format_info, 0, sizeof(format_info));
129  format_info.format = (format & SF_FORMAT_TYPEMASK);
130  sf_command(NULL, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info));
131 
132  MallocString<> tmp { strdup( format_info.name ) };
133  i = 0;
134  while(tmp[i]) {
135  if (tmp[i]==' ')
136  tmp[i] = 0;
137  else
138  i++;
139  }
140 
141  s = LAT1CTOWX(tmp.get());
142 
143  return s;
144 }
std::unique_ptr< Character[], freer > MallocString
Definition: MemoryX.h:417
int format
Definition: ExportPCM.cpp:56
#define LAT1CTOWX(X)
Definition: Internat.h:180
wxString sf_normalize_name ( const char *  name)

Definition at line 239 of file FileFormats.cpp.

References LAT1CTOWX.

Referenced by sf_encoding_index_name(), and sf_encoding_name().

240 {
241  wxString n = LAT1CTOWX(name);
242 
243  n.Replace(wxT("8 bit"), wxT("8-bit"));
244  n.Replace(wxT("16 bit"), wxT("16-bit"));
245  n.Replace(wxT("24 bit"), wxT("24-bit"));
246  n.Replace(wxT("32 bit"), wxT("32-bit"));
247  n.Replace(wxT("64 bit"), wxT("64-bit"));
248 
249  return n;
250 }
#define LAT1CTOWX(X)
Definition: Internat.h:180
const wxChar * name
Definition: Distortion.cpp:94
int sf_num_encodings ( )

Get the number of data encodings libsndfile supports (in any container or none.

Definition at line 75 of file FileFormats.cpp.

Referenced by ExportPCMOptions::ExportPCMOptions(), ImportRawDialog::ImportRawDialog(), and ExportPCMOptions::OnHeaderChoice().

76 {
77  int count ;
78 
79  sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ;
80 
81  return count;
82 }
int sf_num_headers ( )

Get the number of container formats supported by libsndfile.

Uses SFC_GET_FORMAT_MAJOR_COUNT in sf_command interface

Definition at line 37 of file FileFormats.cpp.

Referenced by ExportPCMOptions::ExportPCMOptions().

38 {
39  int count;
40 
41  sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT,
42  &count, sizeof(count));
43 
44  return count;
45 }
int sf_num_simple_formats ( )

Definition at line 168 of file FileFormats.cpp.

Referenced by ExportPCMOptions::OnHeaderChoice().

169 {
170  int count ;
171 
172  sf_command (NULL, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ;
173 
174  return count;
175 }
SF_FORMAT_INFO* sf_simple_format ( int  i)

Definition at line 179 of file FileFormats.cpp.

References g_format_info.

Referenced by ExportPCMOptions::OnHeaderChoice().

180 {
181  memset(&g_format_info, 0, sizeof(g_format_info));
182 
183  g_format_info.format = i;
184  sf_command (NULL, SFC_GET_SIMPLE_FORMAT,
185  &g_format_info, sizeof(g_format_info));
186 
187  return &g_format_info;
188 }
static SF_FORMAT_INFO g_format_info
bool sf_subtype_is_integer ( unsigned int  format)

Definition at line 199 of file FileFormats.cpp.

Referenced by BlockFile::CommonReadData(), and ExportPCM::Export().

200 {
201  unsigned int subtype = format & SF_FORMAT_SUBMASK;
202  return (subtype == SF_FORMAT_PCM_16 ||
203  subtype == SF_FORMAT_PCM_24 ||
204  subtype == SF_FORMAT_PCM_32);
205 }
int format
Definition: ExportPCM.cpp:56
bool sf_subtype_more_than_16_bits ( unsigned int  format)

Definition at line 190 of file FileFormats.cpp.

Referenced by BlockFile::CommonReadData(), ExportPCM::Export(), ImportRaw(), and PCMImportFileHandle::PCMImportFileHandle().

191 {
192  unsigned int subtype = format & SF_FORMAT_SUBMASK;
193  return (subtype == SF_FORMAT_FLOAT ||
194  subtype == SF_FORMAT_DOUBLE ||
195  subtype == SF_FORMAT_PCM_24 ||
196  subtype == SF_FORMAT_PCM_32);
197 }
int format
Definition: ExportPCM.cpp:56
template<typename R , typename F , typename... Args>
R SFCall ( fun,
Args &&...  args 
)
inline

Definition at line 123 of file FileFormats.h.

124 {
125  ODLocker locker{ &libSndFileMutex };
126  return fun(std::forward<Args>(args)...);
127 }
ODLock libSndFileMutex

Variable Documentation

ODLock libSndFileMutex

Definition at line 289 of file FileFormats.cpp.