Fix frame count bug

This commit is contained in:
2023-09-12 21:26:48 +02:00
parent 65a93a3028
commit f1fb2251a2
2 changed files with 11 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
#include <memory>
#include <vector>
#include <ranges>
#include <chrono>
#include "fmt/format.h"
#include "miniaudio.h"
@@ -93,7 +94,6 @@ public:
private:
std::size_t m_frame_count{0};
};
using audio_track_ref_t = std::shared_ptr<audio_track>;
auto ffmpeg_error_str(int err) {
static char str[AV_ERROR_MAX_STRING_SIZE]{};
@@ -162,7 +162,7 @@ public:
while (frame_read < frame_count) {
auto track = std::static_pointer_cast<audio_track>(m_tracks[0]);
if (track->empty()) read(track);
frame_read += track->read_pcm_frame(output, frame_count);
frame_read += track->read_pcm_frame(output, frame_count - frame_read);
}
}
@@ -225,9 +225,12 @@ auto callback([[maybe_unused]]ma_device* device, [[maybe_unused]]void* output, [
auto entry() -> void {
media decoder{};
decoder.load("C:/Users/miku/Downloads/Porter Robinson - Trying to Feel Alive (Official Audio).webm");
fmt::print("{}\n", decoder.str());
decoder.load("/Users/k/Downloads/tryingtofeelalive.mp4");
fmt::print("{}", decoder.str());
if (decoder.tracks().empty())
throw std::runtime_error("There are no tracks readable.");
// TODO: Deocde and cache it in the background.
auto track = std::static_pointer_cast<audio_track>(decoder.tracks()[0]);
ma_device device;