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:
136 return 1; /* ridiculous but used as a magic value */
138 // we don't handle anything else within ardour
144 sndfile_major_format(int format)
146 static map<int, string> m;
149 SF_FORMAT_INFO format_info;
151 sf_command(0, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int));
152 for (int i = 0; i < count; ++i){
153 format_info.format = i;
154 sf_command (0, SFC_GET_FORMAT_MAJOR,
155 &format_info, sizeof (format_info));
156 m[format_info.format & SF_FORMAT_TYPEMASK] = format_info.name;
158 /* normalize a couple of names rather than use what libsndfile gives us */
160 if (strncasecmp (format_info.name, "OGG", 3) == 0) {
161 m[format_info.format & SF_FORMAT_TYPEMASK] = "Ogg";
162 } else if (strncasecmp (format_info.name, "WAV", 3) == 0) {
163 m[format_info.format & SF_FORMAT_TYPEMASK] = "WAV";
165 m[format_info.format & SF_FORMAT_TYPEMASK] = format_info.name;
170 map<int, string>::iterator p = m.find(format & SF_FORMAT_TYPEMASK);
172 return m[format & SF_FORMAT_TYPEMASK];
179 sndfile_minor_format(int format)
181 static map<int, string> m;
184 SF_FORMAT_INFO format_info;
186 sf_command(0, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int));
187 for (int i = 0; i < count; ++i){
188 format_info.format = i;
189 sf_command (0, SFC_GET_FORMAT_SUBTYPE,
190 &format_info, sizeof (format_info));
191 m[format_info.format & SF_FORMAT_SUBMASK] = format_info.name;
195 map<int, string>::iterator p = m.find(format & SF_FORMAT_SUBMASK);
197 return m[format & SF_FORMAT_SUBMASK];