Lines Matching refs:bat
28 #include "bat-signal.h"
33 /* update chunk_fmt data to bat */
34 static int update_fmt_to_bat(struct bat *bat, struct chunk_fmt *fmt)
36 bat->channels = fmt->channels;
37 bat->rate = fmt->sample_rate;
38 bat->sample_size = fmt->sample_length / 8;
39 if (bat->sample_size > 4) {
40 fprintf(bat->err, _("Invalid format: sample size=%d\n"),
41 bat->sample_size);
44 bat->frame_size = fmt->blocks_align;
49 /* calculate frames and update to bat */
50 static int update_frames_to_bat(struct bat *bat, struct wav_chunk_header *header,
56 bat->frames = header->length / bat->frame_size;
57 if (!bat->local)
58 bat->frames /= 2;
63 static int read_chunk_fmt(struct bat *bat, char *file, FILE *fp, bool skip,
72 fprintf(bat->err, _("Read chunk fmt error: %s:%zd\n"),
81 fprintf(bat->err, _("Seek fmt header error: %s:%d\n"),
89 err = update_fmt_to_bat(bat, &chunk_fmt);
97 int read_wav_header(struct bat *bat, char *file, FILE *fp, bool skip)
108 fprintf(bat->err, _("Read header error: %s:%zd\n"), file, err);
113 fprintf(bat->err, _("%s is not a riff/wave file\n"), file);
121 fprintf(bat->err, _("Read chunk header error: "));
122 fprintf(bat->err, _("%s:%zd\n"), file, err);
129 err = read_chunk_fmt(bat, file, fp, skip,
139 err = update_frames_to_bat(bat, &chunk_header,
151 fprintf(bat->err, _("Fail to skip unknown"));
152 fprintf(bat->err, _(" chunk of %s:%d\n"),
162 void prepare_wav_info(struct wav_container *wav, struct bat *bat)
169 wav->format.channels = bat->channels;
170 wav->format.sample_rate = bat->rate;
171 wav->format.sample_length = bat->sample_size * 8;
172 wav->format.blocks_align = bat->channels * bat->sample_size;
173 wav->format.bytes_p_second = wav->format.blocks_align * bat->rate;
174 wav->chunk.length = bat->frames * bat->frame_size;
180 int write_wav_header(FILE *fp, struct wav_container *wav, struct bat *bat)
186 fprintf(bat->err, _("Write file error: header %d\n"), err);
191 fprintf(bat->err, _("Write file error: format %d\n"), err);
196 fprintf(bat->err, _("Write file error: chunk %d\n"), err);
204 int update_wav_header(struct bat *bat, FILE *fp, int bytes)
209 prepare_wav_info(&wav, bat);
214 err = write_wav_header(fp, &wav, bat);
226 int generate_input_data(struct bat *bat, void *buffer, int bytes, int frames)
231 if (bat->playback.file != NULL) {
236 err = fread((char *)buffer + load, 1, bytes - load, bat->fp);
238 if (feof(bat->fp)) {
239 fprintf(bat->log,
244 if (ferror(bat->fp)) {
245 fprintf(bat->err, _("Read file error"));
246 fprintf(bat->err, _(": %d\n"), err);
256 if ((bat->sinus_duration) && (load > bat->sinus_duration))
259 err = generate_sine_wave(bat, frames, buffer);