2 Copyright (C) 2000-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "pbd/convert.h"
27 #include "ardour/sndfile_helpers.h"
34 const char * const sndfile_header_formats_strings
[SNDFILE_HEADER_FORMATS
+1] = {
38 N_("W64 (64 bit WAV)"),
41 N_("raw (no header)"),
45 const char* const sndfile_file_endings_strings
[SNDFILE_HEADER_FORMATS
+1] = {
56 int sndfile_header_formats
[SNDFILE_HEADER_FORMATS
] = {
66 const char * const sndfile_bitdepth_formats_strings
[SNDFILE_BITDEPTH_FORMATS
+1] = {
67 N_("Signed 16 bit PCM"),
68 N_("Signed 24 bit PCM"),
69 N_("Signed 32 bit PCM"),
70 N_("Signed 8 bit PCM"),
75 int sndfile_bitdepth_formats
[SNDFILE_BITDEPTH_FORMATS
] = {
83 const char * const sndfile_endian_formats_strings
[SNDFILE_ENDIAN_FORMATS
+1] = {
84 N_("Little-endian (Intel)"),
85 N_("Big-endian (PowerPC)"),
89 int sndfile_endian_formats
[SNDFILE_ENDIAN_FORMATS
] = {
95 sndfile_header_format_from_string (string str
)
97 for (int n
= 0; sndfile_header_formats_strings
[n
]; ++n
) {
98 if (str
== sndfile_header_formats_strings
[n
]) {
99 return sndfile_header_formats
[n
];
106 sndfile_bitdepth_format_from_string (string str
)
108 for (int n
= 0; sndfile_bitdepth_formats_strings
[n
]; ++n
) {
109 if (str
== sndfile_bitdepth_formats_strings
[n
]) {
110 return sndfile_bitdepth_formats
[n
];
117 sndfile_endian_format_from_string (string str
)
119 for (int n
= 0; sndfile_endian_formats_strings
[n
]; ++n
) {
120 if (str
== sndfile_endian_formats_strings
[n
]) {
121 return sndfile_endian_formats
[n
];
128 sndfile_file_ending_from_string (string str
)
130 static vector
<string
> file_endings
;
132 if (file_endings
.empty()) {
133 file_endings
= I18N((const char **) sndfile_file_endings_strings
);
136 for (int n
= 0; sndfile_header_formats_strings
[n
]; ++n
) {
137 if (str
== sndfile_header_formats_strings
[n
]) {
138 return file_endings
[n
];
145 sndfile_data_width (int format
)
147 int tval
= format
& 0xf;
150 case SF_FORMAT_PCM_S8
:
151 case SF_FORMAT_PCM_U8
:
153 case SF_FORMAT_PCM_16
:
155 case SF_FORMAT_PCM_24
:
157 case SF_FORMAT_PCM_32
:
159 case SF_FORMAT_FLOAT
:
160 return 1; // heh, heh
162 // we don't handle anything else within ardour
168 sndfile_major_format(int format
)
170 static map
<int, string
> m
;
173 SF_FORMAT_INFO format_info
;
175 sf_command(0, SFC_GET_FORMAT_MAJOR_COUNT
, &count
, sizeof (int));
176 for (int i
= 0; i
< count
; ++i
){
177 format_info
.format
= i
;
178 sf_command (0, SFC_GET_FORMAT_MAJOR
,
179 &format_info
, sizeof (format_info
));
180 m
[format_info
.format
& SF_FORMAT_TYPEMASK
] = format_info
.name
;
182 /* normalize a couple of names rather than use what libsndfile gives us */
184 if (strncasecmp (format_info
.name
, "OGG", 3) == 0) {
185 m
[format_info
.format
& SF_FORMAT_TYPEMASK
] = "Ogg";
186 } else if (strncasecmp (format_info
.name
, "WAV", 3) == 0) {
187 m
[format_info
.format
& SF_FORMAT_TYPEMASK
] = "WAV";
189 m
[format_info
.format
& SF_FORMAT_TYPEMASK
] = format_info
.name
;
194 map
<int, string
>::iterator p
= m
.find(format
& SF_FORMAT_TYPEMASK
);
196 return m
[format
& SF_FORMAT_TYPEMASK
];
203 sndfile_minor_format(int format
)
205 static map
<int, string
> m
;
208 SF_FORMAT_INFO format_info
;
210 sf_command(0, SFC_GET_FORMAT_SUBTYPE_COUNT
, &count
, sizeof (int));
211 for (int i
= 0; i
< count
; ++i
){
212 format_info
.format
= i
;
213 sf_command (0, SFC_GET_FORMAT_SUBTYPE
,
214 &format_info
, sizeof (format_info
));
215 m
[format_info
.format
& SF_FORMAT_SUBMASK
] = format_info
.name
;
219 map
<int, string
>::iterator p
= m
.find(format
& SF_FORMAT_SUBMASK
);
221 return m
[format
& SF_FORMAT_SUBMASK
];