Mercurial > audlegacy-plugins
annotate src/filewriter/wav.c @ 2950:dcd8d93ba781
- mp3: adapted to lame-3.98. now filewriter writes valid TLEN.
- deleted unnecessary variable "written".
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 11 Oct 2008 02:02:41 +0900 |
parents | 31d6c44ffef2 |
children |
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 | |
2835 | 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
984 | 21 */ |
22 | |
23 #include "plugins.h" | |
24 | |
25 static gint wav_open(void); | |
26 static void wav_write(void *ptr, gint length); | |
2774
f1f7ee810de8
add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents:
1978
diff
changeset
|
27 static void wav_flush(void); |
984 | 28 static void wav_close(void); |
29 static gint wav_free(void); | |
30 static gint wav_playing(void); | |
31 static gint wav_get_written_time(void); | |
32 | |
33 FileWriter wav_plugin = | |
34 { | |
35 NULL, | |
36 NULL, | |
37 wav_open, | |
38 wav_write, | |
2774
f1f7ee810de8
add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents:
1978
diff
changeset
|
39 wav_flush, |
984 | 40 wav_close, |
41 wav_free, | |
42 wav_playing, | |
2873
31d6c44ffef2
most of encoder backends require GINT16_NE;
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2835
diff
changeset
|
43 wav_get_written_time, |
31d6c44ffef2
most of encoder backends require GINT16_NE;
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2835
diff
changeset
|
44 FMT_S16_LE |
984 | 45 }; |
46 | |
47 | |
48 struct wavhead | |
49 { | |
50 guint32 main_chunk; | |
51 guint32 length; | |
52 guint32 chunk_type; | |
53 guint32 sub_chunk; | |
54 guint32 sc_len; | |
55 guint16 format; | |
56 guint16 modus; | |
57 guint32 sample_fq; | |
58 guint32 byte_p_sec; | |
59 guint16 byte_p_spl; | |
60 guint16 bit_p_spl; | |
61 guint32 data_chunk; | |
62 guint32 data_length; | |
63 }; | |
64 static struct wavhead header; | |
65 | |
2950
dcd8d93ba781
- mp3: adapted to lame-3.98. now filewriter writes valid TLEN.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2873
diff
changeset
|
66 static guint64 written; |
dcd8d93ba781
- mp3: adapted to lame-3.98. now filewriter writes valid TLEN.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2873
diff
changeset
|
67 |
984 | 68 static gint wav_open(void) |
69 { | |
70 memcpy(&header.main_chunk, "RIFF", 4); | |
71 header.length = GUINT32_TO_LE(0); | |
72 memcpy(&header.chunk_type, "WAVE", 4); | |
73 memcpy(&header.sub_chunk, "fmt ", 4); | |
74 header.sc_len = GUINT32_TO_LE(16); | |
75 header.format = GUINT16_TO_LE(1); | |
76 header.modus = GUINT16_TO_LE(input.channels); | |
77 header.sample_fq = GUINT32_TO_LE(input.frequency); | |
78 if (input.format == FMT_U8 || input.format == FMT_S8) | |
79 header.bit_p_spl = GUINT16_TO_LE(8); | |
80 else | |
81 header.bit_p_spl = GUINT16_TO_LE(16); | |
82 header.byte_p_sec = GUINT32_TO_LE(input.frequency * header.modus * (GUINT16_FROM_LE(header.bit_p_spl) / 8)); | |
83 header.byte_p_spl = GUINT16_TO_LE((GUINT16_FROM_LE(header.bit_p_spl) / (8 / input.channels))); | |
84 memcpy(&header.data_chunk, "data", 4); | |
85 header.data_length = GUINT32_TO_LE(0); | |
1978 | 86 aud_vfs_fwrite(&header, sizeof (struct wavhead), 1, output_file); |
984 | 87 |
88 return 1; | |
89 } | |
90 | |
91 static void wav_write(void *ptr, gint length) | |
92 { | |
1978 | 93 written += aud_vfs_fwrite(ptr, 1, length, output_file); |
984 | 94 } |
95 | |
2774
f1f7ee810de8
add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents:
1978
diff
changeset
|
96 static void wav_flush(void) |
f1f7ee810de8
add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents:
1978
diff
changeset
|
97 { |
f1f7ee810de8
add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents:
1978
diff
changeset
|
98 //nothing to do here yet. --AOS |
f1f7ee810de8
add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents:
1978
diff
changeset
|
99 } |
f1f7ee810de8
add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents:
1978
diff
changeset
|
100 |
984 | 101 static void wav_close(void) |
102 { | |
103 if (output_file) | |
104 { | |
105 header.length = GUINT32_TO_LE(written + sizeof (struct wavhead) - 8); | |
106 | |
107 header.data_length = GUINT32_TO_LE(written); | |
1978 | 108 aud_vfs_fseek(output_file, 0, SEEK_SET); |
109 aud_vfs_fwrite(&header, sizeof (struct wavhead), 1, output_file); | |
984 | 110 } |
111 } | |
112 | |
113 static gint wav_free(void) | |
114 { | |
115 return 1000000; | |
116 } | |
117 | |
118 static gint wav_playing(void) | |
119 { | |
120 return 0; | |
121 } | |
122 | |
123 static gint wav_get_written_time(void) | |
124 { | |
125 if (header.byte_p_sec != 0) | |
1269
0e160bafce1c
- adapt filewriter for file:// scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
984
diff
changeset
|
126 return (gint) ((written * 1000) / header.byte_p_sec + offset); |
984 | 127 return 0; |
128 } |