FFmpeg: libavfilter/asrc_flite.c Source File
Go to the documentation of this file. 1 /*
2 * Copyright (c) 2012 Stefano Sabatini
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * flite voice synth source
24 */
25
26 #include <flite/flite.h>
35
50
51 #define OFFSET(x) offsetof(FliteContext, x)
52 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
53
63 };
64
66
68
70
71 /* declare functions for all the supported voices */
72 #define DECLARE_REGISTER_VOICE_FN(name) \
73 cst_voice *register_cmu_us_## name(const char *); \
74 void unregister_cmu_us_## name(cst_voice *)
80
83 cst_voice * (*register_fn)(
const char *);
87 };
88
89 #define MAKE_VOICE_STRUCTURE(voice_name) { \
90 .name = #voice_name, \
91 .register_fn = register_cmu_us_ ## voice_name, \
92 .unregister_fn = unregister_cmu_us_ ## voice_name, \
93 }
100 };
101
103 {
105 for (
i = 0;
i < n;
i++)
108 }
109
111 {
113
116 if (!strcmp(entry->
name, voice_name)) {
127 "Could not register voice '%s'\n", voice_name);
129 }
130 *entry_ret = entry;
131 return 0;
132 }
133 }
134
138
140 }
141
143 {
146
150 }
151
154 if ((
ret = flite_init()) >= 0)
156 }
161 }
162
166
169 "Both text and textfile options set: only one must be specified\n");
171 }
172
174 uint8_t *textbuf;
175 size_t textbuf_size;
176
179 "The text file '%s' could not be read: %s\n",
182 }
183
187 }
188 memcpy(flite->
text, textbuf, textbuf_size);
189 flite->
text[textbuf_size] = 0;
191 }
192
195 "No speech text specified, specify the 'text' or 'textfile' option\n");
197 }
198
199 /* synth all the file data in block */
203 return 0;
204 }
205
207 {
209
215 }
217 }
218 delete_wave(flite->
wave);
220 }
221
223 {
226
231
233
241
242 return 0;
243 }
244
246 {
249
252
256 return 0;
257 }
258
260 {
264
265 if (!nb_samples)
267
269 if (!samplesref)
271
273 nb_samples * flite->
wave->num_channels * 2);
274 samplesref->
pts = flite->
pts;
277 flite->
pts += nb_samples;
280
282 }
283
285 {
290 },
291 };
292
302 .priv_class = &flite_class,
303 };
const AVFilter ff_asrc_flite
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
A list of supported channel layouts.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static const AVOption flite_options[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AVERROR_EOF
End of file.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define FILTER_QUERY_FUNC(func)
#define AV_LOG_VERBOSE
Detailed information.
const char * name
Filter name.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
struct voice_entry * voice_entry
A link between two filters.
AVFILTER_DEFINE_CLASS(flite)
cst_voice *(* register_fn)(const char *)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define MAKE_VOICE_STRUCTURE(voice_name)
static AVMutex flite_mutex
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
void * priv
private data for use by the filter
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
static void list_voices(void *log_ctx, const char *sep)
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Describe the class of an AVClass context structure.
static const AVFilterPad flite_outputs[]
static struct voice_entry voice_entries[]
static int query_formats(AVFilterContext *ctx)
Rational number (pair of numerator and denominator).
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
#define pthread_mutex_unlock(a)
void(* unregister_fn)(cst_voice *)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
An AVChannelLayout holds information about the channel layout of audio data.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int sample_rate
Sample rate of the audio data.
int format
agreed upon media format
#define AV_MUTEX_INITIALIZER
AVFilterContext * src
source filter
#define AVERROR_EXTERNAL
Generic error in an external library.
static int config_props(AVFilterLink *outlink)
#define AV_LOG_INFO
Standard information.
int sample_rate
samples per second
#define i(width, name, range_min, range_max)
@ AV_SAMPLE_FMT_S16
signed 16 bits
const char * name
Pad name.
static av_cold void uninit(AVFilterContext *ctx)
static av_cold int init(AVFilterContext *ctx)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
#define DECLARE_REGISTER_VOICE_FN(name)
#define FILTER_OUTPUTS(array)
static int select_voice(struct voice_entry **entry_ret, const char *voice_name, void *log_ctx)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
int frame_nb_samples
number of samples per frame
static int request_frame(AVFilterLink *outlink)
#define pthread_mutex_lock(a)
Generated on Wed Aug 24 2022 21:42:00 for FFmpeg by
doxygen
1.8.17