diff --git a/ChangeLog b/ChangeLog index b9f2b726..d4ec62cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-01-05 Erik de Castro Lopo + + * src/aiff.c src/wav.c src/common.h + Refactor common code into src/common.h. + 2012-01-04 Erik de Castro Lopo * programs/sndfile-cmp.c diff --git a/src/aiff.c b/src/aiff.c index fb9b6335..6e7ca2a5 100644 --- a/src/aiff.c +++ b/src/aiff.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 1999-2011 Erik de Castro Lopo +** Copyright (C) 1999-2012 Erik de Castro Lopo ** Copyright (C) 2005 David Viens ** ** This program is free software; you can redistribute it and/or modify @@ -1750,20 +1750,9 @@ aiff_read_chanmap (SF_PRIVATE * psf, unsigned dword) /*============================================================================== */ -static int -aiff_id_to_marker (const SF_CHUNK_INFO * chunk_info) -{ const unsigned char * cptr ; - - if (chunk_info->id_size != 4) - return 0 ; - - cptr = (const unsigned char *) chunk_info->id ; - return (cptr [3] << 24) + (cptr [2] << 16) + (cptr [1] << 8) + cptr [0] ; -} /* aiff_id_to_marker */ - static int aiff_set_chunk (SF_PRIVATE *psf, const SF_CHUNK_INFO * chunk_info) -{ int marker = aiff_id_to_marker (chunk_info) ; +{ int marker = fourcc_to_marker (chunk_info) ; return psf_save_write_chunk (&psf->wchunks, marker, chunk_info) ; } /* aiff_set_chunk */ @@ -1771,7 +1760,7 @@ aiff_set_chunk (SF_PRIVATE *psf, const SF_CHUNK_INFO * chunk_info) static int aiff_get_chunk_size (SF_PRIVATE *psf, SF_CHUNK_INFO * chunk_info) -{ int indx, marker = aiff_id_to_marker (chunk_info) ; +{ int indx, marker = fourcc_to_marker (chunk_info) ; if ((indx = psf_find_read_chunk (&psf->rchunks, marker)) < 0) return SFE_UNKNOWN_CHUNK ; @@ -1783,7 +1772,7 @@ aiff_get_chunk_size (SF_PRIVATE *psf, SF_CHUNK_INFO * chunk_info) static int aiff_get_chunk_data (SF_PRIVATE *psf, SF_CHUNK_INFO * chunk_info) -{ int indx, marker = aiff_id_to_marker (chunk_info) ; +{ int indx, marker = fourcc_to_marker (chunk_info) ; sf_count_t pos ; if ((indx = psf_find_read_chunk (&psf->rchunks, marker)) < 0) diff --git a/src/common.h b/src/common.h index 3b3cc543..1fb0578a 100644 --- a/src/common.h +++ b/src/common.h @@ -1,5 +1,5 @@ /* -** Copyright (C) 1999-2011 Erik de Castro Lopo +** Copyright (C) 1999-2012 Erik de Castro Lopo ** ** 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 @@ -866,6 +866,17 @@ int psf_save_write_chunk (WRITE_CHUNKS * pchk, int64_t marker, const SF_CHUNK_I int psf_find_read_chunk (READ_CHUNKS * pchk, int64_t marker) ; int psf_find_write_chunk (WRITE_CHUNKS * pchk, int64_t marker) ; +static inline int +fourcc_to_marker (const SF_CHUNK_INFO * chunk_info) +{ const unsigned char * cptr ; + + if (chunk_info->id_size != 4) + return 0 ; + + cptr = (const unsigned char *) chunk_info->id ; + return (cptr [3] << 24) + (cptr [2] << 16) + (cptr [1] << 8) + cptr [0] ; +} /* fourcc_to_marker */ + /*------------------------------------------------------------------------------------ ** Functions that work like OpenBSD's strlcpy/strlcat to replace strncpy/strncat. ** diff --git a/src/wav.c b/src/wav.c index 55bc6f12..a5676544 100644 --- a/src/wav.c +++ b/src/wav.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 1999-2011 Erik de Castro Lopo +** Copyright (C) 1999-2012 Erik de Castro Lopo ** Copyright (C) 2004-2005 David Viens ** ** This program is free software; you can redistribute it and/or modify @@ -1829,20 +1829,9 @@ exif_subchunk_parse (SF_PRIVATE *psf, unsigned int length) /*============================================================================== */ -static int -wav_id_to_marker (const SF_CHUNK_INFO * chunk_info) -{ const unsigned char * cptr ; - - if (chunk_info->id_size != 4) - return 0 ; - - cptr = (const unsigned char *) chunk_info->id ; - return (cptr [3] << 24) + (cptr [2] << 16) + (cptr [1] << 8) + cptr [0] ; -} /* wav_id_to_marker */ - static int wav_set_chunk (SF_PRIVATE *psf, const SF_CHUNK_INFO * chunk_info) -{ int marker = wav_id_to_marker (chunk_info) ; +{ int marker = fourcc_to_marker (chunk_info) ; return psf_save_write_chunk (&psf->wchunks, marker, chunk_info) ; } /* wav_set_chunk */ @@ -1850,7 +1839,7 @@ wav_set_chunk (SF_PRIVATE *psf, const SF_CHUNK_INFO * chunk_info) static int wav_get_chunk_size (SF_PRIVATE *psf, SF_CHUNK_INFO * chunk_info) -{ int indx, marker = wav_id_to_marker (chunk_info) ; +{ int indx, marker = fourcc_to_marker (chunk_info) ; if ((indx = psf_find_read_chunk (&psf->rchunks, marker)) < 0) return SFE_UNKNOWN_CHUNK ; @@ -1862,7 +1851,7 @@ wav_get_chunk_size (SF_PRIVATE *psf, SF_CHUNK_INFO * chunk_info) static int wav_get_chunk_data (SF_PRIVATE *psf, SF_CHUNK_INFO * chunk_info) -{ int indx, marker = wav_id_to_marker (chunk_info) ; +{ int indx, marker = fourcc_to_marker (chunk_info) ; sf_count_t pos ; if ((indx = psf_find_read_chunk (&psf->rchunks, marker)) < 0)