annotate src/filewriter/wav.c @ 2320:15aa13c91259

forgot new file
author Tomasz Mon <desowin@gmail.com>
date Tue, 15 Jan 2008 20:49:33 +0100
parents fa9f85cebade
children f1f7ee810de8
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
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
27 static void wav_close(void);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
28 static gint wav_free(void);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
29 static gint wav_playing(void);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
30 static gint wav_get_written_time(void);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
31
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
32 FileWriter wav_plugin =
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
33 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
34 NULL,
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 wav_open,
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
37 wav_write,
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
38 wav_close,
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
39 wav_free,
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
40 wav_playing,
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
41 wav_get_written_time
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
42 };
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
43
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
44
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
45 struct wavhead
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 guint32 main_chunk;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
48 guint32 length;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
49 guint32 chunk_type;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
50 guint32 sub_chunk;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
51 guint32 sc_len;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
52 guint16 format;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
53 guint16 modus;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
54 guint32 sample_fq;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
55 guint32 byte_p_sec;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
56 guint16 byte_p_spl;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
57 guint16 bit_p_spl;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
58 guint32 data_chunk;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
59 guint32 data_length;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
60 };
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
61 static struct wavhead header;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
62
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
63 static gint wav_open(void)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
64 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
65 memcpy(&header.main_chunk, "RIFF", 4);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
66 header.length = GUINT32_TO_LE(0);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
67 memcpy(&header.chunk_type, "WAVE", 4);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
68 memcpy(&header.sub_chunk, "fmt ", 4);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
69 header.sc_len = GUINT32_TO_LE(16);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
70 header.format = GUINT16_TO_LE(1);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
71 header.modus = GUINT16_TO_LE(input.channels);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
72 header.sample_fq = GUINT32_TO_LE(input.frequency);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
73 if (input.format == FMT_U8 || input.format == FMT_S8)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
74 header.bit_p_spl = GUINT16_TO_LE(8);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
75 else
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
76 header.bit_p_spl = GUINT16_TO_LE(16);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
77 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
78 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
79 memcpy(&header.data_chunk, "data", 4);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
80 header.data_length = GUINT32_TO_LE(0);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1269
diff changeset
81 aud_vfs_fwrite(&header, sizeof (struct wavhead), 1, output_file);
984
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
82
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
83 return 1;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
84 }
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
85
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
86 static void wav_write(void *ptr, gint length)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
87 {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1269
diff changeset
88 written += aud_vfs_fwrite(ptr, 1, length, output_file);
984
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_close(void)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
92 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
93 if (output_file)
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 header.length = GUINT32_TO_LE(written + sizeof (struct wavhead) - 8);
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
96
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
97 header.data_length = GUINT32_TO_LE(written);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1269
diff changeset
98 aud_vfs_fseek(output_file, 0, SEEK_SET);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1269
diff changeset
99 aud_vfs_fwrite(&header, sizeof (struct wavhead), 1, output_file);
984
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
100 }
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
101 }
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 static gint wav_free(void)
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 return 1000000;
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
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
108 static gint wav_playing(void)
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
109 {
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
110 return 0;
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_get_written_time(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 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
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
117 return 0;
df7b09989aee [svn] - We got a new plugin, captain!
mf0102
parents:
diff changeset
118 }