]>
code.delx.au - pulseaudio/blob - polyp/sound-file.c
6 #include "sound-file.h"
9 #define MAX_FILE_SIZE (1024*1024)
11 int pa_sound_file_load(const char *fname
, struct pa_sample_spec
*ss
, struct pa_memchunk
*chunk
, struct pa_memblock_stat
*s
) {
16 assert(fname
&& ss
&& chunk
);
18 memset(&sfinfo
, 0, sizeof(sfinfo
));
20 chunk
->memblock
= NULL
;
21 chunk
->index
= chunk
->length
= 0;
23 if (!(sf
= sf_open(fname
, SFM_READ
, &sfinfo
))) {
24 fprintf(stderr
, __FILE__
": Failed to open file %s\n", fname
);
28 ss
->format
= PA_SAMPLE_FLOAT32
;
29 ss
->rate
= sfinfo
.samplerate
;
30 ss
->channels
= sfinfo
.channels
;
32 if (!pa_sample_spec_valid(ss
)) {
33 fprintf(stderr
, __FILE__
": Unsupported sample format in file %s\n", fname
);
37 if ((l
= pa_frame_size(ss
)*sfinfo
.frames
) > MAX_FILE_SIZE
) {
38 fprintf(stderr
, __FILE__
": File to large\n");
42 chunk
->memblock
= pa_memblock_new(l
, s
);
43 assert(chunk
->memblock
);
47 if (sf_readf_float(sf
, chunk
->memblock
->data
, sfinfo
.frames
) != sfinfo
.frames
) {
48 fprintf(stderr
, __FILE__
": Premature file end\n");
59 if (ret
!= 0 && chunk
->memblock
)
60 pa_memblock_unref(chunk
->memblock
);