File: support_functions.h

package info (click to toggle)
checkmp3 1.98-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 180 kB
  • ctags: 136
  • sloc: ansic: 1,212; makefile: 60
file content (690 lines) | stat: -rw-r--r-- 17,282 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/***************************************************
*
* These functions below rarely get changed, so
* I'm going to put them here so there's less
* clutter in the main C file.
*
****************************************************/

// Function prototypes go here
inline int	cmp_str(const char *full_str, const char *chk_str, int full_str_offset);
int		check_header_value(unsigned int *header, char *filename, frame_info *FI);
int		check_vbr_and_time(frame_info *mp3_i, vbr_data *vbr_info, gen_info *file_info);
int		copy_int_array_to_str(char *possible_mp3_tag, char *tag_field, int offset, int length, int max_length);
int		dump_id3_tag(id3_tag_info *id3_tag);
int		get_last_char_offset(char *fat_string);
int		print_frame_info(frame_info *mp3_i, gen_info *file_info);
int		rotate_char_array(char *byte_list, int *new_byte, gen_info *file_info);
int		transform_char_array(char *byte_list, gen_info *file_info);
int		validate_id3_tag(char *possible_mp3_tag, id3_tag_info *id3_tag);
void		init_id3_tag_struct(id3_tag_info *TAG);
void		init_vbr_tag_struct(vbr_data *vbr_info);
void		init_mp3_time_struct(mp3_time *song_time);
void		init_gen_info_struct(gen_info *file_info);
void		print_sys_usage(void);
void		translate_time(gen_info *file_info, mp3_time *song_time);


void
init_vbr_tag_struct(vbr_info)
	vbr_data	*vbr_info;
{
	vbr_info->high_rate	= 0;
	vbr_info->low_rate	= 0;
	vbr_info->ave_rate	= 0;
	vbr_info->sum_rate	= 0;
}

void
init_gen_info_struct(file_info)
	gen_info	*file_info;
{
	file_info->file_pos 		= 0;
	file_info->good_frame_count	= 0;
	file_info->bad_frame_count	= 0;
	file_info->frame_sequence_count	= 0;
	file_info->byte_count		= 0;
	file_info->next_expected_frame	= 4;
	file_info->time_in_seconds 	= 0;
}

void
init_mp3_time_struct(song_time)
	mp3_time	*song_time;
{
	song_time->minutes	= 0;
	song_time->seconds	= 0;
	song_time->frac_second	= 0;
}
	
inline int
cmp_str (full_str, chk_str, full_str_offset)
	register const char * full_str;
	register const char * chk_str;
	int full_str_offset;
{
	int     check_state     = FAIL;
	int     start           = 31 - full_str_offset; /* ?? */

	if (!memcmp (full_str+start, chk_str, strlen(chk_str)))
		return PASS;

	return check_state;
}

int
copy_int_array_to_str(possible_mp3_tag, tag_field, offset, length, max_length)
	char		*possible_mp3_tag;
	char		*tag_field;
	int		offset;
	int		length;
	int		max_length;
{
	int 	counter = 0;
	int 	position = 0;

	if (max_length < (offset + length))
		return(FAIL);

	for (position = offset ; position < (offset + length) ; position++) {
		*(tag_field + counter) = (char)*(possible_mp3_tag + position);
		counter++;
	}

	return(PASS);
}	

int
validate_id3_tag(possible_mp3_tag, id3_tag)
	char		*possible_mp3_tag;
	id3_tag_info 	*id3_tag;
{
	//  The first 3 characters must be "TAG" for it 
	//  to be an id3 tag. 

	//  
	//  This section is just to see the 128 bit buffer in numerical format 
	//  
	
	if ((possible_mp3_tag[0] == 'T') && (possible_mp3_tag[1] == 'A') && (possible_mp3_tag[2] == 'G')) {
		id3_tag->TAG_PRESENT = YES;

		if (possible_mp3_tag[126] != '\0') {
			id3_tag->TRACK_NUMBER = possible_mp3_tag[126];
			id3_tag->ID3_311_VERSION = YES;
		} else {
			id3_tag->TRACK_NUMBER = 0;
			id3_tag->ID3_311_VERSION = NO;
		}
			

		id3_tag->GENRE = possible_mp3_tag[127];

		copy_int_array_to_str(possible_mp3_tag, id3_tag->TITLE, 3, 30, 128);
		copy_int_array_to_str(possible_mp3_tag, id3_tag->ARTIST, 33, 30, 128);
		copy_int_array_to_str(possible_mp3_tag, id3_tag->ALBUM, 63, 30, 128);
		copy_int_array_to_str(possible_mp3_tag, id3_tag->YEAR, 93, 4, 128);
		copy_int_array_to_str(possible_mp3_tag, id3_tag->COMMENT, 97, 30, 128);


		//  This section below does not work because I am working with an 
		//  integer array and not a character array. The reason for that is that 
		//  with a character array, if there are any nulls, the array shortens and 
		//  I need the (null)s to find out certain info... 
		
		// memcpy(id3_tag->TITLE, possible_mp3_tag + 3, 30); 
		// memcpy(id3_tag->ARTIST, possible_mp3_tag + 33, 30); 
		// memcpy(id3_tag->ALBUM, possible_mp3_tag + 63, 30); 
		// memcpy(id3_tag->YEAR, possible_mp3_tag + 93, 4); 
		// memcpy(id3_tag->COMMENT, possible_mp3_tag + 97, 30); 
	} else {
		id3_tag->TAG_PRESENT = NO;
		return(FAIL);
	}

	return(PASS);
}

void
init_id3_tag_struct(TAG)
	id3_tag_info *TAG;
{
	TAG->TAG_PRESENT = NO;
	TAG->ID3_311_VERSION = NO;

	memset(TAG->TITLE, '\0', sizeof(TAG->TITLE));
	memset(TAG->ARTIST, '\0', sizeof(TAG->ARTIST));
	memset(TAG->ALBUM, '\0', sizeof(TAG->ALBUM));
	memset(TAG->YEAR, '\0', sizeof(TAG->YEAR));
	memset(TAG->COMMENT, '\0', sizeof(TAG->COMMENT));

	TAG->GENRE = 0;
	TAG->TRACK_NUMBER = 0;
	TAG->COMPLIANT_PAD_FIELDS = NO;
}

int
check_header_value(header, filename, FI)
	unsigned int	*header;
	char		*filename;
	frame_info	*FI;
{
	//  
	//  This is the one function that truely will make this a  
	//  bad-ass proggie. Lots of logic can go in here to check 
	//  for compliant mp3s. 
	//  

	char	bin_string[33] = {0};
	int	i = 0;
	int	value_part = 0;
	int	column_part = 0;


	//  The last column makes it easy to trap the 'everything else' stuff... 
	static int bitrate_matrix[6][16] = {
		{1, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0},
		{1, 32, 48, 56, 64,  80,  96,  112, 128, 160, 192, 224, 256, 320, 384, 0},
		{1, 32, 40, 48, 56,  64,  80,  96,  112, 128, 160, 192, 224, 256, 320, 0},
		{1, 32, 48, 56, 64,  80,  96,  112, 128, 144, 160, 176, 192, 224, 256, 0},
		{1, 8,	16, 24, 32,  40,  48,  56,  64,	 80,  96,  112, 128, 144, 160, 0},
		{0, 0,	0,  0,  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0}
	};

	static int sampling_rate_matrix[4][3] = {
		{44100,	22050,	11025},
		{48000,	24000,	12000},
		{32000,	16000,	8000},
		{0,	0,	0}
	};

	//  For debugging purposes 
	// printf("HV: %d\n", *header); 

	//  
	//  Set the default return value of this funtion to FAIL 
	//  in case of a invalid header. 
	//  
	FI->check_state = FAIL;

	bin_string[32] = '\0';

	for (i=0 ; i < 32 ; i++) {
		bin_string[i] = '0';
	}


	//  
	//  Convert 32bit integer to binary. 
	//  
	for (i=0 ; i < 32 ; i++){
		if (((*header >> i) & 1) == 1){
			bin_string[31 - i] = '1';
		}
	}

	//  Store this data in case I want to print it 
	//  out for debugging stuff. 

	strcpy(FI->BIN_STRING, bin_string);
	FI->INT_HEADER = *header;

	//  
	//  Is it a mp3 sync bit? 
	//  
	//  Don't even continue if it doesn't pass this one. 
	//  

	if (cmp_str(bin_string, "11111111111", 31))
		FI->check_state = PASS;
	else
		return FI->check_state;


	//  
	//  Get the MPEG version 
	//  
	if (cmp_str(bin_string, "00", 20))
		FI->MPV_25 = TRUE;

	else if (cmp_str(bin_string, "01", 20))
		FI->MPV_RESERVED = TRUE;

	else if (cmp_str(bin_string, "10", 20))
		FI->MPV_2 = TRUE;

	else if (cmp_str(bin_string, "11", 20))
		FI->MPV_1 = TRUE;


	//  
	//  Layer Version 
	//  
	if (cmp_str(bin_string, "00", 18)) {
		FI->L_RESERVED = TRUE;
		FI->SAMPLES_PER_FRAME = 0;

	} else if (cmp_str(bin_string, "01", 18)) {
		FI->L3 = TRUE;
		FI->SAMPLES_PER_FRAME = 1152;

	} else if (cmp_str(bin_string, "10", 18)) {
		FI->L2 = TRUE;
		FI->SAMPLES_PER_FRAME = 1152;

	} else if (cmp_str(bin_string, "11", 18)) {
		FI->L1 = TRUE;
		FI->SAMPLES_PER_FRAME = 384;
	}


	//  
	//  CRC Bit 
	//  
	if (cmp_str(bin_string, "0", 16))
		FI->PROT_BIT = TRUE;


	//  
	//  BITRATE 
	//  
	//  Grab the specific integer from the "header" 
	//  that I need. 
	//  
	//  Truncate at the 12th bit (0xf), and shift right 12 bits 
	//  to just get bitrange 15 -> 12. 

	value_part = ((*header >> 12 ) & 0xf);

	//  Column 5 is for everything else (junk) 
	if (FI->MPV_1 && FI->L1)
		column_part = 0;

	else if (FI->MPV_1 && FI->L2)
		column_part = 1;

	else if (FI->MPV_1 && FI->L3)
		column_part = 2;

	else if ((FI->MPV_2 || FI->MPV_25) && FI->L1)
		column_part = 3;

	else if ((FI->MPV_2 || FI->MPV_25) && (FI->L2 || FI->L3))
		column_part = 4;

	else
		column_part = 5;


	FI->BIT_RATE = bitrate_matrix[column_part][value_part];


	//  
	//  Sampling Rate 
	//  
	//  Truncate at the 2nd bit (0x3), and shift right 9 bits 
	//  to just get bitrange 11 -> 10. 

	value_part = ((*header >> 10) & 0x3);

	if (FI->MPV_1)
		FI->SAMPLE_FREQ = sampling_rate_matrix[value_part][0];
		
	else if (FI->MPV_2)
		FI->SAMPLE_FREQ = sampling_rate_matrix[value_part][1];
		
	else if (FI->MPV_25)
		FI->SAMPLE_FREQ = sampling_rate_matrix[value_part][2];

	else
		FI->SAMPLE_FREQ = 0;


	//  
	//  Padding Bit 
	//  
	if (cmp_str(bin_string, "1", 9))
		FI->PAD_BIT = TRUE;


	//  
	//  Private Bit 
	//  
	if (cmp_str(bin_string, "1", 8))
		FI->PRIV_BIT = TRUE;


	//  
	//  Get the channel mode 
	//  
	//  The 'mode_extension' will be added later 
	//  perhaps in V2.0. 
	//  
	if (cmp_str(bin_string, "00", 7))
		FI->STEREO = TRUE;

	else if (cmp_str(bin_string, "01", 7)) 
		{
		FI->JOINT_STEREO = TRUE;
		FI->MODE_EXTENSION = TRUE;
		}

	else if (cmp_str(bin_string, "10", 7))
		FI->DUAL_STEREO = TRUE;

	else if (cmp_str(bin_string, "11", 7))
		FI->SINGLE_CHANNEL = TRUE;


	//  
	//  Copyright Bit 
	//  
	if (cmp_str(bin_string, "1", 3))
		FI->COPYRIGHT = TRUE;


	//  
	//  Original Bit 
	//  
	if (cmp_str(bin_string, "1", 2))
		FI->ORIGINAL = TRUE;


	//  
	//  Emphasis 
	//  
	if (cmp_str(bin_string, "00", 1))
		FI->EMPH_NONE = TRUE;

	else if (cmp_str(bin_string, "01", 1))
		FI->EMPH_5015 = TRUE;

	else if (cmp_str(bin_string, "10", 1))
		FI->EMPH_RESERV = TRUE;

	else if (cmp_str(bin_string, "11", 1))
		FI->EMPH_CCIT = TRUE;


	//  
	//  FRAME LENGTH 
	//  
	if (FI->SAMPLE_FREQ > 0) {
		if (FI->MPV_1) {
			if (FI->L1 && FI->PAD_BIT == TRUE) {
				FI->FRAME_LENGTH = (12 * FI->BIT_RATE * 1000 / FI->SAMPLE_FREQ + 4) * 4;

			} else if (FI->L1 && FI->PAD_BIT == FALSE) {
				FI->FRAME_LENGTH = (12 * FI->BIT_RATE * 1000 / FI->SAMPLE_FREQ) * 4;

			} else if ((FI->L2 || FI->L3) && FI->PAD_BIT == TRUE) {
				FI->FRAME_LENGTH = (144 * FI->BIT_RATE * 1000 / FI->SAMPLE_FREQ + 1);

			} else if ((FI->L2 || FI->L3) && FI->PAD_BIT == FALSE) {
				FI->FRAME_LENGTH = (144 * FI->BIT_RATE * 1000 / FI->SAMPLE_FREQ);
			}
		} else if (FI->MPV_2 || FI->MPV_25) {
			if (FI->L1 && FI->PAD_BIT == TRUE) {
				FI->FRAME_LENGTH = (240 * FI->BIT_RATE * 1000 / FI->SAMPLE_FREQ + 4) * 4;

			} else if (FI->L1 && FI->PAD_BIT == FALSE) {
				FI->FRAME_LENGTH = (240 * FI->BIT_RATE * 1000 / FI->SAMPLE_FREQ) * 4;

			} else if ((FI->L2 || FI->L3) && FI->PAD_BIT == TRUE) { 
				FI->FRAME_LENGTH = (72 * FI->BIT_RATE * 1000 / FI->SAMPLE_FREQ + 1);
		
			} else if ((FI->L2 || FI->L3) && FI->PAD_BIT == FALSE) {
				FI->FRAME_LENGTH = (72 * FI->BIT_RATE * 1000 / FI->SAMPLE_FREQ);
			}
		}
	} else
		FI->FRAME_LENGTH = 0;



	//  
	//  ERROR TRAPPING HAPPENS HERE. 
	//  IN FUTURE VERSIONS, I WILL CHECK FOR 
	//  JOINT STEREO and INTENSITY STEREO. 
	//  
	if (FI->L_RESERVED || FI->BIT_RATE == 0 || FI->BIT_RATE == 1 || FI->SAMPLE_FREQ == 0)
		FI->check_state = FAIL;

	else if (FI->L2 && FI->BIT_RATE == 32 && FI->SINGLE_CHANNEL == FALSE)
		FI->check_state = FAIL;

	else if (FI->L2 && FI->BIT_RATE == 48 && FI->SINGLE_CHANNEL == FALSE)
		FI->check_state = FAIL;

	else if (FI->L2 && FI->BIT_RATE == 56 && FI->SINGLE_CHANNEL == FALSE)
		FI->check_state = FAIL;

	else if (FI->L2 && FI->BIT_RATE == 80 && FI->SINGLE_CHANNEL == FALSE)
		FI->check_state = FAIL;

	else if (FI->L2 && FI->BIT_RATE == 32 && FI->SINGLE_CHANNEL == FALSE)
		FI->check_state = FAIL;

	else if (FI->L2 && FI->BIT_RATE == 224 && !(FI->STEREO || FI->DUAL_STEREO))
		FI->check_state = FAIL;

	else if (FI->L2 && FI->BIT_RATE == 256 && !(FI->STEREO || FI->DUAL_STEREO))
		FI->check_state = FAIL;

	else if (FI->L2 && FI->BIT_RATE == 320 && !(FI->STEREO || FI->DUAL_STEREO))
		FI->check_state = FAIL;

	else if (FI->L2 && FI->BIT_RATE == 384 && !(FI->STEREO || FI->DUAL_STEREO))
		FI->check_state = FAIL;


	return FI->check_state;
}

void
print_sys_usage(void)
{
	struct	rusage	process_usage;

	if (getrusage(RUSAGE_SELF, &process_usage))
		(void)fprintf(stderr, "Could not get system usage for myself.");
	else {
		printf("\n");
		printf("%-20s%1ld.%02lds\n", "USER_TIME", process_usage.ru_utime.tv_sec, process_usage.ru_utime.tv_usec / 10000);
		printf("%-20s%1ld.%02lds\n", "SYS_TIME", process_usage.ru_stime.tv_sec, process_usage.ru_stime.tv_usec / 10000);
	}
}

int
rotate_char_array(byte_list, new_byte, file_info)
	char	*byte_list;
	int	*new_byte;
	gen_info *file_info;
{
	int	place_holder = 0;

	//  I don't think it'll get any faster than this. 
	place_holder = file_info->byte_count % 128;

	*(byte_list + place_holder) = *new_byte;
	
	return(TRUE); 
}

int
transform_char_array(byte_list, file_info)
	char	*byte_list;
	gen_info *file_info;
{
	int	place_holder = 0;
	int	counter;
	char	trans_list[128] = {'*'};

	place_holder = file_info->byte_count % 128 + 1;

	//  This is going to be a little confusing 
	//  at the 'place_holder' mark, the data from place_holder to 127  
	//  is the oldest, and data from 0 to place_holder is newest 

	//  Get the oldest stuff first, and put it at the beginning 
	//  of the array. 
	for(counter = place_holder; counter < 128; counter++)
		*(trans_list + (counter - place_holder)) = *(byte_list + counter); 	

	// Now, grab the newest stuff, and slap it at the end of the array. 
	for(counter = 0; counter < place_holder; counter++)
		*(trans_list + (128 - place_holder + counter)) = *(byte_list + counter); 

	memcpy(byte_list, trans_list, 128);

	return(TRUE);
}

void
translate_time(file_info, song_time)
	mp3_time 	*song_time;
	gen_info	*file_info;
{
	double float_minute = 0.0;
	double float_second = 0.0;

	float_minute = file_info->time_in_seconds / 60.0;
	float_second = 60.0 * (float_minute - (int)float_minute);

	//  Return the values. 
	song_time->frac_second = 100.0 * (float_second - (int)float_second);
	song_time->minutes = (int)float_minute;
	song_time->seconds = (int)float_second;
}

int
dump_id3_tag(id3_tag)
	id3_tag_info    *id3_tag;	
{
	char	title[30];
	char	artist[30];
	char	album[30];
	char	year[4];
	char	comment[30];
	int	i = 0;


	memset(title, '\0', sizeof(title));
	memset(artist, '\0', sizeof(artist));
	memset(album, '\0', sizeof(album));
	memset(year, '\0', sizeof(year));
	memset(comment, '\0', sizeof(comment));

	// The rules state, that nulls should pad the fields,
	// so, that is what I am doing here.

	strncpy(title, id3_tag->TITLE, get_last_char_offset(id3_tag->TITLE));
	strncpy(artist, id3_tag->ARTIST, get_last_char_offset(id3_tag->ARTIST));
	strncpy(album, id3_tag->ALBUM, get_last_char_offset(id3_tag->ALBUM));
	strncpy(year, id3_tag->YEAR, get_last_char_offset(id3_tag->YEAR));
	strncpy(comment, id3_tag->COMMENT, get_last_char_offset(id3_tag->COMMENT));	


	// Now, I am going to send the null-pointed fields to the file pointer.
	// This below is not very elegant. It works though,
	// so I will revisit this at a later time.
	//
	// The problem is that I need to print the null values,
	// if I didn't need to do that, it would be much cleaner.

	
	fputs("TAG", stdout);

	for(i=0; i < 30; i++)
		fputc(*(title + i), stdout);

	for(i=0; i < 30; i++)
		fputc(*(artist + i), stdout);

	for(i=0; i < 30; i++)
		fputc(*(album + i), stdout);

	for(i=0; i < 4; i++)
		fputc(*(year + i), stdout);


	// It's 29 because the last byte may
	// be the track number.

	for(i=0; i < 29; i++)
		fputc(*(comment + i), stdout);

	if(id3_tag->TRACK_NUMBER != 0)	
		fputc(id3_tag->TRACK_NUMBER, stdout);
	else
		fputc(*(comment + 29), stdout);		


	fputc(id3_tag->GENRE, stdout);

	return(TRUE);
}	

int
get_last_char_offset(fat_string)
	char *fat_string;
{
	int	i = 0;

	for (i = strlen(fat_string) - 1 ; i >= 0 ; i--) {
		if (isgraph((int)*(fat_string + i)))
			return(i + 1);	
	}

	return(strlen(fat_string));
}

int
check_vbr_and_time(mp3_i, vbr_info, file_info)
	frame_info	*mp3_i;
	vbr_data	*vbr_info;
	gen_info	*file_info;
{
	//  
	//  Lets get the time of this frame, and 
	//  add it to the total length of the mp3 file 
	//  
	file_info->time_in_seconds += (mp3_i->SAMPLES_PER_FRAME * 1.0) / (mp3_i->SAMPLE_FREQ * 1.0);

	//  
	//  Time to do some nifty VBR checking. 
	//  
	if (vbr_info->high_rate < mp3_i->BIT_RATE)
		vbr_info->high_rate = mp3_i->BIT_RATE;

	if ((mp3_i->BIT_RATE < vbr_info->low_rate) || (vbr_info->low_rate == 0))
		vbr_info->low_rate = mp3_i->BIT_RATE;


	//  Get a running total for division at the end. 
	vbr_info->sum_rate += mp3_i->BIT_RATE;

	return(TRUE);
}

int
print_frame_info(mp3_i, file_info)
	frame_info	*mp3_i;
	gen_info	*file_info;
{
	printf("\n");
	printf("%-20s%d\n", "FRAME", file_info->good_frame_count);
	printf("%-20s%d\n", "FrameOffset", file_info->byte_count);
	printf("%-20s%d\n", "FrameLength", mp3_i->FRAME_LENGTH);
	printf("%-20s%d\n", "FrameDataLength", mp3_i->FRAME_DATA_LENGTH);
	printf("%-20s%d\n", "BitRate", mp3_i->BIT_RATE);
	printf("%-20s%d\n", "SampRate", mp3_i->SAMPLE_FREQ);
	printf("%-20s%s\n", "BinString", mp3_i->BIN_STRING);
	printf("%-20s%lu\n", "BinLen", (unsigned long)strlen(mp3_i->BIN_STRING));
	printf("%-20s%u\n", "IntHeader", mp3_i->INT_HEADER);
	printf("%-20s0x%x\n", "CRC16Value", mp3_i->CRC16_VALUE);
	printf("%-20s0x%x\n", "Correct_CRC16Value", mp3_i->CORRECT_CRC16_VALUE);
	printf("%-20s%d\n", "NEXT_FRAME", file_info->byte_count + mp3_i->FRAME_LENGTH);

	return(TRUE);
}