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
// "afi" - Aldaron's Format Interface
//
// Copyright Jeron A. Lau 2017-2018.
// Distributed under the Boost Software License, Version 1.0.  (See accompanying
// file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)

use AFrame;
use std::collections::VecDeque;

/// Mono, Stereo or Surround.
pub enum AudioChannels {
	/// Mono = 1 channel (front center)
	Mono = 1,
	/// Stereo = 2 channels (front left, front right)
	Stereo = 2,
	/// Surround = 5 channels (front left, front right, front center,
	/// back left, back right)
	Surround = 5,
}

pub use AudioChannels::*;

impl Default for AudioChannels {
	fn default() -> AudioChannels { Stereo }
}

/// An Audio Buffer (48kHz/48,000hz).
pub struct Audio {
	/// Title
	pub title: String,
	/// Artist / Author
	pub artist: String,
	/// Album Artist
	pub album_artist: String,
	/// Album
	pub album: String,
	/// CD
	pub cd: String,
	/// Release Date / Release Year
	pub release: String,
	/// Track #
	pub track_number: String,
	/// Track Count
	pub track_count: String,
	/// Genre
	pub genre: String,
	/// Comment
	pub comment: String,
	/// Composer
	pub composer: String,
	/// Original artist
	pub orig_artist: String,
	/// Copyright / License
	pub copyright: String,
	/// Artist Website / URL
	pub url: String,
	/// Encoded By
	pub encoded_by: String,
	/// The actual audio.
	frames: VecDeque<AFrame>,
	/// The total number of frames in the audio.
	n_frames: u32,
}

impl Audio {
	/// Create a new `Audio`.
	pub fn new(n_frames: u32) -> Audio {
		Audio {
			n_frames,
			frames: VecDeque::new(),
			title: String::new(),
			artist: String::new(),
			album_artist: String::new(),
			album: String::new(),
			cd: String::new(),
			release: String::new(),
			track_number: String::new(),
			track_count: String::new(),
			genre: String::new(),
			comment: String::new(),
			composer: String::new(),
			orig_artist: String::new(),
			copyright: String::new(),
			url: String::new(),
			encoded_by: String::new(),
		}
	}

	/// Returns audio for the next frame on the Queue.
	pub fn pop(&mut self) -> Option<AFrame> {
		Some(self.frames.pop_front()?)
	}

	/// Return the number of frames in the audio.
	pub fn frames(&self) -> u32 {
		self.n_frames
	}
}