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.
24 #include "ardour/sndfile_helpers.h"
31 const char * const sndfile_header_formats_strings[SNDFILE_HEADER_FORMATS+1] = {
35 N_("W64 (64 bit WAV)"),
38 N_("raw (no header)"),
42 const char* const sndfile_file_endings_strings[SNDFILE_HEADER_FORMATS+1] = {
53 int sndfile_header_formats[SNDFILE_HEADER_FORMATS] = {
63 const char * const sndfile_bitdepth_formats_strings[SNDFILE_BITDEPTH_FORMATS+1] = {
64 N_("Signed 16 bit PCM"),
65 N_("Signed 24 bit PCM"),
66 N_("Signed 32 bit PCM"),
67 N_("Signed 8 bit PCM"),
72 int sndfile_bitdepth_formats[SNDFILE_BITDEPTH_FORMATS] = {
80 const char * const sndfile_endian_formats_strings[SNDFILE_ENDIAN_FORMATS+1] = {
81 N_("Little-endian (Intel)"),
82 N_("Big-endian (PowerPC)"),
86 int sndfile_endian_formats[SNDFILE_ENDIAN_FORMATS] = {
92 sndfile_header_format_by_index (int index)
94 if (index >= 0 && index < SNDFILE_HEADER_FORMATS) {
95 return sndfile_header_formats[index];
101 sndfile_bitdepth_format_by_index (int index)
103 if (index >= 0 && index < SNDFILE_BITDEPTH_FORMATS) {
104 return sndfile_bitdepth_formats[index];
110 sndfile_endian_format_by_index (int index)
112 if (index >= 0 && index < SNDFILE_ENDIAN_FORMATS) {
113 return sndfile_endian_formats[index];
119 sndfile_data_width (int format)
121 int tval = format & 0xf;
124 case SF_FORMAT_PCM_S8:
125 case SF_FORMAT_PCM_U8:
127 case SF_FORMAT_PCM_16:
129 case SF_FORMAT_PCM_24:
131 case SF_FORMAT_PCM_32:
133 case SF_FORMAT_FLOAT:
134 return 1; // heh, heh
136 // we don't handle anything else within ardour
142 sndfile_major_format(int format)
144 static map<int, string> m;
147 SF_FORMAT_INFO format_info;
149 sf_command(0, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int));
150 for (int i = 0; i < count; ++i){
151 format_info.format = i;
152 sf_command (0, SFC_GET_FORMAT_MAJOR,
153 &format_info, sizeof (format_info));
154 m[format_info.format & SF_FORMAT_TYPEMASK] = format_info.name;
156 /* normalize a couple of names rather than use what libsndfile gives us */
158 if (strncasecmp (format_info.name, "OGG", 3) == 0) {
159 m[format_info.format & SF_FORMAT_TYPEMASK] = "Ogg";
160 } else if (strncasecmp (format_info.name, "WAV", 3) == 0) {
161 m[format_info.format & SF_FORMAT_TYPEMASK] = "WAV";
163 m[format_info.format & SF_FORMAT_TYPEMASK] = format_info.name;
168 map<int, string>::iterator p = m.find(format & SF_FORMAT_TYPEMASK);
170 return m[format & SF_FORMAT_TYPEMASK];
177 sndfile_minor_format(int format)
179 static map<int, string> m;
182 SF_FORMAT_INFO format_info;
184 sf_command(0, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int));
185 for (int i = 0; i < count; ++i){
186 format_info.format = i;
187 sf_command (0, SFC_GET_FORMAT_SUBTYPE,
188 &format_info, sizeof (format_info));
189 m[format_info.format & SF_FORMAT_SUBMASK] = format_info.name;
193 map<int, string>::iterator p = m.find(format & SF_FORMAT_SUBMASK);
195 return m[format & SF_FORMAT_SUBMASK];