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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
984
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
1 /* FileWriter-Plugin
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
2 * (C) copyright 2007 merging of Disk Writer and Out-Lame by Michael Färber
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
3 *
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
4 * Original Out-Lame-Plugin:
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
5 * (C) copyright 2002 Lars Siebold <khandha5@gmx.net>
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
6 * (C) copyright 2006-2007 porting to audacious by Yoshiki Yazawa <yaz@cc.rim.or.jp>
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
7 *
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
11 * (at your option) any later version.
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
12 *
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
16 * GNU General Public License for more details.
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
17 *
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
2835
f1b6f1b2cdb3 fixed FSF address
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2774
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
984
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
21 */
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
22
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
23 #include "plugins.h"
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
24
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
25 static gint wav_open(void);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
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
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
28 static void wav_close(void);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
29 static gint wav_free(void);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
30 static gint wav_playing(void);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
31 static gint wav_get_written_time(void);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
32
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
33 FileWriter wav_plugin =
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
34 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
35 NULL,
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
36 NULL,
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
37 wav_open,
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
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
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
40 wav_close,
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
41 wav_free,
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
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
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
45 };
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
46
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
47
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
48 struct wavhead
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
49 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
50 guint32 main_chunk;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
51 guint32 length;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
52 guint32 chunk_type;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
53 guint32 sub_chunk;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
54 guint32 sc_len;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
55 guint16 format;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
56 guint16 modus;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
57 guint32 sample_fq;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
58 guint32 byte_p_sec;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
59 guint16 byte_p_spl;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
60 guint16 bit_p_spl;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
61 guint32 data_chunk;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
62 guint32 data_length;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
63 };
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
64 static struct wavhead header;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
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
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
68 static gint wav_open(void)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
69 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
70 memcpy(&header.main_chunk, "RIFF", 4);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
71 header.length = GUINT32_TO_LE(0);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
72 memcpy(&header.chunk_type, "WAVE", 4);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
73 memcpy(&header.sub_chunk, "fmt ", 4);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
74 header.sc_len = GUINT32_TO_LE(16);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
75 header.format = GUINT16_TO_LE(1);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
76 header.modus = GUINT16_TO_LE(input.channels);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
77 header.sample_fq = GUINT32_TO_LE(input.frequency);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
78 if (input.format == FMT_U8 || input.format == FMT_S8)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
79 header.bit_p_spl = GUINT16_TO_LE(8);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
80 else
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
81 header.bit_p_spl = GUINT16_TO_LE(16);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
82 header.byte_p_sec = GUINT32_TO_LE(input.frequency * header.modus * (GUINT16_FROM_LE(header.bit_p_spl) / 8));
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
83 header.byte_p_spl = GUINT16_TO_LE((GUINT16_FROM_LE(header.bit_p_spl) / (8 / input.channels)));
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
84 memcpy(&header.data_chunk, "data", 4);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
85 header.data_length = GUINT32_TO_LE(0);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1269
diff changeset
86 aud_vfs_fwrite(&header, sizeof (struct wavhead), 1, output_file);
984
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
87
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
88 return 1;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
89 }
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
90
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
91 static void wav_write(void *ptr, gint length)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
92 {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1269
diff changeset
93 written += aud_vfs_fwrite(ptr, 1, length, output_file);
984
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
94 }
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
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
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
101 static void wav_close(void)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
102 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
103 if (output_file)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
104 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
105 header.length = GUINT32_TO_LE(written + sizeof (struct wavhead) - 8);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
106
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
107 header.data_length = GUINT32_TO_LE(written);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1269
diff changeset
108 aud_vfs_fseek(output_file, 0, SEEK_SET);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1269
diff changeset
109 aud_vfs_fwrite(&header, sizeof (struct wavhead), 1, output_file);
984
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
110 }
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
111 }
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
112
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
113 static gint wav_free(void)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
114 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
115 return 1000000;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
116 }
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
117
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
118 static gint wav_playing(void)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
119 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
120 return 0;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
121 }
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
122
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
123 static gint wav_get_written_time(void)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
124 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
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
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
127 return 0;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
128 }