mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
symphonia_decoder tweak
* Remove unwrap * Refactor normalisation_data.
This commit is contained in:
parent
47f1362453
commit
85d6c0c714
1 changed files with 35 additions and 36 deletions
|
@ -104,25 +104,25 @@ impl SymphoniaDecoder {
|
||||||
|
|
||||||
pub fn normalisation_data(&mut self) -> Option<NormalisationData> {
|
pub fn normalisation_data(&mut self) -> Option<NormalisationData> {
|
||||||
let mut metadata = self.format.metadata();
|
let mut metadata = self.format.metadata();
|
||||||
loop {
|
|
||||||
if let Some(_discarded_revision) = metadata.pop() {
|
|
||||||
// Advance to the latest metadata revision.
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
let revision = metadata.current()?;
|
|
||||||
let tags = revision.tags();
|
|
||||||
|
|
||||||
if tags.is_empty() {
|
// Advance to the latest metadata revision.
|
||||||
// The latest metadata entry in the log is empty.
|
// None means we hit the latest.
|
||||||
return None;
|
loop {
|
||||||
|
if metadata.pop().is_none() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tags = metadata.current()?.tags();
|
||||||
|
|
||||||
|
if tags.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
let mut data = NormalisationData::default();
|
let mut data = NormalisationData::default();
|
||||||
let mut i = 0;
|
|
||||||
while i < tags.len() {
|
for tag in tags {
|
||||||
if let Value::Float(value) = tags[i].value {
|
if let Value::Float(value) = tag.value {
|
||||||
#[allow(non_snake_case)]
|
match tag.std_key {
|
||||||
match tags[i].std_key {
|
|
||||||
Some(StandardTagKey::ReplayGainAlbumGain) => data.album_gain_db = value,
|
Some(StandardTagKey::ReplayGainAlbumGain) => data.album_gain_db = value,
|
||||||
Some(StandardTagKey::ReplayGainAlbumPeak) => data.album_peak = value,
|
Some(StandardTagKey::ReplayGainAlbumPeak) => data.album_peak = value,
|
||||||
Some(StandardTagKey::ReplayGainTrackGain) => data.track_gain_db = value,
|
Some(StandardTagKey::ReplayGainTrackGain) => data.track_gain_db = value,
|
||||||
|
@ -130,11 +130,9 @@ impl SymphoniaDecoder {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break Some(data);
|
Some(data)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,14 +198,15 @@ impl AudioDecoder for SymphoniaDecoder {
|
||||||
|
|
||||||
match self.decoder.decode(&packet) {
|
match self.decoder.decode(&packet) {
|
||||||
Ok(decoded) => {
|
Ok(decoded) => {
|
||||||
if self.sample_buffer.is_none() {
|
let sample_buffer = match self.sample_buffer.as_mut() {
|
||||||
|
Some(buffer) => buffer,
|
||||||
|
None => {
|
||||||
let spec = *decoded.spec();
|
let spec = *decoded.spec();
|
||||||
let duration = decoded.capacity() as u64;
|
let duration = decoded.capacity() as u64;
|
||||||
self.sample_buffer
|
self.sample_buffer.insert(SampleBuffer::new(duration, spec))
|
||||||
.replace(SampleBuffer::new(duration, spec));
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let sample_buffer = self.sample_buffer.as_mut().unwrap(); // guaranteed above
|
|
||||||
sample_buffer.copy_interleaved_ref(decoded);
|
sample_buffer.copy_interleaved_ref(decoded);
|
||||||
let samples = AudioPacket::Samples(sample_buffer.samples().to_vec());
|
let samples = AudioPacket::Samples(sample_buffer.samples().to_vec());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue