1159b3361Sopenharmony_ci/*
2159b3361Sopenharmony_ci *      GTK plotting routines source file
3159b3361Sopenharmony_ci *
4159b3361Sopenharmony_ci *      Copyright (c) 1999 Mark Taylor
5159b3361Sopenharmony_ci *
6159b3361Sopenharmony_ci * This library is free software; you can redistribute it and/or
7159b3361Sopenharmony_ci * modify it under the terms of the GNU Library General Public
8159b3361Sopenharmony_ci * License as published by the Free Software Foundation; either
9159b3361Sopenharmony_ci * version 2 of the License, or (at your option) any later version.
10159b3361Sopenharmony_ci *
11159b3361Sopenharmony_ci * This library is distributed in the hope that it will be useful,
12159b3361Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
13159b3361Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14159b3361Sopenharmony_ci * Library General Public License for more details.
15159b3361Sopenharmony_ci *
16159b3361Sopenharmony_ci * You should have received a copy of the GNU Library General Public
17159b3361Sopenharmony_ci * License along with this library; if not, write to the
18159b3361Sopenharmony_ci * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19159b3361Sopenharmony_ci * Boston, MA 02111-1307, USA.
20159b3361Sopenharmony_ci */
21159b3361Sopenharmony_ci
22159b3361Sopenharmony_ci/* $Id$ */
23159b3361Sopenharmony_ci
24159b3361Sopenharmony_ci#ifdef HAVE_CONFIG_H
25159b3361Sopenharmony_ci# include <config.h>
26159b3361Sopenharmony_ci#endif
27159b3361Sopenharmony_ci
28159b3361Sopenharmony_ci#include <gtk/gtk.h>
29159b3361Sopenharmony_ci
30159b3361Sopenharmony_ci#include "main.h"
31159b3361Sopenharmony_ci#include "lame.h"
32159b3361Sopenharmony_ci#include "machine.h"
33159b3361Sopenharmony_ci#include "encoder.h"
34159b3361Sopenharmony_ci#include "lame-analysis.h"
35159b3361Sopenharmony_ci#include "get_audio.h"
36159b3361Sopenharmony_ci#include "gtkanal.h"
37159b3361Sopenharmony_ci#include "gpkplotting.h"
38159b3361Sopenharmony_ci#include "lame_global_flags.h"
39159b3361Sopenharmony_ci
40159b3361Sopenharmony_ci/* this file should be removed. The few data items accessed in 'gfc'
41159b3361Sopenharmony_ci   should be made accessable by writing a lame_set_variable() function */
42159b3361Sopenharmony_ci#include "util.h"
43159b3361Sopenharmony_ci
44159b3361Sopenharmony_ci#include "console.h"
45159b3361Sopenharmony_ci
46159b3361Sopenharmony_ci
47159b3361Sopenharmony_ci#ifdef _WIN32
48159b3361Sopenharmony_ci#  include <windows.h>
49159b3361Sopenharmony_ci#  define msleep(t) Sleep(t)
50159b3361Sopenharmony_ci#else
51159b3361Sopenharmony_ci#  include <unistd.h>
52159b3361Sopenharmony_ci#  define msleep(t) usleep((t) * 1000)
53159b3361Sopenharmony_ci#endif
54159b3361Sopenharmony_ci
55159b3361Sopenharmony_ci
56159b3361Sopenharmony_ci
57159b3361Sopenharmony_ci
58159b3361Sopenharmony_ci/*! Stringify \a x. */
59159b3361Sopenharmony_ci#define STR(x)   #x
60159b3361Sopenharmony_ci/*! Stringify \a x, perform macro expansion. */
61159b3361Sopenharmony_ci#define XSTR(x)  STR(x)
62159b3361Sopenharmony_ci
63159b3361Sopenharmony_ci#define MP3X_MAJOR_VERSION      0 /* Major version number */
64159b3361Sopenharmony_ci#define MP3X_MINOR_VERSION     82 /* Minor version number */
65159b3361Sopenharmony_ci#define MP3X_ALPHA_VERSION      0 /* Set number if this is an alpha version, otherwise zero */
66159b3361Sopenharmony_ci#define MP3X_BETA_VERSION       0 /* Set number if this is a beta version, otherwise zero */
67159b3361Sopenharmony_ci
68159b3361Sopenharmony_ci
69159b3361Sopenharmony_ciplotting_data *pinfo;
70159b3361Sopenharmony_ciplotting_data *pplot;
71159b3361Sopenharmony_ciplotting_data Pinfo[NUMPINFO];
72159b3361Sopenharmony_ci
73159b3361Sopenharmony_ci
74159b3361Sopenharmony_ci/* global variables for the state of the system */
75159b3361Sopenharmony_cistatic gint idle_keepgoing;  /* processing of frames is ON */
76159b3361Sopenharmony_cistatic gint idle_count_max;  /* number of frames to process before plotting */
77159b3361Sopenharmony_cistatic gint idle_count;      /* pause & plot when idle_count=idel_count_max */
78159b3361Sopenharmony_cistatic gint idle_end = 0;    /* process all frames, stop at last frame  */
79159b3361Sopenharmony_cistatic gint idle_back = 0;   /* set when we are displaying the old data */
80159b3361Sopenharmony_cistatic int mp3done = 0;      /* last frame has been read */
81159b3361Sopenharmony_cistatic GtkWidget *frameprogress; /* progress bar */
82159b3361Sopenharmony_cistatic GtkWidget *framecounter; /* progress counter */
83159b3361Sopenharmony_ci
84159b3361Sopenharmony_cistatic int subblock_draw[3] = { 1, 1, 1 };
85159b3361Sopenharmony_ci
86159b3361Sopenharmony_ci/* main window */
87159b3361Sopenharmony_ciGtkWidget *window;
88159b3361Sopenharmony_ci/* Backing pixmap for drawing areas */
89159b3361Sopenharmony_ciGtkWidget *pcmbox;           /* PCM data plotted here */
90159b3361Sopenharmony_ciGtkWidget *winbox;           /* mpg123 synthesis data plotted here */
91159b3361Sopenharmony_ciGtkWidget *enerbox[2];       /* spectrum, gr=0,1 plotted here */
92159b3361Sopenharmony_ciGtkWidget *mdctbox[2];       /* mdct coefficients gr=0,1 plotted here */
93159b3361Sopenharmony_ciGtkWidget *sfbbox[2];        /* scalefactors gr=0,1 plotted here */
94159b3361Sopenharmony_ciGtkWidget *headerbox;        /* mpg123 header info shown here */
95159b3361Sopenharmony_ci
96159b3361Sopenharmony_ci
97159b3361Sopenharmony_cistruct gtkinfostruct {
98159b3361Sopenharmony_ci    int     filetype;        /* input file type 0=WAV, 1=MP3 */
99159b3361Sopenharmony_ci    int     msflag;          /* toggle between L&R vs M&S PCM data display */
100159b3361Sopenharmony_ci    int     chflag;          /* toggle between L & R channels */
101159b3361Sopenharmony_ci    int     kbflag;          /* toggle between wave # and barks */
102159b3361Sopenharmony_ci    int     flag123;         /* show mpg123 frame info, OR ISO encoder frame info */
103159b3361Sopenharmony_ci    double  avebits;         /* running average bits per frame */
104159b3361Sopenharmony_ci    int     approxbits;      /* (approx) bits per frame */
105159b3361Sopenharmony_ci    int     maxbits;         /* max bits per frame used so far */
106159b3361Sopenharmony_ci    int     totemph;         /* total of frames with de-emphasis */
107159b3361Sopenharmony_ci    int     totms;           /* total frames with ms_stereo */
108159b3361Sopenharmony_ci    int     totis;           /* total frames with i_stereo */
109159b3361Sopenharmony_ci    int     totshort;        /* total granules with short blocks */
110159b3361Sopenharmony_ci    int     totmix;          /* total granules with mixed blocks */
111159b3361Sopenharmony_ci    int     totpreflag;      /* total granules with preflag */
112159b3361Sopenharmony_ci    int     pupdate;         /* plot while processing, or only when needed */
113159b3361Sopenharmony_ci    int     sfblines;        /* plot scalefactor bands in MDCT plot */
114159b3361Sopenharmony_ci    int     difference;      /* plot original - decoded instead of orig vs. decoded */
115159b3361Sopenharmony_ci    int     totalframes;
116159b3361Sopenharmony_ci} gtkinfo;
117159b3361Sopenharmony_ci
118159b3361Sopenharmony_ci
119159b3361Sopenharmony_cistatic lame_global_flags *gfp;
120159b3361Sopenharmony_cilame_internal_flags *gfc;
121159b3361Sopenharmony_cihip_t hip; /* decoder handle of just encoded data */
122159b3361Sopenharmony_ci
123159b3361Sopenharmony_ci/**********************************************************************
124159b3361Sopenharmony_ci * read one frame and encode it
125159b3361Sopenharmony_ci **********************************************************************/
126159b3361Sopenharmony_ciint
127159b3361Sopenharmony_cigtkmakeframe(void)
128159b3361Sopenharmony_ci{
129159b3361Sopenharmony_ci    int     iread = 0;
130159b3361Sopenharmony_ci    static int init = 0;
131159b3361Sopenharmony_ci    static int mpglag;
132159b3361Sopenharmony_ci    static short int Buffer[2][1152];
133159b3361Sopenharmony_ci    short int mpg123pcm[2][1152];
134159b3361Sopenharmony_ci    int     ch, j;
135159b3361Sopenharmony_ci    int     mp3count = 0;
136159b3361Sopenharmony_ci    int     mp3out = 0;
137159b3361Sopenharmony_ci    int     channels_out;
138159b3361Sopenharmony_ci    unsigned char mp3buffer[LAME_MAXMP3BUFFER];
139159b3361Sopenharmony_ci    static int frameNum = 0;
140159b3361Sopenharmony_ci    int     framesize = lame_get_framesize(gfp);
141159b3361Sopenharmony_ci
142159b3361Sopenharmony_ci    channels_out = (lame_get_mode(gfp) == MONO) ? 1 : 2;
143159b3361Sopenharmony_ci
144159b3361Sopenharmony_ci    pinfo->frameNum = frameNum;
145159b3361Sopenharmony_ci    pinfo->sampfreq = lame_get_out_samplerate(gfp);
146159b3361Sopenharmony_ci    pinfo->framesize = framesize;
147159b3361Sopenharmony_ci    pinfo->stereo = channels_out;
148159b3361Sopenharmony_ci
149159b3361Sopenharmony_ci    /* If the analsys code is enabled, lame will writes data into gfc->pinfo,
150159b3361Sopenharmony_ci     * and mpg123 will write data into pinfo.  Set these so
151159b3361Sopenharmony_ci     * the libraries put this data in the right place: */
152159b3361Sopenharmony_ci    gfc->pinfo = pinfo;
153159b3361Sopenharmony_ci    hip_set_pinfo(hip, pinfo);
154159b3361Sopenharmony_ci
155159b3361Sopenharmony_ci    if (is_mpeg_file_format(global_reader.input_format)) {
156159b3361Sopenharmony_ci        hip_set_pinfo(get_hip(), pplot);
157159b3361Sopenharmony_ci        iread = get_audio16(gfp, Buffer);
158159b3361Sopenharmony_ci
159159b3361Sopenharmony_ci
160159b3361Sopenharmony_ci        /* add a delay of framesize-DECDELAY, which will make the total delay
161159b3361Sopenharmony_ci         * exactly one frame, so we can sync MP3 output with WAV input */
162159b3361Sopenharmony_ci        for (ch = 0; ch < channels_out; ch++) {
163159b3361Sopenharmony_ci            for (j = 0; j < framesize - DECDELAY; j++)
164159b3361Sopenharmony_ci                pinfo->pcmdata2[ch][j] = pinfo->pcmdata2[ch][j + framesize];
165159b3361Sopenharmony_ci            for (j = 0; j < framesize; j++) /*rescale from int to short int */
166159b3361Sopenharmony_ci                pinfo->pcmdata2[ch][j + framesize - DECDELAY] = Buffer[ch][j];
167159b3361Sopenharmony_ci        }
168159b3361Sopenharmony_ci
169159b3361Sopenharmony_ci        pinfo->frameNum123 = frameNum - 1;
170159b3361Sopenharmony_ci        ++frameNum;
171159b3361Sopenharmony_ci
172159b3361Sopenharmony_ci    }
173159b3361Sopenharmony_ci    else {
174159b3361Sopenharmony_ci
175159b3361Sopenharmony_ci        /* feed data to encoder until encoder produces some output */
176159b3361Sopenharmony_ci        while (lame_get_frameNum(gfp) == pinfo->frameNum) {
177159b3361Sopenharmony_ci
178159b3361Sopenharmony_ci            if (!init) {
179159b3361Sopenharmony_ci                init = 1;
180159b3361Sopenharmony_ci                mpglag = 1;
181159b3361Sopenharmony_ci                if (hip) {
182159b3361Sopenharmony_ci                    hip_decode_exit(hip);
183159b3361Sopenharmony_ci                }
184159b3361Sopenharmony_ci                hip = hip_decode_init();
185159b3361Sopenharmony_ci                hip_set_pinfo(hip, pinfo);
186159b3361Sopenharmony_ci            }
187159b3361Sopenharmony_ci
188159b3361Sopenharmony_ci            iread = get_audio16(gfp, Buffer);
189159b3361Sopenharmony_ci            if (iread > framesize) {
190159b3361Sopenharmony_ci                /* NOTE: frame analyzer requires that we encode one frame
191159b3361Sopenharmony_ci                 * for each pass through this loop.  If lame_encode_buffer()
192159b3361Sopenharmony_ci                 * is feed data too quickly, it will sometimes encode multiple frames
193159b3361Sopenharmony_ci                 * breaking this loop.
194159b3361Sopenharmony_ci                 */
195159b3361Sopenharmony_ci                error_printf("Warning: get_audio is returning too much data.\n");
196159b3361Sopenharmony_ci            }
197159b3361Sopenharmony_ci            if (iread <= 0)
198159b3361Sopenharmony_ci                break;  /* eof */
199159b3361Sopenharmony_ci
200159b3361Sopenharmony_ci            mp3count = lame_encode_buffer(gfp, Buffer[0], Buffer[1], iread,
201159b3361Sopenharmony_ci                                          mp3buffer, sizeof(mp3buffer));
202159b3361Sopenharmony_ci
203159b3361Sopenharmony_ci            assert(!(mp3count > 0 && lame_get_frameNum(gfp) == pinfo->frameNum));
204159b3361Sopenharmony_ci            /* not possible to produce mp3 data without encoding at least
205159b3361Sopenharmony_ci             * one frame of data which would increment frameNum */
206159b3361Sopenharmony_ci        }
207159b3361Sopenharmony_ci        frameNum = lame_get_frameNum(gfp); /* use the internal MP3 frame counter */
208159b3361Sopenharmony_ci
209159b3361Sopenharmony_ci
210159b3361Sopenharmony_ci        /* decode one frame of output */
211159b3361Sopenharmony_ci        mp3out = hip_decode1(hip, mp3buffer, mp3count, mpg123pcm[0], mpg123pcm[1]); /* re-synthesis to pcm */
212159b3361Sopenharmony_ci        /* mp3out = 0:  need more data to decode */
213159b3361Sopenharmony_ci        /* mp3out = -1:  error.  Lets assume 0 pcm output */
214159b3361Sopenharmony_ci        /* mp3out = number of samples output */
215159b3361Sopenharmony_ci        if (mp3out > 0)
216159b3361Sopenharmony_ci            assert(mp3out == pinfo->framesize);
217159b3361Sopenharmony_ci        if (mp3out != 0) {
218159b3361Sopenharmony_ci            /* decoded output is for frame pinfo->frameNum123
219159b3361Sopenharmony_ci             * add a delay of framesize-DECDELAY, which will make the total delay
220159b3361Sopenharmony_ci             * exactly one frame */
221159b3361Sopenharmony_ci            pinfo->frameNum123 = pinfo->frameNum - mpglag;
222159b3361Sopenharmony_ci            for (ch = 0; ch < pinfo->stereo; ch++) {
223159b3361Sopenharmony_ci                for (j = 0; j < pinfo->framesize - DECDELAY; j++)
224159b3361Sopenharmony_ci                    pinfo->pcmdata2[ch][j] = pinfo->pcmdata2[ch][j + pinfo->framesize];
225159b3361Sopenharmony_ci                for (j = 0; j < pinfo->framesize; j++) {
226159b3361Sopenharmony_ci                    pinfo->pcmdata2[ch][j + pinfo->framesize - DECDELAY] =
227159b3361Sopenharmony_ci                        (mp3out == -1) ? 0 : mpg123pcm[ch][j];
228159b3361Sopenharmony_ci                }
229159b3361Sopenharmony_ci            }
230159b3361Sopenharmony_ci        }
231159b3361Sopenharmony_ci        else {
232159b3361Sopenharmony_ci            if (mpglag == MAXMPGLAG) {
233159b3361Sopenharmony_ci                error_printf("READ_AHEAD set too low - not enough frame buffering.\n"
234159b3361Sopenharmony_ci                             "MP3x display of input and output PCM data out of sync.\n");
235159b3361Sopenharmony_ci                error_flush();
236159b3361Sopenharmony_ci            }
237159b3361Sopenharmony_ci            else
238159b3361Sopenharmony_ci                mpglag++;
239159b3361Sopenharmony_ci            pinfo->frameNum123 = -1; /* no frame output */
240159b3361Sopenharmony_ci        }
241159b3361Sopenharmony_ci    }
242159b3361Sopenharmony_ci    return iread;
243159b3361Sopenharmony_ci}
244159b3361Sopenharmony_ci
245159b3361Sopenharmony_ci
246159b3361Sopenharmony_civoid
247159b3361Sopenharmony_ciplot_frame(void)
248159b3361Sopenharmony_ci{
249159b3361Sopenharmony_ci    int     i, j, n, ch, gr;
250159b3361Sopenharmony_ci    gdouble *xcord, *ycord;
251159b3361Sopenharmony_ci    gdouble xmx, xmn, ymx, ymn;
252159b3361Sopenharmony_ci    double *data, *data2, *data3;
253159b3361Sopenharmony_ci    char    title2[80];
254159b3361Sopenharmony_ci    char    label[80], label2[80];
255159b3361Sopenharmony_ci    char   *title;
256159b3361Sopenharmony_ci    plotting_data *pplot1;
257159b3361Sopenharmony_ci    plotting_data *pplot2 = NULL;
258159b3361Sopenharmony_ci
259159b3361Sopenharmony_ci    double  en, samp;
260159b3361Sopenharmony_ci    /*int     sampindex, version = 0;*/
261159b3361Sopenharmony_ci    int     barthick;
262159b3361Sopenharmony_ci    static int firstcall = 1;
263159b3361Sopenharmony_ci    static GdkColor *barcolor, *color, *grcolor[2];
264159b3361Sopenharmony_ci    static GdkColor yellow, gray, cyan, magenta, orange, pink, red, green, blue, black, oncolor,
265159b3361Sopenharmony_ci        offcolor;
266159b3361Sopenharmony_ci    int     blocktype[2][2];
267159b3361Sopenharmony_ci    int     headbits;
268159b3361Sopenharmony_ci    int     mode_gr = 2;
269159b3361Sopenharmony_ci
270159b3361Sopenharmony_ci    /* find the frame where mpg123 produced output coming from input frame
271159b3361Sopenharmony_ci     * pinfo.  i.e.:   out_frame + out_frame_lag = input_frame  */
272159b3361Sopenharmony_ci    for (i = 1; i <= MAXMPGLAG; i++) {
273159b3361Sopenharmony_ci        if ((pplot - i)->frameNum123 == pplot->frameNum) {
274159b3361Sopenharmony_ci            pplot2 = pplot - i;
275159b3361Sopenharmony_ci            break;
276159b3361Sopenharmony_ci        }
277159b3361Sopenharmony_ci    }
278159b3361Sopenharmony_ci    if (i > MAXMPGLAG) {
279159b3361Sopenharmony_ci        error_printf("input/output pcm syncing problem.  should not happen!\n");
280159b3361Sopenharmony_ci        pplot2 = pplot - 1;
281159b3361Sopenharmony_ci    }
282159b3361Sopenharmony_ci
283159b3361Sopenharmony_ci
284159b3361Sopenharmony_ci    /* however, the PCM data is delayed by 528 samples in the encoder filterbanks.
285159b3361Sopenharmony_ci     * We added another 1152-528 delay to this so the PCM data is *exactly* one
286159b3361Sopenharmony_ci     * frame behind the header & MDCT information */
287159b3361Sopenharmony_ci    pplot1 = pplot2 + 1; /* back one frame for header info, MDCT */
288159b3361Sopenharmony_ci
289159b3361Sopenharmony_ci    /* allocate these GC's only once */
290159b3361Sopenharmony_ci    if (firstcall) {
291159b3361Sopenharmony_ci        firstcall = 0;
292159b3361Sopenharmony_ci        /*    grcolor[0] = &magenta; */
293159b3361Sopenharmony_ci        grcolor[0] = &blue;
294159b3361Sopenharmony_ci        grcolor[1] = &green;
295159b3361Sopenharmony_ci        barcolor = &gray;
296159b3361Sopenharmony_ci
297159b3361Sopenharmony_ci        setcolor(headerbox, &oncolor, 255, 0, 0);
298159b3361Sopenharmony_ci        setcolor(headerbox, &offcolor, 175, 175, 175);
299159b3361Sopenharmony_ci        setcolor(pcmbox, &red, 255, 0, 0);
300159b3361Sopenharmony_ci        setcolor(pcmbox, &pink, 255, 0, 255);
301159b3361Sopenharmony_ci        setcolor(pcmbox, &magenta, 255, 0, 100);
302159b3361Sopenharmony_ci        setcolor(pcmbox, &orange, 255, 127, 0);
303159b3361Sopenharmony_ci        setcolor(pcmbox, &cyan, 0, 255, 255);
304159b3361Sopenharmony_ci        setcolor(pcmbox, &green, 0, 255, 0);
305159b3361Sopenharmony_ci        setcolor(pcmbox, &blue, 0, 0, 255);
306159b3361Sopenharmony_ci        setcolor(pcmbox, &black, 0, 0, 0);
307159b3361Sopenharmony_ci        setcolor(pcmbox, &gray, 100, 100, 100);
308159b3361Sopenharmony_ci        setcolor(pcmbox, &yellow, 255, 255, 0);
309159b3361Sopenharmony_ci
310159b3361Sopenharmony_ci    }
311159b3361Sopenharmony_ci
312159b3361Sopenharmony_ci  /*******************************************************************
313159b3361Sopenharmony_ci   * frame header info
314159b3361Sopenharmony_ci   *******************************************************************/
315159b3361Sopenharmony_ci    if (pplot1->sampfreq)
316159b3361Sopenharmony_ci        samp = pplot1->sampfreq;
317159b3361Sopenharmony_ci    else
318159b3361Sopenharmony_ci        samp = 1;
319159b3361Sopenharmony_ci    /*sampindex = SmpFrqIndex((long) samp, &version);*/
320159b3361Sopenharmony_ci
321159b3361Sopenharmony_ci    ch = gtkinfo.chflag;
322159b3361Sopenharmony_ci
323159b3361Sopenharmony_ci    headbits = 32 + ((pplot1->stereo == 2) ? 256 : 136);
324159b3361Sopenharmony_ci    gtkinfo.approxbits = (pplot1->bitrate * 1000 * 1152.0 / samp) - headbits;
325159b3361Sopenharmony_ci    sprintf(title2, "%3.1fkHz %ikbs ", samp / 1000, pplot1->bitrate);
326159b3361Sopenharmony_ci    gtk_text_freeze(GTK_TEXT(headerbox));
327159b3361Sopenharmony_ci    gtk_text_backward_delete(GTK_TEXT(headerbox), gtk_text_get_length(GTK_TEXT(headerbox)));
328159b3361Sopenharmony_ci    gtk_text_set_point(GTK_TEXT(headerbox), 0);
329159b3361Sopenharmony_ci    gtk_text_insert(GTK_TEXT(headerbox), NULL, &oncolor, NULL, title2, -1);
330159b3361Sopenharmony_ci    title = " mono ";
331159b3361Sopenharmony_ci    if (2 == pplot1->stereo)
332159b3361Sopenharmony_ci        title = pplot1->js ? " js " : " s ";
333159b3361Sopenharmony_ci    gtk_text_insert(GTK_TEXT(headerbox), NULL, &oncolor, NULL, title, -1);
334159b3361Sopenharmony_ci    color = pplot1->ms_stereo ? &oncolor : &offcolor;
335159b3361Sopenharmony_ci    gtk_text_insert(GTK_TEXT(headerbox), NULL, color, NULL, "ms ", -1);
336159b3361Sopenharmony_ci    color = pplot1->i_stereo ? &oncolor : &offcolor;
337159b3361Sopenharmony_ci    gtk_text_insert(GTK_TEXT(headerbox), NULL, color, NULL, "is ", -1);
338159b3361Sopenharmony_ci
339159b3361Sopenharmony_ci    color = pplot1->crc ? &oncolor : &offcolor;
340159b3361Sopenharmony_ci    gtk_text_insert(GTK_TEXT(headerbox), NULL, color, NULL, "crc ", -1);
341159b3361Sopenharmony_ci    color = pplot1->padding ? &oncolor : &offcolor;
342159b3361Sopenharmony_ci    gtk_text_insert(GTK_TEXT(headerbox), NULL, color, NULL, "pad ", -1);
343159b3361Sopenharmony_ci
344159b3361Sopenharmony_ci    color = pplot1->emph ? &oncolor : &offcolor;
345159b3361Sopenharmony_ci    gtk_text_insert(GTK_TEXT(headerbox), NULL, color, NULL, "em ", -1);
346159b3361Sopenharmony_ci
347159b3361Sopenharmony_ci    sprintf(title2, "bv=%i,%i ", pplot1->big_values[0][ch], pplot1->big_values[1][ch]);
348159b3361Sopenharmony_ci    gtk_text_insert(GTK_TEXT(headerbox), NULL, &black, NULL, title2, -1);
349159b3361Sopenharmony_ci
350159b3361Sopenharmony_ci    color = pplot1->scfsi[ch] ? &oncolor : &offcolor;
351159b3361Sopenharmony_ci    sprintf(title2, "scfsi=%i            ", pplot1->scfsi[ch]);
352159b3361Sopenharmony_ci    gtk_text_insert(GTK_TEXT(headerbox), NULL, color, NULL, title2, -1);
353159b3361Sopenharmony_ci    if (gtkinfo.filetype)
354159b3361Sopenharmony_ci        sprintf(title2, " mdb=%i %i/NA", pplot1->maindata, pplot1->totbits);
355159b3361Sopenharmony_ci    else
356159b3361Sopenharmony_ci        sprintf(title2, " mdb=%i   %i/%i",
357159b3361Sopenharmony_ci                pplot1->maindata, pplot1->totbits, pplot1->totbits + pplot->resvsize);
358159b3361Sopenharmony_ci    gtk_text_insert(GTK_TEXT(headerbox), NULL, &oncolor, NULL, title2, -1);
359159b3361Sopenharmony_ci    gtk_text_thaw(GTK_TEXT(headerbox));
360159b3361Sopenharmony_ci
361159b3361Sopenharmony_ci
362159b3361Sopenharmony_ci
363159b3361Sopenharmony_ci  /*******************************************************************
364159b3361Sopenharmony_ci   * block type
365159b3361Sopenharmony_ci   *******************************************************************/
366159b3361Sopenharmony_ci    for (gr = 0; gr < mode_gr; gr++)
367159b3361Sopenharmony_ci        if (gtkinfo.flag123)
368159b3361Sopenharmony_ci            blocktype[gr][ch] = pplot1->mpg123blocktype[gr][ch];
369159b3361Sopenharmony_ci        else
370159b3361Sopenharmony_ci            blocktype[gr][ch] = pplot->blocktype[gr][ch];
371159b3361Sopenharmony_ci
372159b3361Sopenharmony_ci
373159b3361Sopenharmony_ci  /*******************************************************************
374159b3361Sopenharmony_ci   * draw the PCM data *
375159b3361Sopenharmony_ci   *******************************************************************/
376159b3361Sopenharmony_ci    n = 1600;           /* PCM frame + FFT window:   224 + 1152 + 224  */
377159b3361Sopenharmony_ci    xcord = g_malloc(n * sizeof(gdouble));
378159b3361Sopenharmony_ci    ycord = g_malloc(n * sizeof(gdouble));
379159b3361Sopenharmony_ci
380159b3361Sopenharmony_ci
381159b3361Sopenharmony_ci    if (gtkinfo.msflag)
382159b3361Sopenharmony_ci        title = ch ? "Side Channel" : "Mid Channel";
383159b3361Sopenharmony_ci    else
384159b3361Sopenharmony_ci        title = ch ? "Right Channel" : "Left Channel";
385159b3361Sopenharmony_ci
386159b3361Sopenharmony_ci    sprintf(title2, "%s  mask_ratio=%3.2f  %3.2f  ener_ratio=%3.2f  %3.2f",
387159b3361Sopenharmony_ci            title,
388159b3361Sopenharmony_ci            pplot->ms_ratio[0], pplot->ms_ratio[1],
389159b3361Sopenharmony_ci            pplot->ms_ener_ratio[0], pplot->ms_ener_ratio[1]);
390159b3361Sopenharmony_ci
391159b3361Sopenharmony_ci
392159b3361Sopenharmony_ci    ymn = -32767;
393159b3361Sopenharmony_ci    ymx = 32767;
394159b3361Sopenharmony_ci    xmn = 0;
395159b3361Sopenharmony_ci    xmx = 1600 - 1;
396159b3361Sopenharmony_ci
397159b3361Sopenharmony_ci    /*  0  ... 224      draw in black, connecting to 224 pixel
398159b3361Sopenharmony_ci     * 1375 .. 1599     draw in black  connecting to 1375 pixel
399159b3361Sopenharmony_ci     * 224 ... 1375     MP3 frame.  draw in blue
400159b3361Sopenharmony_ci     */
401159b3361Sopenharmony_ci
402159b3361Sopenharmony_ci    /* draw the title */
403159b3361Sopenharmony_ci    gpk_graph_draw(pcmbox, 0, xcord, ycord, xmn, ymn, xmx, ymx, 1, title2, &black);
404159b3361Sopenharmony_ci
405159b3361Sopenharmony_ci
406159b3361Sopenharmony_ci    /* draw some hash marks dividing the frames */
407159b3361Sopenharmony_ci    ycord[0] = ymx * .8;
408159b3361Sopenharmony_ci    ycord[1] = ymn * .8;
409159b3361Sopenharmony_ci    for (gr = 0; gr <= 2; gr++) {
410159b3361Sopenharmony_ci        xcord[0] = 223.5 + gr * 576;
411159b3361Sopenharmony_ci        xcord[1] = 223.5 + gr * 576;
412159b3361Sopenharmony_ci        gpk_rectangle_draw(pcmbox, xcord, ycord, xmn, ymn, xmx, ymx, &yellow);
413159b3361Sopenharmony_ci    }
414159b3361Sopenharmony_ci    for (gr = 0; gr < mode_gr; gr++) {
415159b3361Sopenharmony_ci        if (blocktype[gr][ch] == 2)
416159b3361Sopenharmony_ci            for (i = 1; i <= 2; i++) {
417159b3361Sopenharmony_ci                xcord[0] = 223.5 + gr * 576 + i * 192;
418159b3361Sopenharmony_ci                xcord[1] = 223.5 + gr * 576 + i * 192;
419159b3361Sopenharmony_ci                gpk_rectangle_draw(pcmbox, xcord, ycord, xmn, ymn, xmx, ymx, &yellow);
420159b3361Sopenharmony_ci            }
421159b3361Sopenharmony_ci    }
422159b3361Sopenharmony_ci    /* bars representing FFT windows */
423159b3361Sopenharmony_ci    xcord[0] = 0;
424159b3361Sopenharmony_ci    ycord[0] = ymn + 3000;
425159b3361Sopenharmony_ci    xcord[1] = 1024 - 1;
426159b3361Sopenharmony_ci    ycord[1] = ymn + 1000;
427159b3361Sopenharmony_ci    gpk_rectangle_draw(pcmbox, xcord, ycord, xmn, ymn, xmx, ymx, grcolor[0]);
428159b3361Sopenharmony_ci    xcord[0] = 576;
429159b3361Sopenharmony_ci    ycord[0] = ymn + 2000;
430159b3361Sopenharmony_ci    xcord[1] = 576 + 1024 - 1;
431159b3361Sopenharmony_ci    ycord[1] = ymn;
432159b3361Sopenharmony_ci    gpk_rectangle_draw(pcmbox, xcord, ycord, xmn, ymn, xmx, ymx, grcolor[1]);
433159b3361Sopenharmony_ci
434159b3361Sopenharmony_ci
435159b3361Sopenharmony_ci    /* plot PCM data */
436159b3361Sopenharmony_ci    for (i = 0; i < n; i++) {
437159b3361Sopenharmony_ci        xcord[i] = i;
438159b3361Sopenharmony_ci        if (gtkinfo.msflag)
439159b3361Sopenharmony_ci            ycord[i] = ch ? .5 * (pplot->pcmdata[0][i] - pplot->pcmdata[1][i]) :
440159b3361Sopenharmony_ci                .5 * (pplot->pcmdata[0][i] + pplot->pcmdata[1][i]);
441159b3361Sopenharmony_ci        else
442159b3361Sopenharmony_ci            ycord[i] = pplot->pcmdata[ch][i];
443159b3361Sopenharmony_ci    }
444159b3361Sopenharmony_ci
445159b3361Sopenharmony_ci    /* skip plot if we are doing an mp3 file */
446159b3361Sopenharmony_ci    if (!gtkinfo.filetype) {
447159b3361Sopenharmony_ci        gpk_graph_draw(pcmbox, n, xcord, ycord, xmn, ymn, xmx, ymx, 0, title2, &black);
448159b3361Sopenharmony_ci    }
449159b3361Sopenharmony_ci
450159b3361Sopenharmony_ci
451159b3361Sopenharmony_ci  /*******************************************************************/
452159b3361Sopenharmony_ci    /* draw the PCM re-synthesis data */
453159b3361Sopenharmony_ci  /*******************************************************************/
454159b3361Sopenharmony_ci    n = 1152;
455159b3361Sopenharmony_ci    /*
456159b3361Sopenharmony_ci       sprintf(title2,"Re-synthesis  mask_ratio=%3.2f  %3.2f  ener_ratio=%3.2f  %3.2f",
457159b3361Sopenharmony_ci       pplot->ms_ratio[0],pplot->ms_ratio[1],
458159b3361Sopenharmony_ci       pplot->ms_ener_ratio[0],pplot->ms_ener_ratio[1]);
459159b3361Sopenharmony_ci     */
460159b3361Sopenharmony_ci    title = "Re-synthesis";
461159b3361Sopenharmony_ci    if (gtkinfo.difference)
462159b3361Sopenharmony_ci        title = "Re-synthesis difference (amplified 20db)";
463159b3361Sopenharmony_ci
464159b3361Sopenharmony_ci
465159b3361Sopenharmony_ci    ymn = -32767;
466159b3361Sopenharmony_ci    ymx = 32767;
467159b3361Sopenharmony_ci    xmn = 0;
468159b3361Sopenharmony_ci    xmx = 1600 - 1;
469159b3361Sopenharmony_ci    gpk_graph_draw(winbox, 0, xcord, ycord, xmn, ymn, xmx, ymx, 1, title, &black);
470159b3361Sopenharmony_ci    /* draw some hash marks dividing the frames */
471159b3361Sopenharmony_ci    ycord[0] = ymx * .8;
472159b3361Sopenharmony_ci    ycord[1] = ymn * .8;
473159b3361Sopenharmony_ci    for (gr = 0; gr <= 2; gr++) {
474159b3361Sopenharmony_ci        xcord[0] = 223.5 + gr * 576;
475159b3361Sopenharmony_ci        xcord[1] = 223.5 + gr * 576;
476159b3361Sopenharmony_ci        gpk_rectangle_draw(winbox, xcord, ycord, xmn, ymn, xmx, ymx, &yellow);
477159b3361Sopenharmony_ci    }
478159b3361Sopenharmony_ci    for (gr = 0; gr < 2; gr++) {
479159b3361Sopenharmony_ci        if (blocktype[gr][ch] == 2)
480159b3361Sopenharmony_ci            for (i = 1; i <= 2; i++) {
481159b3361Sopenharmony_ci                xcord[0] = 223.5 + gr * 576 + i * 192;
482159b3361Sopenharmony_ci                xcord[1] = 223.5 + gr * 576 + i * 192;
483159b3361Sopenharmony_ci                gpk_rectangle_draw(winbox, xcord, ycord, xmn, ymn, xmx, ymx, &yellow);
484159b3361Sopenharmony_ci            }
485159b3361Sopenharmony_ci    }
486159b3361Sopenharmony_ci
487159b3361Sopenharmony_ci    /* this piece of PCM data from previous frame */
488159b3361Sopenharmony_ci    n = 224;
489159b3361Sopenharmony_ci    for (j = 1152 - n, i = 0; i < n; i++, j++) {
490159b3361Sopenharmony_ci        xcord[i] = i;
491159b3361Sopenharmony_ci        if (gtkinfo.msflag)
492159b3361Sopenharmony_ci            ycord[i] = ch ? .5 * (pplot1->pcmdata2[0][j] -
493159b3361Sopenharmony_ci                                  pplot1->pcmdata2[1][j]) :
494159b3361Sopenharmony_ci                .5 * (pplot1->pcmdata2[0][j] + pplot1->pcmdata2[1][j]);
495159b3361Sopenharmony_ci        else
496159b3361Sopenharmony_ci            ycord[i] = pplot1->pcmdata2[ch][j];
497159b3361Sopenharmony_ci    }
498159b3361Sopenharmony_ci
499159b3361Sopenharmony_ci    /* this piece of PCM data from current frame */
500159b3361Sopenharmony_ci    n = 1152;
501159b3361Sopenharmony_ci    for (i = 0; i < n; i++) {
502159b3361Sopenharmony_ci        xcord[i + 224] = i + 224;
503159b3361Sopenharmony_ci        if (gtkinfo.msflag)
504159b3361Sopenharmony_ci            ycord[i + 224] = ch ? .5 * (pplot2->pcmdata2[0][i] - pplot2->pcmdata2[1][i]) :
505159b3361Sopenharmony_ci                .5 * (pplot2->pcmdata2[0][i] + pplot2->pcmdata2[1][i]);
506159b3361Sopenharmony_ci        else
507159b3361Sopenharmony_ci            ycord[i + 224] = pplot2->pcmdata2[ch][i];
508159b3361Sopenharmony_ci    }
509159b3361Sopenharmony_ci
510159b3361Sopenharmony_ci    n = 1152 + 224;
511159b3361Sopenharmony_ci    if (gtkinfo.difference) {
512159b3361Sopenharmony_ci        for (i = 0; i < n; i++) {
513159b3361Sopenharmony_ci            if (gtkinfo.msflag)
514159b3361Sopenharmony_ci                ycord[i] -= ch ? .5 * (pplot->pcmdata[0][i] - pplot->pcmdata[1][i]) :
515159b3361Sopenharmony_ci                    .5 * (pplot->pcmdata[0][i] + pplot->pcmdata[1][i]);
516159b3361Sopenharmony_ci            else
517159b3361Sopenharmony_ci                ycord[i] -= pplot->pcmdata[ch][i];
518159b3361Sopenharmony_ci        }
519159b3361Sopenharmony_ci        ycord[i] *= 100;
520159b3361Sopenharmony_ci    }
521159b3361Sopenharmony_ci
522159b3361Sopenharmony_ci
523159b3361Sopenharmony_ci    gpk_graph_draw(winbox, n, xcord, ycord, xmn, ymn, xmx, ymx, 0, title, &black);
524159b3361Sopenharmony_ci
525159b3361Sopenharmony_ci
526159b3361Sopenharmony_ci
527159b3361Sopenharmony_ci
528159b3361Sopenharmony_ci
529159b3361Sopenharmony_ci  /*******************************************************************/
530159b3361Sopenharmony_ci    /* draw the MDCT energy spectrum */
531159b3361Sopenharmony_ci  /*******************************************************************/
532159b3361Sopenharmony_ci    for (gr = 0; gr < mode_gr; gr++) {
533159b3361Sopenharmony_ci        int     bits, bits2;
534159b3361Sopenharmony_ci        char   *blockname = "";
535159b3361Sopenharmony_ci        switch (blocktype[gr][ch]) {
536159b3361Sopenharmony_ci        case 0:
537159b3361Sopenharmony_ci            blockname = "normal";
538159b3361Sopenharmony_ci            break;
539159b3361Sopenharmony_ci        case 1:
540159b3361Sopenharmony_ci            blockname = "start";
541159b3361Sopenharmony_ci            break;
542159b3361Sopenharmony_ci        case 2:
543159b3361Sopenharmony_ci            blockname = "short";
544159b3361Sopenharmony_ci            break;
545159b3361Sopenharmony_ci        case 3:
546159b3361Sopenharmony_ci            blockname = "end";
547159b3361Sopenharmony_ci            break;
548159b3361Sopenharmony_ci        }
549159b3361Sopenharmony_ci        strcpy(label, blockname);
550159b3361Sopenharmony_ci        if (pplot1->mixed[gr][ch])
551159b3361Sopenharmony_ci            strcat(label, "(mixed)");
552159b3361Sopenharmony_ci
553159b3361Sopenharmony_ci
554159b3361Sopenharmony_ci
555159b3361Sopenharmony_ci
556159b3361Sopenharmony_ci        n = 576;
557159b3361Sopenharmony_ci        if (gtkinfo.flag123) {
558159b3361Sopenharmony_ci            data = pplot1->mpg123xr[gr][0];
559159b3361Sopenharmony_ci            data2 = pplot1->mpg123xr[gr][1];
560159b3361Sopenharmony_ci        }
561159b3361Sopenharmony_ci        else {
562159b3361Sopenharmony_ci            data = pplot->xr[gr][0];
563159b3361Sopenharmony_ci            data2 = pplot->xr[gr][1];
564159b3361Sopenharmony_ci        }
565159b3361Sopenharmony_ci
566159b3361Sopenharmony_ci
567159b3361Sopenharmony_ci        xmn = 0;
568159b3361Sopenharmony_ci        xmx = n - 1;
569159b3361Sopenharmony_ci        ymn = 0;
570159b3361Sopenharmony_ci        ymx = 11;
571159b3361Sopenharmony_ci
572159b3361Sopenharmony_ci        /* draw title, erase old plot */
573159b3361Sopenharmony_ci        if (gtkinfo.flag123) {
574159b3361Sopenharmony_ci            bits = pplot1->mainbits[gr][ch];
575159b3361Sopenharmony_ci            bits2 = pplot1->sfbits[gr][ch];
576159b3361Sopenharmony_ci        }
577159b3361Sopenharmony_ci        else {
578159b3361Sopenharmony_ci            bits = pplot->LAMEmainbits[gr][ch];
579159b3361Sopenharmony_ci            bits2 = pplot->LAMEsfbits[gr][ch];
580159b3361Sopenharmony_ci        }
581159b3361Sopenharmony_ci        sprintf(title2, "MDCT%1i(%s) bits=%i/%i ", gr, label, bits, bits2);
582159b3361Sopenharmony_ci        gpk_bargraph_draw(mdctbox[gr], 0, xcord, ycord, xmn, ymn, xmx, ymx, 1, title2, 0, barcolor);
583159b3361Sopenharmony_ci
584159b3361Sopenharmony_ci        /* draw some hash marks showing scalefactor bands */
585159b3361Sopenharmony_ci        if (gtkinfo.sfblines) {
586159b3361Sopenharmony_ci            int     fac, nsfb, *scalefac;
587159b3361Sopenharmony_ci            if (blocktype[gr][ch] == SHORT_TYPE) {
588159b3361Sopenharmony_ci                nsfb = SBMAX_s;
589159b3361Sopenharmony_ci                i = nsfb - 7;
590159b3361Sopenharmony_ci                fac = 3;
591159b3361Sopenharmony_ci                scalefac = gfc->scalefac_band.s;
592159b3361Sopenharmony_ci            }
593159b3361Sopenharmony_ci            else {
594159b3361Sopenharmony_ci                nsfb = SBMAX_l;
595159b3361Sopenharmony_ci                i = nsfb - 10;
596159b3361Sopenharmony_ci                fac = 1;
597159b3361Sopenharmony_ci                scalefac = gfc->scalefac_band.l;
598159b3361Sopenharmony_ci            }
599159b3361Sopenharmony_ci            for (; i < nsfb; i++) {
600159b3361Sopenharmony_ci                ycord[0] = .8 * ymx;
601159b3361Sopenharmony_ci                ycord[1] = ymn;
602159b3361Sopenharmony_ci                xcord[0] = fac * scalefac[i];
603159b3361Sopenharmony_ci                xcord[1] = xcord[0];
604159b3361Sopenharmony_ci                gpk_rectangle_draw(mdctbox[gr], xcord, ycord, xmn, ymn, xmx, ymx, &yellow);
605159b3361Sopenharmony_ci            }
606159b3361Sopenharmony_ci        }
607159b3361Sopenharmony_ci
608159b3361Sopenharmony_ci
609159b3361Sopenharmony_ci
610159b3361Sopenharmony_ci        ymn = 9e20;
611159b3361Sopenharmony_ci        ymx = -9e20;
612159b3361Sopenharmony_ci        for (i = 0; i < n; i++) {
613159b3361Sopenharmony_ci            double  coeff;
614159b3361Sopenharmony_ci            xcord[i] = i;
615159b3361Sopenharmony_ci            if (gtkinfo.msflag) {
616159b3361Sopenharmony_ci                coeff = ch ? .5 * (data[i] - data2[i]) : .5 * (data[i] + data2[i]);
617159b3361Sopenharmony_ci            }
618159b3361Sopenharmony_ci            else {
619159b3361Sopenharmony_ci                coeff = ch ? data2[i] : data[i];
620159b3361Sopenharmony_ci            }
621159b3361Sopenharmony_ci            if (blocktype[gr][ch] == SHORT_TYPE && !subblock_draw[i % 3])
622159b3361Sopenharmony_ci                coeff = 0;
623159b3361Sopenharmony_ci            ycord[i] = coeff * coeff * 1e10;
624159b3361Sopenharmony_ci            ycord[i] = log10(MAX(ycord[i], (double) 1));
625159b3361Sopenharmony_ci
626159b3361Sopenharmony_ci#if 0
627159b3361Sopenharmony_ci            if (ch == 0)
628159b3361Sopenharmony_ci                if (i == 26)
629159b3361Sopenharmony_ci                    if (data[i] != 0)
630159b3361Sopenharmony_ci                        console_printf("%i %i i=%i  mdct: (db) %f  %f \n", pplot->frameNum, gr, i,
631159b3361Sopenharmony_ci                                       10 * log10(data[i] * data[i]),
632159b3361Sopenharmony_ci                                       10 * log10(.33 *
633159b3361Sopenharmony_ci                                                  (data[i - 1] * data[i - 1] + data[i] * data[i] +
634159b3361Sopenharmony_ci                                                   data[i + 1] * data[i + 1]))
635159b3361Sopenharmony_ci                            );
636159b3361Sopenharmony_ci#endif
637159b3361Sopenharmony_ci
638159b3361Sopenharmony_ci            ymx = (ycord[i] > ymx) ? ycord[i] : ymx;
639159b3361Sopenharmony_ci            ymn = (ycord[i] < ymn) ? ycord[i] : ymn;
640159b3361Sopenharmony_ci        }
641159b3361Sopenharmony_ci        /*  print the min/max
642159b3361Sopenharmony_ci           sprintf(title2,"MDCT%1i %5.2f %5.2f  bits=%i",gr,ymn,ymx,
643159b3361Sopenharmony_ci           pplot1->mainbits[gr][ch]);
644159b3361Sopenharmony_ci         */
645159b3361Sopenharmony_ci        if (gtkinfo.flag123)
646159b3361Sopenharmony_ci            bits = pplot1->mainbits[gr][ch];
647159b3361Sopenharmony_ci        else
648159b3361Sopenharmony_ci            bits = pplot->LAMEmainbits[gr][ch];
649159b3361Sopenharmony_ci
650159b3361Sopenharmony_ci
651159b3361Sopenharmony_ci        sprintf(title2, "MDCT%1i(%s) bits=%i ", gr, label, bits);
652159b3361Sopenharmony_ci
653159b3361Sopenharmony_ci        xmn = 0;
654159b3361Sopenharmony_ci        xmx = n - 1;
655159b3361Sopenharmony_ci        ymn = 0;
656159b3361Sopenharmony_ci        ymx = 11;
657159b3361Sopenharmony_ci        gpk_bargraph_draw(mdctbox[gr], n, xcord, ycord, xmn, ymn, xmx, ymx, 0, title2, 0, barcolor);
658159b3361Sopenharmony_ci    }
659159b3361Sopenharmony_ci
660159b3361Sopenharmony_ci
661159b3361Sopenharmony_ci
662159b3361Sopenharmony_ci
663159b3361Sopenharmony_ci  /*******************************************************************
664159b3361Sopenharmony_ci   * draw the psy model energy spectrum (k space)
665159b3361Sopenharmony_ci   * l3psy.c computes pe, en, thm for THIS granule.
666159b3361Sopenharmony_ci   *******************************************************************/
667159b3361Sopenharmony_ci    if (gtkinfo.kbflag) {
668159b3361Sopenharmony_ci        for (gr = 0; gr < mode_gr; gr++) {
669159b3361Sopenharmony_ci            n = HBLKSIZE; /* only show half the spectrum */
670159b3361Sopenharmony_ci
671159b3361Sopenharmony_ci            data = &pplot->energy[gr][ch][0];
672159b3361Sopenharmony_ci
673159b3361Sopenharmony_ci            ymn = 9e20;
674159b3361Sopenharmony_ci            ymx = -9e20;
675159b3361Sopenharmony_ci            for (i = 0; i < n; i++) {
676159b3361Sopenharmony_ci                xcord[i] = i + 1;
677159b3361Sopenharmony_ci                if (blocktype[gr][ch] == SHORT_TYPE && !subblock_draw[i % 3])
678159b3361Sopenharmony_ci                    ycord[i] = 0;
679159b3361Sopenharmony_ci                else
680159b3361Sopenharmony_ci                    ycord[i] = log10(MAX(data[i], (double) 1));
681159b3361Sopenharmony_ci                ymx = (ycord[i] > ymx) ? ycord[i] : ymx;
682159b3361Sopenharmony_ci                ymn = (ycord[i] < ymn) ? ycord[i] : ymn;
683159b3361Sopenharmony_ci            }
684159b3361Sopenharmony_ci            for (en = 0, j = 0; j < BLKSIZE; j++)
685159b3361Sopenharmony_ci                en += pplot->energy[gr][ch][j];
686159b3361Sopenharmony_ci
687159b3361Sopenharmony_ci            sprintf(title2, "FFT%1i  pe=%5.2fK  en=%5.2e ", gr, pplot->pe[gr][ch] / 1000, en);
688159b3361Sopenharmony_ci
689159b3361Sopenharmony_ci            ymn = 3;
690159b3361Sopenharmony_ci            ymx = 15;
691159b3361Sopenharmony_ci            xmn = 1;
692159b3361Sopenharmony_ci            xmx = n;
693159b3361Sopenharmony_ci            gpk_bargraph_draw(enerbox[gr], n, xcord, ycord,
694159b3361Sopenharmony_ci                              xmn, ymn, xmx, ymx, 1, title2, 0, barcolor);
695159b3361Sopenharmony_ci
696159b3361Sopenharmony_ci        }
697159b3361Sopenharmony_ci    }
698159b3361Sopenharmony_ci    else {
699159b3361Sopenharmony_ci    /*******************************************************************
700159b3361Sopenharmony_ci     * draw the psy model energy spectrum (scalefactor bands)
701159b3361Sopenharmony_ci     *******************************************************************/
702159b3361Sopenharmony_ci        for (gr = 0; gr < mode_gr; gr++) {
703159b3361Sopenharmony_ci
704159b3361Sopenharmony_ci            if (blocktype[gr][ch] == 2) {
705159b3361Sopenharmony_ci                n = 3 * SBMAX_s;
706159b3361Sopenharmony_ci                data = &pplot->en_s[gr][ch][0];
707159b3361Sopenharmony_ci                data2 = &pplot->thr_s[gr][ch][0];
708159b3361Sopenharmony_ci                data3 = &pplot->xfsf_s[gr][ch][0];
709159b3361Sopenharmony_ci            }
710159b3361Sopenharmony_ci            else {
711159b3361Sopenharmony_ci                n = SBMAX_l;
712159b3361Sopenharmony_ci                data = &pplot->en[gr][ch][0];
713159b3361Sopenharmony_ci                data2 = &pplot->thr[gr][ch][0];
714159b3361Sopenharmony_ci                data3 = &pplot->xfsf[gr][ch][0];
715159b3361Sopenharmony_ci            }
716159b3361Sopenharmony_ci            ymn = 9e20;
717159b3361Sopenharmony_ci            ymx = -9e20;
718159b3361Sopenharmony_ci            for (i = 0; i < n; i++) {
719159b3361Sopenharmony_ci                xcord[i] = i + 1;
720159b3361Sopenharmony_ci                if (blocktype[gr][ch] == SHORT_TYPE && !subblock_draw[i % 3])
721159b3361Sopenharmony_ci                    ycord[i] = 0;
722159b3361Sopenharmony_ci                else
723159b3361Sopenharmony_ci                    ycord[i] = log10(MAX(data[i], (double) 1));
724159b3361Sopenharmony_ci                /*
725159b3361Sopenharmony_ci                   ymx=(ycord[i] > ymx) ? ycord[i] : ymx;
726159b3361Sopenharmony_ci                   ymn=(ycord[i] < ymn) ? ycord[i] : ymn;
727159b3361Sopenharmony_ci                 */
728159b3361Sopenharmony_ci            }
729159b3361Sopenharmony_ci
730159b3361Sopenharmony_ci
731159b3361Sopenharmony_ci
732159b3361Sopenharmony_ci            /* en = max energy difference amoung the 3 short FFTs for this granule */
733159b3361Sopenharmony_ci            en = pplot->ers[gr][ch];
734159b3361Sopenharmony_ci            if (en > 999)
735159b3361Sopenharmony_ci                en = 999;
736159b3361Sopenharmony_ci            sprintf(title2,
737159b3361Sopenharmony_ci                    "FFT%1i pe=%5.2fK/%3.1f \nnoise ovr_b:%i/max:%3.1f/ovr:%3.1f/tot:%3.1f/ssd:%i",
738159b3361Sopenharmony_ci                    gr, pplot->pe[gr][ch] / 1000, en, pplot->over[gr][ch], pplot->max_noise[gr][ch],
739159b3361Sopenharmony_ci                    pplot->over_noise[gr][ch], pplot->tot_noise[gr][ch], pplot->over_SSD[gr][ch]);
740159b3361Sopenharmony_ci
741159b3361Sopenharmony_ci            barthick = 3;
742159b3361Sopenharmony_ci            if (blocktype[gr][ch] == SHORT_TYPE)
743159b3361Sopenharmony_ci                barthick = 2;
744159b3361Sopenharmony_ci            if (!(subblock_draw[0] && subblock_draw[1] && subblock_draw[2]))
745159b3361Sopenharmony_ci                barthick = 3;
746159b3361Sopenharmony_ci
747159b3361Sopenharmony_ci            ymn = 3;
748159b3361Sopenharmony_ci            ymx = 15;
749159b3361Sopenharmony_ci            xmn = 1;
750159b3361Sopenharmony_ci            xmx = n + 1; /* a little extra because of the bar thickness */
751159b3361Sopenharmony_ci            gpk_bargraph_draw(enerbox[gr], n, xcord, ycord,
752159b3361Sopenharmony_ci                              xmn, ymn, xmx, ymx, 1, title2, barthick, barcolor);
753159b3361Sopenharmony_ci
754159b3361Sopenharmony_ci            for (i = 0; i < n; i++) {
755159b3361Sopenharmony_ci                xcord[i] = i + 1 + .20;
756159b3361Sopenharmony_ci                if (blocktype[gr][ch] == SHORT_TYPE && !subblock_draw[i % 3])
757159b3361Sopenharmony_ci                    ycord[i] = 0;
758159b3361Sopenharmony_ci                else
759159b3361Sopenharmony_ci                    ycord[i] = log10(MAX(data2[i], (double) 1));
760159b3361Sopenharmony_ci            }
761159b3361Sopenharmony_ci
762159b3361Sopenharmony_ci            gpk_bargraph_draw(enerbox[gr], n, xcord, ycord,
763159b3361Sopenharmony_ci                              xmn, ymn, xmx, ymx, 0, title2, barthick, grcolor[gr]);
764159b3361Sopenharmony_ci
765159b3361Sopenharmony_ci            for (i = 0; i < n; i++) {
766159b3361Sopenharmony_ci                xcord[i] = i + 1 + .40;
767159b3361Sopenharmony_ci                if (blocktype[gr][ch] == SHORT_TYPE && !subblock_draw[i % 3])
768159b3361Sopenharmony_ci                    ycord[i] = 0;
769159b3361Sopenharmony_ci                else
770159b3361Sopenharmony_ci                    ycord[i] = log10(MAX(data3[i], (double) 1));
771159b3361Sopenharmony_ci            }
772159b3361Sopenharmony_ci            gpk_bargraph_draw(enerbox[gr], n, xcord, ycord,
773159b3361Sopenharmony_ci                              xmn, ymn, xmx, ymx, 0, title2, barthick, &red);
774159b3361Sopenharmony_ci
775159b3361Sopenharmony_ci        }
776159b3361Sopenharmony_ci    }
777159b3361Sopenharmony_ci
778159b3361Sopenharmony_ci  /*******************************************************************
779159b3361Sopenharmony_ci   * draw scalefactors
780159b3361Sopenharmony_ci   *******************************************************************/
781159b3361Sopenharmony_ci    for (gr = 0; gr < mode_gr; gr++) {
782159b3361Sopenharmony_ci        int     ggain;
783159b3361Sopenharmony_ci        if (blocktype[gr][ch] == 2) {
784159b3361Sopenharmony_ci            n = 3 * SBMAX_s;
785159b3361Sopenharmony_ci            if (gtkinfo.flag123)
786159b3361Sopenharmony_ci                data = pplot1->sfb_s[gr][ch];
787159b3361Sopenharmony_ci            else
788159b3361Sopenharmony_ci                data = pplot->LAMEsfb_s[gr][ch];
789159b3361Sopenharmony_ci        }
790159b3361Sopenharmony_ci        else {
791159b3361Sopenharmony_ci            n = SBMAX_l;
792159b3361Sopenharmony_ci            if (gtkinfo.flag123)
793159b3361Sopenharmony_ci                data = pplot1->sfb[gr][ch];
794159b3361Sopenharmony_ci            else
795159b3361Sopenharmony_ci                data = pplot->LAMEsfb[gr][ch];
796159b3361Sopenharmony_ci        }
797159b3361Sopenharmony_ci
798159b3361Sopenharmony_ci        ymn = -1;
799159b3361Sopenharmony_ci        ymx = 10;
800159b3361Sopenharmony_ci        for (i = 0; i < n; i++) {
801159b3361Sopenharmony_ci            xcord[i] = i + 1;
802159b3361Sopenharmony_ci            if (blocktype[gr][ch] == SHORT_TYPE && !subblock_draw[i % 3])
803159b3361Sopenharmony_ci                ycord[i] = 0;
804159b3361Sopenharmony_ci            else
805159b3361Sopenharmony_ci                ycord[i] = -data[i];
806159b3361Sopenharmony_ci
807159b3361Sopenharmony_ci            ymx = (ycord[i] > ymx - 2) ? ycord[i] + 2 : ymx;
808159b3361Sopenharmony_ci            ymn = (ycord[i] < ymn) ? ycord[i] - 1 : ymn;
809159b3361Sopenharmony_ci        }
810159b3361Sopenharmony_ci
811159b3361Sopenharmony_ci        if (blocktype[gr][ch] == 2) {
812159b3361Sopenharmony_ci            sprintf(label2,
813159b3361Sopenharmony_ci                    "SFB scale=%i preflag=%i  %i%i%i",
814159b3361Sopenharmony_ci                    pplot1->scalefac_scale[gr][ch],
815159b3361Sopenharmony_ci                    pplot1->preflag[gr][ch],
816159b3361Sopenharmony_ci                    pplot1->sub_gain[gr][ch][0],
817159b3361Sopenharmony_ci                    pplot1->sub_gain[gr][ch][1], pplot1->sub_gain[gr][ch][2]);
818159b3361Sopenharmony_ci        }
819159b3361Sopenharmony_ci        else {
820159b3361Sopenharmony_ci            sprintf(label2, "SFB scale=%i preflag=%i", pplot1->scalefac_scale[gr][ch],
821159b3361Sopenharmony_ci                    pplot1->preflag[gr][ch]);
822159b3361Sopenharmony_ci        }
823159b3361Sopenharmony_ci
824159b3361Sopenharmony_ci        if (gtkinfo.flag123)
825159b3361Sopenharmony_ci            ggain = (pplot1->qss[gr][ch]);
826159b3361Sopenharmony_ci        else
827159b3361Sopenharmony_ci            ggain = (pplot->LAMEqss[gr][ch]);
828159b3361Sopenharmony_ci
829159b3361Sopenharmony_ci        sprintf(title2, " ggain=%i", ggain);
830159b3361Sopenharmony_ci        strcat(label2, title2);
831159b3361Sopenharmony_ci
832159b3361Sopenharmony_ci        xmn = 1;
833159b3361Sopenharmony_ci        xmx = n + 1;
834159b3361Sopenharmony_ci        gpk_bargraph_draw(sfbbox[gr], n, xcord, ycord,
835159b3361Sopenharmony_ci                          xmn, ymn, xmx, ymx, 1, label2, 0, grcolor[gr]);
836159b3361Sopenharmony_ci
837159b3361Sopenharmony_ci        ycord[0] = ycord[1] = 0;
838159b3361Sopenharmony_ci        xcord[0] = 1;
839159b3361Sopenharmony_ci        xcord[1] = n + 1;
840159b3361Sopenharmony_ci        gpk_rectangle_draw(sfbbox[gr], xcord, ycord, xmn, ymn, xmx, ymx, &yellow);
841159b3361Sopenharmony_ci
842159b3361Sopenharmony_ci
843159b3361Sopenharmony_ci    }
844159b3361Sopenharmony_ci
845159b3361Sopenharmony_ci
846159b3361Sopenharmony_ci}
847159b3361Sopenharmony_ci
848159b3361Sopenharmony_ci
849159b3361Sopenharmony_ci
850159b3361Sopenharmony_cistatic void
851159b3361Sopenharmony_ciupdate_progress(void)
852159b3361Sopenharmony_ci{
853159b3361Sopenharmony_ci    char    label[80];
854159b3361Sopenharmony_ci
855159b3361Sopenharmony_ci    int     tf = lame_get_totalframes(gfp);
856159b3361Sopenharmony_ci    if (gtkinfo.totalframes > 0)
857159b3361Sopenharmony_ci        tf = gtkinfo.totalframes;
858159b3361Sopenharmony_ci
859159b3361Sopenharmony_ci    sprintf(label, "Frame:%4i/%4i  %6.2fs", pplot->frameNum, (int) tf - 1, pplot->frametime);
860159b3361Sopenharmony_ci    gtk_progress_set_value(GTK_PROGRESS(frameprogress), (gdouble) pplot->frameNum);
861159b3361Sopenharmony_ci    gtk_label_set_text(GTK_LABEL(framecounter), label);
862159b3361Sopenharmony_ci}
863159b3361Sopenharmony_ci
864159b3361Sopenharmony_ci
865159b3361Sopenharmony_ci
866159b3361Sopenharmony_cistatic void
867159b3361Sopenharmony_cianalyze(void)
868159b3361Sopenharmony_ci{
869159b3361Sopenharmony_ci    if (idle_keepgoing) {
870159b3361Sopenharmony_ci        idle_count = 0;
871159b3361Sopenharmony_ci        idle_count_max = 0;
872159b3361Sopenharmony_ci        idle_keepgoing = 0;
873159b3361Sopenharmony_ci        idle_end = 0;
874159b3361Sopenharmony_ci    }
875159b3361Sopenharmony_ci    plot_frame();
876159b3361Sopenharmony_ci    update_progress();
877159b3361Sopenharmony_ci}
878159b3361Sopenharmony_ci
879159b3361Sopenharmony_cistatic void
880159b3361Sopenharmony_ciplotclick(GtkWidget * widget, gpointer data)
881159b3361Sopenharmony_ci{
882159b3361Sopenharmony_ci    analyze();
883159b3361Sopenharmony_ci}
884159b3361Sopenharmony_ci
885159b3361Sopenharmony_ci
886159b3361Sopenharmony_ci
887159b3361Sopenharmony_ci
888159b3361Sopenharmony_cistatic int
889159b3361Sopenharmony_ciframeadv1(GtkWidget * widget, gpointer data)
890159b3361Sopenharmony_ci{
891159b3361Sopenharmony_ci    int     i;
892159b3361Sopenharmony_ci    if (idle_keepgoing) {
893159b3361Sopenharmony_ci        if (idle_back) {
894159b3361Sopenharmony_ci            /* frame displayed is the old frame.  to advance, just swap in new frame */
895159b3361Sopenharmony_ci            idle_back--;
896159b3361Sopenharmony_ci            pplot = &Pinfo[READ_AHEAD + idle_back];
897159b3361Sopenharmony_ci        }
898159b3361Sopenharmony_ci        else {
899159b3361Sopenharmony_ci            /* advance the frame by reading in a new frame */
900159b3361Sopenharmony_ci            pplot = &Pinfo[READ_AHEAD];
901159b3361Sopenharmony_ci            if (mp3done) {
902159b3361Sopenharmony_ci                /* dont try to read any more frames, and quit if "finish MP3" was selected */
903159b3361Sopenharmony_ci                /* if (idle_finish) gtk_main_quit(); */
904159b3361Sopenharmony_ci                idle_count_max = 0;
905159b3361Sopenharmony_ci                idle_end = 0;
906159b3361Sopenharmony_ci            }
907159b3361Sopenharmony_ci            else {
908159b3361Sopenharmony_ci                /* read in the next frame */
909159b3361Sopenharmony_ci                for (i = NUMPINFO - 1; i > 0; i--)
910159b3361Sopenharmony_ci                    memcpy(&Pinfo[i], &Pinfo[i - 1], sizeof(plotting_data));
911159b3361Sopenharmony_ci                pinfo = &Pinfo[0];
912159b3361Sopenharmony_ci                pinfo->num_samples = gtkmakeframe();
913159b3361Sopenharmony_ci                if (pinfo->num_samples == 0 && gtkinfo.totalframes == 0)
914159b3361Sopenharmony_ci                    /* allow an extra frame to flush decoder buffers */
915159b3361Sopenharmony_ci                    gtkinfo.totalframes = pinfo->frameNum + 2;
916159b3361Sopenharmony_ci
917159b3361Sopenharmony_ci                if (pinfo->sampfreq)
918159b3361Sopenharmony_ci                    pinfo->frametime = (pinfo->frameNum) * 1152.0 / pinfo->sampfreq;
919159b3361Sopenharmony_ci                else
920159b3361Sopenharmony_ci                    pinfo->frametime = 0;
921159b3361Sopenharmony_ci
922159b3361Sopenharmony_ci                /* eof?
923159b3361Sopenharmony_ci                   if (!pinfo->num_samples) if (idle_finish) gtk_main_quit();
924159b3361Sopenharmony_ci                 */
925159b3361Sopenharmony_ci
926159b3361Sopenharmony_ci                pinfo->totbits = 0;
927159b3361Sopenharmony_ci                {
928159b3361Sopenharmony_ci                    int     gr, ch;
929159b3361Sopenharmony_ci                    for (gr = 0; gr < 2; gr++)
930159b3361Sopenharmony_ci                        for (ch = 0; ch < 2; ch++) {
931159b3361Sopenharmony_ci                            gtkinfo.totshort += (pinfo->mpg123blocktype[gr][ch] == 2);
932159b3361Sopenharmony_ci                            gtkinfo.totmix += !(pinfo->mixed[gr][ch] == 0);
933159b3361Sopenharmony_ci                            gtkinfo.totpreflag += (pinfo->preflag[gr][ch] == 1);
934159b3361Sopenharmony_ci                            pinfo->totbits += pinfo->mainbits[gr][ch];
935159b3361Sopenharmony_ci                        }
936159b3361Sopenharmony_ci                }
937159b3361Sopenharmony_ci                if (pinfo->frameNum > 0) /* start averaging at second frame */
938159b3361Sopenharmony_ci                    gtkinfo.avebits = (gtkinfo.avebits * ((pinfo->frameNum) - 1)
939159b3361Sopenharmony_ci                                       + pinfo->totbits) / (pinfo->frameNum);
940159b3361Sopenharmony_ci
941159b3361Sopenharmony_ci                gtkinfo.maxbits = MAX(gtkinfo.maxbits, pinfo->totbits);
942159b3361Sopenharmony_ci                gtkinfo.totemph += !(pinfo->emph == 0);
943159b3361Sopenharmony_ci                gtkinfo.totms += !(pinfo->ms_stereo == 0);
944159b3361Sopenharmony_ci                gtkinfo.totis += !(pinfo->i_stereo == 0);
945159b3361Sopenharmony_ci
946159b3361Sopenharmony_ci                if (gtkinfo.totalframes > 0)
947159b3361Sopenharmony_ci                    if (pplot->frameNum >= gtkinfo.totalframes - 1)
948159b3361Sopenharmony_ci                        mp3done = 1;
949159b3361Sopenharmony_ci            }
950159b3361Sopenharmony_ci        }
951159b3361Sopenharmony_ci
952159b3361Sopenharmony_ci        idle_count++;
953159b3361Sopenharmony_ci        if (gtkinfo.pupdate)
954159b3361Sopenharmony_ci            plot_frame();
955159b3361Sopenharmony_ci        update_progress();
956159b3361Sopenharmony_ci        if ((idle_count >= idle_count_max) && (!idle_end))
957159b3361Sopenharmony_ci            analyze();
958159b3361Sopenharmony_ci    }
959159b3361Sopenharmony_ci    else {
960159b3361Sopenharmony_ci        /*no processing to do, sleep in order to not monopolize CPU */
961159b3361Sopenharmony_ci        msleep(10);
962159b3361Sopenharmony_ci    }
963159b3361Sopenharmony_ci    return 1;
964159b3361Sopenharmony_ci}
965159b3361Sopenharmony_ci
966159b3361Sopenharmony_ci
967159b3361Sopenharmony_cistatic void
968159b3361Sopenharmony_ciframeadv(GtkWidget * widget, gpointer data)
969159b3361Sopenharmony_ci{
970159b3361Sopenharmony_ci    int     adv;
971159b3361Sopenharmony_ci
972159b3361Sopenharmony_ci    if (!strcmp((char *) data, "-1")) {
973159b3361Sopenharmony_ci        /* ignore if we've already gone back as far as possible */
974159b3361Sopenharmony_ci        if (pplot->frameNum == 0 || (idle_back == NUMBACK))
975159b3361Sopenharmony_ci            return;
976159b3361Sopenharmony_ci        idle_back++;
977159b3361Sopenharmony_ci        pplot = &Pinfo[READ_AHEAD + idle_back];
978159b3361Sopenharmony_ci        analyze();
979159b3361Sopenharmony_ci        return;
980159b3361Sopenharmony_ci    }
981159b3361Sopenharmony_ci
982159b3361Sopenharmony_ci
983159b3361Sopenharmony_ci    adv = 1;
984159b3361Sopenharmony_ci    if (!strcmp((char *) data, "1"))
985159b3361Sopenharmony_ci        adv = 1;
986159b3361Sopenharmony_ci    if (!strcmp((char *) data, "10"))
987159b3361Sopenharmony_ci        adv = 10;
988159b3361Sopenharmony_ci    if (!strcmp((char *) data, "100"))
989159b3361Sopenharmony_ci        adv = 100;
990159b3361Sopenharmony_ci    if (!strcmp((char *) data, "finish"))
991159b3361Sopenharmony_ci        idle_end = 1;
992159b3361Sopenharmony_ci
993159b3361Sopenharmony_ci
994159b3361Sopenharmony_ci    if (idle_keepgoing) {
995159b3361Sopenharmony_ci        /* already running - que up additional frame advance requests */
996159b3361Sopenharmony_ci        idle_count_max += adv;
997159b3361Sopenharmony_ci    }
998159b3361Sopenharmony_ci    else {
999159b3361Sopenharmony_ci        /* turn on idleing */
1000159b3361Sopenharmony_ci        idle_count_max = adv;
1001159b3361Sopenharmony_ci        idle_count = 0;
1002159b3361Sopenharmony_ci        idle_keepgoing = 1;
1003159b3361Sopenharmony_ci    }
1004159b3361Sopenharmony_ci}
1005159b3361Sopenharmony_ci
1006159b3361Sopenharmony_ci
1007159b3361Sopenharmony_ci
1008159b3361Sopenharmony_ci
1009159b3361Sopenharmony_ci/* another callback */
1010159b3361Sopenharmony_cistatic void
1011159b3361Sopenharmony_cidelete_event(GtkWidget * widget, GdkEvent * event, gpointer data)
1012159b3361Sopenharmony_ci{
1013159b3361Sopenharmony_ci    /* set MP3 done flag in case the File/Quit menu item has been selected */
1014159b3361Sopenharmony_ci    mp3done = 1;
1015159b3361Sopenharmony_ci
1016159b3361Sopenharmony_ci    if (hip) {
1017159b3361Sopenharmony_ci        hip_decode_exit(hip);
1018159b3361Sopenharmony_ci        hip = 0;
1019159b3361Sopenharmony_ci    }
1020159b3361Sopenharmony_ci    gtk_main_quit();
1021159b3361Sopenharmony_ci}
1022159b3361Sopenharmony_ci
1023159b3361Sopenharmony_ci
1024159b3361Sopenharmony_ci
1025159b3361Sopenharmony_ci
1026159b3361Sopenharmony_ci
1027159b3361Sopenharmony_ci
1028159b3361Sopenharmony_ci
1029159b3361Sopenharmony_cistatic void
1030159b3361Sopenharmony_cichannel_option(GtkWidget * widget, gpointer data)
1031159b3361Sopenharmony_ci{
1032159b3361Sopenharmony_ci    long    option;
1033159b3361Sopenharmony_ci    option = (long) data;
1034159b3361Sopenharmony_ci    switch (option) {
1035159b3361Sopenharmony_ci    case 1:
1036159b3361Sopenharmony_ci        gtkinfo.msflag = 0;
1037159b3361Sopenharmony_ci        gtkinfo.chflag = 0;
1038159b3361Sopenharmony_ci        break;
1039159b3361Sopenharmony_ci    case 2:
1040159b3361Sopenharmony_ci        gtkinfo.msflag = 0;
1041159b3361Sopenharmony_ci        gtkinfo.chflag = 1;
1042159b3361Sopenharmony_ci        break;
1043159b3361Sopenharmony_ci    case 3:
1044159b3361Sopenharmony_ci        gtkinfo.msflag = 1;
1045159b3361Sopenharmony_ci        gtkinfo.chflag = 0;
1046159b3361Sopenharmony_ci        break;
1047159b3361Sopenharmony_ci    case 4:
1048159b3361Sopenharmony_ci        gtkinfo.msflag = 1;
1049159b3361Sopenharmony_ci        gtkinfo.chflag = 1;
1050159b3361Sopenharmony_ci    }
1051159b3361Sopenharmony_ci    analyze();
1052159b3361Sopenharmony_ci}
1053159b3361Sopenharmony_cistatic void
1054159b3361Sopenharmony_cispec_option(GtkWidget * widget, gpointer data)
1055159b3361Sopenharmony_ci{
1056159b3361Sopenharmony_ci    long    option;
1057159b3361Sopenharmony_ci    option = (long) data;
1058159b3361Sopenharmony_ci    switch (option) {
1059159b3361Sopenharmony_ci    case 1:
1060159b3361Sopenharmony_ci        gtkinfo.kbflag = 0;
1061159b3361Sopenharmony_ci        break;
1062159b3361Sopenharmony_ci    case 2:
1063159b3361Sopenharmony_ci        gtkinfo.kbflag = 1;
1064159b3361Sopenharmony_ci        break;
1065159b3361Sopenharmony_ci    case 3:
1066159b3361Sopenharmony_ci        gtkinfo.flag123 = 0;
1067159b3361Sopenharmony_ci        break;
1068159b3361Sopenharmony_ci    case 4:
1069159b3361Sopenharmony_ci        gtkinfo.flag123 = 1;
1070159b3361Sopenharmony_ci        break;
1071159b3361Sopenharmony_ci    case 5:
1072159b3361Sopenharmony_ci        gtkinfo.pupdate = 1;
1073159b3361Sopenharmony_ci        break;
1074159b3361Sopenharmony_ci    case 6:
1075159b3361Sopenharmony_ci        gtkinfo.pupdate = 0;
1076159b3361Sopenharmony_ci        break;
1077159b3361Sopenharmony_ci    case 7:
1078159b3361Sopenharmony_ci        gtkinfo.sfblines = !gtkinfo.sfblines;
1079159b3361Sopenharmony_ci        break;
1080159b3361Sopenharmony_ci    case 8:
1081159b3361Sopenharmony_ci        gtkinfo.difference = !gtkinfo.difference;
1082159b3361Sopenharmony_ci        break;
1083159b3361Sopenharmony_ci    }
1084159b3361Sopenharmony_ci    analyze();
1085159b3361Sopenharmony_ci}
1086159b3361Sopenharmony_ci
1087159b3361Sopenharmony_cistatic  gint
1088159b3361Sopenharmony_cikey_press_event(GtkWidget * widget, GdkEventKey * event)
1089159b3361Sopenharmony_ci{
1090159b3361Sopenharmony_ci    /* is a switch() statement in lame forbidden? */
1091159b3361Sopenharmony_ci    if (event->keyval == '1') {
1092159b3361Sopenharmony_ci        subblock_draw[0] = 1;
1093159b3361Sopenharmony_ci        subblock_draw[1] = 0;
1094159b3361Sopenharmony_ci        subblock_draw[2] = 0;
1095159b3361Sopenharmony_ci        analyze();
1096159b3361Sopenharmony_ci    }
1097159b3361Sopenharmony_ci    else if (event->keyval == '2') {
1098159b3361Sopenharmony_ci        subblock_draw[0] = 0;
1099159b3361Sopenharmony_ci        subblock_draw[1] = 1;
1100159b3361Sopenharmony_ci        subblock_draw[2] = 0;
1101159b3361Sopenharmony_ci        analyze();
1102159b3361Sopenharmony_ci    }
1103159b3361Sopenharmony_ci    else if (event->keyval == '3') {
1104159b3361Sopenharmony_ci        subblock_draw[0] = 0;
1105159b3361Sopenharmony_ci        subblock_draw[1] = 0;
1106159b3361Sopenharmony_ci        subblock_draw[2] = 1;
1107159b3361Sopenharmony_ci        analyze();
1108159b3361Sopenharmony_ci    }
1109159b3361Sopenharmony_ci    else if (event->keyval == '0') {
1110159b3361Sopenharmony_ci        subblock_draw[0] = 1;
1111159b3361Sopenharmony_ci        subblock_draw[1] = 1;
1112159b3361Sopenharmony_ci        subblock_draw[2] = 1;
1113159b3361Sopenharmony_ci        analyze();
1114159b3361Sopenharmony_ci    }
1115159b3361Sopenharmony_ci    /* analyze(); */ /* dont redraw entire window for every key! */
1116159b3361Sopenharmony_ci    return 0;
1117159b3361Sopenharmony_ci}
1118159b3361Sopenharmony_ci
1119159b3361Sopenharmony_ci
1120159b3361Sopenharmony_ci/*! Get the mp3x version string. */
1121159b3361Sopenharmony_ci/*!
1122159b3361Sopenharmony_ci  \param void
1123159b3361Sopenharmony_ci  \return a pointer to a string which describes the version of mp3x.
1124159b3361Sopenharmony_ci*/
1125159b3361Sopenharmony_ciconst char *
1126159b3361Sopenharmony_ciget_mp3x_version(void)
1127159b3361Sopenharmony_ci{
1128159b3361Sopenharmony_ci#if   MP3X_ALPHA_VERSION > 0
1129159b3361Sopenharmony_ci    static /*@observer@ */ const char *const str =
1130159b3361Sopenharmony_ci        XSTR(MP3X_MAJOR_VERSION) "." XSTR(MP3X_MINOR_VERSION)
1131159b3361Sopenharmony_ci        " (alpha " XSTR(MP3X_ALPHA_VERSION) ", " __DATE__ " " __TIME__ ")";
1132159b3361Sopenharmony_ci#elif MP3X_BETA_VERSION > 0
1133159b3361Sopenharmony_ci    static /*@observer@ */ const char *const str =
1134159b3361Sopenharmony_ci        XSTR(MP3X_MAJOR_VERSION) "." XSTR(MP3X_MINOR_VERSION)
1135159b3361Sopenharmony_ci        " (beta " XSTR(MP3X_BETA_VERSION) ", " __DATE__ ")";
1136159b3361Sopenharmony_ci#else
1137159b3361Sopenharmony_ci    static /*@observer@ */ const char *const str =
1138159b3361Sopenharmony_ci        XSTR(MP3X_MAJOR_VERSION) "." XSTR(MP3X_MINOR_VERSION);
1139159b3361Sopenharmony_ci#endif
1140159b3361Sopenharmony_ci
1141159b3361Sopenharmony_ci    return str;
1142159b3361Sopenharmony_ci}
1143159b3361Sopenharmony_ci
1144159b3361Sopenharmony_ci
1145159b3361Sopenharmony_cistatic void
1146159b3361Sopenharmony_citext_window(GtkWidget * widget, gpointer data)
1147159b3361Sopenharmony_ci{
1148159b3361Sopenharmony_ci    long    option;
1149159b3361Sopenharmony_ci    GtkWidget *hbox, *vbox, *button, *box;
1150159b3361Sopenharmony_ci    GtkWidget *textwindow, *vscrollbar;
1151159b3361Sopenharmony_ci    char    text[256];
1152159b3361Sopenharmony_ci
1153159b3361Sopenharmony_ci    option = (long) data;
1154159b3361Sopenharmony_ci
1155159b3361Sopenharmony_ci    textwindow = gtk_window_new(GTK_WINDOW_DIALOG);
1156159b3361Sopenharmony_ci    gtk_signal_connect_object(GTK_OBJECT(window), "delete_event",
1157159b3361Sopenharmony_ci                              GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(textwindow));
1158159b3361Sopenharmony_ci
1159159b3361Sopenharmony_ci    gtk_container_set_border_width(GTK_CONTAINER(textwindow), 0);
1160159b3361Sopenharmony_ci    vbox = gtk_vbox_new(FALSE, 0);
1161159b3361Sopenharmony_ci    hbox = gtk_hbox_new(FALSE, 0);
1162159b3361Sopenharmony_ci
1163159b3361Sopenharmony_ci    button = gtk_button_new_with_label("close");
1164159b3361Sopenharmony_ci    gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
1165159b3361Sopenharmony_ci                              GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(textwindow));
1166159b3361Sopenharmony_ci
1167159b3361Sopenharmony_ci    box = gtk_text_new(NULL, NULL);
1168159b3361Sopenharmony_ci    gtk_text_set_editable(GTK_TEXT(box), FALSE);
1169159b3361Sopenharmony_ci    vscrollbar = gtk_vscrollbar_new(GTK_TEXT(box)->vadj);
1170159b3361Sopenharmony_ci
1171159b3361Sopenharmony_ci
1172159b3361Sopenharmony_ci    switch (option) {
1173159b3361Sopenharmony_ci    case 0:
1174159b3361Sopenharmony_ci        gtk_window_set_title(GTK_WINDOW(textwindow), "Documentation");
1175159b3361Sopenharmony_ci        gtk_widget_set_usize(box, 450, 500);
1176159b3361Sopenharmony_ci        gtk_text_set_word_wrap(GTK_TEXT(box), TRUE);
1177159b3361Sopenharmony_ci        /* text should be moved outside this function, may be in a separate file */
1178159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL,
1179159b3361Sopenharmony_ci                        "Frame header information: "
1180159b3361Sopenharmony_ci                        "First the bitrate, sampling frequency and mono, stereo or jstereo "
1181159b3361Sopenharmony_ci                        "indicators are displayed .  If the bitstream is jstereo, then mid/side "
1182159b3361Sopenharmony_ci                        "stereo or intensity stereo may be on (indicated in red).  If "
1183159b3361Sopenharmony_ci                        "de-emphasis is used, this is also indicated in red.  The mdb value is "
1184159b3361Sopenharmony_ci                        "main_data_begin.  The encoded data starts this many bytes *before* the "
1185159b3361Sopenharmony_ci                        "frame header.  A large value of mdb means the bitstream has saved some "
1186159b3361Sopenharmony_ci                        "bits into the reservoir, which it may allocate for some future frame. "
1187159b3361Sopenharmony_ci                        "The two numbers after mdb are the size (in bits) used to encode the "
1188159b3361Sopenharmony_ci                        "MDCT coefficients for this frame, followed byt the size of the bit "
1189159b3361Sopenharmony_ci                        "resevoir before encoding this frame.  The maximum frame size and a "
1190159b3361Sopenharmony_ci                        "running average are given in the Stats pull down menu.  A large "
1191159b3361Sopenharmony_ci                        "maximum frame size indicates the bitstream has made use of the bit "
1192159b3361Sopenharmony_ci                        "reservoir. \n\n", -1);
1193159b3361Sopenharmony_ci
1194159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL,
1195159b3361Sopenharmony_ci                        "PCM data (top graph): "
1196159b3361Sopenharmony_ci                        "The PCM data is plotted in black.  The layer3 frame is divided into 2 "
1197159b3361Sopenharmony_ci                        "granules of 576 samples (marked with yellow vertical lines).  In the "
1198159b3361Sopenharmony_ci                        "case of normal, start and stop blocks, the MDCT coefficients for each "
1199159b3361Sopenharmony_ci                        "granule are computed using a 1152 sample window centered over the "
1200159b3361Sopenharmony_ci                        "granule.  In the case of short blocks, the granule is further divided "
1201159b3361Sopenharmony_ci                        "into 3 blocks of 192 samples (also marked with yellow vertical lines)."
1202159b3361Sopenharmony_ci                        "The MDCT coefficients for these blocks are computed using 384 sample "
1203159b3361Sopenharmony_ci                        "windows centered over the 192 sample window.  (This info not available "
1204159b3361Sopenharmony_ci                        "when analyzing .mp3 files.)  For the psycho-acoustic model, a windowed "
1205159b3361Sopenharmony_ci                        "FFT is computed for each granule.  The range of these windows "
1206159b3361Sopenharmony_ci                        "is denoted by the blue and green bars.\n\n", -1);
1207159b3361Sopenharmony_ci
1208159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL,
1209159b3361Sopenharmony_ci                        "PCM re-synthesis data (second graph): "
1210159b3361Sopenharmony_ci                        "Same as the PCM window described above.  The data displayed is the "
1211159b3361Sopenharmony_ci                        "result of encoding and then decoding the original sample. \n\n", -1);
1212159b3361Sopenharmony_ci
1213159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL,
1214159b3361Sopenharmony_ci                        "MDCT windows: "
1215159b3361Sopenharmony_ci                        "Shows the energy in the MDCT spectrum for granule 0 (left window) "
1216159b3361Sopenharmony_ci                        "and granule 1 (right window).  The text also shows the blocktype "
1217159b3361Sopenharmony_ci                        "used, the number of bits used to encode the coefficients and the "
1218159b3361Sopenharmony_ci                        "number of extra bits allocated from the reservoir.  The MDCT pull down "
1219159b3361Sopenharmony_ci                        "window will toggle between the original unquantized MDCT coefficients "
1220159b3361Sopenharmony_ci                        "and the compressed (quantized) coefficients.\n\n", -1);
1221159b3361Sopenharmony_ci
1222159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL,
1223159b3361Sopenharmony_ci                        "FFT window: "
1224159b3361Sopenharmony_ci                        "The gray bars show the energy in the FFT spectrum used by the "
1225159b3361Sopenharmony_ci                        "psycho-acoustic model.  Granule 0 is in the left window, granule 1 in "
1226159b3361Sopenharmony_ci                        "the right window.  The green and blue bars show how much distortion is "
1227159b3361Sopenharmony_ci                        "allowable, as computed by the psycho-acoustic model. The red bars show "
1228159b3361Sopenharmony_ci                        "the actual distortion after encoding.  There is one FFT for each "
1229159b3361Sopenharmony_ci                        "granule, computed with a 1024 Hann window centered over the "
1230159b3361Sopenharmony_ci                        "appropriate granule.  (the range of this 1024 sample window is shown "
1231159b3361Sopenharmony_ci                        "by the blue and green bars in the PCM data window).  The Spectrum pull "
1232159b3361Sopenharmony_ci                        "down window will toggle between showing the energy in equally spaced "
1233159b3361Sopenharmony_ci                        "frequency domain and the scale factor bands used by layer3.  Finally, "
1234159b3361Sopenharmony_ci                        "the perceptual entropy, total energy and number of scalefactor bands "
1235159b3361Sopenharmony_ci                        "with audible distortion is shown.  (This info not available when "
1236159b3361Sopenharmony_ci                        "analyzing .mp3 files.)", -1);
1237159b3361Sopenharmony_ci
1238159b3361Sopenharmony_ci        break;
1239159b3361Sopenharmony_ci    case 1:
1240159b3361Sopenharmony_ci        /* Set the about box information */
1241159b3361Sopenharmony_ci        gtk_window_set_title(GTK_WINDOW(textwindow), "About");
1242159b3361Sopenharmony_ci        gtk_widget_set_usize(box, 350, 260);
1243159b3361Sopenharmony_ci
1244159b3361Sopenharmony_ci        sprintf(text, "LAME version %s \n%s\n\n", get_lame_version(), get_lame_url());
1245159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1246159b3361Sopenharmony_ci
1247159b3361Sopenharmony_ci        sprintf(text, "psycho-acoustic model:  GPSYCHO version %s\n", get_psy_version());
1248159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1249159b3361Sopenharmony_ci
1250159b3361Sopenharmony_ci        sprintf(text, "frame analyzer: MP3x version %s\n\n", get_mp3x_version());
1251159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1252159b3361Sopenharmony_ci
1253159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL,
1254159b3361Sopenharmony_ci                        "decoder:  mpg123/mpglib  .59q  \nMichael Hipp (www.mpg123.de)\n\n", -1);
1255159b3361Sopenharmony_ci
1256159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL,
1257159b3361Sopenharmony_ci                        "Encoder, decoder & psy-models based on ISO\ndemonstration source. ", -1);
1258159b3361Sopenharmony_ci        break;
1259159b3361Sopenharmony_ci
1260159b3361Sopenharmony_ci    case 2:
1261159b3361Sopenharmony_ci        gtk_window_set_title(GTK_WINDOW(textwindow), "Statistics");
1262159b3361Sopenharmony_ci        gtk_widget_set_usize(box, 350, 260);
1263159b3361Sopenharmony_ci        sprintf(text, "frames processed so far: %i \n", Pinfo[0].frameNum + 1);
1264159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1265159b3361Sopenharmony_ci        sprintf(text, "granules processed so far: %i \n\n", 4 * (Pinfo[0].frameNum + 1));
1266159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1267159b3361Sopenharmony_ci        sprintf(text, "mean bits/frame (approximate): %i\n", gtkinfo.approxbits);
1268159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1269159b3361Sopenharmony_ci        sprintf(text, "mean bits/frame (from LAME): %i\n", 4 * Pinfo[0].mean_bits);
1270159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1271159b3361Sopenharmony_ci        sprintf(text, "bitsize of largest frame: %i \n", gtkinfo.maxbits);
1272159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1273159b3361Sopenharmony_ci        sprintf(text, "average bits/frame: %3.1f \n\n", gtkinfo.avebits);
1274159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1275159b3361Sopenharmony_ci        sprintf(text, "ms_stereo frames: %i \n", gtkinfo.totms);
1276159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1277159b3361Sopenharmony_ci        sprintf(text, "i_stereo frames: %i \n", gtkinfo.totis);
1278159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1279159b3361Sopenharmony_ci        sprintf(text, "de-emphasis frames: %i \n", gtkinfo.totemph);
1280159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1281159b3361Sopenharmony_ci        sprintf(text, "short block granules: %i \n", gtkinfo.totshort);
1282159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1283159b3361Sopenharmony_ci        sprintf(text, "mixed block granules: %i \n", gtkinfo.totmix);
1284159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1285159b3361Sopenharmony_ci        sprintf(text, "preflag granules: %i \n", gtkinfo.totpreflag);
1286159b3361Sopenharmony_ci        gtk_text_insert(GTK_TEXT(box), NULL, NULL, NULL, text, -1);
1287159b3361Sopenharmony_ci        break;
1288159b3361Sopenharmony_ci    }
1289159b3361Sopenharmony_ci
1290159b3361Sopenharmony_ci
1291159b3361Sopenharmony_ci
1292159b3361Sopenharmony_ci    gtk_widget_show(vscrollbar);
1293159b3361Sopenharmony_ci    gtk_widget_show(box);
1294159b3361Sopenharmony_ci    gtk_widget_show(vbox);
1295159b3361Sopenharmony_ci    gtk_widget_show(hbox);
1296159b3361Sopenharmony_ci    gtk_widget_show(button);
1297159b3361Sopenharmony_ci
1298159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(hbox), box, FALSE, TRUE, 0);
1299159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(hbox), vscrollbar, FALSE, FALSE, 0);
1300159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
1301159b3361Sopenharmony_ci    gtk_box_pack_end(GTK_BOX(vbox), button, FALSE, TRUE, 0);
1302159b3361Sopenharmony_ci    gtk_container_add(GTK_CONTAINER(textwindow), vbox);
1303159b3361Sopenharmony_ci    gtk_widget_show(textwindow);
1304159b3361Sopenharmony_ci
1305159b3361Sopenharmony_ci}
1306159b3361Sopenharmony_ci
1307159b3361Sopenharmony_ci
1308159b3361Sopenharmony_ci
1309159b3361Sopenharmony_ci
1310159b3361Sopenharmony_ci/* #include <strings.h>*/
1311159b3361Sopenharmony_ci
1312159b3361Sopenharmony_ci
1313159b3361Sopenharmony_ci/* This is the GtkItemFactoryEntry structure used to generate new menus.
1314159b3361Sopenharmony_ci   Item 1: The menu path. The letter after the underscore indicates an
1315159b3361Sopenharmony_ci           accelerator key once the menu is open.
1316159b3361Sopenharmony_ci   Item 2: The accelerator key for the entry
1317159b3361Sopenharmony_ci   Item 3: The callback function.
1318159b3361Sopenharmony_ci   Item 4: The callback action.  This changes the parameters with
1319159b3361Sopenharmony_ci           which the function is called.  The default is 0.
1320159b3361Sopenharmony_ci   Item 5: The item type, used to define what kind of an item it is.
1321159b3361Sopenharmony_ci           Here are the possible values:
1322159b3361Sopenharmony_ci
1323159b3361Sopenharmony_ci           NULL               -> "<Item>"
1324159b3361Sopenharmony_ci           ""                 -> "<Item>"
1325159b3361Sopenharmony_ci           "<Title>"          -> create a title item
1326159b3361Sopenharmony_ci           "<Item>"           -> create a simple item
1327159b3361Sopenharmony_ci           "<CheckItem>"      -> create a check item
1328159b3361Sopenharmony_ci           "<ToggleItem>"     -> create a toggle item
1329159b3361Sopenharmony_ci           "<RadioItem>"      -> create a radio item
1330159b3361Sopenharmony_ci           <path>             -> path of a radio item to link against
1331159b3361Sopenharmony_ci           "<Separator>"      -> create a separator
1332159b3361Sopenharmony_ci           "<Branch>"         -> create an item to hold sub items
1333159b3361Sopenharmony_ci           "<LastBranch>"     -> create a right justified branch
1334159b3361Sopenharmony_ci*/
1335159b3361Sopenharmony_ci
1336159b3361Sopenharmony_ci
1337159b3361Sopenharmony_ci#define C(chr)       "<control>" #chr
1338159b3361Sopenharmony_ci#define func(name)   (GtkItemFactoryCallback) (name)
1339159b3361Sopenharmony_ci
1340159b3361Sopenharmony_cistatic const GtkItemFactoryEntry menu_items[] = {
1341159b3361Sopenharmony_ci    {"/_File", NULL, NULL, 0, "<Branch>"},
1342159b3361Sopenharmony_ci#if 0
1343159b3361Sopenharmony_ci    {"/File/_New", C(N), func(print_hello), 0, NULL},
1344159b3361Sopenharmony_ci    {"/File/_Open", C(O), func(print_hello), 0, NULL},
1345159b3361Sopenharmony_ci    {"/File/_Save", C(S), func(print_hello), 0, NULL},
1346159b3361Sopenharmony_ci    {"/File/Save _As", NULL, NULL, 0, NULL},
1347159b3361Sopenharmony_ci    {"/File/sep1", NULL, NULL, 0, "<Separator>"},
1348159b3361Sopenharmony_ci    {"/File/Quit", C(Q), func(gtk_main_quit), 0, NULL},
1349159b3361Sopenharmony_ci#endif
1350159b3361Sopenharmony_ci    {"/File/_Quit", C(Q), func(delete_event), 0, NULL},
1351159b3361Sopenharmony_ci
1352159b3361Sopenharmony_ci    {"/_Plotting", NULL, NULL, 0, "<Branch>"},
1353159b3361Sopenharmony_ci    {"/Plotting/_While advancing", NULL, func(spec_option), 5, NULL},
1354159b3361Sopenharmony_ci    {"/Plotting/_After advancing", NULL, func(spec_option), 6, NULL},
1355159b3361Sopenharmony_ci    {"/Plotting/Toggle SFB lines", NULL, func(spec_option), 7, NULL},
1356159b3361Sopenharmony_ci    {"/Plotting/Toggle orig-diff", NULL, func(spec_option), 8, NULL},
1357159b3361Sopenharmony_ci
1358159b3361Sopenharmony_ci    {"/_Channel", NULL, NULL, 0, "<Branch>"},
1359159b3361Sopenharmony_ci    {"/Channel/show _Left", NULL, func(channel_option), 1, NULL},
1360159b3361Sopenharmony_ci    {"/Channel/show _Right", NULL, func(channel_option), 2, NULL},
1361159b3361Sopenharmony_ci    {"/Channel/show _Mid", NULL, func(channel_option), 3, NULL},
1362159b3361Sopenharmony_ci    {"/Channel/show _Side", NULL, func(channel_option), 4, NULL},
1363159b3361Sopenharmony_ci
1364159b3361Sopenharmony_ci    {"/_Spectrum", NULL, NULL, 0, "<Branch>"},
1365159b3361Sopenharmony_ci    {"/Spectrum/_Scalefactor bands", NULL, func(spec_option), 1, NULL},
1366159b3361Sopenharmony_ci    {"/Spectrum/_Wave number", NULL, func(spec_option), 2, NULL},
1367159b3361Sopenharmony_ci
1368159b3361Sopenharmony_ci    {"/_MDCT", NULL, NULL, 0, "<Branch>"},
1369159b3361Sopenharmony_ci    {"/MDCT/_Original", NULL, func(spec_option), 3, NULL},
1370159b3361Sopenharmony_ci    {"/MDCT/_Compressed", NULL, func(spec_option), 4, NULL},
1371159b3361Sopenharmony_ci    {"/MDCT/_Toggle SFB lines", NULL, func(spec_option), 7, NULL},
1372159b3361Sopenharmony_ci
1373159b3361Sopenharmony_ci    {"/_Stats", NULL, NULL, 0, "<Branch>"},
1374159b3361Sopenharmony_ci    {"/Stats/_Show", NULL, func(text_window), 2, NULL},
1375159b3361Sopenharmony_ci
1376159b3361Sopenharmony_ci    {"/_Help", NULL, NULL, 0, "<LastBranch>"},
1377159b3361Sopenharmony_ci    {"/_Help/_Documentation", NULL, func(text_window), 0, NULL},
1378159b3361Sopenharmony_ci    {"/_Help/_About", NULL, func(text_window), 1, NULL},
1379159b3361Sopenharmony_ci};
1380159b3361Sopenharmony_ci
1381159b3361Sopenharmony_ci#undef C
1382159b3361Sopenharmony_ci#undef func
1383159b3361Sopenharmony_ci
1384159b3361Sopenharmony_ci
1385159b3361Sopenharmony_cistatic void
1386159b3361Sopenharmony_ciget_main_menu(GtkWidget * windows, GtkWidget ** menubar)
1387159b3361Sopenharmony_ci{
1388159b3361Sopenharmony_ci    unsigned int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
1389159b3361Sopenharmony_ci    GtkItemFactory *item_factory;
1390159b3361Sopenharmony_ci    GtkAccelGroup *accel_group;
1391159b3361Sopenharmony_ci
1392159b3361Sopenharmony_ci    accel_group = gtk_accel_group_new();
1393159b3361Sopenharmony_ci
1394159b3361Sopenharmony_ci    /* This function initializes the item factory.
1395159b3361Sopenharmony_ci       Param 1: The type of menu - can be GTK_TYPE_MENU_BAR, GTK_TYPE_MENU,
1396159b3361Sopenharmony_ci       or GTK_TYPE_OPTION_MENU.
1397159b3361Sopenharmony_ci       Param 2: The path of the menu.
1398159b3361Sopenharmony_ci       Param 3: A pointer to a gtk_accel_group.  The item factory sets up
1399159b3361Sopenharmony_ci       the accelerator table while generating menus.
1400159b3361Sopenharmony_ci     */
1401159b3361Sopenharmony_ci
1402159b3361Sopenharmony_ci    item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group);
1403159b3361Sopenharmony_ci
1404159b3361Sopenharmony_ci    /* This function generates the menu items. Pass the item factory,
1405159b3361Sopenharmony_ci       the number of items in the array, the array itself, and any
1406159b3361Sopenharmony_ci       callback data for the the menu items. */
1407159b3361Sopenharmony_ci    gtk_item_factory_create_items(item_factory, nmenu_items, (GtkItemFactoryEntry *) menu_items,
1408159b3361Sopenharmony_ci                                  NULL);
1409159b3361Sopenharmony_ci
1410159b3361Sopenharmony_ci    /* Attach the new accelerator group to the window. */
1411159b3361Sopenharmony_ci    gtk_accel_group_attach(accel_group, GTK_OBJECT(windows));
1412159b3361Sopenharmony_ci
1413159b3361Sopenharmony_ci    if (menubar)
1414159b3361Sopenharmony_ci        /* Finally, return the actual menu bar created by the item factory. */
1415159b3361Sopenharmony_ci        *menubar = gtk_item_factory_get_widget(item_factory, "<main>");
1416159b3361Sopenharmony_ci}
1417159b3361Sopenharmony_ci
1418159b3361Sopenharmony_ci
1419159b3361Sopenharmony_ci
1420159b3361Sopenharmony_ci
1421159b3361Sopenharmony_ci
1422159b3361Sopenharmony_ci
1423159b3361Sopenharmony_ci
1424159b3361Sopenharmony_ci
1425159b3361Sopenharmony_ci
1426159b3361Sopenharmony_ci
1427159b3361Sopenharmony_ci
1428159b3361Sopenharmony_ci
1429159b3361Sopenharmony_ci
1430159b3361Sopenharmony_ci
1431159b3361Sopenharmony_ci
1432159b3361Sopenharmony_ci
1433159b3361Sopenharmony_ciint
1434159b3361Sopenharmony_cigtkcontrol(lame_global_flags * gfp2, char *inPath)
1435159b3361Sopenharmony_ci{
1436159b3361Sopenharmony_ci    /* GtkWidget is the storage type for widgets */
1437159b3361Sopenharmony_ci    GtkWidget *button;
1438159b3361Sopenharmony_ci    GtkAdjustment *adj;
1439159b3361Sopenharmony_ci    GtkWidget *mbox;         /* main box */
1440159b3361Sopenharmony_ci    GtkWidget *box1;         /* frame control buttons go */
1441159b3361Sopenharmony_ci    GtkWidget *box2;         /* frame counters */
1442159b3361Sopenharmony_ci    GtkWidget *box3;         /* frame header info */
1443159b3361Sopenharmony_ci    GtkWidget *table;        /* table for all the plotting areas */
1444159b3361Sopenharmony_ci    GtkWidget *menubar;
1445159b3361Sopenharmony_ci
1446159b3361Sopenharmony_ci    gint    tableops, graphx, graphy;
1447159b3361Sopenharmony_ci    char    frameinfo[80];
1448159b3361Sopenharmony_ci
1449159b3361Sopenharmony_ci    graphx = 600;       /* minimum allowed size of pixmap */
1450159b3361Sopenharmony_ci    graphy = 95;
1451159b3361Sopenharmony_ci
1452159b3361Sopenharmony_ci    gfp = gfp2;
1453159b3361Sopenharmony_ci    gfc = gfp->internal_flags;
1454159b3361Sopenharmony_ci
1455159b3361Sopenharmony_ci    /* set some global defaults/variables */
1456159b3361Sopenharmony_ci    gtkinfo.filetype = is_mpeg_file_format(global_reader.input_format) ? 1 : 0;
1457159b3361Sopenharmony_ci    gtkinfo.msflag = 0;
1458159b3361Sopenharmony_ci    gtkinfo.chflag = 0;
1459159b3361Sopenharmony_ci    gtkinfo.kbflag = 0;
1460159b3361Sopenharmony_ci    gtkinfo.flag123 = is_mpeg_file_format(global_reader.input_format) ? 1 : 0; /* MP3 file=use mpg123 output */
1461159b3361Sopenharmony_ci    gtkinfo.pupdate = 0;
1462159b3361Sopenharmony_ci    gtkinfo.avebits = 0;
1463159b3361Sopenharmony_ci    gtkinfo.maxbits = 0;
1464159b3361Sopenharmony_ci    gtkinfo.approxbits = 0;
1465159b3361Sopenharmony_ci    gtkinfo.totemph = 0;
1466159b3361Sopenharmony_ci    gtkinfo.totms = 0;
1467159b3361Sopenharmony_ci    gtkinfo.totis = 0;
1468159b3361Sopenharmony_ci    gtkinfo.totshort = 0;
1469159b3361Sopenharmony_ci    gtkinfo.totmix = 0;
1470159b3361Sopenharmony_ci    gtkinfo.sfblines = 1;
1471159b3361Sopenharmony_ci    gtkinfo.difference = 0;
1472159b3361Sopenharmony_ci    gtkinfo.totalframes = 0;
1473159b3361Sopenharmony_ci
1474159b3361Sopenharmony_ci    memset((char *) Pinfo, 0, sizeof(Pinfo));
1475159b3361Sopenharmony_ci    pplot = &Pinfo[READ_AHEAD];
1476159b3361Sopenharmony_ci
1477159b3361Sopenharmony_ci    strcpy(frameinfo, "MP3x: ");
1478159b3361Sopenharmony_ci    strncat(frameinfo, inPath, 70);
1479159b3361Sopenharmony_ci
1480159b3361Sopenharmony_ci    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1481159b3361Sopenharmony_ci    gtk_window_set_title(GTK_WINDOW(window), frameinfo);
1482159b3361Sopenharmony_ci    gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL);
1483159b3361Sopenharmony_ci
1484159b3361Sopenharmony_ci    gtk_signal_connect_object(GTK_OBJECT(window), "key_press_event",
1485159b3361Sopenharmony_ci                              GTK_SIGNAL_FUNC(key_press_event), GTK_OBJECT(window));
1486159b3361Sopenharmony_ci
1487159b3361Sopenharmony_ci    gtk_container_set_border_width(GTK_CONTAINER(window), 0);
1488159b3361Sopenharmony_ci
1489159b3361Sopenharmony_ci
1490159b3361Sopenharmony_ci    mbox = gtk_vbox_new(FALSE, 0);
1491159b3361Sopenharmony_ci
1492159b3361Sopenharmony_ci
1493159b3361Sopenharmony_ci    /* layout of mbox */
1494159b3361Sopenharmony_ci    box1 = gtk_hbox_new(FALSE, 0);
1495159b3361Sopenharmony_ci    box2 = gtk_hbox_new(FALSE, 0);
1496159b3361Sopenharmony_ci    box3 = gtk_hbox_new(FALSE, 0);
1497159b3361Sopenharmony_ci    table = gtk_table_new(5, 2, FALSE);
1498159b3361Sopenharmony_ci    tableops = GTK_FILL | GTK_EXPAND | GTK_SHRINK;
1499159b3361Sopenharmony_ci    get_main_menu(window, &menubar);
1500159b3361Sopenharmony_ci
1501159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(mbox), menubar, FALSE, TRUE, 0);
1502159b3361Sopenharmony_ci    gtk_box_pack_end(GTK_BOX(mbox), box1, FALSE, TRUE, 0);
1503159b3361Sopenharmony_ci    gtk_box_pack_end(GTK_BOX(mbox), box2, FALSE, TRUE, 0);
1504159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(mbox), box3, FALSE, TRUE, 0);
1505159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(mbox), table, TRUE, TRUE, 0);
1506159b3361Sopenharmony_ci    gtk_container_add(GTK_CONTAINER(window), mbox);
1507159b3361Sopenharmony_ci
1508159b3361Sopenharmony_ci
1509159b3361Sopenharmony_ci    /*********************************************************************/
1510159b3361Sopenharmony_ci    /* stuff in box3  frame header info */
1511159b3361Sopenharmony_ci    /*********************************************************************/
1512159b3361Sopenharmony_ci    /*
1513159b3361Sopenharmony_ci       headerbox = gtk_label_new(" ");
1514159b3361Sopenharmony_ci       gtk_label_set_justify(GTK_LABEL(headerbox),GTK_JUSTIFY_LEFT);
1515159b3361Sopenharmony_ci     */
1516159b3361Sopenharmony_ci    headerbox = gtk_text_new(NULL, NULL);
1517159b3361Sopenharmony_ci    gtk_text_set_editable(GTK_TEXT(headerbox), FALSE);
1518159b3361Sopenharmony_ci    gtk_widget_set_usize(headerbox, 200, 20);
1519159b3361Sopenharmony_ci    gtk_widget_show(headerbox);
1520159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(box3), headerbox, TRUE, TRUE, 0);
1521159b3361Sopenharmony_ci
1522159b3361Sopenharmony_ci
1523159b3361Sopenharmony_ci
1524159b3361Sopenharmony_ci    /*********************************************************************/
1525159b3361Sopenharmony_ci    /* stuff in box2   frame counters  */
1526159b3361Sopenharmony_ci    /*********************************************************************/
1527159b3361Sopenharmony_ci    framecounter = gtk_label_new("");
1528159b3361Sopenharmony_ci    gtk_widget_show(framecounter);
1529159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(box2), framecounter, FALSE, TRUE, 0);
1530159b3361Sopenharmony_ci
1531159b3361Sopenharmony_ci    adj = (GtkAdjustment *) gtk_adjustment_new(0, 0, (gint) lame_get_totalframes(gfp) - 1, 0, 0, 0);
1532159b3361Sopenharmony_ci    frameprogress = gtk_progress_bar_new_with_adjustment(adj);
1533159b3361Sopenharmony_ci    /* Set the format of the string that can be displayed in the
1534159b3361Sopenharmony_ci     * trough of the progress bar:
1535159b3361Sopenharmony_ci     * %p - percentage
1536159b3361Sopenharmony_ci     * %v - value
1537159b3361Sopenharmony_ci     * %l - lower range value
1538159b3361Sopenharmony_ci     * %u - upper range value */
1539159b3361Sopenharmony_ci    gtk_progress_set_format_string(GTK_PROGRESS(frameprogress), "%p%%");
1540159b3361Sopenharmony_ci    gtk_progress_set_value(GTK_PROGRESS(frameprogress), (gdouble) 0);
1541159b3361Sopenharmony_ci    gtk_progress_set_show_text(GTK_PROGRESS(frameprogress), TRUE);
1542159b3361Sopenharmony_ci    gtk_widget_show(frameprogress);
1543159b3361Sopenharmony_ci    gtk_box_pack_end(GTK_BOX(box2), frameprogress, FALSE, TRUE, 0);
1544159b3361Sopenharmony_ci
1545159b3361Sopenharmony_ci
1546159b3361Sopenharmony_ci
1547159b3361Sopenharmony_ci    /*********************************************************************/
1548159b3361Sopenharmony_ci    /* stuff in box1  buttons along bottom */
1549159b3361Sopenharmony_ci    /*********************************************************************/
1550159b3361Sopenharmony_ci    button = gtk_button_new_with_label("-1");
1551159b3361Sopenharmony_ci    gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(frameadv), (gpointer) "-1");
1552159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
1553159b3361Sopenharmony_ci    gtk_widget_show(button);
1554159b3361Sopenharmony_ci
1555159b3361Sopenharmony_ci    button = gtk_button_new_with_label("+1");
1556159b3361Sopenharmony_ci    gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(frameadv), (gpointer) "1");
1557159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
1558159b3361Sopenharmony_ci    gtk_widget_show(button);
1559159b3361Sopenharmony_ci
1560159b3361Sopenharmony_ci    button = gtk_button_new_with_label("+10");
1561159b3361Sopenharmony_ci    gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(frameadv), (gpointer) "10");
1562159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
1563159b3361Sopenharmony_ci    gtk_widget_show(button);
1564159b3361Sopenharmony_ci
1565159b3361Sopenharmony_ci    button = gtk_button_new_with_label("+100");
1566159b3361Sopenharmony_ci    gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(frameadv), (gpointer) "100");
1567159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
1568159b3361Sopenharmony_ci    gtk_widget_show(button);
1569159b3361Sopenharmony_ci
1570159b3361Sopenharmony_ci    button = gtk_button_new_with_label("last frame");
1571159b3361Sopenharmony_ci    gtk_signal_connect(GTK_OBJECT(button), "clicked",
1572159b3361Sopenharmony_ci                       GTK_SIGNAL_FUNC(frameadv), (gpointer) "finish");
1573159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
1574159b3361Sopenharmony_ci    gtk_widget_show(button);
1575159b3361Sopenharmony_ci
1576159b3361Sopenharmony_ci    button = gtk_button_new_with_label("stop/plot");
1577159b3361Sopenharmony_ci    gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(plotclick), NULL);
1578159b3361Sopenharmony_ci    gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
1579159b3361Sopenharmony_ci    gtk_widget_show(button);
1580159b3361Sopenharmony_ci
1581159b3361Sopenharmony_ci
1582159b3361Sopenharmony_ci    /*********************************************************************/
1583159b3361Sopenharmony_ci    /* stuff in table.  all the plotting windows */
1584159b3361Sopenharmony_ci    /*********************************************************************/
1585159b3361Sopenharmony_ci    pcmbox = gpk_plot_new(graphx, graphy);
1586159b3361Sopenharmony_ci    gtk_table_attach(GTK_TABLE(table), pcmbox, 0, 2, 0, 1, tableops, tableops, 2, 2);
1587159b3361Sopenharmony_ci    gtk_widget_show(pcmbox);
1588159b3361Sopenharmony_ci
1589159b3361Sopenharmony_ci    winbox = gpk_plot_new(graphy, graphy);
1590159b3361Sopenharmony_ci    gtk_table_attach(GTK_TABLE(table), winbox, 0, 2, 1, 2, tableops, tableops, 2, 2);
1591159b3361Sopenharmony_ci    gtk_widget_show(winbox);
1592159b3361Sopenharmony_ci
1593159b3361Sopenharmony_ci
1594159b3361Sopenharmony_ci    mdctbox[0] = gpk_plot_new(graphy, graphy);
1595159b3361Sopenharmony_ci    gtk_table_attach(GTK_TABLE(table), mdctbox[0], 0, 1, 2, 3, tableops, tableops, 2, 2);
1596159b3361Sopenharmony_ci    gtk_widget_show(mdctbox[0]);
1597159b3361Sopenharmony_ci
1598159b3361Sopenharmony_ci    mdctbox[1] = gpk_plot_new(graphy, graphy);
1599159b3361Sopenharmony_ci    gtk_table_attach(GTK_TABLE(table), mdctbox[1], 1, 2, 2, 3, tableops, tableops, 2, 2);
1600159b3361Sopenharmony_ci    gtk_widget_show(mdctbox[1]);
1601159b3361Sopenharmony_ci
1602159b3361Sopenharmony_ci    enerbox[0] = gpk_plot_new(graphy, graphy);
1603159b3361Sopenharmony_ci    gtk_table_attach(GTK_TABLE(table), enerbox[0], 0, 1, 3, 4, tableops, tableops, 2, 2);
1604159b3361Sopenharmony_ci    gtk_widget_show(enerbox[0]);
1605159b3361Sopenharmony_ci
1606159b3361Sopenharmony_ci    enerbox[1] = gpk_plot_new(graphy, graphy);
1607159b3361Sopenharmony_ci    gtk_table_attach(GTK_TABLE(table), enerbox[1], 1, 2, 3, 4, tableops, tableops, 2, 2);
1608159b3361Sopenharmony_ci    gtk_widget_show(enerbox[1]);
1609159b3361Sopenharmony_ci
1610159b3361Sopenharmony_ci    sfbbox[0] = gpk_plot_new(graphy, graphy);
1611159b3361Sopenharmony_ci    gtk_table_attach(GTK_TABLE(table), sfbbox[0], 0, 1, 4, 5, tableops, tableops, 2, 2);
1612159b3361Sopenharmony_ci    gtk_widget_show(sfbbox[0]);
1613159b3361Sopenharmony_ci
1614159b3361Sopenharmony_ci    sfbbox[1] = gpk_plot_new(graphy, graphy);
1615159b3361Sopenharmony_ci    gtk_table_attach(GTK_TABLE(table), sfbbox[1], 1, 2, 4, 5, tableops, tableops, 2, 2);
1616159b3361Sopenharmony_ci    gtk_widget_show(sfbbox[1]);
1617159b3361Sopenharmony_ci
1618159b3361Sopenharmony_ci
1619159b3361Sopenharmony_ci
1620159b3361Sopenharmony_ci
1621159b3361Sopenharmony_ci    gtk_idle_add((GtkFunction) frameadv1, NULL);
1622159b3361Sopenharmony_ci    gtk_widget_show(menubar);
1623159b3361Sopenharmony_ci    gtk_widget_show(box2);
1624159b3361Sopenharmony_ci    gtk_widget_show(box3);
1625159b3361Sopenharmony_ci    gtk_widget_show(table);
1626159b3361Sopenharmony_ci    gtk_widget_show(box1);
1627159b3361Sopenharmony_ci    gtk_widget_show(mbox);
1628159b3361Sopenharmony_ci    gtk_widget_show(window); /* show smallest allowed window */
1629159b3361Sopenharmony_ci
1630159b3361Sopenharmony_ci    /* make window bigger.   */
1631159b3361Sopenharmony_ci    /* now the user will be able to shrink it, if desired */
1632159b3361Sopenharmony_ci    /* gtk_widget_set_usize(mbox,500,500);  */
1633159b3361Sopenharmony_ci    /* gtk_widget_show (window); */ /* show smallest allowed window */
1634159b3361Sopenharmony_ci
1635159b3361Sopenharmony_ci
1636159b3361Sopenharmony_ci
1637159b3361Sopenharmony_ci    idle_keepgoing = 1; /* processing of frames is ON */
1638159b3361Sopenharmony_ci    idle_count_max = READ_AHEAD + 1; /* number of frames to process before plotting */
1639159b3361Sopenharmony_ci    idle_count = 0;     /* pause & plot when idle_count=idle_count_max */
1640159b3361Sopenharmony_ci
1641159b3361Sopenharmony_ci    gtk_main();
1642159b3361Sopenharmony_ci
1643159b3361Sopenharmony_ci    assert(mp3done);
1644159b3361Sopenharmony_ci    return (0);
1645159b3361Sopenharmony_ci}
1646