Cleaned up code
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
add_subdirectory(audioinfo)
|
add_subdirectory(audioinfo)
|
||||||
add_subdirectory(audiodecode)
|
add_subdirectory(audioplay)
|
||||||
add_subdirectory(db-generator)
|
add_subdirectory(db-generator)
|
||||||
add_subdirectory(recommendation)
|
add_subdirectory(recommendation)
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
|
|
||||||
add_executable(lms-audiodecode
|
|
||||||
LmsAudioDecode.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(lms-audiodecode PRIVATE
|
|
||||||
lmsaudio
|
|
||||||
lmscore
|
|
||||||
Boost::program_options
|
|
||||||
)
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
add_executable(lms-audioplay
|
||||||
|
LmsAudioPlay.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(lms-audioplay PRIVATE
|
||||||
|
lmsaudio
|
||||||
|
lmscore
|
||||||
|
Boost::program_options
|
||||||
|
)
|
||||||
@@ -19,15 +19,11 @@
|
|||||||
|
|
||||||
#include <bit>
|
#include <bit>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <format>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <boost/asio/io_context.hpp>
|
#include <boost/asio/io_context.hpp>
|
||||||
|
#include <boost/asio/post.hpp>
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
#include <pulse/def.h>
|
|
||||||
#include <pulse/error.h>
|
|
||||||
#include <pulse/sample.h>
|
|
||||||
#include <pulse/simple.h>
|
|
||||||
|
|
||||||
#include "core/ILogger.hpp"
|
#include "core/ILogger.hpp"
|
||||||
|
|
||||||
@@ -79,9 +75,8 @@ namespace lms
|
|||||||
const audio::PcmParameters& pcmParams{ getPcmParameters() };
|
const audio::PcmParameters& pcmParams{ getPcmParameters() };
|
||||||
_sampleCountPerBuffer = static_cast<std::size_t>(std::chrono::duration_cast<std::chrono::microseconds>(bufferDuration).count() * pcmParams.sampleRate / std::chrono::microseconds::period::den);
|
_sampleCountPerBuffer = static_cast<std::size_t>(std::chrono::duration_cast<std::chrono::microseconds>(bufferDuration).count() * pcmParams.sampleRate / std::chrono::microseconds::period::den);
|
||||||
const std::size_t bufferSize{ sampleCountToByteCount(_sampleCountPerBuffer) };
|
const std::size_t bufferSize{ sampleCountToByteCount(_sampleCountPerBuffer) };
|
||||||
std::cout << "Using buffer size = " << bufferSize << ", " << _sampleCountPerBuffer << " samples per channel" << std::endl;
|
|
||||||
|
|
||||||
_buffers.resize(4); // TODO parametrize?
|
_buffers.resize(bufferCount);
|
||||||
for (BufferDesc& bufferDesc : _buffers)
|
for (BufferDesc& bufferDesc : _buffers)
|
||||||
bufferDesc.buffer.resize(bufferSize);
|
bufferDesc.buffer.resize(bufferSize);
|
||||||
}
|
}
|
||||||
@@ -100,12 +95,10 @@ namespace lms
|
|||||||
|
|
||||||
std::span<std::byte> buffer{ bufferDesc.buffer };
|
std::span<std::byte> buffer{ bufferDesc.buffer };
|
||||||
const std::size_t sampleCount{ readSamples(buffer) };
|
const std::size_t sampleCount{ readSamples(buffer) };
|
||||||
if (sampleCount == 0)
|
if (sampleCount == 0) // EOF
|
||||||
{
|
{
|
||||||
// EOF
|
|
||||||
std::cout << "EOF: draining!" << std::endl;
|
|
||||||
_draining = true;
|
_draining = true;
|
||||||
_outputStream->asyncDrain([this] { std::cout << "Drain complete!!" << std::endl; });
|
_outputStream->asyncDrain([this] {});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,9 +109,7 @@ namespace lms
|
|||||||
onBufferWriteComplete(bufferIndex);
|
onBufferWriteComplete(bufferIndex);
|
||||||
});
|
});
|
||||||
|
|
||||||
std::cout << "Playback time = " << std::format("{:%T}", std::chrono::duration_cast<std ::chrono::milliseconds>(_outputStream->getPlaybackTime())) << std::endl;
|
boost::asio::post(_ioContext, [this] { decodeSome(); });
|
||||||
|
|
||||||
// TODO, reschedule instead of looping?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +158,7 @@ namespace lms
|
|||||||
Buffer buffer;
|
Buffer buffer;
|
||||||
bool isInWrite{};
|
bool isInWrite{};
|
||||||
};
|
};
|
||||||
|
static constexpr std::size_t bufferCount{ 4 };
|
||||||
std::vector<BufferDesc> _buffers;
|
std::vector<BufferDesc> _buffers;
|
||||||
std::size_t _nextBufferIndex{};
|
std::size_t _nextBufferIndex{};
|
||||||
std::size_t _sampleCountPerBuffer;
|
std::size_t _sampleCountPerBuffer;
|
||||||
@@ -204,7 +196,7 @@ int main(int argc, char* argv[])
|
|||||||
if (!std::filesystem::exists(inputPath))
|
if (!std::filesystem::exists(inputPath))
|
||||||
throw std::runtime_error{ "File '" + inputPath.string() + "' does not exist!" };
|
throw std::runtime_error{ "File '" + inputPath.string() + "' does not exist!" };
|
||||||
|
|
||||||
core::Service<core::logging::ILogger> logger{ core::logging::createLogger(core::logging::Severity::DEBUG) };
|
core::Service<core::logging::ILogger> logger{ core::logging::createLogger(core::logging::Severity::INFO) };
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -218,9 +210,7 @@ int main(int argc, char* argv[])
|
|||||||
boost::asio::io_context context;
|
boost::asio::io_context context;
|
||||||
FilePlayer filePlayer{ context, inputPath, decoderParams };
|
FilePlayer filePlayer{ context, inputPath, decoderParams };
|
||||||
|
|
||||||
std::cout << "Running..." << std::endl;
|
|
||||||
context.run();
|
context.run();
|
||||||
std::cout << "Running DONE..." << std::endl;
|
|
||||||
}
|
}
|
||||||
catch (audio::Exception& e)
|
catch (audio::Exception& e)
|
||||||
{
|
{
|
||||||
Reference in New Issue
Block a user