775077e7cd62d67e57b254d9189043e0a6953e70
2 ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU Lesser General Public License as published by
6 ** the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14 ** You should have received a copy of the GNU Lesser General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
42 static void vote_for_format (VOTE
* vote
, const unsigned char * data
, int datalen
) ;
45 audio_detect (SF_PRIVATE
* psf
, AUDIO_DETECT
*ad
, const unsigned char * data
, int datalen
)
51 if (ad
== NULL
|| datalen
< 256)
54 vote_for_format (&vote
, data
, datalen
) ;
56 psf_log_printf (psf
, "audio_detect :\n"
59 " le_int_24_32 : %d\n"
60 " be_int_24_32 : %d\n",
61 vote
.le_float
, vote
.be_float
, vote
.le_int_24_32
, vote
.be_int_24_32
) ;
63 if (0) puts (psf
->logbuffer
) ;
65 if (ad
->endianness
== SF_ENDIAN_LITTLE
&& vote
.le_float
> (3 * datalen
) / 4)
66 { /* Almost certainly 32 bit floats. */
67 return SF_FORMAT_FLOAT
;
70 if (ad
->endianness
== SF_ENDIAN_LITTLE
&& vote
.le_int_24_32
> (3 * datalen
) / 4)
71 { /* Almost certainly 24 bit data stored in 32 bit ints. */
72 return SF_FORMAT_PCM_32
;
79 vote_for_format (VOTE
* vote
, const unsigned char * data
, int datalen
)
83 memset (vote
, 0, sizeof (VOTE
)) ;
85 datalen
-= datalen
% 4 ;
87 for (k
= 0 ; k
< datalen
; k
++)
89 { if (data
[k
] == 0 && data
[k
+ 1] != 0)
90 vote
->le_int_24_32
+= 4 ;
92 if (data
[2] != 0 && data
[3] == 0)
93 vote
->le_int_24_32
+= 4 ;
95 if (data
[0] != 0 && data
[3] > 0x43 && data
[3] < 0x4B)
98 if (data
[3] != 0 && data
[0] > 0x43 && data
[0] < 0x4B)
104 } /* vote_for_format */