From 049d2a9a337331295b4a2d4ad13061bc73536236 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Sun, 2 Jul 2023 21:36:34 +1200 Subject: Initial commit --- src/c_asndfile.c | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 src/c_asndfile.c (limited to 'src/c_asndfile.c') diff --git a/src/c_asndfile.c b/src/c_asndfile.c new file mode 100644 index 0000000..116fa0c --- /dev/null +++ b/src/c_asndfile.c @@ -0,0 +1,189 @@ + + +// Programmed by Jedidiah Barber +// Released into the public domain + + +#include +#include "c_asndfile.h" + + + +const int sf_false = SF_FALSE; +const int sf_true = SF_TRUE; + +const int sfm_read = SFM_READ; +const int sfm_write = SFM_WRITE; +const int sfm_rdwr = SFM_RDWR; + +const int sf_seek_set = SF_SEEK_SET; +const int sf_seek_cur = SF_SEEK_CUR; +const int sf_seek_end = SF_SEEK_END; + +const int sf_str_title = SF_STR_TITLE; +const int sf_str_copyright = SF_STR_COPYRIGHT; +const int sf_str_software = SF_STR_SOFTWARE; +const int sf_str_artist = SF_STR_ARTIST; +const int sf_str_comment = SF_STR_COMMENT; +const int sf_str_date = SF_STR_DATE; +const int sf_str_album = SF_STR_ALBUM; +const int sf_str_license = SF_STR_LICENSE; +const int sf_str_tracknumber = SF_STR_TRACKNUMBER; +const int sf_str_genre = SF_STR_GENRE; + +const int format_wav = SF_FORMAT_WAV; +const int format_aiff = SF_FORMAT_AIFF; +const int format_au = SF_FORMAT_AU; +const int format_raw = SF_FORMAT_RAW; +const int format_paf = SF_FORMAT_PAF; +const int format_svx = SF_FORMAT_SVX; +const int format_nist = SF_FORMAT_NIST; +const int format_voc = SF_FORMAT_VOC; +const int format_ircam = SF_FORMAT_IRCAM; +const int format_w64 = SF_FORMAT_W64; +const int format_mat4 = SF_FORMAT_MAT4; +const int format_mat5 = SF_FORMAT_MAT5; +const int format_pvf = SF_FORMAT_PVF; +const int format_xi = SF_FORMAT_XI; +const int format_htk = SF_FORMAT_HTK; +const int format_sds = SF_FORMAT_SDS; +const int format_avr = SF_FORMAT_AVR; +const int format_wavex = SF_FORMAT_WAVEX; +const int format_sd2 = SF_FORMAT_SD2; +const int format_flac = SF_FORMAT_FLAC; +const int format_caf = SF_FORMAT_CAF; +const int format_wve = SF_FORMAT_WVE; +const int format_ogg = SF_FORMAT_OGG; +const int format_mpc2k = SF_FORMAT_MPC2K; +const int format_rf64 = SF_FORMAT_RF64; +const int format_mpeg = SF_FORMAT_MPEG; + +const int format_pcm_s8 = SF_FORMAT_PCM_S8; +const int format_pcm_16 = SF_FORMAT_PCM_16; +const int format_pcm_24 = SF_FORMAT_PCM_24; +const int format_pcm_32 = SF_FORMAT_PCM_32; +const int format_pcm_u8 = SF_FORMAT_PCM_U8; +const int format_float = SF_FORMAT_FLOAT; +const int format_double = SF_FORMAT_DOUBLE; +const int format_ulaw = SF_FORMAT_ULAW; +const int format_alaw = SF_FORMAT_ALAW; +const int format_ima_adpcm = SF_FORMAT_IMA_ADPCM; +const int format_ms_adpcm = SF_FORMAT_MS_ADPCM; +const int format_gsm610 = SF_FORMAT_GSM610; +const int format_vox_adpcm = SF_FORMAT_VOX_ADPCM; +const int format_nms_adpcm_16 = SF_FORMAT_NMS_ADPCM_16; +const int format_nms_adpcm_24 = SF_FORMAT_NMS_ADPCM_24; +const int format_nms_adpcm_32 = SF_FORMAT_NMS_ADPCM_32; +const int format_g721_32 = SF_FORMAT_G721_32; +const int format_g723_24 = SF_FORMAT_G723_24; +const int format_g723_40 = SF_FORMAT_G723_40; +const int format_dwvw_12 = SF_FORMAT_DWVW_12; +const int format_dwvw_16 = SF_FORMAT_DWVW_16; +const int format_dwvw_24 = SF_FORMAT_DWVW_24; +const int format_dwvw_n = SF_FORMAT_DWVW_N; +const int format_dpcm_8 = SF_FORMAT_DPCM_8; +const int format_dpcm_16 = SF_FORMAT_DPCM_16; +const int format_vorbis = SF_FORMAT_VORBIS; +const int format_opus = SF_FORMAT_OPUS; +const int format_alac_16 = SF_FORMAT_ALAC_16; +const int format_alac_20 = SF_FORMAT_ALAC_20; +const int format_alac_24 = SF_FORMAT_ALAC_24; +const int format_alac_32 = SF_FORMAT_ALAC_32; +const int format_mpeg_layer_i = SF_FORMAT_MPEG_LAYER_I; +const int format_mpeg_layer_ii = SF_FORMAT_MPEG_LAYER_II; +const int format_mpeg_layer_iii = SF_FORMAT_MPEG_LAYER_III; + +const int endian_file = SF_ENDIAN_FILE; +const int endian_little = SF_ENDIAN_LITTLE; +const int endian_big = SF_ENDIAN_BIG; +const int endian_cpu = SF_ENDIAN_CPU; + +const int err_no_error = SF_ERR_NO_ERROR; +const int err_unrecognised_format = SF_ERR_UNRECOGNISED_FORMAT; +const int err_system = SF_ERR_SYSTEM; +const int err_malformed_file = SF_ERR_MALFORMED_FILE; +const int err_unsupported_encoding = SF_ERR_UNSUPPORTED_ENCODING; + + + +SNDFILE * asf_open(const char * path, int mode, Asf_Info * sfinfo) { + SF_INFO actual; + + actual.frames = (sf_count_t)sfinfo->frames; + actual.samplerate = sfinfo->samplerate; + actual.channels = sfinfo->channels; + actual.format = sfinfo->major & sfinfo->minor & sfinfo->endian; + actual.sections = sfinfo->sections; + actual.seekable = sfinfo->seekable; + + SNDFILE * result = sf_open(path, mode, &actual); + if (result == NULL) { return NULL; } + + sfinfo->frames = (long long)actual.frames; + sfinfo->samplerate = actual.samplerate; + sfinfo->channels = actual.channels; + sfinfo->major = actual.format & SF_FORMAT_TYPEMASK; + sfinfo->minor = actual.format & SF_FORMAT_SUBMASK; + sfinfo->endian = actual.format & SF_FORMAT_ENDMASK; + sfinfo->sections = actual.sections; + sfinfo->seekable = actual.seekable; + + return result; +} + + +int asf_format_check(Asf_Info * sfinfo) { + SF_INFO actual; + + actual.frames = (sf_count_t)sfinfo->frames; + actual.samplerate = sfinfo->samplerate; + actual.channels = sfinfo->channels; + actual.format = sfinfo->major & sfinfo->minor & sfinfo->endian; + actual.sections = sfinfo->sections; + actual.seekable = sfinfo->seekable; + + return sf_format_check (&actual); +} + + +int64_t asf_seek(SNDFILE * sndfile, int64_t frames, int whence) { + return (int64_t) sf_seek(sndfile, (sf_count_t) frames, whence); +} + + +int64_t asf_readf_short(SNDFILE * sndfile, short *ptr, int64_t items) { + return (int64_t) sf_readf_short(sndfile, ptr, (sf_count_t) items); +} +int64_t asf_readf_int(SNDFILE * sndfile, int * ptr, int64_t items) { + return (int64_t) sf_readf_int(sndfile, ptr, (sf_count_t) items); +} +int64_t asf_readf_float(SNDFILE * sndfile, float * ptr, int64_t items) { + return (int64_t) sf_readf_float(sndfile, ptr, (sf_count_t) items); +} +int64_t asf_readf_double(SNDFILE * sndfile, double * ptr, int64_t items) { + return (int64_t) sf_readf_double(sndfile, ptr, (sf_count_t) items); +} + + +int64_t asf_writef_short(SNDFILE * sndfile, short * ptr, int64_t items) { + return (int64_t) sf_writef_short(sndfile, ptr, (sf_count_t) items); +} +int64_t asf_writef_int(SNDFILE * sndfile, int * ptr, int64_t items) { + return (int64_t) sf_writef_int(sndfile, ptr, (sf_count_t) items); +} +int64_t asf_writef_float(SNDFILE * sndfile, float * ptr, int64_t items) { + return (int64_t) sf_writef_float(sndfile, ptr, (sf_count_t) items); +} +int64_t asf_writef_double(SNDFILE * sndfile, double * ptr, int64_t items) { + return (int64_t) sf_writef_double(sndfile, ptr, (sf_count_t) items); +} + + +int64_t asf_read_raw(SNDFILE * sndfile, void * ptr, int64_t bytes) { + return (int64_t) sf_read_raw(sndfile, ptr, (sf_count_t) bytes); +} +int64_t asf_write_raw(SNDFILE * sndfile, void * ptr, int64_t bytes) { + return (int64_t) sf_write_raw(sndfile, ptr, (sf_count_t) bytes); +} + + -- cgit