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)"),
40 N_("raw (no header)"),
44 const char* const sndfile_file_endings_strings[SNDFILE_HEADER_FORMATS+1] = {
55 int sndfile_header_formats[SNDFILE_HEADER_FORMATS] = {
65 const char * const sndfile_bitdepth_formats_strings[SNDFILE_BITDEPTH_FORMATS+1] = {
66 N_("Signed 16 bit PCM"),
67 N_("Signed 24 bit PCM"),
68 N_("Signed 32 bit PCM"),
69 N_("Signed 8 bit PCM"),
74 int sndfile_bitdepth_formats[SNDFILE_BITDEPTH_FORMATS] = {
82 const char * const sndfile_endian_formats_strings[SNDFILE_ENDIAN_FORMATS+1] = {
83 N_("Little-endian (Intel)"),
84 N_("Big-endian (Mac)"),
88 int sndfile_endian_formats[SNDFILE_ENDIAN_FORMATS] = {
94 sndfile_header_format_from_string (string str)
96 for (int n = 0; sndfile_header_formats_strings[n]; ++n) {
97 if (str == sndfile_header_formats_strings[n]) {
98 return sndfile_header_formats[n];
105 sndfile_bitdepth_format_from_string (string str)
107 for (int n = 0; sndfile_bitdepth_formats_strings[n]; ++n) {
108 if (str == sndfile_bitdepth_formats_strings[n]) {
109 return sndfile_bitdepth_formats[n];
116 sndfile_endian_format_from_string (string str)
118 for (int n = 0; sndfile_endian_formats_strings[n]; ++n) {
119 if (str == sndfile_endian_formats_strings[n]) {
120 return sndfile_endian_formats[n];
127 sndfile_file_ending_from_string (string str)
129 static vector<string> file_endings;
131 if (file_endings.empty()) {
132 file_endings = I18N((const char **) sndfile_file_endings_strings);
135 for (int n = 0; sndfile_header_formats_strings[n]; ++n) {
136 if (str == sndfile_header_formats_strings[n]) {
137 return file_endings[n];
144 sndfile_data_width (int format)
146 int tval = format & 0xf;
149 case SF_FORMAT_PCM_S8:
150 case SF_FORMAT_PCM_U8:
152 case SF_FORMAT_PCM_16:
154 case SF_FORMAT_PCM_24:
156 case SF_FORMAT_PCM_32:
158 case SF_FORMAT_FLOAT:
159 return 1; // heh, heh
161 // we don't handle anything else within ardour
167 sndfile_major_format(int format)
169 static map<int, string> m;
172 SF_FORMAT_INFO format_info;
174 sf_command(0, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int));
175 for (int i = 0; i < count; ++i){
176 format_info.format = i;
177 sf_command (0, SFC_GET_FORMAT_MAJOR,
178 &format_info, sizeof (format_info));
179 m[format_info.format & SF_FORMAT_TYPEMASK] = format_info.name;
183 map<int, string>::iterator p = m.find(format & SF_FORMAT_TYPEMASK);
185 return m[format & SF_FORMAT_TYPEMASK];
192 sndfile_minor_format(int format)
194 static map<int, string> m;
197 SF_FORMAT_INFO format_info;
199 sf_command(0, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int));
200 for (int i = 0; i < count; ++i){
201 format_info.format = i;
202 sf_command (0, SFC_GET_FORMAT_SUBTYPE,
203 &format_info, sizeof (format_info));
204 m[format_info.format & SF_FORMAT_SUBMASK] = format_info.name;
208 map<int, string>::iterator p = m.find(format & SF_FORMAT_SUBMASK);
210 return m[format & SF_FORMAT_SUBMASK];