summaryrefslogtreecommitdiff
path: root/Gui.d
blob: b083c14ea0dff7840b90ad3522b36f69991a0215 (plain)
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
691
692
693
694
695
696
697
module Gui;

import gtkc.gtk;

import gtk.Main;
import gtk.MainWindow;
import gtk.Alignment;
import gtk.Button;
import gtk.ToggleButton;
import gtk.CheckButton;
import gtk.RadioButton;
import gtk.ComboBox;
import gtk.SpinButton;
import gtk.Label;
import gtk.Frame;
import gtk.HBox;
import gtk.VBox;
import gtk.Table;
import gtk.Widget;
import gtkc.gtktypes;
import glib.ListSG;
import tango.math.Math;

import tango.io.Stdout;

import BitrateCalculator;

void main(char[][] args)
{
	Main.init(args);
	new BitrateWindow();
	Main.run();
}

public class BitrateWindow : MainWindow
{
	VideoFrame  videoFrame;
	AudioFrame  audioFrame1;
	AudioFrame  audioFrame2;
	ComboBox    codecCombo;
	ComboBox    containCombo;
	RadioButton fileRadio;
	SpinButton  sizeKBSpin;
	SpinButton  sizeMBSpin;
	ComboBox    mediumCombo;
	RadioButton bitrRadio;
	SpinButton  bitrSpin;
	SpinButton  videoSizeKBSpin;
	SpinButton  videoSizeMBSpin;

	bool handlingEvents;

	this()
	{
		super("Bitrate Calculator");

		Initialize();
		CreateLayout();
		SetDefaults();
		SetEvents();

		showAll();
	}

	void Initialize()
	{
		//Video
		videoFrame = new VideoFrame;

		//Audio
		audioFrame1 = new AudioFrame("Audio 1");
		audioFrame2 = new AudioFrame("Audio 2");

		//Codec
		codecCombo = new ComboBox(true);
		foreach(char[] string; videoCodecs) codecCombo.appendText(string);

		//Container
		containCombo = new ComboBox(true);
		foreach(char[] string; containerTypes) containCombo.appendText(string);
		
		//Size
		fileRadio = new RadioButton(cast(ListSG)null, "File Size");
		sizeKBSpin = new SpinButton(0, int.max, 1);
		sizeMBSpin = new SpinButton(0, int.max, 1);
		mediumCombo = new ComboBox(true);
		foreach(char[] string; storageMediums) mediumCombo.appendText(string);

		//Results
		bitrRadio = new RadioButton(fileRadio, "Average Bitrate");
		bitrSpin = new SpinButton(0, int.max, 1);
		videoSizeKBSpin = new SpinButton(0, int.max, 1);
		videoSizeMBSpin = new SpinButton(0, int.max, 1);

		videoSizeKBSpin.setState(StateType.INSENSITIVE);
		videoSizeMBSpin.setState(StateType.INSENSITIVE);
	}

	void CreateLayout()
	{
		//Audio
		HBox audioBox = new HBox(false, 4);
		audioBox.add(audioFrame1);
		audioBox.add(audioFrame2);

		//Codec
		Frame codecFrame = new Frame("Codec");

		Alignment codecAlign = new Alignment(0, 0.5, 0.2, 0);
		codecAlign.setPadding(4, 4, 4, 4);
		codecAlign.add(codecCombo);

		codecFrame.add(codecAlign);

		//Container
		Frame containFrame = new Frame("Container");

		Alignment containAlign = new Alignment(0, 0.5, 0.2, 0);
		containAlign.setPadding(4, 4, 4, 4);
		containAlign.add(containCombo);

		containFrame.add(containAlign);

		//Size
		Frame sizeFrame = new Frame("Total size");
		Table sizeTable = new Table(3, 3, false);
		sizeTable.setRowSpacings(5);
		sizeTable.setColSpacings(5);

		Alignment sizeAlign = new Alignment(0, 0.5, 0.2, 0);
		sizeAlign.setPadding(4, 4, 4, 4);
		sizeFrame.add(sizeAlign);

		sizeTable.attachDefaults(fileRadio, 0, 1, 0, 1);
		sizeTable.attachDefaults(sizeKBSpin, 1, 2, 0, 1);
		sizeTable.attachDefaults(new Label("KB"), 2, 3, 0, 1);
		sizeTable.attachDefaults(sizeMBSpin, 1, 2, 1, 2);
		sizeTable.attachDefaults(new Label("MB"), 2, 3, 1, 2);
		sizeTable.attachDefaults(new Label("Storage medium"), 0, 1, 2, 3);
		sizeTable.attachDefaults(mediumCombo, 1, 2, 2, 3);
		sizeAlign.add(sizeTable);

		//Results
		Frame resultFrame = new Frame("Results");
		Table resultTable = new Table(3, 3, false);
		resultTable.setRowSpacings(5);
		resultTable.setColSpacings(5);

		Alignment resultAlign = new Alignment(0, 0.5, 0.2, 0);
		resultAlign.setPadding(4, 4, 4, 4);
		resultFrame.add(resultAlign);

		Alignment fileSizeAlign = new Alignment(1, 0.5, 0, 0);
		fileSizeAlign.add(new Label("Video file size"));

		resultTable.attachDefaults(bitrRadio, 0, 1, 0, 1);
		resultTable.attachDefaults(bitrSpin, 1, 2, 0, 1);
		resultTable.attachDefaults(new Label("kbit/s"), 2, 3, 0, 1);
		resultTable.attachDefaults(fileSizeAlign, 0, 1, 1, 2);
		resultTable.attachDefaults(videoSizeKBSpin, 1, 2, 1, 2);
		resultTable.attachDefaults(new Label("KB"), 2, 3, 1, 2);
		resultTable.attachDefaults(videoSizeMBSpin, 1, 2, 2, 3);
		resultTable.attachDefaults(new Label("MB"), 2, 3, 2, 3);
		resultAlign.add(resultTable);

		//Left
		VBox leftBox  = new VBox(false, 4);

		leftBox.add(videoFrame);
		leftBox.add(audioBox);

		//Right
		VBox rightBox = new VBox(false, 4);

		Alignment closeAlign = new Alignment(1, 1, 0.1, 0);
		closeAlign.add(new Button(StockID.CLOSE, &OnClose));

		rightBox.packStart(codecFrame, false, false, 0);
		rightBox.packStart(containFrame, false, false, 0);
		rightBox.packStart(sizeFrame, false, false, 0);
		rightBox.packStart(resultFrame, false, false, 0);
		rightBox.add(closeAlign);

		//top
		HBox topBox = new HBox(false, 6);
		topBox.setBorderWidth(4);

		topBox.add(leftBox);
		topBox.add(rightBox);

		this.add(topBox);
	}

	void SetDefaults()
	{
		handlingEvents = true;

		codecCombo.setActive(1);
		containCombo.setActive(0);
		sizeKBSpin.setValue(storageMediumSizeKB[8]);
		sizeMBSpin.setValue(rndint(cast(double)storageMediumSizeKB[8] / 1024));
		mediumCombo.setActive(8);

		handlingEvents = false;
	}

	void SetEvents()
	{
		videoFrame.addOnFramesChanged( &onFramesChanged);
		videoFrame.addOnBFramesChanged(&onBFramesChanged);

		audioFrame1.addOnAudioChanged(&onAudioChanged);
		audioFrame2.addOnAudioChanged(&onAudioChanged);

		codecCombo.addOnChanged(   &OnCodecContainerChange);
		containCombo.addOnChanged( &OnCodecContainerChange);

		sizeKBSpin.addOnValueChanged( &OnSizeChange);
		sizeMBSpin.addOnValueChanged( &OnSizeChange);
		mediumCombo.addOnChanged(     &OnMediumChange);

		bitrSpin.addOnValueChanged(        &OnBitrateChange);
		//videoSizeKBSpin.addOnValueChanged( &OnVideoSizeChange);
		//videoSizeMBSpin.addOnValueChanged( &OnVideoSizeChange);
	}

	public void onFramesChanged()
	{
		audioFrame1.setLengthInSeconds(videoFrame.getTotalLengthInSeconds);
		audioFrame2.setLengthInSeconds(videoFrame.getTotalLengthInSeconds);

		Calculate();
	}

	public void onBFramesChanged()
	{
		Calculate();
	}

	public void onAudioChanged()
	{
		Calculate();
	}

	public void OnCodecContainerChange(ComboBox cmb)
	{
		Calculate();
	}

	public void OnSizeChange(SpinButton spin)
	{
		if (handlingEvents) return;
		handlingEvents = true;

		fileRadio.setActive(true);

		if(spin is sizeKBSpin)
			sizeMBSpin.setValue(rndint(sizeKBSpin.getValue() / 1024));
		else
			sizeKBSpin.setValue(sizeMBSpin.getValueAsInt() * 1024);

		Calculate();

		handlingEvents = false;
	}

	public void OnMediumChange(ComboBox cmb)
	{
		if (handlingEvents) return;
		handlingEvents = true;

		fileRadio.setActive(true);

		sizeKBSpin.setValue(storageMediumSizeKB[mediumCombo.getActive()]);
		sizeMBSpin.setValue(rndint(cast(double)storageMediumSizeKB[mediumCombo.getActive()] / 1024));

		Calculate();

		handlingEvents = false;
	}

	public void OnBitrateChange(SpinButton spin)
	{
		if (handlingEvents) return;
		handlingEvents = true;

		bitrRadio.setActive(true);

		Calculate();

		handlingEvents = false;
	}

	public void OnVideoSizeChange(SpinButton spin)
	{
		if (handlingEvents) return;
		handlingEvents = true;

		fileRadio.setActive(true);
		long audioSizeKB = (audioFrame1.getAudioStream.SizeBytes + audioFrame2.getAudioStream.SizeBytes) / 1024;

		Stdout(audioSizeKB).newline;

		if(spin is videoSizeKBSpin)
		{
			Stdout(rndint(videoSizeKBSpin.getValue() + audioSizeKB)).newline;
			sizeKBSpin.setValue(rndint(videoSizeKBSpin.getValue() + audioSizeKB));
			sizeMBSpin.setValue(rndint(videoSizeKBSpin.getValue() + audioSizeKB / 1024));
		}
		else
		{
			Stdout(rndint(videoSizeMBSpin.getValue() * 1024 + audioSizeKB)).newline;
			sizeKBSpin.setValue(rndint(videoSizeMBSpin.getValue() * 1024 + audioSizeKB));
			sizeMBSpin.setValue(rndint(videoSizeMBSpin.getValue() + audioSizeKB / 1024));
		}

		Calculate();

		bitrRadio.setActive(true);

		handlingEvents = false;
	}


	public void OnClose(Button btn)
	{
		Main.exit(0);
	}

	void Calculate()
	{
		handlingEvents = true;

		BitrateCalculator bitr = new BitrateCalculator();

		VideoCodec codec = cast(VideoCodec)codecCombo.getActive();
		bool useBframes = videoFrame.getUseBFrames();
		ContainerType container = cast(ContainerType)containCombo.getActive();
		AudioStream [] audioStreams;
		int nbOfFrames = videoFrame.getFrames();
		double framerate = videoFrame.getFrameRate();
		int videoSizeKB;

		if(audioFrame1.getAudioStream.SizeBytes > 0)
			audioStreams ~= audioFrame1.getAudioStream;
		if(audioFrame2.getAudioStream.SizeBytes > 0)
			audioStreams ~= audioFrame2.getAudioStream;

		if(bitrRadio.getActive() == true) // calculate FileSize
		{
			int desiredBitrate = bitrSpin.getValueAsInt();

			int sizeKB = bitr.CalculateFileSizeKB(codec, useBframes, container, audioStreams, desiredBitrate, nbOfFrames, framerate, videoSizeKB);

			sizeKBSpin.setValue(sizeKB);
			sizeMBSpin.setValue(rndint(cast(double)sizeKB / 1024));
		}
		else // calculate Bitrate
		{
			long desiredOutputSizeBytes = sizeKBSpin.getValueAsInt() * 1024L;
			
			bitrSpin.setValue(bitr.CalculateBitrateKBits(codec, useBframes, container, audioStreams, desiredOutputSizeBytes, nbOfFrames, framerate, videoSizeKB));
		}

		videoSizeKBSpin.setValue(videoSizeKB);
		videoSizeMBSpin.setValue(rndint(cast(double)videoSizeKB / 1024));

		handlingEvents = false;
	}
}

class VideoFrame : Frame
{
	void delegate()[] onFramesChangedDelegates;
	void delegate()[] onBFramesChangedDelegates;

	SpinButton  hourSpin;
	SpinButton  minSpin;
	SpinButton  secSpin;
	SpinButton  totalSecSpin;
	ComboBox    frameRateCombo;
	SpinButton  framesSpin;
	CheckButton bFramesCheckBtn;

	bool handlingEvents;

	public this(char[] title = "Video")
	{
		super(title);

		hourSpin = new SpinButton(0, 40, 1);
		hourSpin.setWidthChars(3);
		minSpin = new SpinButton(0, 59, 1);
		minSpin.setWidthChars(3);
		secSpin = new SpinButton(0, 59, 1);
		secSpin.setWidthChars(3);

		HBox timeBox = new HBox(false, 4);
		timeBox.add(new Label("Hours"));
		timeBox.add(hourSpin);
		timeBox.add(new Label("Minutes"));
		timeBox.add(minSpin);
		timeBox.add(new Label("Seconds"));
		timeBox.add(secSpin);

		totalSecSpin = new SpinButton(0, 363599, 1);
		frameRateCombo = new ComboBox(true);
		foreach(char[] string; frameRates) frameRateCombo.appendText(string);
		framesSpin = new SpinButton(0, 9089975, 1);
		bFramesCheckBtn = new CheckButton("B-frames");

		Table videoTable = new Table(4, 2, false);
		videoTable.setRowSpacings(5);
		videoTable.attachDefaults(Alignment.west(new Label("Total lenght in seconds")), 0, 1, 0, 1);
		videoTable.attachDefaults(totalSecSpin, 1, 2, 0, 1);
		videoTable.attachDefaults(Alignment.west(new Label("Framerate")), 0, 1, 1, 2);
		videoTable.attachDefaults(frameRateCombo, 1, 2, 1, 2);
		videoTable.attachDefaults(Alignment.west(new Label("Number of frames")), 0, 1, 2, 3);
		videoTable.attachDefaults(framesSpin, 1, 2, 2, 3);
		videoTable.attachDefaults(bFramesCheckBtn, 0, 2, 3, 4);

		VBox videoBox = new VBox(false, 4);
		videoBox.setBorderWidth(4);
		videoBox.add(timeBox);
		videoBox.add(videoTable);

		this.add(videoBox);

		hourSpin.addOnValueChanged(     &onTimeChanged);
		minSpin.addOnValueChanged(      &onTimeChanged);
		secSpin.addOnValueChanged(      &onTimeChanged);
		totalSecSpin.addOnValueChanged( &onSecondsChanged);
		frameRateCombo.addOnChanged(    &onFrameRateChanged);
		framesSpin.addOnValueChanged(   &onFramesChanged);
		bFramesCheckBtn.addOnToggled(   &onBFramesChanged);

		hourSpin.grabFocus();
		frameRateCombo.setActive(2);
		bFramesCheckBtn.setActive(true);
	}

	int getTotalLengthInSeconds()
		{ return totalSecSpin.getValueAsInt(); }

	double getFrameRate()
		{ return FrameRate[frameRateCombo.getActive()]; }

	int getFrames()
		{ return framesSpin.getValueAsInt(); }

	bool getUseBFrames()
		{ return cast(bool)bFramesCheckBtn.getActive(); }

	void addOnFramesChanged(void delegate() dlg)
	{
		onFramesChangedDelegates ~= dlg;
	}
	void framesChanged()
	{
		foreach(dlg; onFramesChangedDelegates)
			dlg();
	}

	void addOnBFramesChanged(void delegate() dlg)
	{
		onBFramesChangedDelegates ~= dlg;
	}
	void bFramesChanged()
	{
		foreach(dlg; onBFramesChangedDelegates)
			dlg();
	}

	void onTimeChanged(SpinButton sb)
	{
		if (handlingEvents) return;
		handlingEvents = true;

		int seconds = hourSpin.getValueAsInt * 3600;
		seconds += minSpin.getValueAsInt * 60;
		seconds += secSpin.getValueAsInt;

		totalSecSpin.setValue(seconds);

		framesSpin.setValue(cast(int)(seconds * FrameRate[frameRateCombo.getActive()]));
		framesChanged();

		handlingEvents = false;
	}

	void onSecondsChanged(SpinButton sb)
	{
		if (handlingEvents) return;
		handlingEvents = true;

		CalculateTime();

		framesSpin.setValue(cast(int)(totalSecSpin.getValue() * FrameRate[frameRateCombo.getActive()]));
		framesChanged();

		handlingEvents = false;
	}

	void onFrameRateChanged(ComboBox cb)
	{
		framesSpin.setValue(rndint(totalSecSpin.getValue() * FrameRate[frameRateCombo.getActive()]));
	}

	void onFramesChanged(SpinButton sb)
	{
		if (handlingEvents) return;
		handlingEvents = true;

		framesChanged();

		totalSecSpin.setValue(rndint(framesSpin.getValue() / FrameRate[frameRateCombo.getActive()]));

		CalculateTime();

		handlingEvents = false;
	}

	void onBFramesChanged(ToggleButton tb)
	{
		bFramesChanged();
	}

	public void CalculateTime()
	{
		int seconds = totalSecSpin.getValueAsInt();

		hourSpin.setValue(cast(int)floor(seconds / 3600));
		seconds -= hourSpin.getValueAsInt() * 3600;

		minSpin.setValue(cast(int)floor(seconds / 60));
		seconds -= minSpin.getValueAsInt() * 60;

		secSpin.setValue(seconds);
	}
}

class AudioFrame : Frame
{
	void delegate()[] onAudioChangedDelegates;

	SpinButton  bitrSpin;
	SpinButton  sizeKBSpin;
	SpinButton  sizeMBSpin;
	ComboBox    typeCombo;

	bool handlingEvents;
	int totalLengthInSeconds;
	AudioStream audioStream;

	public this(char[] title = "Audio")
	{
		super(title);

		bitrSpin = new SpinButton(0, 1000, 1);
		sizeKBSpin = new SpinButton(0, int.max, 1);
		sizeMBSpin = new SpinButton(0, int.max, 1);
		typeCombo = new ComboBox(true);
		foreach(char[] string; audioTypes) typeCombo.appendText(string);

		Alignment clearAlign = new Alignment(1, 0.5, 0.2, 0);
		clearAlign.add(new Button(StockID.CLEAR, &OnClearAudio));

		HBox kbBox = new HBox(false, 0);
		kbBox.add(sizeKBSpin);
		kbBox.add(new Label("KB"));

		HBox mbBox = new HBox(false, 0);
		mbBox.add(sizeMBSpin);
		mbBox.add(new Label("MB"));

		HBox typeBox = new HBox(false, 0);
		typeBox.add(new Label("Type"));
		typeBox.add(typeCombo);

		VBox audioBox = new VBox(false, 4);
		audioBox.setBorderWidth(4);
		audioBox.add(new Label("Bitrate"));
		audioBox.add(bitrSpin);
		audioBox.add(new Label("Size"));
		audioBox.add(kbBox);
		audioBox.add(mbBox);
		audioBox.add(typeBox);
		audioBox.add(clearAlign);

		this.add(audioBox);

		bitrSpin.addOnValueChanged(   &OnAudioBitrateChange);
		sizeKBSpin.addOnValueChanged( &OnAudioSizeChange);
		sizeMBSpin.addOnValueChanged( &OnAudioSizeChange);
		typeCombo.addOnChanged(       &OnAudioTypeChange);

		typeCombo.setActive(0);
	}

	void setLengthInSeconds(int length)
	{
		totalLengthInSeconds = length;
		CalculateAudioSize();
	}

	AudioStream getAudioStream()
	{
		return audioStream;
	}

	void addOnAudioChanged(void delegate() dlg)
	{
		onAudioChangedDelegates ~= dlg;
	}
	void audioChanged()
	{
		foreach(dlg; onAudioChangedDelegates)
			dlg();
	}

	public void OnAudioBitrateChange(SpinButton spin)
	{
		if (handlingEvents) return;
		handlingEvents = true;

		CalculateAudioSize();
		audioChanged();

		handlingEvents = false;
	}

	public void OnAudioSizeChange(SpinButton spin)
	{
		if (handlingEvents) return;
		handlingEvents = true;

		if(spin is sizeMBSpin)
		{
			sizeKBSpin.setValue(sizeMBSpin.getValueAsInt() * 1024);
			audioStream.SizeBytes = sizeKBSpin.getValueAsInt() * 1024;
		}
		else if(spin is sizeKBSpin)
		{
			sizeMBSpin.setValue(rndint(sizeKBSpin.getValue() / 1024));
			audioStream.SizeBytes = sizeKBSpin.getValueAsInt() * 1024;
		}

		audioChanged();
		CalculateAudioBitrate();

		handlingEvents = false;
	}

	public void OnAudioTypeChange(ComboBox cmb)
	{
		audioStream.Type = cast(AudioType)typeCombo.getActive();
		audioChanged();
	}

	public void OnClearAudio(Button btn)
	{
		bitrSpin.setValue(0);
		sizeKBSpin.setValue(0);
		sizeMBSpin.setValue(0);
		typeCombo.setActive(0);

		audioStream = AudioStream.init;
		audioChanged();
	}

	void CalculateAudioSize()
	{
		double CalculateSize(int bitrate)
		{
			double bytesPerSecond = cast(double)bitrate * 1000 / 8;
			return (totalLengthInSeconds * bytesPerSecond);
			return 100;
		}

		double sizeInBytes = CalculateSize(bitrSpin.getValueAsInt());

		audioStream.SizeBytes = rndlong(sizeInBytes);
		sizeKBSpin.setValue(rndint(sizeInBytes / 1024));
		sizeMBSpin.setValue(rndint(sizeInBytes / 1024 / 1024));
	}

	void CalculateAudioBitrate()
	{
		int CalculateBitrate(long sizeInBytes)
		{
			double bytesPerSecond = sizeInBytes / totalLengthInSeconds;
			return cast(int)floor(bytesPerSecond * 8 / 1000);
		}

		bitrSpin.setValue(CalculateBitrate(audioStream.SizeBytes));
	}
}