瀏覽代碼

LibAudio: Expose the format name from the loader plugins

The format of these names is "Full Abbreviation (.fileformat)". For
example: "FLAC (.flac)", "RIFF WAVE (.wav)", "MPEG Layer III (.mp3)",
"Vorbis (.ogg)" The reasoning is that the container and therefore the
file ending may differ significantly from the actual format, and the
format should be given as unambiguously as possible and necessary.
kleines Filmröllchen 3 年之前
父節點
當前提交
54ac4ba8cc

+ 1 - 0
Userland/Libraries/LibAudio/FlacLoader.h

@@ -100,6 +100,7 @@ public:
     virtual int total_samples() override { return static_cast<int>(m_total_samples); }
     virtual u32 sample_rate() override { return m_sample_rate; }
     virtual u16 num_channels() override { return m_num_channels; }
+    virtual String format_name() override { return "FLAC (.flac)"; }
     virtual PcmSampleFormat pcm_format() override { return m_sample_format; }
     virtual RefPtr<Core::File> file() override { return m_file; }
 

+ 3 - 0
Userland/Libraries/LibAudio/Loader.h

@@ -50,6 +50,8 @@ public:
     virtual u32 sample_rate() = 0;
     virtual u16 num_channels() = 0;
 
+    // Human-readable name of the file format, of the form <full abbreviation> (.<ending>)
+    virtual String format_name() = 0;
     virtual PcmSampleFormat pcm_format() = 0;
     virtual RefPtr<Core::File> file() = 0;
 };
@@ -68,6 +70,7 @@ public:
     int total_samples() const { return m_plugin->total_samples(); }
     u32 sample_rate() const { return m_plugin->sample_rate(); }
     u16 num_channels() const { return m_plugin->num_channels(); }
+    String format_name() const { return m_plugin->format_name(); }
     u16 bits_per_sample() const { return pcm_bits_per_sample(m_plugin->pcm_format()); }
     RefPtr<Core::File> file() const { return m_plugin->file(); }
 

+ 1 - 0
Userland/Libraries/LibAudio/WavLoader.h

@@ -52,6 +52,7 @@ public:
     virtual int total_samples() override { return m_total_samples; }
     virtual u32 sample_rate() override { return m_sample_rate; }
     virtual u16 num_channels() override { return m_num_channels; }
+    virtual String format_name() override { return "RIFF WAVE (.wav)"; }
     virtual PcmSampleFormat pcm_format() override { return m_sample_format; }
     virtual RefPtr<Core::File> file() override { return m_file; }