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.
23 #include <pbd/convert.h>
26 #include <ardour/sndfile_helpers.h>
33 const char * const sndfile_header_formats_strings[SNDFILE_HEADER_FORMATS+1] = {
37 N_("W64 (64 bit WAV)"),
38 N_("raw (no header)"),
42 const char* const sndfile_file_endings_strings[SNDFILE_HEADER_FORMATS+1] = {
51 int sndfile_header_formats[SNDFILE_HEADER_FORMATS] = {
59 const char * const sndfile_bitdepth_formats_strings[SNDFILE_BITDEPTH_FORMATS+1] = {
60 N_("Signed 16 bit PCM"),
61 N_("Signed 24 bit PCM"),
62 N_("Signed 32 bit PCM"),
63 N_("Signed 8 bit PCM"),
68 int sndfile_bitdepth_formats[SNDFILE_BITDEPTH_FORMATS] = {
76 const char * const sndfile_endian_formats_strings[SNDFILE_ENDIAN_FORMATS+1] = {
77 N_("Little-endian (Intel)"),
78 N_("Big-endian (Mac)"),
82 int sndfile_endian_formats[SNDFILE_ENDIAN_FORMATS] = {
88 sndfile_header_format_from_string (string str)
90 for (int n = 0; sndfile_header_formats_strings[n]; ++n) {
91 if (str == sndfile_header_formats_strings[n]) {
92 return sndfile_header_formats[n];
99 sndfile_bitdepth_format_from_string (string str)
101 for (int n = 0; sndfile_bitdepth_formats_strings[n]; ++n) {
102 if (str == sndfile_bitdepth_formats_strings[n]) {
103 return sndfile_bitdepth_formats[n];
110 sndfile_endian_format_from_string (string str)
112 for (int n = 0; sndfile_endian_formats_strings[n]; ++n) {
113 if (str == sndfile_endian_formats_strings[n]) {
114 return sndfile_endian_formats[n];
121 sndfile_file_ending_from_string (string str)
123 static vector<string> file_endings;
125 if (file_endings.empty()) {
126 file_endings = I18N((const char **) sndfile_file_endings_strings);
129 for (int n = 0; sndfile_header_formats_strings[n]; ++n) {
130 if (str == sndfile_header_formats_strings[n]) {
131 return file_endings[n];
138 sndfile_data_width (int format)
140 int tval = format & 0xf;
143 case SF_FORMAT_PCM_S8:
144 case SF_FORMAT_PCM_U8:
146 case SF_FORMAT_PCM_16:
148 case SF_FORMAT_PCM_24:
150 case SF_FORMAT_PCM_32:
152 case SF_FORMAT_FLOAT:
153 return 1; // heh, heh
155 // we don't handle anything else within ardour
161 sndfile_major_format(int format)
163 static map<int, string> m;
166 SF_FORMAT_INFO format_info;
168 sf_command(0, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int));
169 for (int i = 0; i < count; ++i){
170 format_info.format = i;
171 sf_command (0, SFC_GET_FORMAT_MAJOR,
172 &format_info, sizeof (format_info));
173 m[format_info.format & SF_FORMAT_TYPEMASK] = format_info.name;
177 map<int, string>::iterator p = m.find(format & SF_FORMAT_TYPEMASK);
179 return m[format & SF_FORMAT_TYPEMASK];
186 sndfile_minor_format(int format)
188 static map<int, string> m;
191 SF_FORMAT_INFO format_info;
193 sf_command(0, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int));
194 for (int i = 0; i < count; ++i){
195 format_info.format = i;
196 sf_command (0, SFC_GET_FORMAT_SUBTYPE,
197 &format_info, sizeof (format_info));
198 m[format_info.format & SF_FORMAT_SUBMASK] = format_info.name;
202 map<int, string>::iterator p = m.find(format & SF_FORMAT_SUBMASK);
204 return m[format & SF_FORMAT_SUBMASK];