summaryrefslogtreecommitdiffstats
path: root/polyp
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-09-16 00:04:29 +0000
committerLennart Poettering <lennart@poettering.net>2005-09-16 00:04:29 +0000
commit48b2a87ed8ef8a40602f4c139432513a49eecf35 (patch)
treecb47fbab9a640a32a50540a349e3ebee9f5a5bd0 /polyp
parent668f3cdcbc02ebb5074a31016f1766bfe4992240 (diff)
add pa_sound_file_too_big_to_cache()
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@355 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp')
-rw-r--r--polyp/sound-file.c37
-rw-r--r--polyp/sound-file.h2
2 files changed, 38 insertions, 1 deletions
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