mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2025-04-02 05:21:37 +00:00
Add files src/audio_detect.c src/test_audio_detect.c, hook into build.
This commit is contained in:
parent
b1112ed550
commit
8805e441c0
@ -43,7 +43,7 @@ rc/OGG/include/ogg/config_types.h
|
||||
regtest/sndfile-regtest
|
||||
sndfile.pc
|
||||
src/*sndfile.def
|
||||
src/FLAC/tests/test_libFLAC
|
||||
src/FLAC/test_libFLAC/test_libFLAC
|
||||
src/G72x/g72x_test
|
||||
src/OGG/test_bitwise
|
||||
src/OGG/test_framing
|
||||
@ -53,6 +53,7 @@ src/config.h
|
||||
src/config.h.in
|
||||
src/sndfile.h
|
||||
src/stamp-h1
|
||||
src/test_audio_detect
|
||||
src/test_conversions
|
||||
src/test_endswap
|
||||
src/test_endswap.c
|
||||
|
@ -1,3 +1,11 @@
|
||||
2007-02-13 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/wav.c src/wav_w64.c src/wav_w64.h
|
||||
Start work towards detecting ausio codec type from the actual audio data.
|
||||
|
||||
* src/audio_detect.c src/test_audio_detect.c
|
||||
Add new file and its unit test.
|
||||
|
||||
2007-02-07 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* examples/cooledit-fixer.c examples/Makefile.am
|
||||
|
@ -17,11 +17,12 @@ EXTRA_DIST = sndfile.h.in config.h.in test_endswap.tpl test_endswap.def \
|
||||
|
||||
noinst_HEADERS = common.h sfconfig.h sfendian.h float_cast.h wav_w64.h sf_unistd.h
|
||||
|
||||
noinst_PROGRAMS = test_endswap test_file_io test_conversions test_log_printf
|
||||
noinst_PROGRAMS = test_endswap test_file_io test_conversions test_log_printf \
|
||||
test_audio_detect
|
||||
|
||||
COMMON = common.c file_io.c command.c pcm.c ulaw.c alaw.c float32.c \
|
||||
double64.c ima_adpcm.c ms_adpcm.c gsm610.c dwvw.c vox_adpcm.c \
|
||||
interleave.c strings.c dither.c broadcast.c
|
||||
interleave.c strings.c dither.c broadcast.c audio_detect.c
|
||||
|
||||
FILESPECIFIC = sndfile.c aiff.c au.c avr.c caf.c dwd.c flac.c g72x.c htk.c ircam.c \
|
||||
macbinary3.c macos.c mat4.c mat5.c nist.c ogg.c paf.c pvf.c raw.c rx2.c sd2.c \
|
||||
@ -49,6 +50,10 @@ test_conversions_CFLAGS = $(AM_CFLAGS)
|
||||
test_conversions_SOURCES = test_conversions.c
|
||||
test_conversions_LDADD = libcommon.la
|
||||
|
||||
test_audio_detect_CFLAGS = $(AM_CFLAGS)
|
||||
test_audio_detect_SOURCES = test_audio_detect.c
|
||||
test_audio_detect_LDADD = libcommon.la
|
||||
|
||||
test_endswap.c: test_endswap.def test_endswap.tpl
|
||||
autogen --writable test_endswap.def
|
||||
|
||||
@ -68,6 +73,7 @@ check: test_endswap test_file_io test_conversions test_log_printf
|
||||
./test_file_io
|
||||
./test_conversions
|
||||
./test_log_printf
|
||||
./test_audio_detect
|
||||
@echo "============================================================"
|
||||
@echo
|
||||
@echo
|
||||
|
@ -1,20 +1,4 @@
|
||||
/*
|
||||
** Copyright (C) 1999-2006 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
** the Free Software Foundation; either version 2.1 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU Lesser General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU Lesser General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "sfconfig.h"
|
||||
@ -32,75 +16,13 @@
|
||||
#include "common.h"
|
||||
#include "sfendian.h"
|
||||
|
||||
typedef struct
|
||||
{ int le_float ;
|
||||
int be_float ;
|
||||
int le_int_24_32 ;
|
||||
int be_int_24_32 ;
|
||||
} VOTE ;
|
||||
|
||||
|
||||
static void vote_for_format (VOTE * vote, const unsigned char * data, int datalen) ;
|
||||
|
||||
int
|
||||
audio_detect (SF_PRIVATE * psf, AUDIO_DETECT *ad, const unsigned char * data, int datalen)
|
||||
{ VOTE vote ;
|
||||
|
||||
if (psf == NULL)
|
||||
return 0 ;
|
||||
|
||||
if (ad == NULL || datalen < 256)
|
||||
return 0 ;
|
||||
|
||||
vote_for_format (&vote, data, datalen) ;
|
||||
|
||||
psf_log_printf (psf, "audio_detect :\n"
|
||||
" le_float : %d\n"
|
||||
" be_float : %d\n"
|
||||
" le_int_24_32 : %d\n"
|
||||
" be_int_24_32 : %d\n",
|
||||
vote.le_float, vote.be_float, vote.le_int_24_32, vote.be_int_24_32) ;
|
||||
|
||||
if (0) puts (psf->logbuffer) ;
|
||||
|
||||
if (ad->endianness == SF_ENDIAN_LITTLE && vote.le_float > (3 * datalen) / 4)
|
||||
{ /* Almost certainly 32 bit floats. */
|
||||
return SF_FORMAT_FLOAT ;
|
||||
} ;
|
||||
|
||||
if (ad->endianness == SF_ENDIAN_LITTLE && vote.le_int_24_32 > (3 * datalen) / 4)
|
||||
{ /* Almost certainly 24 bit data stored in 32 bit ints. */
|
||||
return SF_FORMAT_PCM_32 ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* data_detect */
|
||||
|
||||
static void
|
||||
vote_for_format (VOTE * vote, const unsigned char * data, int datalen)
|
||||
audio_detect (AUDIO_DETECT *ad, unsigned char * data, int datalen)
|
||||
{
|
||||
int k ;
|
||||
|
||||
memset (vote, 0, sizeof (VOTE)) ;
|
||||
|
||||
datalen -= datalen % 4 ;
|
||||
|
||||
for (k = 0 ; k < datalen ; k ++)
|
||||
{ if ((k % 4) == 0)
|
||||
{ if (data [k] == 0 && data [k + 1] != 0)
|
||||
vote->le_int_24_32 += 4 ;
|
||||
|
||||
if (data [2] != 0 && data [3] == 0)
|
||||
vote->le_int_24_32 += 4 ;
|
||||
|
||||
if (data [0] != 0 && data [3] > 0x43 && data [3] < 0x4B)
|
||||
vote->le_float += 4 ;
|
||||
|
||||
if (data [3] != 0 && data [0] > 0x43 && data [0] < 0x4B)
|
||||
vote->be_float += 4 ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* vote_for_format */
|
||||
if (ad != NULL && data [datalen - 1] == 0)
|
||||
return 0 ;
|
||||
|
||||
return 1 ;
|
||||
} /* data_detect */
|
||||
|
@ -746,6 +746,14 @@ SF_BROADCAST_INFO* broadcast_info_alloc (void) ;
|
||||
int broadcast_info_copy (SF_BROADCAST_INFO* dst, SF_BROADCAST_INFO* src) ;
|
||||
int broadcast_add_coding_history (SF_BROADCAST_INFO* bext, unsigned int channels, unsigned int samplerate) ;
|
||||
|
||||
typedef struct
|
||||
{ int channels ;
|
||||
int endianness ;
|
||||
} AUDIO_DETECT ;
|
||||
|
||||
int audio_detect (AUDIO_DETECT *ad, unsigned char * data, int datalen) ;
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
** Here's how we fix systems which don't snprintf / vsnprintf.
|
||||
** Systems without these functions should use the
|
||||
|
@ -61,8 +61,6 @@ static unsigned char float_le_mono [] =
|
||||
0xA8, 0xD3, 0xB7, 0x45, 0xEB, 0x51, 0xB9, 0x45, 0x6F, 0xAF, 0xBA, 0x45, 0xF5, 0xEB, 0xBB, 0x45,
|
||||
0x41, 0x07, 0xBD, 0x45, 0x21, 0x01, 0xBE, 0x45, 0x64, 0xD9, 0xBE, 0x45, 0xE3, 0x8F, 0xBF, 0x45,
|
||||
0x7E, 0x24, 0xC0, 0x45, 0x15, 0x97, 0xC0, 0x45, 0x92, 0xE7, 0xC0, 0x45, 0xE8, 0x15, 0xC1, 0x45,
|
||||
0x7E, 0x24, 0xC0, 0x45, 0x15, 0x97, 0xC0, 0x45, 0x92, 0xE7, 0xC0, 0x45, 0xE8, 0x15, 0xC1, 0x45,
|
||||
0x7E, 0x24, 0xC0, 0x45, 0x15, 0x97, 0xC0, 0x45, 0x92, 0xE7, 0xC0, 0x45, 0xE8, 0x15, 0xC1, 0x45,
|
||||
} ;
|
||||
|
||||
static unsigned char int24_32_le_stereo [] =
|
||||
@ -90,18 +88,12 @@ static unsigned char int24_32_le_stereo [] =
|
||||
static void
|
||||
test_audio_detect (void)
|
||||
{
|
||||
SF_PRIVATE psf ;
|
||||
AUDIO_DETECT ad ;
|
||||
int errors = 0 ;
|
||||
|
||||
printf (" test_audio_detect : ") ;
|
||||
fflush (stdout) ;
|
||||
|
||||
memset (&psf, 0, sizeof (psf)) ;
|
||||
|
||||
ad.endianness = SF_ENDIAN_LITTLE ;
|
||||
ad.channels = 1 ;
|
||||
if (audio_detect (&psf, &ad, float_le_mono, sizeof (float_le_mono)) != SF_FORMAT_FLOAT)
|
||||
if (audio_detect (&ad, float_le_mono, sizeof (float_le_mono)) != SF_FORMAT_FLOAT)
|
||||
{ if (errors == 0) puts ("\nFailed tests :\n") ;
|
||||
puts (" float_le_mono") ;
|
||||
errors ++ ;
|
||||
@ -109,7 +101,7 @@ test_audio_detect (void)
|
||||
|
||||
ad.endianness = SF_ENDIAN_LITTLE ;
|
||||
ad.channels = 2 ;
|
||||
if (audio_detect (&psf, &ad, int24_32_le_stereo, sizeof (int24_32_le_stereo)) != SF_FORMAT_PCM_32)
|
||||
if (audio_detect (&ad, int24_32_le_stereo, sizeof (int24_32_le_stereo)) != SF_FORMAT_PCM_32)
|
||||
{ if (errors == 0) puts ("\nFailed tests :\n") ;
|
||||
puts (" int24_32_le_stereo") ;
|
||||
errors ++ ;
|
||||
@ -120,7 +112,5 @@ test_audio_detect (void)
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* test_audio_detect */
|
||||
|
Loading…
x
Reference in New Issue
Block a user