summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-05-17 14:55:17 +0000
committerLennart Poettering <lennart@poettering.net>2006-05-17 14:55:17 +0000
commitb47b257a91441dbfb2c716d71f8008ad4f2db1d5 (patch)
treeb9eca9195c222b52c5d3391f6d61f2b7032c8f02
parente6695538d721941132db2183e40f142b9e52076e (diff)
support loading ULAW/ALAW files into ULAW/ALAW memchunks
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@900 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r--src/polypcore/sound-file.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/src/polypcore/sound-file.c b/src/polypcore/sound-file.c
index f0378009..bd0cf596 100644
--- a/src/polypcore/sound-file.c
+++ b/src/polypcore/sound-file.c
@@ -39,7 +39,7 @@ int pa_sound_file_load(const char *fname, pa_sample_spec *ss, pa_channel_map *ma
SF_INFO sfinfo;
int ret = -1;
size_t l;
- sf_count_t (*readf_function)(SNDFILE *sndfile, void *ptr, sf_count_t frames);
+ sf_count_t (*readf_function)(SNDFILE *sndfile, void *ptr, sf_count_t frames) = NULL;
assert(fname && ss && chunk);
chunk->memblock = NULL;
@@ -53,17 +53,27 @@ int pa_sound_file_load(const char *fname, pa_sample_spec *ss, pa_channel_map *ma
}
switch (sfinfo.format & SF_FORMAT_SUBMASK) {
+ case SF_FORMAT_PCM_16:
+ case SF_FORMAT_PCM_U8:
+ case SF_FORMAT_PCM_S8:
+ ss->format = PA_SAMPLE_S16NE;
+ readf_function = (sf_count_t (*)(SNDFILE *sndfile, void *ptr, sf_count_t frames)) sf_readf_short;
+ break;
+
+ case SF_FORMAT_ULAW:
+ ss->format = PA_SAMPLE_ULAW;
+ break;
+
+ case SF_FORMAT_ALAW:
+ ss->format = PA_SAMPLE_ALAW;
+ break;
+
case SF_FORMAT_FLOAT:
case SF_FORMAT_DOUBLE:
- /* Only float and double need a special case. */
+ default:
ss->format = PA_SAMPLE_FLOAT32NE;
readf_function = (sf_count_t (*)(SNDFILE *sndfile, void *ptr, sf_count_t frames)) sf_readf_float;
break;
- default:
- /* Everything else is cleanly converted to signed 16 bit. */
- ss->format = PA_SAMPLE_S16NE;
- readf_function = (sf_count_t (*)(SNDFILE *sndfile, void *ptr, sf_count_t frames)) sf_readf_short;
- break;
}
ss->rate = sfinfo.samplerate;
@@ -87,11 +97,12 @@ int pa_sound_file_load(const char *fname, pa_sample_spec *ss, pa_channel_map *ma
chunk->index = 0;
chunk->length = l;
- if (readf_function(sf, chunk->memblock->data, sfinfo.frames) != sfinfo.frames) {
+ if ((readf_function && readf_function(sf, chunk->memblock->data, sfinfo.frames) != sfinfo.frames) ||
+ (!readf_function && sf_read_raw(sf, chunk->memblock->data, l) != l)) {
pa_log(__FILE__": Premature file end");
goto finish;
}
-
+
ret = 0;
finish:
@@ -119,14 +130,24 @@ int pa_sound_file_too_big_to_cache(const char *fname) {
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;
+ case SF_FORMAT_PCM_16:
+ case SF_FORMAT_PCM_U8:
+ case SF_FORMAT_PCM_S8:
+ ss.format = PA_SAMPLE_S16NE;
+ break;
+
+ case SF_FORMAT_ULAW:
+ ss.format = PA_SAMPLE_ULAW;
break;
+
+ case SF_FORMAT_ALAW:
+ ss.format = PA_SAMPLE_ALAW;
+ break;
+
+ case SF_FORMAT_DOUBLE:
+ case SF_FORMAT_FLOAT:
default:
- /* Everything else is cleanly converted to signed 16 bit. */
- ss.format = PA_SAMPLE_S16NE;
+ ss.format = PA_SAMPLE_FLOAT32NE;
break;
}