Audacity 3.2.0
Macros | Functions | Variables
FileFormats.cpp File Reference

Works with libsndfile to provide encoding and other file information. More...

#include "FileFormats.h"
#include "wxArrayStringEx.h"
#include "Internat.h"
#include "MemoryX.h"
#include "BasicUI.h"
#include <Types.h>
Include dependency graph for FileFormats.cpp:

Go to the source code of this file.

Macros

#define NUM_HEADERS   13
 

Functions

int sf_num_headers ()
 Get the number of container formats supported by libsndfile. More...
 
wxString sf_header_index_name (int format)
 Get the name of a container format from libsndfile. More...
 
unsigned int sf_header_index_to_type (int i)
 
int sf_num_encodings ()
 Get the number of data encodings libsndfile supports (in any container or none. More...
 
wxString sf_encoding_index_name (int i)
 Get the string name of the data encoding of the requested format. More...
 
unsigned int sf_encoding_index_to_subtype (int i)
 
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)
 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)
 
int sf_subtype_bytes_per_sample (unsigned int format)
 
sampleFormat sf_subtype_to_effective_format (unsigned int format)
 Choose the narrowest value in the sampleFormat enumeration for a given libsndfile format. More...
 
FileExtensions sf_get_all_extensions ()
 
wxString sf_normalize_name (const char *name)
 
static OSType sf_header_mactype (int format)
 

Variables

static SF_FORMAT_INFO g_format_info
 
OSType MacNames [NUM_HEADERS]
 

Detailed Description

Works with libsndfile to provide encoding and other file information.

Definition in file FileFormats.cpp.

Macro Definition Documentation

◆ NUM_HEADERS

#define NUM_HEADERS   13

Definition at line 290 of file FileFormats.cpp.

Function Documentation

◆ sf_encoding_index_name()

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

80{
81 SF_FORMAT_INFO format_info ;
82
83 memset(&format_info, 0, sizeof(format_info));
84 format_info.format = i;
85 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE,
86 &format_info, sizeof (format_info));
87 return sf_normalize_name(format_info.name);
88}
wxString sf_normalize_name(const char *name)

References sf_normalize_name().

Referenced by anonymous_namespace{ExportPCM.cpp}::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()

unsigned int sf_encoding_index_to_subtype ( int  i)

Definition at line 90 of file FileFormats.cpp.

91{
92 SF_FORMAT_INFO format_info ;
93
94 memset(&format_info, 0, sizeof(format_info));
95 format_info.format = i;
96 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE,
97 &format_info, sizeof (format_info));
98
99 return format_info.format & SF_FORMAT_SUBMASK;
100}

Referenced by anonymous_namespace{ExportPCM.cpp}::GetEncodings(), and ImportRawDialog::ImportRawDialog().

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

153{
154 SF_FORMAT_INFO format_info;
155
156 memset(&format_info, 0, sizeof(format_info));
157 format_info.format = (encoding & SF_FORMAT_SUBMASK);
158 sf_command(NULL, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info));
159
160 return sf_normalize_name(format_info.name);
161}

References sf_normalize_name().

Here is the call graph for this function:

◆ sf_get_all_extensions()

FileExtensions sf_get_all_extensions ( )

Definition at line 236 of file FileFormats.cpp.

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

References exts, and LAT1CTOWX.

◆ sf_header_extension()

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

142{
143 SF_FORMAT_INFO format_info;
144
145 memset(&format_info, 0, sizeof(format_info));
146 format_info.format = (format & SF_FORMAT_TYPEMASK);
147 sf_command(NULL, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info));
148
149 return LAT1CTOWX(format_info.extension);
150}

References anonymous_namespace{ExportPCM.cpp}::format, and LAT1CTOWX.

Referenced by ExportPCM::GetFormatInfo().

Here is the caller graph for this function:

◆ sf_header_index_name()

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

43{
44 SF_FORMAT_INFO format_info;
45
46 memset(&format_info, 0, sizeof(format_info));
47 format_info.format = format;
48 sf_command(NULL, SFC_GET_FORMAT_MAJOR,
49 &format_info, sizeof (format_info)) ;
50
51 return LAT1CTOWX(format_info.name);
52}

References anonymous_namespace{ExportPCM.cpp}::format, and LAT1CTOWX.

Referenced by anonymous_namespace{ExportPCM.cpp}::ExportOptionsSFEditor::ExportOptionsSFEditor().

Here is the caller graph for this function:

◆ sf_header_index_to_type()

unsigned int sf_header_index_to_type ( int  i)

Definition at line 54 of file FileFormats.cpp.

55{
56 SF_FORMAT_INFO format_info ;
57
58 memset(&format_info, 0, sizeof(format_info));
59 format_info.format = i;
60 sf_command (NULL, SFC_GET_FORMAT_MAJOR,
61 &format_info, sizeof (format_info));
62
63 return format_info.format & SF_FORMAT_TYPEMASK;
64}

Referenced by anonymous_namespace{ExportPCM.cpp}::ExportOptionsSFEditor::ExportOptionsSFEditor().

Here is the caller graph for this function:

◆ sf_header_mactype()

static OSType sf_header_mactype ( int  format)
static

Definition at line 318 of file FileFormats.cpp.

319{
320 if (format >= 0x10000)
321 return MacNames[(format/0x10000)-1];
322 else if (format>=0 && format<NUM_HEADERS)
323 return MacNames[format];
324 else
325 return '\?\?\?\?';
326}
OSType MacNames[NUM_HEADERS]
#define NUM_HEADERS

References anonymous_namespace{ExportPCM.cpp}::format, MacNames, and NUM_HEADERS.

◆ sf_header_name()

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

107{
108 SF_FORMAT_INFO format_info;
109
110 memset(&format_info, 0, sizeof(format_info));
111 format_info.format = (format & SF_FORMAT_TYPEMASK);
112 sf_command(NULL, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info));
113
114 return LAT1CTOWX(format_info.name);
115}

References anonymous_namespace{ExportPCM.cpp}::format, and LAT1CTOWX.

Referenced by PCMImportFileHandle::GetFileDescription(), and PCMExportProcessor::Initialize().

Here is the caller graph for this function:

◆ sf_header_shortname()

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

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

References anonymous_namespace{ExportPCM.cpp}::format, and LAT1CTOWX.

Referenced by ExportPCM::GetFormatInfo(), anonymous_namespace{ExportPCM.cpp}::LoadEncoding(), and anonymous_namespace{ExportPCM.cpp}::SaveEncoding().

Here is the caller graph for this function:

◆ sf_normalize_name()

wxString sf_normalize_name ( const char *  name)

Definition at line 270 of file FileFormats.cpp.

271{
272 wxString n = LAT1CTOWX(name);
273
274 n.Replace(wxT("8 bit"), wxT("8-bit"));
275 n.Replace(wxT("16 bit"), wxT("16-bit"));
276 n.Replace(wxT("24 bit"), wxT("24-bit"));
277 n.Replace(wxT("32 bit"), wxT("32-bit"));
278 n.Replace(wxT("64 bit"), wxT("64-bit"));
279
280 return n;
281}
wxT("CloseDown"))
const TranslatableString name
Definition: Distortion.cpp:76

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()

int sf_num_encodings ( )

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

Definition at line 70 of file FileFormats.cpp.

71{
72 int count ;
73
74 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ;
75
76 return count;
77}

Referenced by anonymous_namespace{ExportPCM.cpp}::GetEncodings(), and ImportRawDialog::ImportRawDialog().

Here is the caller graph for this function:

◆ sf_num_headers()

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

33{
34 int count;
35
36 sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT,
37 &count, sizeof(count));
38
39 return count;
40}

Referenced by anonymous_namespace{ExportPCM.cpp}::ExportOptionsSFEditor::ExportOptionsSFEditor().

Here is the caller graph for this function:

◆ sf_num_simple_formats()

int sf_num_simple_formats ( )

Definition at line 163 of file FileFormats.cpp.

164{
165 int count ;
166
167 sf_command (NULL, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ;
168
169 return count;
170}

◆ sf_simple_format()

SF_FORMAT_INFO * sf_simple_format ( int  i)

Definition at line 174 of file FileFormats.cpp.

175{
176 memset(&g_format_info, 0, sizeof(g_format_info));
177
178 g_format_info.format = i;
179 sf_command (NULL, SFC_GET_SIMPLE_FORMAT,
180 &g_format_info, sizeof(g_format_info));
181
182 return &g_format_info;
183}
static SF_FORMAT_INFO g_format_info

References g_format_info.

◆ sf_subtype_bytes_per_sample()

int sf_subtype_bytes_per_sample ( unsigned int  format)

Definition at line 202 of file FileFormats.cpp.

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

References anonymous_namespace{ExportPCM.cpp}::format.

Referenced by PCMExportProcessor::Initialize().

Here is the caller graph for this function:

◆ sf_subtype_is_integer()

bool sf_subtype_is_integer ( unsigned int  format)

Definition at line 194 of file FileFormats.cpp.

195{
196 unsigned int subtype = format & SF_FORMAT_SUBMASK;
197 return (subtype == SF_FORMAT_PCM_16 ||
198 subtype == SF_FORMAT_PCM_24 ||
199 subtype == SF_FORMAT_PCM_32);
200}

References anonymous_namespace{ExportPCM.cpp}::format.

Referenced by AUPImportFileHandle::AddSamples(), and PCMExportProcessor::Initialize().

Here is the caller graph for this function:

◆ sf_subtype_more_than_16_bits()

bool sf_subtype_more_than_16_bits ( unsigned int  format)

Definition at line 185 of file FileFormats.cpp.

186{
187 unsigned int subtype = format & SF_FORMAT_SUBMASK;
188 return (subtype == SF_FORMAT_FLOAT ||
189 subtype == SF_FORMAT_DOUBLE ||
190 subtype == SF_FORMAT_PCM_24 ||
191 subtype == SF_FORMAT_PCM_32);
192}

References anonymous_namespace{ExportPCM.cpp}::format.

Referenced by AUPImportFileHandle::AddSamples(), PCMExportProcessor::Initialize(), and sf_subtype_to_effective_format().

Here is the caller graph for this function:

◆ sf_subtype_to_effective_format()

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

225{
226 unsigned int subtype = format & SF_FORMAT_SUBMASK;
227 if (subtype == SF_FORMAT_PCM_24)
228 return int24Sample;
230 return widestSampleFormat;
231 else
232 return int16Sample;
233}
bool sf_subtype_more_than_16_bits(unsigned int format)
constexpr sampleFormat int16Sample
Definition: SampleFormat.h:43
constexpr sampleFormat int24Sample
Definition: SampleFormat.h:44
constexpr sampleFormat widestSampleFormat
Definition: SampleFormat.h:47

References anonymous_namespace{ExportPCM.cpp}::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:

Variable Documentation

◆ g_format_info

SF_FORMAT_INFO g_format_info
static

Definition at line 172 of file FileFormats.cpp.

Referenced by sf_simple_format().

◆ MacNames

OSType MacNames[NUM_HEADERS]
Initial value:
= {
'WAVE',
'AIFF',
'NeXT',
'BINA',
'PAR ',
'8SVX',
'NIST',
'VOC ',
'\?\?\?\?',
'SF ',
'W64 ',
'MAT4',
'MAT5',
}

Definition at line 302 of file FileFormats.cpp.

Referenced by sf_header_mactype().