Audacity 3.2.0
Classes | Functions | Variables
FileFormats.h File Reference
#include "Identifier.h"
#include "SampleFormat.h"
#include <memory>
#include "sndfile.h"
Include dependency graph for FileFormats.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SFFileCloser
 
struct  SFFile
 

Functions

AUDACITY_DLL_API int sf_num_headers ()
 Get the number of container formats supported by libsndfile. More...
 
AUDACITY_DLL_API wxString sf_header_index_name (int format_num)
 Get the name of a container format from libsndfile. More...
 
AUDACITY_DLL_API unsigned int sf_header_index_to_type (int format_num)
 
AUDACITY_DLL_API int sf_num_encodings ()
 Get the number of data encodings libsndfile supports (in any container or none. More...
 
AUDACITY_DLL_API wxString sf_encoding_index_name (int encoding_num)
 Get the string name of the data encoding of the requested format. More...
 
AUDACITY_DLL_API unsigned int sf_encoding_index_to_subtype (int encoding_num)
 
AUDACITY_DLL_API wxString sf_header_name (int format)
 Get the string name of the specified container format. More...
 
AUDACITY_DLL_API wxString sf_header_shortname (int format)
 Get an abbreviated form of the string name of the specified format. More...
 
AUDACITY_DLL_API 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)
 
AUDACITY_DLL_API bool sf_subtype_more_than_16_bits (unsigned int format)
 
AUDACITY_DLL_API bool sf_subtype_is_integer (unsigned int format)
 
AUDACITY_DLL_API int sf_subtype_bytes_per_sample (unsigned int format)
 
AUDACITY_DLL_API sampleFormat sf_subtype_to_effective_format (unsigned int format)
 Choose the narrowest value in the sampleFormat enumeration for a given libsndfile format. More...
 
AUDACITY_DLL_API FileExtensions sf_get_all_extensions ()
 
wxString sf_normalize_name (const char *name)
 
template<typename R , typename F , typename... Args>
SFCall (F fun, Args &&... args)
 

Variables

ChoiceSetting FileFormatsCopyOrEditSetting
 
ChoiceSetting FileFormatsSaveWithDependenciesSetting
 

Function Documentation

◆ sf_encoding_index_name()

AUDACITY_DLL_API 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 83 of file FileFormats.cpp.

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

References sf_normalize_name().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sf_encoding_index_to_subtype()

AUDACITY_DLL_API unsigned int sf_encoding_index_to_subtype ( int  encoding_num)

Definition at line 94 of file FileFormats.cpp.

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

Referenced by ExportPCMOptions::GetEncodings(), ImportRawDialog::ImportRawDialog(), ExportPCMOptions::OnEncodingChoice(), and ExportPCMOptions::~ExportPCMOptions().

Here is the caller graph for this function:

◆ sf_encoding_name()

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 156 of file FileFormats.cpp.

157{
158 SF_FORMAT_INFO format_info;
159
160 memset(&format_info, 0, sizeof(format_info));
161 format_info.format = (encoding & SF_FORMAT_SUBMASK);
162 sf_command(NULL, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info));
163
164 return sf_normalize_name(format_info.name);
165}

References sf_normalize_name().

Here is the call graph for this function:

◆ sf_get_all_extensions()

AUDACITY_DLL_API FileExtensions sf_get_all_extensions ( )

Definition at line 240 of file FileFormats.cpp.

241{
243 SF_FORMAT_INFO format_info;
244 int count, k;
245
246 memset(&format_info, 0, sizeof(format_info));
247
248 sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT,
249 &count, sizeof(count));
250
251 for(k=0; k<count; k++) {
252 format_info.format = k;
253 sf_command(NULL, SFC_GET_FORMAT_MAJOR,
254 &format_info, sizeof (format_info)) ;
255
256 exts.push_back(LAT1CTOWX(format_info.extension));
257 }
258
259 // Some other extensions that are often sound files
260 // but aren't included by libsndfile
261
262 exts.insert( exts.end(), {
263 wxT("aif") , // AIFF file with a DOS-style extension
264 wxT("ircam") ,
265 wxT("snd") ,
266 wxT("svx") ,
267 wxT("svx8") ,
268 wxT("sv16") ,
269 } );
270
271 return exts;
272}
static const auto exts
Definition: ImportAUP.cpp:57
#define LAT1CTOWX(X)
Definition: Internat.h:160
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.

References exts, and LAT1CTOWX.

Referenced by ExportPCM::ExportPCM().

Here is the caller graph for this function:

◆ sf_header_extension()

AUDACITY_DLL_API 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 retrieve 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 145 of file FileFormats.cpp.

146{
147 SF_FORMAT_INFO format_info;
148
149 memset(&format_info, 0, sizeof(format_info));
150 format_info.format = (format & SF_FORMAT_TYPEMASK);
151 sf_command(NULL, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info));
152
153 return LAT1CTOWX(format_info.extension);
154}
int format
Definition: ExportPCM.cpp:53

References format, and LAT1CTOWX.

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

Here is the caller graph for this function:

◆ sf_header_index_name()

AUDACITY_DLL_API 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 46 of file FileFormats.cpp.

47{
48 SF_FORMAT_INFO format_info;
49
50 memset(&format_info, 0, sizeof(format_info));
51 format_info.format = format;
52 sf_command(NULL, SFC_GET_FORMAT_MAJOR,
53 &format_info, sizeof (format_info)) ;
54
55 return LAT1CTOWX(format_info.name);
56}

References format, and LAT1CTOWX.

Referenced by ExportPCMOptions::GetTypes().

Here is the caller graph for this function:

◆ sf_header_index_to_type()

AUDACITY_DLL_API unsigned int sf_header_index_to_type ( int  format_num)

Definition at line 58 of file FileFormats.cpp.

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

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

Here is the caller graph for this function:

◆ sf_header_name()

AUDACITY_DLL_API 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 110 of file FileFormats.cpp.

111{
112 SF_FORMAT_INFO format_info;
113
114 memset(&format_info, 0, sizeof(format_info));
115 format_info.format = (format & SF_FORMAT_TYPEMASK);
116 sf_command(NULL, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info));
117
118 return LAT1CTOWX(format_info.name);
119}

References format, and LAT1CTOWX.

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

Here is the caller graph for this function:

◆ sf_header_shortname()

AUDACITY_DLL_API 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 121 of file FileFormats.cpp.

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

References format, and LAT1CTOWX.

Referenced by ExportPCM::GetFormat(), LoadEncoding(), and SaveEncoding().

Here is the caller graph for this function:

◆ sf_normalize_name()

wxString sf_normalize_name ( const char *  name)

Definition at line 274 of file FileFormats.cpp.

275{
276 wxString n = LAT1CTOWX(name);
277
278 n.Replace(wxT("8 bit"), wxT("8-bit"));
279 n.Replace(wxT("16 bit"), wxT("16-bit"));
280 n.Replace(wxT("24 bit"), wxT("24-bit"));
281 n.Replace(wxT("32 bit"), wxT("32-bit"));
282 n.Replace(wxT("64 bit"), wxT("64-bit"));
283
284 return n;
285}
wxT("CloseDown"))
const TranslatableString name
Definition: Distortion.cpp:74

References LAT1CTOWX, name, and wxT().

Referenced by sf_encoding_index_name(), and sf_encoding_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sf_num_encodings()

AUDACITY_DLL_API int sf_num_encodings ( )

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

Definition at line 74 of file FileFormats.cpp.

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

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

Here is the caller graph for this function:

◆ sf_num_headers()

AUDACITY_DLL_API 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 36 of file FileFormats.cpp.

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

Referenced by ExportPCMOptions::GetTypes().

Here is the caller graph for this function:

◆ sf_num_simple_formats()

int sf_num_simple_formats ( )

Definition at line 167 of file FileFormats.cpp.

168{
169 int count ;
170
171 sf_command (NULL, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ;
172
173 return count;
174}

◆ sf_simple_format()

SF_FORMAT_INFO * sf_simple_format ( int  i)

Definition at line 178 of file FileFormats.cpp.

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

References g_format_info.

◆ sf_subtype_bytes_per_sample()

AUDACITY_DLL_API int sf_subtype_bytes_per_sample ( unsigned int  format)

Definition at line 206 of file FileFormats.cpp.

206 {
207 unsigned int subtype = format & SF_FORMAT_SUBMASK;
208 if( subtype == SF_FORMAT_PCM_S8 )
209 return 1;
210 if( subtype == SF_FORMAT_PCM_U8 )
211 return 1;
212 if( subtype == SF_FORMAT_PCM_16 )
213 return 2;
214 if( subtype == SF_FORMAT_PCM_24 )
215 return 3;
216 if( subtype == SF_FORMAT_PCM_32 )
217 return 4;
218 if( subtype == SF_FORMAT_FLOAT )
219 return 4;
220 if( subtype == SF_FORMAT_DOUBLE )
221 return 8;
222
223 // might be different to 2, but this is good enough for
224 // WAV and AIFF file size error trapping.
225 return 2;
226}

References format.

Referenced by ExportPCM::Export().

Here is the caller graph for this function:

◆ sf_subtype_is_integer()

AUDACITY_DLL_API bool sf_subtype_is_integer ( unsigned int  format)

Definition at line 198 of file FileFormats.cpp.

199{
200 unsigned int subtype = format & SF_FORMAT_SUBMASK;
201 return (subtype == SF_FORMAT_PCM_16 ||
202 subtype == SF_FORMAT_PCM_24 ||
203 subtype == SF_FORMAT_PCM_32);
204}

References format.

Referenced by AUPImportFileHandle::AddSamples(), and ExportPCM::Export().

Here is the caller graph for this function:

◆ sf_subtype_more_than_16_bits()

AUDACITY_DLL_API bool sf_subtype_more_than_16_bits ( unsigned int  format)

Definition at line 189 of file FileFormats.cpp.

190{
191 unsigned int subtype = format & SF_FORMAT_SUBMASK;
192 return (subtype == SF_FORMAT_FLOAT ||
193 subtype == SF_FORMAT_DOUBLE ||
194 subtype == SF_FORMAT_PCM_24 ||
195 subtype == SF_FORMAT_PCM_32);
196}

References format.

Referenced by AUPImportFileHandle::AddSamples(), ExportPCM::Export(), and sf_subtype_to_effective_format().

Here is the caller graph for this function:

◆ sf_subtype_to_effective_format()

AUDACITY_DLL_API sampleFormat sf_subtype_to_effective_format ( unsigned int  format)

Choose the narrowest value in the sampleFormat enumeration for a given libsndfile format.

Definition at line 228 of file FileFormats.cpp.

229{
230 unsigned int subtype = format & SF_FORMAT_SUBMASK;
231 if (subtype == SF_FORMAT_PCM_24)
232 return int24Sample;
234 return widestSampleFormat;
235 else
236 return int16Sample;
237}
bool sf_subtype_more_than_16_bits(unsigned int format)
constexpr sampleFormat int16Sample
Definition: SampleFormat.h:41
constexpr sampleFormat int24Sample
Definition: SampleFormat.h:42
constexpr sampleFormat widestSampleFormat
Definition: SampleFormat.h:45

References format, int16Sample, int24Sample, sf_subtype_more_than_16_bits(), and widestSampleFormat.

Referenced by ImportRaw(), and PCMImportFileHandle::PCMImportFileHandle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SFCall()

template<typename R , typename F , typename... Args>
R SFCall ( fun,
Args &&...  args 
)
inline

Definition at line 134 of file FileFormats.h.

135{
136 //std::lock_guard<std::mutex> guard{ libSndFileMutex };
137 return fun(std::forward<Args>(args)...);
138}

Variable Documentation

◆ FileFormatsCopyOrEditSetting

ChoiceSetting FileFormatsCopyOrEditSetting
extern

Definition at line 352 of file FileFormats.cpp.

◆ FileFormatsSaveWithDependenciesSetting

ChoiceSetting FileFormatsSaveWithDependenciesSetting
extern

Definition at line 367 of file FileFormats.cpp.

Referenced by DependencyDialog::SaveFutureActionChoice().