annotate src/filewriter/vorbis.c @ 1569:25ea2127eefa

filewriter: fix symbol collisions
author William Pitcock <nenolod@atheme.org>
date Sun, 02 Sep 2007 22:01:45 -0500
parents 1b52e7eacd4c
children d158ce84fda7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
1 /* FileWriter Vorbis Plugin
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
2 * Copyright (c) 2007 William Pitcock <nenolod@sacredspiral.co.uk>
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
3 *
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
4 * Partially derived from Og(g)re - Ogg-Output-Plugin:
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
5 * Copyright (c) 2002 Lars Siebold <khandha5@gmx.net>
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
6 *
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
10 * (at your option) any later version.
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
11 *
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
16 *
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
20 */
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
21
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
22 #include "plugins.h"
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
23 #include <vorbis/vorbisenc.h>
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
24 #include <stdlib.h>
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
25
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
26 static void vorbis_init(void);
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
27 static void vorbis_configure(void);
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
28 static gint vorbis_open(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
29 static void vorbis_write(gpointer data, gint length);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
30 static void vorbis_close(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
31 static gint vorbis_free(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
32 static gint vorbis_playing(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
33 static gint vorbis_get_written_time(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
34
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
35 FileWriter vorbis_plugin =
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
36 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
37 vorbis_init,
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
38 vorbis_configure,
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
39 vorbis_open,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
40 vorbis_write,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
41 vorbis_close,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
42 vorbis_free,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
43 vorbis_playing,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
44 vorbis_get_written_time
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
45 };
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
46
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
47 static float v_base_quality = 0.5;
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
48
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
49 static ogg_stream_state os;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
50 static ogg_page og;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
51 static ogg_packet op;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
52
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
53 static vorbis_dsp_state vd;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
54 static vorbis_block vb;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
55 static vorbis_info vi;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
56 static vorbis_comment vc;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
57
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
58 static float **encbuffer;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
59 static guint64 olen = 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
60
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
61 static void vorbis_init(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
62 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
63 ConfigDb *db = bmp_cfg_db_open();
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
64
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
65 bmp_cfg_db_get_float(db, "filewriter_vorbis", "base_quality", &v_base_quality);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
66
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
67 bmp_cfg_db_close(db);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
68 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
69
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
70 static gint vorbis_open(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
71 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
72 gint result;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
73 ogg_packet header;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
74 ogg_packet header_comm;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
75 ogg_packet header_code;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
76
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
77 vorbis_init();
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
78
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
79 written = 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
80 olen = 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
81
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
82 vorbis_info_init(&vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
83 vorbis_comment_init(&vc);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
84
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
85 if (tuple)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
86 {
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
87 const gchar *scratch;
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
88
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
89 if ((scratch = tuple_get_string(tuple, "title")))
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
90 vorbis_comment_add_tag(&vc, "title", (gchar *) scratch);
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
91 if ((scratch = tuple_get_string(tuple, "artist")))
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
92 vorbis_comment_add_tag(&vc, "artist", (gchar *) scratch);
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
93 if ((scratch = tuple_get_string(tuple, "album")))
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
94 vorbis_comment_add_tag(&vc, "album", (gchar *) scratch);
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
95 if ((scratch = tuple_get_string(tuple, "genre")))
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
96 vorbis_comment_add_tag(&vc, "genre", (gchar *) scratch);
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
97 if ((scratch = tuple_get_string(tuple, "date")))
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
98 vorbis_comment_add_tag(&vc, "date", (gchar *) scratch);
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
99 if ((scratch = tuple_get_string(tuple, "comment")))
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
100 vorbis_comment_add_tag(&vc, "comment", (gchar *) scratch);
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
101
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
102 if (tuple_get_int(tuple, "track-number"))
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
103 {
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
104 gchar *tmp = g_strdup_printf("%d", tuple_get_int(tuple, "track-number"));
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
105 vorbis_comment_add_tag(&vc, "tracknumber", tmp);
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
106 g_free(tmp);
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
107 }
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
108
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
109 if (tuple_get_int(tuple, "year"))
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
110 {
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
111 gchar *tmp = g_strdup_printf("%d", tuple_get_int(tuple, "year"));
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
112 vorbis_comment_add_tag(&vc, "year", tmp);
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
113 g_free(tmp);
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
114 }
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
115 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
116
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
117 if ((result = vorbis_encode_init_vbr(&vi, (long)input.channels, (long)input.frequency, v_base_quality)) != 0)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
118 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
119 vorbis_info_clear(&vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
120 return 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
121 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
122
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
123 vorbis_analysis_init(&vd, &vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
124 vorbis_block_init(&vd, &vb);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
125
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
126 srand(time(NULL));
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
127 ogg_stream_init(&os, rand());
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
128
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
129 vorbis_analysis_headerout(&vd, &vc, &header, &header_comm, &header_code);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
130
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
131 ogg_stream_packetin(&os, &header);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
132 ogg_stream_packetin(&os, &header_comm);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
133 ogg_stream_packetin(&os, &header_code);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
134
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
135 while((result = ogg_stream_flush(&os, &og)))
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
136 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
137 if (result == 0)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
138 break;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
139
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
140 written += vfs_fwrite(og.header, 1, og.header_len, output_file);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
141 written += vfs_fwrite(og.body, 1, og.body_len, output_file);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
142 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
143
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
144 return 1;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
145 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
146
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
147 static void vorbis_write(gpointer data, gint length)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
148 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
149 int i;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
150 int result;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
151 short int *tmpdata;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
152
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
153 /* ask vorbisenc for a buffer to fill with pcm data */
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
154 encbuffer = vorbis_analysis_buffer(&vd, length);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
155 tmpdata = data;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
156
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
157 /*
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
158 * deinterleave the audio signal, 32768.0 is the highest peak level allowed
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
159 * in a 16-bit PCM signal.
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
160 */
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
161 if (input.channels == 1)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
162 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
163 for (i = 0; i < (length / 2); i++)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
164 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
165 encbuffer[0][i] = tmpdata[i] / 32768.0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
166 encbuffer[1][i] = tmpdata[i] / 32768.0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
167 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
168 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
169 else
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
170 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
171 for (i = 0; i < (length / 4); i++)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
172 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
173 encbuffer[0][i] = tmpdata[2 * i] / 32768.0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
174 encbuffer[1][i] = tmpdata[2 * i + 1] / 32768.0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
175 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
176 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
177
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
178 vorbis_analysis_wrote(&vd, i);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
179
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
180 while(vorbis_analysis_blockout(&vd, &vb) == 1)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
181 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
182 vorbis_analysis(&vb, &op);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
183 vorbis_bitrate_addblock(&vb);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
184
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
185 while (vorbis_bitrate_flushpacket(&vd, &op))
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
186 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
187 ogg_stream_packetin(&os, &op);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
188
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
189 while ((result = ogg_stream_pageout(&os, &og)))
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
190 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
191 if (result == 0)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
192 break;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
193
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
194 written += vfs_fwrite(og.header, 1, og.header_len, output_file);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
195 written += vfs_fwrite(og.body, 1, og.body_len, output_file);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
196 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
197 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
198 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
199
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
200 olen += length;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
201 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
202
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
203 static void vorbis_close(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
204 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
205 ogg_stream_clear(&os);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
206
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
207 vorbis_block_clear(&vb);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
208 vorbis_dsp_clear(&vd);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
209 vorbis_info_clear(&vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
210 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
211
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
212 static gint vorbis_free(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
213 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
214 return 1000000;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
215 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
216
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
217 static gint vorbis_playing(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
218 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
219 return 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
220 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
221
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
222 static gint vorbis_get_written_time(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
223 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
224 if (input.frequency && input.channels)
1269
0e160bafce1c - adapt filewriter for file:// scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1004
diff changeset
225 return (gint) ((olen * 1000) / (input.frequency * 2 * input.channels) + offset);
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
226
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
227 return 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
228 }
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
229
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
230 /* configuration stuff */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
231 static GtkWidget *configure_win = NULL;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
232 static GtkWidget *quality_frame, *quality_vbox, *quality_hbox1, *quality_spin, *quality_label;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
233 static GtkObject *quality_adj;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
234
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
235 static void quality_change(GtkAdjustment *adjustment, gpointer user_data)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
236 {
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
237 if (gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON(quality_spin)))
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
238 v_base_quality = gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON(quality_spin)) / 10;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
239 else
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
240 v_base_quality = 0.0;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
241 }
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
242
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
243 static void configure_ok_cb(gpointer data)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
244 {
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
245 ConfigDb *db = bmp_cfg_db_open();
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
246
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
247 bmp_cfg_db_set_float(db, "filewrite_vorbis", "base_quality", v_base_quality);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
248
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
249 bmp_cfg_db_close(db);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
250
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
251 gtk_widget_hide(configure_win);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
252 }
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
253
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
254 static void vorbis_configure(void)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
255 {
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
256 GtkWidget *vbox, *bbox;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
257 GtkWidget *button;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
258
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
259 if (configure_win == NULL)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
260 {
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
261 configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
262 g_signal_connect(G_OBJECT(configure_win), "destroy", G_CALLBACK(gtk_widget_destroyed), NULL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
263
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
264 gtk_window_set_title(GTK_WINDOW(configure_win), _("Vorbis Encoder Configuration"));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
265 gtk_container_set_border_width(GTK_CONTAINER(configure_win), 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
266
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
267 vbox = gtk_vbox_new(FALSE, 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
268 gtk_container_add(GTK_CONTAINER(configure_win), vbox);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
269
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
270 /* quality options */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
271 quality_frame = gtk_frame_new(_("Quality"));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
272 gtk_container_set_border_width(GTK_CONTAINER(quality_frame), 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
273 gtk_box_pack_start(GTK_BOX(vbox), quality_frame, FALSE, FALSE, 2);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
274
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
275 quality_vbox = gtk_vbox_new(FALSE, 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
276 gtk_container_set_border_width(GTK_CONTAINER(quality_vbox), 10);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
277 gtk_container_add(GTK_CONTAINER(quality_frame), quality_vbox);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
278
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
279 /* quality option: vbr level */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
280 quality_hbox1 = gtk_hbox_new(FALSE, 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
281 gtk_container_set_border_width(GTK_CONTAINER(quality_hbox1), 10);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
282 gtk_container_add(GTK_CONTAINER(quality_vbox), quality_hbox1);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
283
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
284 quality_label = gtk_label_new(_("Quality level (0 - 10):"));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
285 gtk_misc_set_alignment(GTK_MISC(quality_label), 0, 0.5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
286 gtk_box_pack_start(GTK_BOX(quality_hbox1), quality_label, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
287
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
288 quality_adj = gtk_adjustment_new(5, 0, 10, 0.1, 1, 1);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
289 quality_spin = gtk_spin_button_new(GTK_ADJUSTMENT(quality_adj), 1, 2);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
290 gtk_box_pack_start(GTK_BOX(quality_hbox1), quality_spin, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
291 g_signal_connect(G_OBJECT(quality_adj), "value-changed", G_CALLBACK(quality_change), NULL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
292
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
293 gtk_spin_button_set_value(GTK_SPIN_BUTTON(quality_spin), (v_base_quality * 10));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
294
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
295 /* buttons */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
296 bbox = gtk_hbutton_box_new();
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
297 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
298 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
299 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
300
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
301 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
302 g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK(gtk_widget_hide), GTK_OBJECT(configure_win));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
303 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
304
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
305 button = gtk_button_new_from_stock(GTK_STOCK_OK);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
306 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(configure_ok_cb), NULL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
307 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
308 gtk_widget_grab_default(button);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
309 }
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
310
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
311 gtk_widget_show_all(configure_win);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
312 }