annotate src/filewriter/vorbis.c @ 3163:26a2c237ef53

alsa-ng: Destroy the ringbuffer when the plugin closes.
author William Pitcock <nenolod@atheme.org>
date Thu, 14 May 2009 21:08:03 -0500
parents dcd8d93ba781
children
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
2835
f1b6f1b2cdb3 fixed FSF address
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2775
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
986
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
2766
6d08e3120615 make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2124
diff changeset
29 static void vorbis_init(write_output_callback write_output_func);
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);
2774
f1f7ee810de8 add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2766
diff changeset
33 static void vorbis_flush(void);
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
34 static void vorbis_close(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
35 static gint vorbis_free(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
36 static gint vorbis_playing(void);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
37 static gint vorbis_get_written_time(void);
2766
6d08e3120615 make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2124
diff changeset
38 static gint (*write_output)(void *ptr, gint length);
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
39
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
40 FileWriter vorbis_plugin =
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
41 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
42 vorbis_init,
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
43 vorbis_configure,
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
44 vorbis_open,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
45 vorbis_write,
2774
f1f7ee810de8 add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2766
diff changeset
46 vorbis_flush,
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
47 vorbis_close,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
48 vorbis_free,
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
49 vorbis_playing,
2873
31d6c44ffef2 most of encoder backends require GINT16_NE;
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2835
diff changeset
50 vorbis_get_written_time,
31d6c44ffef2 most of encoder backends require GINT16_NE;
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2835
diff changeset
51 FMT_S16_NE
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
52 };
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
53
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
54 static float v_base_quality = 0.5;
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
55
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
56 static ogg_stream_state os;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
57 static ogg_page og;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
58 static ogg_packet op;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
59
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
60 static vorbis_dsp_state vd;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
61 static vorbis_block vb;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
62 static vorbis_info vi;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
63 static vorbis_comment vc;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
64
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
65 static float **encbuffer;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
66 static guint64 olen = 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
67
2766
6d08e3120615 make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2124
diff changeset
68 static void vorbis_init(write_output_callback write_output_func)
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
69 {
2124
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1978
diff changeset
70 ConfigDb *db = aud_cfg_db_open();
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
71
2124
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1978
diff changeset
72 aud_cfg_db_get_float(db, "filewriter_vorbis", "base_quality", &v_base_quality);
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
73
2124
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1978
diff changeset
74 aud_cfg_db_close(db);
2766
6d08e3120615 make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2124
diff changeset
75
6d08e3120615 make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2124
diff changeset
76 if (write_output_func)
6d08e3120615 make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2124
diff changeset
77 write_output=write_output_func;
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
78 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
79
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
80 static gint vorbis_open(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
81 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
82 gint result;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
83 ogg_packet header;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
84 ogg_packet header_comm;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
85 ogg_packet header_code;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
86
2766
6d08e3120615 make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2124
diff changeset
87 vorbis_init(NULL);
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
88
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
89 olen = 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
90
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
91 vorbis_info_init(&vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
92 vorbis_comment_init(&vc);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
93
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
94 if (tuple)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
95 {
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
96 const gchar *scratch;
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1441
diff changeset
97 gchar tmpstr[32];
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1441
diff changeset
98 gint scrint;
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
99
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_TITLE, NULL)))
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
101 vorbis_comment_add_tag(&vc, "title", (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_ARTIST, NULL)))
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
103 vorbis_comment_add_tag(&vc, "artist", (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_ALBUM, NULL)))
1441
1b52e7eacd4c filewriter: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1269
diff changeset
105 vorbis_comment_add_tag(&vc, "album", (gchar *) scratch);
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
106 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
107 vorbis_comment_add_tag(&vc, "genre", (gchar *) scratch);
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
108 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
109 vorbis_comment_add_tag(&vc, "date", (gchar *) scratch);
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
110 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
111 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
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_TRACK_NUMBER, 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, "tracknumber", tmpstr);
989
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
117 }
84bef123b22e [svn] - provide full metadata from the file's tuple when performing the transcode
nenolod
parents: 988
diff changeset
118
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1911
diff changeset
119 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
120 {
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1441
diff changeset
121 g_snprintf(tmpstr, sizeof(tmpstr), "%d", scrint);
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1441
diff changeset
122 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
123 }
986
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 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
127 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
128 vorbis_info_clear(&vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
129 return 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
130 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
131
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
132 vorbis_analysis_init(&vd, &vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
133 vorbis_block_init(&vd, &vb);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
134
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
135 srand(time(NULL));
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
136 ogg_stream_init(&os, rand());
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
137
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
138 vorbis_analysis_headerout(&vd, &vc, &header, &header_comm, &header_code);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
139
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
140 ogg_stream_packetin(&os, &header);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
141 ogg_stream_packetin(&os, &header_comm);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
142 ogg_stream_packetin(&os, &header_code);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
143
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
144 while((result = ogg_stream_flush(&os, &og)))
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
145 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
146 if (result == 0)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
147 break;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
148
2950
dcd8d93ba781 - mp3: adapted to lame-3.98. now filewriter writes valid TLEN.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2873
diff changeset
149 write_output(og.header, og.header_len);
dcd8d93ba781 - mp3: adapted to lame-3.98. now filewriter writes valid TLEN.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2873
diff changeset
150 write_output(og.body, og.body_len);
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
151 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
152
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
153 return 1;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
154 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
155
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
156 static void vorbis_write(gpointer data, gint length)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
157 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
158 int i;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
159 int result;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
160 short int *tmpdata;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
161
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
162 /* ask vorbisenc for a buffer to fill with pcm data */
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
163 encbuffer = vorbis_analysis_buffer(&vd, length);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
164 tmpdata = data;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
165
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
166 /*
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
167 * deinterleave the audio signal, 32768.0 is the highest peak level allowed
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
168 * in a 16-bit PCM signal.
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
169 */
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
170 if (input.channels == 1)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
171 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
172 for (i = 0; i < (length / 2); i++)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
173 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
174 encbuffer[0][i] = tmpdata[i] / 32768.0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
175 encbuffer[1][i] = tmpdata[i] / 32768.0;
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 else
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
179 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
180 for (i = 0; i < (length / 4); i++)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
181 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
182 encbuffer[0][i] = tmpdata[2 * i] / 32768.0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
183 encbuffer[1][i] = tmpdata[2 * i + 1] / 32768.0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
184 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
185 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
186
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
187 vorbis_analysis_wrote(&vd, i);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
188
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
189 while(vorbis_analysis_blockout(&vd, &vb) == 1)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
190 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
191 vorbis_analysis(&vb, &op);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
192 vorbis_bitrate_addblock(&vb);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
193
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
194 while (vorbis_bitrate_flushpacket(&vd, &op))
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
195 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
196 ogg_stream_packetin(&os, &op);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
197
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
198 while ((result = ogg_stream_pageout(&os, &og)))
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
199 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
200 if (result == 0)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
201 break;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
202
2950
dcd8d93ba781 - mp3: adapted to lame-3.98. now filewriter writes valid TLEN.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2873
diff changeset
203 write_output(og.header, og.header_len);
dcd8d93ba781 - mp3: adapted to lame-3.98. now filewriter writes valid TLEN.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2873
diff changeset
204 write_output(og.body, og.body_len);
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
205 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
206 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
207 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
208
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
209 olen += length;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
210 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
211
2774
f1f7ee810de8 add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2766
diff changeset
212 static void vorbis_flush(void)
f1f7ee810de8 add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2766
diff changeset
213 {
f1f7ee810de8 add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2766
diff changeset
214 //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: 2766
diff changeset
215 }
f1f7ee810de8 add metadata to stream + flush() should do a real flush at least with mp3
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2766
diff changeset
216
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
217 static void vorbis_close(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
218 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
219 ogg_stream_clear(&os);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
220
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
221 vorbis_block_clear(&vb);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
222 vorbis_dsp_clear(&vd);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
223 vorbis_info_clear(&vi);
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
224 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
225
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
226 static gint vorbis_free(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
227 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
228 return 1000000;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
229 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
230
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
231 static gint vorbis_playing(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
232 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
233 return 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
234 }
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
235
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
236 static gint vorbis_get_written_time(void)
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
237 {
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
238 if (input.frequency && input.channels)
1269
0e160bafce1c - adapt filewriter for file:// scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1004
diff changeset
239 return (gint) ((olen * 1000) / (input.frequency * 2 * input.channels) + offset);
986
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
240
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
241 return 0;
5523559a1eac [svn] - add Vorbis output mode
nenolod
parents:
diff changeset
242 }
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
243
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
244 /* configuration stuff */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
245 static GtkWidget *configure_win = NULL;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
246 static GtkWidget *quality_frame, *quality_vbox, *quality_hbox1, *quality_spin, *quality_label;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
247 static GtkObject *quality_adj;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
248
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
249 static void quality_change(GtkAdjustment *adjustment, gpointer user_data)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
250 {
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
251 if (gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON(quality_spin)))
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
252 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
253 else
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
254 v_base_quality = 0.0;
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 configure_ok_cb(gpointer data)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
258 {
2124
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1978
diff changeset
259 ConfigDb *db = aud_cfg_db_open();
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
260
2124
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1978
diff changeset
261 aud_cfg_db_set_float(db, "filewrite_vorbis", "base_quality", v_base_quality);
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
262
2124
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1978
diff changeset
263 aud_cfg_db_close(db);
988
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
264
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
265 gtk_widget_hide(configure_win);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
266 }
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
267
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
268 static void vorbis_configure(void)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
269 {
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
270 GtkWidget *vbox, *bbox;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
271 GtkWidget *button;
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
272
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
273 if (configure_win == NULL)
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
274 {
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
275 configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
276 g_signal_connect(G_OBJECT(configure_win), "destroy", G_CALLBACK(gtk_widget_destroyed), NULL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
277
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
278 gtk_window_set_title(GTK_WINDOW(configure_win), _("Vorbis Encoder Configuration"));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
279 gtk_container_set_border_width(GTK_CONTAINER(configure_win), 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
280
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
281 vbox = gtk_vbox_new(FALSE, 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
282 gtk_container_add(GTK_CONTAINER(configure_win), vbox);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
283
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
284 /* quality options */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
285 quality_frame = gtk_frame_new(_("Quality"));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
286 gtk_container_set_border_width(GTK_CONTAINER(quality_frame), 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
287 gtk_box_pack_start(GTK_BOX(vbox), quality_frame, FALSE, FALSE, 2);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
288
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
289 quality_vbox = gtk_vbox_new(FALSE, 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
290 gtk_container_set_border_width(GTK_CONTAINER(quality_vbox), 10);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
291 gtk_container_add(GTK_CONTAINER(quality_frame), quality_vbox);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
292
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
293 /* quality option: vbr level */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
294 quality_hbox1 = gtk_hbox_new(FALSE, 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
295 gtk_container_set_border_width(GTK_CONTAINER(quality_hbox1), 10);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
296 gtk_container_add(GTK_CONTAINER(quality_vbox), quality_hbox1);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
297
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
298 quality_label = gtk_label_new(_("Quality level (0 - 10):"));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
299 gtk_misc_set_alignment(GTK_MISC(quality_label), 0, 0.5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
300 gtk_box_pack_start(GTK_BOX(quality_hbox1), quality_label, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
301
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
302 quality_adj = gtk_adjustment_new(5, 0, 10, 0.1, 1, 1);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
303 quality_spin = gtk_spin_button_new(GTK_ADJUSTMENT(quality_adj), 1, 2);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
304 gtk_box_pack_start(GTK_BOX(quality_hbox1), quality_spin, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
305 g_signal_connect(G_OBJECT(quality_adj), "value-changed", G_CALLBACK(quality_change), NULL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
306
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
307 gtk_spin_button_set_value(GTK_SPIN_BUTTON(quality_spin), (v_base_quality * 10));
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
308
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
309 /* buttons */
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
310 bbox = gtk_hbutton_box_new();
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
311 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
312 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
313 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
314
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
315 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
316 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
317 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
318
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
319 button = gtk_button_new_from_stock(GTK_STOCK_OK);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
320 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(configure_ok_cb), NULL);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
321 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
322 gtk_widget_grab_default(button);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
323 }
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
324
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
325 gtk_widget_show_all(configure_win);
1d25b3513a17 [svn] - add configure interface
nenolod
parents: 986
diff changeset
326 }
1911
c123420debd7 Add missing #ifdef.
Jonathan Schleifer <js@h3c.de>
parents: 1687
diff changeset
327
c123420debd7 Add missing #ifdef.
Jonathan Schleifer <js@h3c.de>
parents: 1687
diff changeset
328 #endif