2 * Copyright (C) 2000-2016 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
4 * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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_by_index (int index)
97 if (index >= 0 && index < SNDFILE_HEADER_FORMATS) {
98 return sndfile_header_formats[index];
104 sndfile_bitdepth_format_by_index (int index)
106 if (index >= 0 && index < SNDFILE_BITDEPTH_FORMATS) {
107 return sndfile_bitdepth_formats[index];
113 sndfile_endian_format_by_index (int index)
115 if (index >= 0 && index < SNDFILE_ENDIAN_FORMATS) {
116 return sndfile_endian_formats[index];
122 sndfile_data_width (int format)
124 int tval = format & 0xf;
127 case SF_FORMAT_PCM_S8:
128 case SF_FORMAT_PCM_U8:
130 case SF_FORMAT_PCM_16:
132 case SF_FORMAT_PCM_24:
134 case SF_FORMAT_PCM_32:
136 case SF_FORMAT_FLOAT:
137 return 1; /* ridiculous but used as a magic value */
139 // we don't handle anything else within ardour
145 sndfile_major_format(int format)
147 static map<int, string> m;
150 SF_FORMAT_INFO format_info;
152 sf_command(0, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int));
153 for (int i = 0; i < count; ++i){
154 format_info.format = i;
155 sf_command (0, SFC_GET_FORMAT_MAJOR,
156 &format_info, sizeof (format_info));
157 m[format_info.format & SF_FORMAT_TYPEMASK] = format_info.name;
159 /* normalize a couple of names rather than use what libsndfile gives us */
161 if (strncasecmp (format_info.name, "OGG", 3) == 0) {
162 m[format_info.format & SF_FORMAT_TYPEMASK] = "Ogg";
163 } else if (strncasecmp (format_info.name, "WAV", 3) == 0) {
164 m[format_info.format & SF_FORMAT_TYPEMASK] = "WAV";
166 m[format_info.format & SF_FORMAT_TYPEMASK] = format_info.name;
171 map<int, string>::iterator p = m.find(format & SF_FORMAT_TYPEMASK);
173 return m[format & SF_FORMAT_TYPEMASK];
180 sndfile_minor_format(int format)
182 static map<int, string> m;
185 SF_FORMAT_INFO format_info;
187 sf_command(0, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int));
188 for (int i = 0; i < count; ++i){
189 format_info.format = i;
190 sf_command (0, SFC_GET_FORMAT_SUBTYPE,
191 &format_info, sizeof (format_info));
192 m[format_info.format & SF_FORMAT_SUBMASK] = format_info.name;
196 map<int, string>::iterator p = m.find(format & SF_FORMAT_SUBMASK);
198 return m[format & SF_FORMAT_SUBMASK];