From 48b2a87ed8ef8a40602f4c139432513a49eecf35 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 16 Sep 2005 00:04:29 +0000 Subject: add pa_sound_file_too_big_to_cache() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@355 fefdeb5f-60dc-0310-8127-8f9354f1896f --- polyp/sound-file.c | 37 ++++++++++++++++++++++++++++++++++++- polyp/sound-file.h | 2 ++ 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'polyp') diff --git a/polyp/sound-file.c b/polyp/sound-file.c index f16d326a..326ddd8b 100644 --- a/polyp/sound-file.c +++ b/polyp/sound-file.c @@ -75,7 +75,7 @@ int pa_sound_file_load(const char *fname, struct pa_sample_spec *ss, struct pa_m } if ((l = pa_frame_size(ss)*sfinfo.frames) > MAX_FILE_SIZE) { - pa_log(__FILE__": File to large\n"); + pa_log(__FILE__": File too large\n"); goto finish; } @@ -102,3 +102,38 @@ finish: return ret; } + +int pa_sound_file_too_big_to_cache(const char *fname) { + SNDFILE*sf = NULL; + SF_INFO sfinfo; + struct pa_sample_spec ss; + + if (!(sf = sf_open(fname, SFM_READ, &sfinfo))) { + pa_log(__FILE__": Failed to open file %s\n", fname); + return 0; + } + + sf_close(sf); + + switch (sfinfo.format & SF_FORMAT_SUBMASK) { + case SF_FORMAT_FLOAT: + case SF_FORMAT_DOUBLE: + /* Only float and double need a special case. */ + ss.format = PA_SAMPLE_FLOAT32NE; + break; + default: + /* Everything else is cleanly converted to signed 16 bit. */ + ss.format = PA_SAMPLE_S16NE; + break; + } + + ss.rate = sfinfo.samplerate; + ss.channels = sfinfo.channels; + + if ((pa_frame_size(&ss) * sfinfo.frames) > MAX_FILE_SIZE) { + pa_log(__FILE__": File too large %s\n", fname); + return 1; + } + + return 0; +} diff --git a/polyp/sound-file.h b/polyp/sound-file.h index e5359853..855e6883 100644 --- a/polyp/sound-file.h +++ b/polyp/sound-file.h @@ -27,4 +27,6 @@ int pa_sound_file_load(const char *fname, struct pa_sample_spec *ss, struct pa_memchunk *chunk, struct pa_memblock_stat *s); +int pa_sound_file_too_big_to_cache(const char *fname); + #endif -- cgit