Mercurial > audlegacy-plugins
annotate src/filewriter/wav.c @ 1772:bbebc130f8f5
cue: Mk2, HAVE_CONFIG_H removal, etc
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Mon, 24 Sep 2007 11:22:01 -0500 |
parents | 0e160bafce1c |
children | fa9f85cebade |
rev | line source |
---|---|
984 | 1 /* FileWriter-Plugin |
2 * (C) copyright 2007 merging of Disk Writer and Out-Lame by Michael Färber | |
3 * | |
4 * Original Out-Lame-Plugin: | |
5 * (C) copyright 2002 Lars Siebold <khandha5@gmx.net> | |
6 * (C) copyright 2006-2007 porting to audacious by Yoshiki Yazawa <yaz@cc.rim.or.jp> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
21 */ | |
22 | |
23 #include "plugins.h" | |
24 | |
25 static gint wav_open(void); | |
26 static void wav_write(void *ptr, gint length); | |
27 static void wav_close(void); | |
28 static gint wav_free(void); | |
29 static gint wav_playing(void); | |
30 static gint wav_get_written_time(void); | |
31 | |
32 FileWriter wav_plugin = | |
33 { | |
34 NULL, | |
35 NULL, | |
36 wav_open, | |
37 wav_write, | |
38 wav_close, | |
39 wav_free, | |
40 wav_playing, | |
41 wav_get_written_time | |
42 }; | |
43 | |
44 | |
45 struct wavhead | |
46 { | |
47 guint32 main_chunk; | |
48 guint32 length; | |
49 guint32 chunk_type; | |
50 guint32 sub_chunk; | |
51 guint32 sc_len; | |
52 guint16 format; | |
53 guint16 modus; | |
54 guint32 sample_fq; | |
55 guint32 byte_p_sec; | |
56 guint16 byte_p_spl; | |
57 guint16 bit_p_spl; | |
58 guint32 data_chunk; | |
59 guint32 data_length; | |
60 }; | |
61 static struct wavhead header; | |
62 | |
63 static gint wav_open(void) | |
64 { | |
65 memcpy(&header.main_chunk, "RIFF", 4); | |
66 header.length = GUINT32_TO_LE(0); | |
67 memcpy(&header.chunk_type, "WAVE", 4); | |
68 memcpy(&header.sub_chunk, "fmt ", 4); | |
69 header.sc_len = GUINT32_TO_LE(16); | |
70 header.format = GUINT16_TO_LE(1); | |
71 header.modus = GUINT16_TO_LE(input.channels); | |
72 header.sample_fq = GUINT32_TO_LE(input.frequency); | |
73 if (input.format == FMT_U8 || input.format == FMT_S8) | |
74 header.bit_p_spl = GUINT16_TO_LE(8); | |
75 else | |
76 header.bit_p_spl = GUINT16_TO_LE(16); | |
77 header.byte_p_sec = GUINT32_TO_LE(input.frequency * header.modus * (GUINT16_FROM_LE(header.bit_p_spl) / 8)); | |
78 header.byte_p_spl = GUINT16_TO_LE((GUINT16_FROM_LE(header.bit_p_spl) / (8 / input.channels))); | |
79 memcpy(&header.data_chunk, "data", 4); | |
80 header.data_length = GUINT32_TO_LE(0); | |
81 vfs_fwrite(&header, sizeof (struct wavhead), 1, output_file); | |
82 | |
83 return 1; | |
84 } | |
85 | |
86 static void wav_write(void *ptr, gint length) | |
87 { | |
88 written += vfs_fwrite(ptr, 1, length, output_file); | |
89 } | |
90 | |
91 static void wav_close(void) | |
92 { | |
93 if (output_file) | |
94 { | |
95 header.length = GUINT32_TO_LE(written + sizeof (struct wavhead) - 8); | |
96 | |
97 header.data_length = GUINT32_TO_LE(written); | |
98 vfs_fseek(output_file, 0, SEEK_SET); | |
99 vfs_fwrite(&header, sizeof (struct wavhead), 1, output_file); | |
100 } | |
101 } | |
102 | |
103 static gint wav_free(void) | |
104 { | |
105 return 1000000; | |
106 } | |
107 | |
108 static gint wav_playing(void) | |
109 { | |
110 return 0; | |
111 } | |
112 | |
113 static gint wav_get_written_time(void) | |
114 { | |
115 if (header.byte_p_sec != 0) | |
1269
0e160bafce1c
- adapt filewriter for file:// scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
984
diff
changeset
|
116 return (gint) ((written * 1000) / header.byte_p_sec + offset); |
984 | 117 return 0; |
118 } |