fixed the sampleFormat size used in the frames calculation

This commit is contained in:
faraphel 2024-10-22 20:21:29 +02:00
parent c3c452ff5d
commit 824a48f8d2
2 changed files with 1 additions and 4 deletions

View file

@ -171,12 +171,10 @@ void Client::loopPlayer() {
throw std::runtime_error("[Client] Could not start the PortAudio stream: " + std::string(Pa_GetErrorText(error))); throw std::runtime_error("[Client] Could not start the PortAudio stream: " + std::string(Pa_GetErrorText(error)));
// write the new audio data into the audio buffer // write the new audio data into the audio buffer
// TODO(Faraphel) / 2 => / encoding size
// TODO(Faraphel): the number of frames could be improved
const int error = Pa_WriteStream( const int error = Pa_WriteStream(
this->stream, this->stream,
audioPacket.content.data(), audioPacket.content.data(),
audioPacket.contentSize / 2 / this->streamChannels audioPacket.contentSize / Pa_GetSampleSize(this->streamSampleFormat) / this->streamChannels
); );
switch (error) { switch (error) {
// success // success

View file

@ -114,7 +114,6 @@ void Server::loop() const {
std::cout << "[Server] Sent: " << done << " bytes" << std::endl; std::cout << "[Server] Sent: " << done << " bytes" << std::endl;
// TODO(Faraphel): should be extended to simulate live music streaming
// wait for the duration of the audio chunk // wait for the duration of the audio chunk
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<uint64_t>( std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<uint64_t>(
(1 / static_cast<double>(this->sampleRate * this->channels * mpg123_encsize(this->encoding))) * (1 / static_cast<double>(this->sampleRate * this->channels * mpg123_encsize(this->encoding))) *