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.
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 (PowerPC)"),
88 int sndfile_endian_formats[SNDFILE_ENDIAN_FORMATS] = {
94 sndfile_header_format_by_index (int index)
96 if (index >= 0 && index < SNDFILE_HEADER_FORMATS) {
97 return sndfile_header_formats[index];
103 sndfile_bitdepth_format_by_index (int index)
105 if (index >= 0 && index < SNDFILE_BITDEPTH_FORMATS) {
106 return sndfile_bitdepth_formats[index];
112 sndfile_endian_format_by_index (int index)
114 if (index >= 0 && index < SNDFILE_ENDIAN_FORMATS) {
115 return sndfile_endian_formats[index];
121 sndfile_data_width (int format)
123 int tval = format & 0xf;
126 case SF_FORMAT_PCM_S8:
127 case SF_FORMAT_PCM_U8:
129 case SF_FORMAT_PCM_16:
131 case SF_FORMAT_PCM_24:
133 case SF_FORMAT_PCM_32:
135 case SF_FORMAT_FLOAT:
138 // we don't handle anything else within ardour
144 sndfile_data_width (ARDOUR::SampleFormat format)
147 case ARDOUR::FormatInt16:
148 return sndfile_data_width (SF_FORMAT_PCM_16);
149 case ARDOUR::FormatInt24:
150 return sndfile_data_width (SF_FORMAT_PCM_24);
152 return sndfile_data_width (SF_FORMAT_FLOAT);
157 sndfile_major_format(int format)
159 static map<int, string> m;
162 SF_FORMAT_INFO format_info;
164 sf_command(0, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int));
165 for (int i = 0; i < count; ++i){
166 format_info.format = i;
167 sf_command (0, SFC_GET_FORMAT_MAJOR,
168 &format_info, sizeof (format_info));
169 m[format_info.format & SF_FORMAT_TYPEMASK] = format_info.name;
171 /* normalize a couple of names rather than use what libsndfile gives us */
173 if (strncasecmp (format_info.name, "OGG", 3) == 0) {
174 m[format_info.format & SF_FORMAT_TYPEMASK] = "Ogg";
175 } else if (strncasecmp (format_info.name, "WAV", 3) == 0) {
176 m[format_info.format & SF_FORMAT_TYPEMASK] = "WAV";
178 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];