mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-31 01:46:16 +02:00
server runs on OpenWrt
This commit is contained in:
parent
212c9c1c6b
commit
41db245efc
4 changed files with 42 additions and 34 deletions
|
@ -17,9 +17,16 @@
|
|||
***/
|
||||
|
||||
#include <memory>
|
||||
#include "common/endian.h"
|
||||
#include "pcmEncoder.h"
|
||||
|
||||
|
||||
#define ID_RIFF 0x46464952
|
||||
#define ID_WAVE 0x45564157
|
||||
#define ID_FMT 0x20746d66
|
||||
#define ID_DATA 0x61746164
|
||||
|
||||
|
||||
PcmEncoder::PcmEncoder(const std::string& codecOptions) : Encoder(codecOptions)
|
||||
{
|
||||
headerChunk_.reset(new msg::Header("pcm"));
|
||||
|
@ -35,30 +42,22 @@ void PcmEncoder::encode(const msg::PcmChunk* chunk)
|
|||
|
||||
void PcmEncoder::initEncoder()
|
||||
{
|
||||
//TODO: Endianess
|
||||
headerChunk_->payloadSize = 44;
|
||||
headerChunk_->payload = (char*)malloc(headerChunk_->payloadSize);
|
||||
memcpy(headerChunk_->payload, "RIFF", 4);
|
||||
uint32_t int32 = 36;
|
||||
memcpy(headerChunk_->payload + 4, reinterpret_cast<const char *>(&int32), sizeof(uint32_t));
|
||||
memcpy(headerChunk_->payload + 8, "WAVEfmt ", 8);
|
||||
int32 = 16;
|
||||
memcpy(headerChunk_->payload + 16, reinterpret_cast<const char *>(&int32), sizeof(uint32_t));
|
||||
uint16_t int16 = 1;
|
||||
memcpy(headerChunk_->payload + 20, reinterpret_cast<const char *>(&int16), sizeof(uint16_t));
|
||||
int16 = sampleFormat_.channels;
|
||||
memcpy(headerChunk_->payload + 22, reinterpret_cast<const char *>(&int16), sizeof(uint16_t));
|
||||
int32 = sampleFormat_.rate;
|
||||
memcpy(headerChunk_->payload + 24, reinterpret_cast<const char *>(&int32), sizeof(uint32_t));
|
||||
int32 = sampleFormat_.rate * sampleFormat_.bits * sampleFormat_.channels / 8;
|
||||
memcpy(headerChunk_->payload + 28, reinterpret_cast<const char *>(&int32), sizeof(uint32_t));
|
||||
int16 = sampleFormat_.channels * ((sampleFormat_.bits + 7) / 8);
|
||||
memcpy(headerChunk_->payload + 32, reinterpret_cast<const char *>(&int16), sizeof(uint16_t));
|
||||
int16 = sampleFormat_.bits;
|
||||
memcpy(headerChunk_->payload + 34, reinterpret_cast<const char *>(&int16), sizeof(uint16_t));
|
||||
memcpy(headerChunk_->payload + 36, "data", 4);
|
||||
int32 = 0;
|
||||
memcpy(headerChunk_->payload + 40, reinterpret_cast<const char *>(&int32), sizeof(uint32_t));
|
||||
char* payload = headerChunk_->payload;
|
||||
assign(payload, SWAP_32(ID_RIFF));
|
||||
assign(payload + 4, SWAP_32(36));
|
||||
assign(payload + 8, SWAP_32(ID_WAVE));
|
||||
assign(payload + 12, SWAP_32(ID_FMT));
|
||||
assign(payload + 16, SWAP_32(16));
|
||||
assign(payload + 20, SWAP_16(1));
|
||||
assign(payload + 22, SWAP_16(sampleFormat_.channels));
|
||||
assign(payload + 24, SWAP_32(sampleFormat_.rate));
|
||||
assign(payload + 28, SWAP_32(sampleFormat_.rate * sampleFormat_.bits * sampleFormat_.channels / 8));
|
||||
assign(payload + 32, SWAP_16(sampleFormat_.channels * ((sampleFormat_.bits + 7) / 8)));
|
||||
assign(payload + 34, SWAP_16(sampleFormat_.bits));
|
||||
assign(payload + 36, SWAP_32(ID_DATA));
|
||||
assign(payload + 40, SWAP_32(0));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue