mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 09:59:54 +00:00
Add AVR file handling.
Patches applied: * erikd@miles--2004/libsndfile--avr--0--base-0 tag of erikd@miles--2004/libsndfile--mdev--1.0--patch-68 * erikd@miles--2004/libsndfile--avr--0--patch-1 Move config.h to top of file. * erikd@miles--2004/libsndfile--avr--0--patch-2 Add AVR file support. * erikd@miles--2004/libsndfile--avr--0--patch-3 Fix minor bugs in AVR handling. * erikd@miles--2004/libsndfile--avr--0--patch-4 Add AVR tests.
This commit is contained in:
parent
768cca5299
commit
7dd9999097
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
||||
2004-03-26 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/avr.c
|
||||
New file to handle Audio Visual Resaerch files.
|
||||
|
||||
* src/sndfile.h.in src/common.h src/sndfile.c src/command.c
|
||||
Hook AVR into everything else.
|
||||
|
||||
* tests/Makefile.am tests/write_read_test.tpl tests/misc_test.c
|
||||
Add testing for AVR files.
|
||||
|
||||
2004-03-22 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/file_io.c
|
||||
|
@ -19,9 +19,9 @@ COMMON = sndfile.c 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 sfendian.c vox_adpcm.c \
|
||||
interleave.c strings.c dither.c
|
||||
|
||||
FILESPECIFIC = aiff.c au.c au_g72x.c ircam.c macbinary3.c macos.c mat4.c mat5.c \
|
||||
nist.c paf.c pvf.c raw.c svx.c voc.c htk.c dwd.c ogg.c rx2.c \
|
||||
sd2.c sds.c txw.c wve.c w64.c wav_w64.c wav.c xi.c
|
||||
FILESPECIFIC = aiff.c au.c au_g72x.c avr.c ircam.c macbinary3.c macos.c mat4.c \
|
||||
mat5.c nist.c paf.c pvf.c raw.c svx.c voc.c htk.c dwd.c ogg.c \
|
||||
rx2.c sd2.c sds.c txw.c wve.c w64.c wav_w64.c wav.c xi.c
|
||||
|
||||
libsndfile_la_SOURCES = $(COMMON) $(FILESPECIFIC) $(noinst_HEADERS) sndfile.h
|
||||
libsndfile_la_LDFLAGS = -version-info @SHARED_VERSION_INFO@ @SHLIB_VERSION_ARG@
|
||||
|
3
src/au.c
3
src/au.c
@ -16,13 +16,14 @@
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "sndfile.h"
|
||||
#include "config.h"
|
||||
#include "sfendian.h"
|
||||
#include "common.h"
|
||||
#include "au.h"
|
||||
|
22
src/avr.c
22
src/avr.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2004-2006 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 2004 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
|
||||
@ -16,7 +16,7 @@
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -78,7 +78,8 @@ static int avr_write_header (SF_PRIVATE *psf, int calc_length) ;
|
||||
|
||||
int
|
||||
avr_open (SF_PRIVATE *psf)
|
||||
{ int error = 0 ;
|
||||
{ int subformat ;
|
||||
int error = 0 ;
|
||||
|
||||
if (psf->mode == SFM_READ || (psf->mode == SFM_RDWR && psf->filelength > 0))
|
||||
{ if ((error = avr_read_header (psf)))
|
||||
@ -88,6 +89,8 @@ avr_open (SF_PRIVATE *psf)
|
||||
if ((psf->sf.format & SF_FORMAT_TYPEMASK) != SF_FORMAT_AVR)
|
||||
return SFE_BAD_OPEN_FORMAT ;
|
||||
|
||||
subformat = psf->sf.format & SF_FORMAT_SUBMASK ;
|
||||
|
||||
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
|
||||
{ psf->endian = psf->sf.format & SF_FORMAT_ENDMASK ;
|
||||
psf->endian = SF_ENDIAN_BIG ;
|
||||
@ -98,7 +101,7 @@ avr_open (SF_PRIVATE *psf)
|
||||
psf->write_header = avr_write_header ;
|
||||
} ;
|
||||
|
||||
psf->container_close = avr_close ;
|
||||
psf->close = avr_close ;
|
||||
|
||||
psf->blockwidth = psf->bytewidth * psf->sf.channels ;
|
||||
|
||||
@ -147,6 +150,7 @@ avr_read_header (SF_PRIVATE *psf)
|
||||
default :
|
||||
psf_log_printf (psf, "Error : bad rez/sign combination.\n") ;
|
||||
return SFE_AVR_X ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
psf_binheader_readf (psf, "E4444", &hdr.srate, &hdr.frames, &hdr.lbeg, &hdr.lend) ;
|
||||
@ -173,6 +177,8 @@ avr_read_header (SF_PRIVATE *psf)
|
||||
if (psf_ftell (psf) != psf->dataoffset)
|
||||
psf_binheader_readf (psf, "j", psf->dataoffset - psf_ftell (psf)) ;
|
||||
|
||||
psf->close = avr_close ;
|
||||
|
||||
psf->blockwidth = psf->sf.channels * psf->bytewidth ;
|
||||
|
||||
if (psf->sf.frames == 0 && psf->blockwidth)
|
||||
@ -184,7 +190,7 @@ avr_read_header (SF_PRIVATE *psf)
|
||||
static int
|
||||
avr_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
{ sf_count_t current ;
|
||||
int sign ;
|
||||
int sign, datalength ;
|
||||
|
||||
if (psf->pipeoffset > 0)
|
||||
return 0 ;
|
||||
@ -212,7 +218,9 @@ avr_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
if (psf->is_pipe == SF_FALSE)
|
||||
psf_fseek (psf, 0, SEEK_SET) ;
|
||||
|
||||
psf_binheader_writef (psf, "Emz22", TWOBIT_MARKER, make_size_t (8),
|
||||
datalength = (int) (psf->datalength & 0x7FFFFFFF) ;
|
||||
|
||||
psf_binheader_writef (psf, "Emz22", TWOBIT_MARKER, 8,
|
||||
psf->sf.channels == 2 ? 0xFFFF : 0, psf->bytewidth * 8) ;
|
||||
|
||||
sign = ((psf->sf.format & SF_FORMAT_SUBMASK) == SF_FORMAT_PCM_U8) ? 0 : 0xFFFF ;
|
||||
@ -220,7 +228,7 @@ avr_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
psf_binheader_writef (psf, "E222", sign, 0, 0xFFFF) ;
|
||||
psf_binheader_writef (psf, "E4444", psf->sf.samplerate, psf->sf.frames, 0, 0) ;
|
||||
|
||||
psf_binheader_writef (psf, "E222zz", 0, 0, 0, make_size_t (20), make_size_t (64)) ;
|
||||
psf_binheader_writef (psf, "E222zz", 0, 0, 0, 20, 64) ;
|
||||
|
||||
/* Header construction complete so write it out. */
|
||||
psf_fwrite (psf->header, psf->headindex, 1, psf) ;
|
||||
|
@ -98,6 +98,7 @@ static SF_FORMAT_INFO const major_formats [] =
|
||||
{
|
||||
{ SF_FORMAT_AIFF, "AIFF (Apple/SGI)", "aiff" },
|
||||
{ SF_FORMAT_AU, "AU (Sun/NeXT)", "au" },
|
||||
{ SF_FORMAT_AVR, "AVR (Audio Visual Research)", "avr" },
|
||||
{ SF_FORMAT_HTK, "HTK (HMM Tool Kit)", "htk" },
|
||||
{ SF_FORMAT_SVX, "IFF (Amiga IFF/SVX8/SV16)", "iff" },
|
||||
{ SF_FORMAT_MAT4, "MAT4 (GNU Octave 2.0 / Matlab 4.2)", "mat" },
|
||||
|
@ -506,6 +506,7 @@ int psf_ferror (SF_PRIVATE *psf) ;
|
||||
int aiff_open (SF_PRIVATE *psf) ;
|
||||
int au_open (SF_PRIVATE *psf) ;
|
||||
int au_nh_open (SF_PRIVATE *psf) ; /* Headerless version of AU. */
|
||||
int avr_open (SF_PRIVATE *psf) ;
|
||||
int htk_open (SF_PRIVATE *psf) ;
|
||||
int ircam_open (SF_PRIVATE *psf) ;
|
||||
int mat4_open (SF_PRIVATE *psf) ;
|
||||
|
@ -661,6 +661,16 @@ sf_format_check (const SF_INFO *info)
|
||||
return 1 ;
|
||||
break ;
|
||||
|
||||
case SF_FORMAT_AVR :
|
||||
/* SDS is strictly big endian. */
|
||||
if (endian == SF_ENDIAN_LITTLE || endian == SF_ENDIAN_CPU)
|
||||
return 0 ;
|
||||
if (info->channels < 1 || info->channels > 2)
|
||||
return 0 ;
|
||||
if (subformat == SF_FORMAT_PCM_U8 || subformat == SF_FORMAT_PCM_S8 || subformat == SF_FORMAT_PCM_16)
|
||||
return 1 ;
|
||||
break ;
|
||||
|
||||
/*-
|
||||
case SF_FORMAT_SD2 :
|
||||
/+* SD2 is strictly big endian. *+/
|
||||
@ -2034,6 +2044,9 @@ guess_file_type (SF_PRIVATE *psf, const char *filename)
|
||||
if (buffer [0] == MAKE_MARKER ('a', 'j', 'k', 'g'))
|
||||
return 0 /*-SF_FORMAT_SHN-*/ ;
|
||||
|
||||
if (buffer [0] == MAKE_MARKER ('2', 'B', 'I', 'T'))
|
||||
return SF_FORMAT_AVR ;
|
||||
|
||||
if (OS_IS_MACOSX && (format = macos_guess_file_type (psf, filename)) != 0)
|
||||
return format ;
|
||||
|
||||
@ -2366,6 +2379,11 @@ psf_open_file (SF_PRIVATE *psf, int mode, SF_INFO *sfinfo)
|
||||
case SF_FORMAT_REX2 :
|
||||
error = rx2_open (psf) ;
|
||||
break ;
|
||||
|
||||
case SF_FORMAT_AVR :
|
||||
error = avr_open (psf) ;
|
||||
break ;
|
||||
|
||||
/* Lite remove end */
|
||||
|
||||
default :
|
||||
|
@ -68,6 +68,7 @@ enum
|
||||
SF_FORMAT_XI = 0x0F0000, /* Fasttracker 2 Extended Instrument */
|
||||
SF_FORMAT_HTK = 0x100000, /* HMM Tool Kit format */
|
||||
SF_FORMAT_SDS = 0x110000, /* Midi Sample Dump Standard */
|
||||
SF_FORMAT_AVR = 0x120000, /* Audio Visual Research */
|
||||
|
||||
/* Subtypes from here on. */
|
||||
|
||||
|
@ -128,8 +128,9 @@ benchmark.c: benchmark.def benchmark.tpl
|
||||
#===============================================================================
|
||||
|
||||
check: generic-tests wav-tests aiff-tests au-tests raw-tests paf-tests \
|
||||
svx-tests nist-tests ircam-tests voc-tests w64-tests mat4-tests \
|
||||
mat5-tests pvf-tests xi-tests htk-tests sds-tests stdio-tests
|
||||
svx-tests nist-tests ircam-tests voc-tests w64-tests mat4-tests \
|
||||
mat5-tests pvf-tests xi-tests htk-tests avr-tests sds-tests \
|
||||
stdio-tests
|
||||
|
||||
generic-tests : error_test$(EXEEXT) ulaw_test$(EXEEXT) alaw_test$(EXEEXT) command_test$(EXEEXT) floating_point_test$(EXEEXT) pcm_test$(EXEEXT)
|
||||
uname -a
|
||||
@ -293,6 +294,13 @@ htk-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT)
|
||||
@echo " `./sfversion$(EXEEXT)` passed tests on HTK files."
|
||||
@echo "----------------------------------------------------------------------"
|
||||
|
||||
avr-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT)
|
||||
./write_read_test$(EXEEXT) avr
|
||||
./misc_test$(EXEEXT) avr
|
||||
@echo "----------------------------------------------------------------------"
|
||||
@echo " `./sfversion$(EXEEXT)` passed tests on AVR files."
|
||||
@echo "----------------------------------------------------------------------"
|
||||
|
||||
sds-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT)
|
||||
./write_read_test$(EXEEXT) sds
|
||||
./misc_test$(EXEEXT) sds
|
||||
|
@ -176,6 +176,14 @@ main (int argc, char *argv [])
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "avr"))
|
||||
{ update_header_test ("header.avr", SF_FORMAT_AVR) ;
|
||||
zero_data_test ("zerolen.avr", SF_FORMAT_AVR) ;
|
||||
filesystem_full_test (SF_FORMAT_AVR) ;
|
||||
permission_test ("readonly.avr", SF_FORMAT_AVR) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "sds"))
|
||||
{ update_header_test ("header.sds", SF_FORMAT_SDS) ;
|
||||
zero_data_test ("zerolen.sds", SF_FORMAT_SDS) ;
|
||||
|
@ -62,6 +62,7 @@ main (int argc, char **argv)
|
||||
printf (" wav - test WAV file functions (little endian)\n") ;
|
||||
printf (" aiff - test AIFF file functions (big endian)\n") ;
|
||||
printf (" au - test AU file functions\n") ;
|
||||
printf (" avr - test AVR file functions\n") ;
|
||||
printf (" raw - test RAW header-less PCM file functions\n") ;
|
||||
printf (" paf - test PAF file functions\n") ;
|
||||
printf (" svx - test 8SVX/16SV file functions\n") ;
|
||||
@ -235,6 +236,13 @@ main (int argc, char **argv)
|
||||
{ pcm_test_short ("short.htk", SF_FORMAT_HTK | SF_FORMAT_PCM_16, SF_FALSE) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "avr"))
|
||||
{ pcm_test_char ("char_u8.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
||||
pcm_test_char ("char_s8.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
||||
pcm_test_short ("short.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_16, SF_FALSE) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
/* Lite remove end */
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "w64"))
|
||||
|
Loading…
Reference in New Issue
Block a user