]>
code.delx.au - pulseaudio/blob - polyp/sound-file.c
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #include "sound-file.h"
35 #define MAX_FILE_SIZE (1024*1024)
37 int pa_sound_file_load(const char *fname
, struct pa_sample_spec
*ss
, struct pa_memchunk
*chunk
, struct pa_memblock_stat
*s
) {
42 assert(fname
&& ss
&& chunk
);
44 memset(&sfinfo
, 0, sizeof(sfinfo
));
46 chunk
->memblock
= NULL
;
47 chunk
->index
= chunk
->length
= 0;
49 if (!(sf
= sf_open(fname
, SFM_READ
, &sfinfo
))) {
50 pa_log(__FILE__
": Failed to open file %s\n", fname
);
54 ss
->format
= PA_SAMPLE_FLOAT32
;
55 ss
->rate
= sfinfo
.samplerate
;
56 ss
->channels
= sfinfo
.channels
;
58 if (!pa_sample_spec_valid(ss
)) {
59 pa_log(__FILE__
": Unsupported sample format in file %s\n", fname
);
63 if ((l
= pa_frame_size(ss
)*sfinfo
.frames
) > MAX_FILE_SIZE
) {
64 pa_log(__FILE__
": File to large\n");
68 chunk
->memblock
= pa_memblock_new(l
, s
);
69 assert(chunk
->memblock
);
73 if (sf_readf_float(sf
, chunk
->memblock
->data
, sfinfo
.frames
) != sfinfo
.frames
) {
74 pa_log(__FILE__
": Premature file end\n");
85 if (ret
!= 0 && chunk
->memblock
)
86 pa_memblock_unref(chunk
->memblock
);