annotate src/filewriter/vorbis.c @ 1976:5fa26178eaef

s/tuple_/aud_tuple_/g
author William Pitcock <nenolod@atheme.org>
date Sun, 07 Oct 2007 00:22:59 -0500
parents c123420debd7
children fa9f85cebade
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"
1911
c123420debd7 Add missing #ifdef.
Jonathan Schleifer <js@h3c.de>
parents: 1687
diff changeset
23
c123420debd7 Add missing #ifdef.
Jonathan Schleifer <js@h3c.de>
parents: 1687
diff changeset
24 #ifdef FILEWRITER_VORBIS
c123420debd7 Add missing #ifdef.
Jonathan Schleifer <js@h3c.de>
parents: 1687
diff changeset
25
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
26 #include <vorbis/vorbisenc.h>
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
27 #include <stdlib.h>
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
28
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
29 static void vorbis_init(void);
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
30 static void vorbis_configure(void);
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
31 static gint vorbis_open(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
32 static void vorbis_write(gpointer data, gint length);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
33 static void vorbis_close(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
34 static gint vorbis_free(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
35 static gint vorbis_playing(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
36 static gint vorbis_get_written_time(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
37
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
38 FileWriter vorbis_plugin =
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
39 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
40 vorbis_init,
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
41 vorbis_configure,
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
42 vorbis_open,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
43 vorbis_write,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
44 vorbis_close,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
45 vorbis_free,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
46 vorbis_playing,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
47 vorbis_get_written_time
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
48 };
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
49
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
50 static float v_base_quality = 0.5;
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
51
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
52 static ogg_stream_state os;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
53 static ogg_page og;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
54 static ogg_packet op;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
55
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
56 static vorbis_dsp_state vd;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
57 static vorbis_block vb;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
58 static vorbis_info vi;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
59 static vorbis_comment vc;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
60
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
61 static float **encbuffer;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
62 static guint64 olen = 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
63
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
64 static void vorbis_init(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
65 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
66 ConfigDb *db = bmp_cfg_db_open();
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
67
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
68 bmp_cfg_db_get_float(db, "filewriter_vorbis", "base_quality", &v_base_quality);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
69
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
70 bmp_cfg_db_close(db);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
71 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
72
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
73 static gint vorbis_open(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
74 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
75 gint result;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
76 ogg_packet header;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
77 ogg_packet header_comm;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
78 ogg_packet header_code;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
79
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
80 vorbis_init();
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
81
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
82 written = 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
83 olen = 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
84
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
85 vorbis_info_init(&vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
86 vorbis_comment_init(&vc);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
87
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
88 if (tuple)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
89 {
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
90 const gchar *scratch;
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1441
diff changeset
91 gchar tmpstr[32];
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1441
diff changeset
92 gint scrint;
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
93
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
94 if ((scratch = aud_tuple_get_string(tuple, FIELD_TITLE, NULL)))
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
95 vorbis_comment_add_tag(&vc, "title", (gchar *) scratch);
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
96 if ((scratch = aud_tuple_get_string(tuple, FIELD_ARTIST, NULL)))
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
97 vorbis_comment_add_tag(&vc, "artist", (gchar *) scratch);
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
98 if ((scratch = aud_tuple_get_string(tuple, FIELD_ALBUM, NULL)))
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
99 vorbis_comment_add_tag(&vc, "album", (gchar *) scratch);
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
100 if ((scratch = aud_tuple_get_string(tuple, FIELD_GENRE, NULL)))
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
101 vorbis_comment_add_tag(&vc, "genre", (gchar *) scratch);
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
102 if ((scratch = aud_tuple_get_string(tuple, FIELD_DATE, NULL)))
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
103 vorbis_comment_add_tag(&vc, "date", (gchar *) scratch);
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
104 if ((scratch = aud_tuple_get_string(tuple, FIELD_COMMENT, NULL)))
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
105 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
106
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
107 if ((scrint = aud_tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL)))
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
108 {
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1441
diff changeset
109 g_snprintf(tmpstr, sizeof(tmpstr), "%d", scrint);
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1441
diff changeset
110 vorbis_comment_add_tag(&vc, "tracknumber", tmpstr);
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
111 }
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
112
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
113 if ((scrint = aud_tuple_get_int(tuple, FIELD_YEAR, NULL)))
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
114 {
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1441
diff changeset
115 g_snprintf(tmpstr, sizeof(tmpstr), "%d", scrint);
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1441
diff changeset
116 vorbis_comment_add_tag(&vc, "year", tmpstr);
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
117 }
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
118 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
119
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
120 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
121 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
122 vorbis_info_clear(&vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
123 return 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
124 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
125
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
126 vorbis_analysis_init(&vd, &vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
127 vorbis_block_init(&vd, &vb);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
128
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
129 srand(time(NULL));
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
130 ogg_stream_init(&os, rand());
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
131
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
132 vorbis_analysis_headerout(&vd, &vc, &header, &header_comm, &header_code);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
133
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
134 ogg_stream_packetin(&os, &header);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
135 ogg_stream_packetin(&os, &header_comm);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
136 ogg_stream_packetin(&os, &header_code);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
137
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
138 while((result = ogg_stream_flush(&os, &og)))
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
139 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
140 if (result == 0)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
141 break;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
142
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
143 written += vfs_fwrite(og.header, 1, og.header_len, output_file);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
144 written += vfs_fwrite(og.body, 1, og.body_len, output_file);
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 return 1;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
148 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
149
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
150 static void vorbis_write(gpointer data, gint length)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
151 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
152 int i;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
153 int result;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
154 short int *tmpdata;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
155
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
156 /* ask vorbisenc for a buffer to fill with pcm data */
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
157 encbuffer = vorbis_analysis_buffer(&vd, length);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
158 tmpdata = data;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
159
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
160 /*
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
161 * deinterleave the audio signal, 32768.0 is the highest peak level allowed
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
162 * in a 16-bit PCM signal.
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
163 */
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
164 if (input.channels == 1)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
165 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
166 for (i = 0; i < (length / 2); i++)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
167 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
168 encbuffer[0][i] = tmpdata[i] / 32768.0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
169 encbuffer[1][i] = tmpdata[i] / 32768.0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
170 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
171 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
172 else
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
173 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
174 for (i = 0; i < (length / 4); i++)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
175 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
176 encbuffer[0][i] = tmpdata[2 * i] / 32768.0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
177 encbuffer[1][i] = tmpdata[2 * i + 1] / 32768.0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
178 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
179 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
180
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
181 vorbis_analysis_wrote(&vd, i);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
182
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
183 while(vorbis_analysis_blockout(&vd, &vb) == 1)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
184 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
185 vorbis_analysis(&vb, &op);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
186 vorbis_bitrate_addblock(&vb);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
187
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
188 while (vorbis_bitrate_flushpacket(&vd, &op))
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
189 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
190 ogg_stream_packetin(&os, &op);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
191
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
192 while ((result = ogg_stream_pageout(&os, &og)))
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
193 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
194 if (result == 0)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
195 break;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
196
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
197 written += vfs_fwrite(og.header, 1, og.header_len, output_file);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
198 written += vfs_fwrite(og.body, 1, og.body_len, output_file);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
199 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
200 }
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 olen += length;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
204 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
205
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
206 static void vorbis_close(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
207 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
208 ogg_stream_clear(&os);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
209
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
210 vorbis_block_clear(&vb);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
211 vorbis_dsp_clear(&vd);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
212 vorbis_info_clear(&vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
213 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
214
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
215 static gint vorbis_free(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
216 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
217 return 1000000;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
218 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
219
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
220 static gint vorbis_playing(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
221 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
222 return 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
223 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
224
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
225 static gint vorbis_get_written_time(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
226 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
227 if (input.frequency && input.channels)
1269
0e160bafce1c - adapt filewriter for file:// scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1004
diff changeset
228 return (gint) ((olen * 1000) / (input.frequency * 2 * input.channels) + offset);
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
229
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
230 return 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
231 }
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
232
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
233 /* configuration stuff */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
234 static GtkWidget *configure_win = NULL;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
235 static GtkWidget *quality_frame, *quality_vbox, *quality_hbox1, *quality_spin, *quality_label;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
236 static GtkObject *quality_adj;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
237
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
238 static void quality_change(GtkAdjustment *adjustment, gpointer user_data)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
239 {
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
240 if (gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON(quality_spin)))
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
241 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
242 else
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
243 v_base_quality = 0.0;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
244 }
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
245
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
246 static void configure_ok_cb(gpointer data)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
247 {
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
248 ConfigDb *db = bmp_cfg_db_open();
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
249
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
250 bmp_cfg_db_set_float(db, "filewrite_vorbis", "base_quality", v_base_quality);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
251
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
252 bmp_cfg_db_close(db);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
253
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
254 gtk_widget_hide(configure_win);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
255 }
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
256
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
257 static void vorbis_configure(void)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
258 {
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
259 GtkWidget *vbox, *bbox;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
260 GtkWidget *button;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
261
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
262 if (configure_win == NULL)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
263 {
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
264 configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
265 g_signal_connect(G_OBJECT(configure_win), "destroy", G_CALLBACK(gtk_widget_destroyed), NULL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
266
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
267 gtk_window_set_title(GTK_WINDOW(configure_win), _("Vorbis Encoder Configuration"));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
268 gtk_container_set_border_width(GTK_CONTAINER(configure_win), 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
269
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
270 vbox = gtk_vbox_new(FALSE, 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
271 gtk_container_add(GTK_CONTAINER(configure_win), vbox);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
272
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
273 /* quality options */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
274 quality_frame = gtk_frame_new(_("Quality"));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
275 gtk_container_set_border_width(GTK_CONTAINER(quality_frame), 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
276 gtk_box_pack_start(GTK_BOX(vbox), quality_frame, FALSE, FALSE, 2);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
277
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
278 quality_vbox = gtk_vbox_new(FALSE, 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
279 gtk_container_set_border_width(GTK_CONTAINER(quality_vbox), 10);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
280 gtk_container_add(GTK_CONTAINER(quality_frame), quality_vbox);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
281
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
282 /* quality option: vbr level */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
283 quality_hbox1 = gtk_hbox_new(FALSE, 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
284 gtk_container_set_border_width(GTK_CONTAINER(quality_hbox1), 10);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
285 gtk_container_add(GTK_CONTAINER(quality_vbox), quality_hbox1);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
286
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
287 quality_label = gtk_label_new(_("Quality level (0 - 10):"));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
288 gtk_misc_set_alignment(GTK_MISC(quality_label), 0, 0.5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
289 gtk_box_pack_start(GTK_BOX(quality_hbox1), quality_label, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
290
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
291 quality_adj = gtk_adjustment_new(5, 0, 10, 0.1, 1, 1);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
292 quality_spin = gtk_spin_button_new(GTK_ADJUSTMENT(quality_adj), 1, 2);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
293 gtk_box_pack_start(GTK_BOX(quality_hbox1), quality_spin, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
294 g_signal_connect(G_OBJECT(quality_adj), "value-changed", G_CALLBACK(quality_change), NULL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
295
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
296 gtk_spin_button_set_value(GTK_SPIN_BUTTON(quality_spin), (v_base_quality * 10));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
297
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
298 /* buttons */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
299 bbox = gtk_hbutton_box_new();
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
300 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
301 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
302 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
303
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
304 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
305 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
306 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
307
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
308 button = gtk_button_new_from_stock(GTK_STOCK_OK);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
309 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(configure_ok_cb), NULL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
310 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
311 gtk_widget_grab_default(button);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
312 }
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
313
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
314 gtk_widget_show_all(configure_win);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
315 }
1911
c123420debd7 Add missing #ifdef.
Jonathan Schleifer <js@h3c.de>
parents: 1687
diff changeset
316
c123420debd7 Add missing #ifdef.
Jonathan Schleifer <js@h3c.de>
parents: 1687
diff changeset
317 #endif