Fix frame count bug
This commit is contained in:
@@ -2,3 +2,7 @@
|
|||||||
|
|
||||||
Using `miniaudio` and `ffmpeg` together.
|
Using `miniaudio` and `ffmpeg` together.
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
- Audio Sample Frames - <https://techpubs.jurassic.nl/manuals/0650/developer/DMSDK_PG/sgi_html/ch08.html>
|
||||||
|
|
||||||
|
|||||||
11
ffmini.cpp
11
ffmini.cpp
@@ -3,6 +3,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "miniaudio.h"
|
#include "miniaudio.h"
|
||||||
@@ -93,7 +94,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::size_t m_frame_count{0};
|
std::size_t m_frame_count{0};
|
||||||
};
|
};
|
||||||
using audio_track_ref_t = std::shared_ptr<audio_track>;
|
|
||||||
|
|
||||||
auto ffmpeg_error_str(int err) {
|
auto ffmpeg_error_str(int err) {
|
||||||
static char str[AV_ERROR_MAX_STRING_SIZE]{};
|
static char str[AV_ERROR_MAX_STRING_SIZE]{};
|
||||||
@@ -162,7 +162,7 @@ public:
|
|||||||
while (frame_read < frame_count) {
|
while (frame_read < frame_count) {
|
||||||
auto track = std::static_pointer_cast<audio_track>(m_tracks[0]);
|
auto track = std::static_pointer_cast<audio_track>(m_tracks[0]);
|
||||||
if (track->empty()) read(track);
|
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 {
|
auto entry() -> void {
|
||||||
media decoder{};
|
media decoder{};
|
||||||
decoder.load("C:/Users/miku/Downloads/Porter Robinson - Trying to Feel Alive (Official Audio).webm");
|
decoder.load("/Users/k/Downloads/tryingtofeelalive.mp4");
|
||||||
fmt::print("{}\n", decoder.str());
|
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]);
|
auto track = std::static_pointer_cast<audio_track>(decoder.tracks()[0]);
|
||||||
|
|
||||||
ma_device device;
|
ma_device device;
|
||||||
|
|||||||
Reference in New Issue
Block a user