mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 16:18:03 +02:00
wire up audio codec
This commit is contained in:
parent
f5b693cebb
commit
540ab9f07c
2 changed files with 33 additions and 11 deletions
|
@ -12,7 +12,7 @@ if (WIN32)
|
||||||
set(TARGET_NAME hifiCodec)
|
set(TARGET_NAME hifiCodec)
|
||||||
setup_hifi_client_server_plugin()
|
setup_hifi_client_server_plugin()
|
||||||
|
|
||||||
link_hifi_libraries(shared plugins)
|
link_hifi_libraries(audio shared plugins)
|
||||||
|
|
||||||
add_dependency_external_projects(HiFiAudioCodec)
|
add_dependency_external_projects(HiFiAudioCodec)
|
||||||
target_include_directories(${TARGET_NAME} PRIVATE ${HIFIAUDIOCODEC_INCLUDE_DIRS})
|
target_include_directories(${TARGET_NAME} PRIVATE ${HIFIAUDIOCODEC_INCLUDE_DIRS})
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
|
|
||||||
#include <qapplication.h>
|
#include <qapplication.h>
|
||||||
|
|
||||||
#include <AudioCodec.h> // should be from the external...
|
#include <AudioCodec.h>
|
||||||
|
#include <AudioConstants.h>
|
||||||
|
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
|
|
||||||
|
@ -39,28 +40,49 @@ bool HiFiCodec::isSupported() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class HiFiEncoder : public Encoder {
|
class HiFiEncoder : public Encoder, public AudioEncoder {
|
||||||
public:
|
public:
|
||||||
virtual void encode(const QByteArray& decodedBuffer, QByteArray& encodedBuffer) override {
|
HiFiEncoder(int sampleRate, int numChannels) : AudioEncoder(sampleRate, numChannels) {
|
||||||
encodedBuffer = decodedBuffer;
|
qDebug() << __FUNCTION__ << "sampleRate:" << sampleRate << "numChannels:" << numChannels;
|
||||||
|
_encodedSize = (AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * sizeof(int16_t) * numChannels) / 4; // codec reduces by 1/4th
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void encode(const QByteArray& decodedBuffer, QByteArray& encodedBuffer) override {
|
||||||
|
encodedBuffer.resize(_encodedSize);
|
||||||
|
AudioEncoder::process((const int16_t*)decodedBuffer.constData(), (int16_t*)encodedBuffer.data(), AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
int _encodedSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HiFiDecoder : public Decoder {
|
class HiFiDecoder : public Decoder, public AudioDecoder {
|
||||||
public:
|
public:
|
||||||
virtual void decode(const QByteArray& encodedBuffer, QByteArray& decodedBuffer) override {
|
HiFiDecoder(int sampleRate, int numChannels) : AudioDecoder(sampleRate, numChannels) {
|
||||||
decodedBuffer = encodedBuffer;
|
qDebug() << __FUNCTION__ << "sampleRate:" << sampleRate << "numChannels:" << numChannels;
|
||||||
|
_decodedSize = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * sizeof(int16_t) * numChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void trackLostFrames(int numFrames) override { }
|
virtual void decode(const QByteArray& encodedBuffer, QByteArray& decodedBuffer) override {
|
||||||
|
decodedBuffer.resize(_decodedSize);
|
||||||
|
AudioDecoder::process((const int16_t*)encodedBuffer.constData(), (int16_t*)decodedBuffer.data(), AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void trackLostFrames(int numFrames) override {
|
||||||
|
QByteArray encodedBuffer;
|
||||||
|
QByteArray decodedBuffer;
|
||||||
|
decodedBuffer.resize(_decodedSize);
|
||||||
|
AudioDecoder::process((const int16_t*)encodedBuffer.constData(), (int16_t*)decodedBuffer.data(), AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL, false);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
int _decodedSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
Encoder* HiFiCodec::createEncoder(int sampleRate, int numChannels) {
|
Encoder* HiFiCodec::createEncoder(int sampleRate, int numChannels) {
|
||||||
return new HiFiEncoder();
|
return new HiFiEncoder(sampleRate, numChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
Decoder* HiFiCodec::createDecoder(int sampleRate, int numChannels) {
|
Decoder* HiFiCodec::createDecoder(int sampleRate, int numChannels) {
|
||||||
return new HiFiDecoder();
|
return new HiFiDecoder(sampleRate, numChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HiFiCodec::releaseEncoder(Encoder* encoder) {
|
void HiFiCodec::releaseEncoder(Encoder* encoder) {
|
||||||
|
|
Loading…
Reference in a new issue