summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-28 21:52:30 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-28 21:52:30 +0200
commitae4a9e017aba665a9d432d6cac785048be013f30 (patch)
tree561e4abf23cc926e7e06134a973e07c9ecbe147b /Libraries
parentb44d3faa1c926204643d41eb1dac31a3ec301029 (diff)
downloadserenity-ae4a9e017aba665a9d432d6cac785048be013f30.zip
LibAudio+aplay: Make the aplay output look a little funner.
Show some information about the file we're playing, and display how many samples we've played out of how many total. This might be a bit buggy as I haven't tested it with many different files, but it's a start. :^)
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibAudio/AWavLoader.cpp8
-rw-r--r--Libraries/LibAudio/AWavLoader.h9
2 files changed, 16 insertions, 1 deletions
diff --git a/Libraries/LibAudio/AWavLoader.cpp b/Libraries/LibAudio/AWavLoader.cpp
index 93e6a2bd17..f4078cd4dc 100644
--- a/Libraries/LibAudio/AWavLoader.cpp
+++ b/Libraries/LibAudio/AWavLoader.cpp
@@ -25,7 +25,10 @@ RefPtr<ABuffer> AWavLoader::get_more_samples()
auto raw_samples = m_file.read(128 * KB);
if (raw_samples.is_empty())
return nullptr;
- return ABuffer::from_pcm_data(raw_samples, m_num_channels, m_bits_per_sample, m_sample_rate);
+
+ auto buffer = ABuffer::from_pcm_data(raw_samples, m_num_channels, m_bits_per_sample, m_sample_rate);
+ m_loaded_samples += buffer->sample_count();
+ return buffer;
}
bool AWavLoader::parse_header()
@@ -125,6 +128,9 @@ bool AWavLoader::parse_header()
ok = ok && data_sz < INT32_MAX;
CHECK_OK("Data was too large");
+ int bytes_per_sample = (m_bits_per_sample / 8) * m_num_channels;
+ m_total_samples = data_sz / bytes_per_sample;
+
// Just make sure we're good before we read the data...
ASSERT(!stream.handle_read_failure());
diff --git a/Libraries/LibAudio/AWavLoader.h b/Libraries/LibAudio/AWavLoader.h
index d1d30a3884..43d24657fe 100644
--- a/Libraries/LibAudio/AWavLoader.h
+++ b/Libraries/LibAudio/AWavLoader.h
@@ -20,6 +20,12 @@ public:
RefPtr<ABuffer> get_more_samples();
+ int loaded_samples() const { return m_loaded_samples; }
+ int total_samples() const { return m_total_samples; }
+ u32 sample_rate() const { return m_sample_rate; }
+ u16 num_channels() const { return m_num_channels; }
+ u16 bits_per_sample() const { return m_bits_per_sample; }
+
private:
bool parse_header();
CFile m_file;
@@ -28,4 +34,7 @@ private:
u32 m_sample_rate { 0 };
u16 m_num_channels { 0 };
u16 m_bits_per_sample { 0 };
+
+ int m_loaded_samples { 0 };
+ int m_total_samples { 0 };
};