in_flac.c 14.7 KB
Newer Older
Josh Coalson's avatar
Josh Coalson committed
1
/* in_flac - Winamp2 FLAC input plugin
2
 * Copyright (C) 2000,2001,2002  Josh Coalson
Josh Coalson's avatar
Josh Coalson committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#include <windows.h>
#include <mmreg.h>
#include <msacm.h>
#include <math.h>
Josh Coalson's avatar
Josh Coalson committed
23
#include <stdio.h>
Josh Coalson's avatar
Josh Coalson committed
24
25
26
27

#include "in2.h"
#include "FLAC/all.h"

Josh Coalson's avatar
Josh Coalson committed
28
29
30
31
32
33
34
35
36
37
38
39
typedef struct {
	FLAC__byte raw[128];
	char title[31];
	char artist[31];
	char album[31];
	char comment[31];
	unsigned year;
	unsigned track; /* may be 0 if v1 (not v1.1) tag */
	unsigned genre;
	char description[1024]; /* the formatted description passed to player */
} id3v1_struct;

Josh Coalson's avatar
Josh Coalson committed
40
41
42
43
44
45
46
47
48
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
	return TRUE;
}

/* post this to the main window at end of file (after playback as stopped) */
#define WM_WA_MPEG_EOF WM_USER+2

typedef struct {
Josh Coalson's avatar
Josh Coalson committed
49
	FLAC__bool abort_flag;
Josh Coalson's avatar
Josh Coalson committed
50
51
52
53
54
	unsigned total_samples;
	unsigned bits_per_sample;
	unsigned channels;
	unsigned sample_rate;
	unsigned length_in_ms;
55
56
57
58
59
} file_info_struct;

static FLAC__bool safe_decoder_init_(const char *infilename, FLAC__FileDecoder *decoder);
static void safe_decoder_finish_(FLAC__FileDecoder *decoder);
static void safe_decoder_delete_(FLAC__FileDecoder *decoder);
Josh Coalson's avatar
Josh Coalson committed
60
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
61
static void metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
62
static void error_callback_(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
Josh Coalson's avatar
Josh Coalson committed
63
static FLAC__bool get_id3v1_tag_(const char *filename, id3v1_struct *tag);
Josh Coalson's avatar
Josh Coalson committed
64

65
66
67
68
69
70
71
72
73
74
In_Module mod_; /* the output module (declared near the bottom of this file) */
char lastfn_[MAX_PATH]; /* currently playing file (used for getting info on the current file) */
int decode_pos_ms_; /* current decoding position, in milliseconds */
int paused_; /* are we paused? */
int seek_needed_; /* if != -1, it is the point that the decode thread should seek to, in ms. */
FLAC__int16 reservoir_[FLAC__MAX_BLOCK_SIZE * 2 * 2]; /* *2 for max channels, another *2 for overflow */
char sample_buffer_[576 * 2 * (16/8) * 2]; /* 2 for max channels, (16/8) for max bytes per sample, and 2 for who knows what */
unsigned samples_in_reservoir_;
static file_info_struct file_info_;
static FLAC__FileDecoder *decoder_;
Josh Coalson's avatar
Josh Coalson committed
75

76
77
int killDecodeThread = 0;					/* the kill switch for the decode thread */
HANDLE thread_handle = INVALID_HANDLE_VALUE;	/* the handle to the decode thread */
Josh Coalson's avatar
Josh Coalson committed
78
79
80
81
82
83
84
85
86
87

DWORD WINAPI __stdcall DecodeThread(void *b); /* the decode thread procedure */

void config(HWND hwndParent)
{
	MessageBox(hwndParent, "No configuration.", "Configuration", MB_OK);
	/* if we had a configuration we'd want to write it here :) */
}
void about(HWND hwndParent)
{
88
	MessageBox(hwndParent, "Winamp FLAC Plugin v" FLAC__VERSION_STRING ", by Josh Coalson\nSee http://flac.sourceforge.net/", "About FLAC Plugin", MB_OK);
Josh Coalson's avatar
Josh Coalson committed
89
90
91
92
}

void init()
{
93
94
	decoder_ = FLAC__file_decoder_new();
	strcpy(lastfn_, "");
Josh Coalson's avatar
Josh Coalson committed
95
96
97
98
}

void quit()
{
99
100
	safe_decoder_delete_(decoder_);
	decoder_ = 0;
Josh Coalson's avatar
Josh Coalson committed
101
102
103
}

int isourfile(char *fn) { return 0; }
104
/* used for detecting URL streams.. unused here. strncmp(fn, "http://", 7) to detect HTTP streams, etc */
Josh Coalson's avatar
Josh Coalson committed
105
106
107
108
109

int play(char *fn)
{
	int maxlatency;
	int thread_id;
110
	HANDLE input_file = INVALID_HANDLE_VALUE;
Josh Coalson's avatar
Josh Coalson committed
111

112
	if(0 == decoder_) {
Josh Coalson's avatar
Josh Coalson committed
113
114
115
		return 1;
	}

116
	input_file = CreateFile(fn, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
117
118
	if(input_file == INVALID_HANDLE_VALUE) {
		return -1;
Josh Coalson's avatar
Josh Coalson committed
119
120
121
	}
	CloseHandle(input_file);

122
	if(!safe_decoder_init_(fn, decoder_)) {
Josh Coalson's avatar
Josh Coalson committed
123
124
125
		return 1;
	}

126
127
128
129
130
	strcpy(lastfn_, fn);
	paused_ = 0;
	decode_pos_ms_ = 0;
	seek_needed_ = -1;
	samples_in_reservoir_ = 0;
Josh Coalson's avatar
Josh Coalson committed
131

132
	maxlatency = mod_.outMod->Open(file_info_.sample_rate, file_info_.channels, file_info_.bits_per_sample, -1, -1);
Josh Coalson's avatar
Josh Coalson committed
133
134
135
136
137
138
	if (maxlatency < 0) { /* error opening device */
		return 1;
	}

	/* dividing by 1000 for the first parameter of setinfo makes it */
	/* display 'H'... for hundred.. i.e. 14H Kbps. */
139
	mod_.SetInfo((file_info_.sample_rate*file_info_.bits_per_sample*file_info_.channels)/1000, file_info_.sample_rate/1000, file_info_.channels, 1);
Josh Coalson's avatar
Josh Coalson committed
140
141

	/* initialize vis stuff */
142
143
	mod_.SAVSAInit(maxlatency, file_info_.sample_rate);
	mod_.VSASetInfo(file_info_.sample_rate, file_info_.channels);
Josh Coalson's avatar
Josh Coalson committed
144

145
	mod_.outMod->SetVolume(-666); /* set the output plug-ins default volume */
Josh Coalson's avatar
Josh Coalson committed
146

147
148
	killDecodeThread = 0;
	thread_handle = (HANDLE) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) DecodeThread, (void *) &killDecodeThread, 0, &thread_id);
Josh Coalson's avatar
Josh Coalson committed
149
150
151
152
153
154

	return 0;
}

void pause()
{
155
156
	paused_ = 1;
	mod_.outMod->Pause(1);
Josh Coalson's avatar
Josh Coalson committed
157
158
159
160
}

void unpause()
{
161
162
	paused_ = 0;
	mod_.outMod->Pause(0);
Josh Coalson's avatar
Josh Coalson committed
163
164
165
}
int ispaused()
{
166
	return paused_;
Josh Coalson's avatar
Josh Coalson committed
167
168
169
170
171
}

void stop()
{
	if (thread_handle != INVALID_HANDLE_VALUE) {
172
173
		killDecodeThread = 1;
		if (WaitForSingleObject(thread_handle, INFINITE) == WAIT_TIMEOUT) {
174
			MessageBox(mod_.hMainWindow, "error asking thread to die!\n", "error killing decode thread", 0);
175
			TerminateThread(thread_handle, 0);
Josh Coalson's avatar
Josh Coalson committed
176
177
178
179
		}
		CloseHandle(thread_handle);
		thread_handle = INVALID_HANDLE_VALUE;
	}
180
	safe_decoder_finish_(decoder_);
Josh Coalson's avatar
Josh Coalson committed
181

182
	mod_.outMod->Close();
Josh Coalson's avatar
Josh Coalson committed
183

184
	mod_.SAVSADeInit();
Josh Coalson's avatar
Josh Coalson committed
185
186
187
188
}

int getlength()
{
189
	return (int)file_info_.length_in_ms;
Josh Coalson's avatar
Josh Coalson committed
190
191
192
193
}

int getoutputtime()
{
194
	return decode_pos_ms_ + (mod_.outMod->GetOutputTime() - mod_.outMod->GetWrittenTime());
Josh Coalson's avatar
Josh Coalson committed
195
196
197
198
}

void setoutputtime(int time_in_ms)
{
199
	seek_needed_ = time_in_ms;
Josh Coalson's avatar
Josh Coalson committed
200
201
}

202
203
void setvolume(int volume) { mod_.outMod->SetVolume(volume); }
void setpan(int pan) { mod_.outMod->SetPan(pan); }
Josh Coalson's avatar
Josh Coalson committed
204
205
206
207
208
209
210

int infoDlg(char *fn, HWND hwnd)
{
	/* TODO: implement info dialog. */
	return 0;
}

211
void getfileinfo(char *filename, char *title, int *length_in_msec)
Josh Coalson's avatar
Josh Coalson committed
212
{
Josh Coalson's avatar
Josh Coalson committed
213
	id3v1_struct tag;
214
	FLAC__StreamMetadata streaminfo;
Josh Coalson's avatar
Josh Coalson committed
215

216
	if(0 == filename || filename[0] == '\0') {
217
		filename = lastfn_;
218
219
220
		if (length_in_msec) {
			*length_in_msec = getlength();
			length_in_msec = 0; /* force skip in following code */
Josh Coalson's avatar
Josh Coalson committed
221
222
		}
	}
Josh Coalson's avatar
Josh Coalson committed
223

224
225
226
	if(!FLAC__metadata_get_streaminfo(filename, &streaminfo)) {
		MessageBox(mod_.hMainWindow, filename, "ERROR: invalid/missing FLAC metadata", 0);
		if(title) {
227
			static const char *errtitle = "Invalid FLAC File: ";
228
229
230
231
232
			sprintf(title, "%s\"%s\"", errtitle, filename);
		}
		if(length_in_msec)
			*length_in_msec = -1;
		return;
Josh Coalson's avatar
Josh Coalson committed
233
	}
234
235

	if(title) {
Josh Coalson's avatar
Josh Coalson committed
236
237
238
		(void)get_id3v1_tag_(filename, &tag);
		strcpy(title, tag.description);
	}
239
	if(length_in_msec)
240
		*length_in_msec = (int)(streaminfo.data.stream_info.total_samples * 10 / (streaminfo.data.stream_info.sample_rate / 100));
Josh Coalson's avatar
Josh Coalson committed
241
242
243
244
245
246
247
248
}

void eq_set(int on, char data[10], int preamp)
{
}

DWORD WINAPI __stdcall DecodeThread(void *b)
{
249
	int done = 0;
Josh Coalson's avatar
Josh Coalson committed
250
251

	while (! *((int *)b) ) {
252
253
		unsigned channels = file_info_.channels;
		unsigned bits_per_sample = file_info_.bits_per_sample;
Josh Coalson's avatar
Josh Coalson committed
254
		unsigned bytes_per_sample = (bits_per_sample+7)/8;
255
256
257
258
259
260
261
		unsigned sample_rate = file_info_.sample_rate;
		if (seek_needed_ != -1) {
			const double distance = (double)seek_needed_ / (double)getlength();
			unsigned target_sample = (unsigned)(distance * (double)file_info_.total_samples);
			if(FLAC__file_decoder_seek_absolute(decoder_, (FLAC__uint64)target_sample)) {
				decode_pos_ms_ = (int)(distance * (double)getlength());
				seek_needed_ = -1;
262
				done = 0;
263
				mod_.outMod->Flush(decode_pos_ms_);
Josh Coalson's avatar
Josh Coalson committed
264
265
266
			}
		}
		if (done) {
267
268
			if (!mod_.outMod->IsPlaying()) {
				PostMessage(mod_.hMainWindow, WM_WA_MPEG_EOF, 0, 0);
Josh Coalson's avatar
Josh Coalson committed
269
270
271
272
				return 0;
			}
			Sleep(10);
		}
273
274
275
		else if (mod_.outMod->CanWrite() >= ((int)(576*channels*bytes_per_sample) << (mod_.dsp_isactive()?1:0))) {
			while(samples_in_reservoir_ < 576) {
				if(FLAC__file_decoder_get_state(decoder_) == FLAC__FILE_DECODER_END_OF_FILE) {
Josh Coalson's avatar
Josh Coalson committed
276
277
278
					done = 1;
					break;
				}
279
280
281
				else if(!FLAC__file_decoder_process_one_frame(decoder_)) {
					MessageBox(mod_.hMainWindow, FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder_)], "READ ERROR processing frame", 0);
					done = 1;
Josh Coalson's avatar
Josh Coalson committed
282
					break;
283
				}
Josh Coalson's avatar
Josh Coalson committed
284
285
			}

286
			if (samples_in_reservoir_ == 0) {
287
				done = 1;
Josh Coalson's avatar
Josh Coalson committed
288
289
			}
			else {
290
				unsigned i, n = min(samples_in_reservoir_, 576), delta;
291
				int bytes;
292
				signed short *ssbuffer = (signed short *)sample_buffer_;
Josh Coalson's avatar
Josh Coalson committed
293
294

				for(i = 0; i < n*channels; i++)
295
					ssbuffer[i] = reservoir_[i];
Josh Coalson's avatar
Josh Coalson committed
296
				delta = i;
297
298
299
300
301
302
303
304
305
				for( ; i < samples_in_reservoir_ * channels; i++)
					reservoir_[i-delta] = reservoir_[i];
				samples_in_reservoir_ -= n;

				mod_.SAAddPCMData((char *)sample_buffer_, channels, bits_per_sample, decode_pos_ms_);
				mod_.VSAAddPCMData((char *)sample_buffer_, channels, bits_per_sample, decode_pos_ms_);
				decode_pos_ms_ += (n*1000 + sample_rate/2)/sample_rate;
				if (mod_.dsp_isactive())
					bytes = mod_.dsp_dosamples((short *)sample_buffer_, n, bits_per_sample, channels, sample_rate) * (channels*bytes_per_sample);
306
307
				else
					bytes = n * channels * bytes_per_sample;
308
				mod_.outMod->Write(sample_buffer_, bytes);
Josh Coalson's avatar
Josh Coalson committed
309
310
311
312
313
314
315
316
317
			}
		}
		else Sleep(20);
	}
	return 0;
}



318
In_Module mod_ =
Josh Coalson's avatar
Josh Coalson committed
319
320
{
	IN_VER,
Josh Coalson's avatar
Josh Coalson committed
321
	"Reference FLAC Player v" FLAC__VERSION_STRING,
Josh Coalson's avatar
Josh Coalson committed
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
	0,	/* hMainWindow */
	0,  /* hDllInstance */
	"FLAC\0FLAC Audio File (*.FLAC)\0"
	,
	1,	/* is_seekable */
	1, /* uses output */
	config,
	about,
	init,
	quit,
	getfileinfo,
	infoDlg,
	isourfile,
	play,
	pause,
	unpause,
	ispaused,
	stop,

	getlength,
	getoutputtime,
	setoutputtime,

	setvolume,
	setpan,

	0,0,0,0,0,0,0,0,0, /* vis stuff */


	0,0, /* dsp */

	eq_set,

	NULL,		/* setinfo */

	0 /* out_mod */

};

__declspec( dllexport ) In_Module * winampGetInModule2()
{
363
	return &mod_;
Josh Coalson's avatar
Josh Coalson committed
364
365
366
367
368
369
}


/***********************************************************************
 * local routines
 **********************************************************************/
370
FLAC__bool safe_decoder_init_(const char *filename, FLAC__FileDecoder *decoder)
Josh Coalson's avatar
Josh Coalson committed
371
{
372
373
374
375
376
377
378
	if(decoder == 0) {
		MessageBox(mod_.hMainWindow, "Decoder instance is NULL", "ERROR initializing decoder", 0);
		return false;
	}

	safe_decoder_finish_(decoder);

379
	FLAC__file_decoder_set_md5_checking(decoder, false);
380
381
382
383
384
	FLAC__file_decoder_set_filename(decoder, filename);
	FLAC__file_decoder_set_write_callback(decoder, write_callback_);
	FLAC__file_decoder_set_metadata_callback(decoder, metadata_callback_);
	FLAC__file_decoder_set_error_callback(decoder, error_callback_);
	FLAC__file_decoder_set_client_data(decoder, &file_info_);
385
	if(FLAC__file_decoder_init(decoder) != FLAC__FILE_DECODER_OK) {
386
		MessageBox(mod_.hMainWindow, FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)], "ERROR initializing decoder", 0);
Josh Coalson's avatar
Josh Coalson committed
387
388
389
		return false;
	}

390
	file_info_.abort_flag = false;
Josh Coalson's avatar
Josh Coalson committed
391
	if(!FLAC__file_decoder_process_metadata(decoder)) {
392
		MessageBox(mod_.hMainWindow, FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)], "ERROR processing metadata", 0);
Josh Coalson's avatar
Josh Coalson committed
393
394
395
396
397
398
		return false;
	}

	return true;
}

399
400
401
402
403
404
405
406
407
408
409
410
411
412
void safe_decoder_finish_(FLAC__FileDecoder *decoder)
{
	if(decoder && FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
		FLAC__file_decoder_finish(decoder);
}

void safe_decoder_delete_(FLAC__FileDecoder *decoder)
{
	if(decoder) {
		safe_decoder_finish_(decoder);
		FLAC__file_decoder_delete(decoder);
	}
}

Josh Coalson's avatar
Josh Coalson committed
413
FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
Josh Coalson's avatar
Josh Coalson committed
414
{
415
416
	file_info_struct *file_info_ = (file_info_struct *)client_data;
	const unsigned bps = file_info_->bits_per_sample, channels = file_info_->channels, wide_samples = frame->header.blocksize;
Josh Coalson's avatar
Josh Coalson committed
417
	unsigned wide_sample, sample, channel;
Josh Coalson's avatar
Josh Coalson committed
418
419
420

	(void)decoder;

421
	if(file_info_->abort_flag)
Josh Coalson's avatar
Josh Coalson committed
422
		return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
Josh Coalson's avatar
Josh Coalson committed
423

424
	for(sample = samples_in_reservoir_ * channels, wide_sample = 0; wide_sample < wide_samples; wide_sample++)
Josh Coalson's avatar
Josh Coalson committed
425
		for(channel = 0; channel < channels; channel++, sample++)
426
			reservoir_[sample] = (FLAC__int16)buffer[channel][wide_sample];
Josh Coalson's avatar
Josh Coalson committed
427

428
	samples_in_reservoir_ += wide_samples;
Josh Coalson's avatar
Josh Coalson committed
429

Josh Coalson's avatar
Josh Coalson committed
430
	return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
Josh Coalson's avatar
Josh Coalson committed
431
432
}

433
void metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
Josh Coalson's avatar
Josh Coalson committed
434
{
435
	file_info_struct *file_info_ = (file_info_struct *)client_data;
Josh Coalson's avatar
Josh Coalson committed
436
	(void)decoder;
Josh Coalson's avatar
Josh Coalson committed
437
	if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
438
		FLAC__ASSERT(metadata->data.stream_info.total_samples < 0x100000000); /* this plugin can only handle < 4 gigasamples */
439
440
441
442
443
444
445
446
		file_info_->total_samples = (unsigned)(metadata->data.stream_info.total_samples&0xffffffff);
		file_info_->bits_per_sample = metadata->data.stream_info.bits_per_sample;
		file_info_->channels = metadata->data.stream_info.channels;
		file_info_->sample_rate = metadata->data.stream_info.sample_rate;

		if(file_info_->bits_per_sample != 16) {
			MessageBox(mod_.hMainWindow, "ERROR: plugin can only handle 16-bit samples\n", "ERROR: plugin can only handle 16-bit samples", 0);
			file_info_->abort_flag = true;
Josh Coalson's avatar
Josh Coalson committed
447
448
			return;
		}
449
		file_info_->length_in_ms = file_info_->total_samples * 10 / (file_info_->sample_rate / 100);
Josh Coalson's avatar
Josh Coalson committed
450
451
452
	}
}

453
void error_callback_(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
Josh Coalson's avatar
Josh Coalson committed
454
{
455
	file_info_struct *file_info_ = (file_info_struct *)client_data;
Josh Coalson's avatar
Josh Coalson committed
456
	(void)decoder;
Josh Coalson's avatar
Josh Coalson committed
457
	if(status != FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC)
458
		file_info_->abort_flag = true;
Josh Coalson's avatar
Josh Coalson committed
459
}
Josh Coalson's avatar
Josh Coalson committed
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

FLAC__bool get_id3v1_tag_(const char *filename, id3v1_struct *tag)
{
	const char *temp;
	FILE *f = fopen(filename, "rb");
	memset(tag, 0, sizeof(id3v1_struct));

	/* set the title and description to the filename by default */
	temp = strrchr(filename, '/');
	if(!temp)
		temp = filename;
	else
		temp++;
	strcpy(tag->description, temp);
	*strrchr(tag->description, '.') = '\0';
	strncpy(tag->title, tag->description, 30); tag->title[30] = '\0';

	if(0 == f)
		return false;
	if(-1 == fseek(f, -128, SEEK_END)) {
		fclose(f);
		return false;
	}
	if(fread(tag->raw, 1, 128, f) < 128) {
		fclose(f);
		return false;
	}
	fclose(f);
	if(strncmp(tag->raw, "TAG", 3))
		return false;
	else {
		char year_str[5];

		memcpy(tag->title, tag->raw+3, 30);
		memcpy(tag->artist, tag->raw+33, 30);
		memcpy(tag->album, tag->raw+63, 30);
		memcpy(year_str, tag->raw+93, 4); year_str[4] = '\0'; tag->year = atoi(year_str);
		memcpy(tag->comment, tag->raw+97, 30);
		tag->genre = (unsigned)((FLAC__byte)tag->raw[127]);
		tag->track = (unsigned)((FLAC__byte)tag->raw[126]);

		sprintf(tag->description, "%s - %s", tag->artist[0]? tag->artist : "Unknown Artist", tag->title[0]? tag->title : "Untitled");

		return true;
	}
}