mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-02 10:51:45 +02:00
fixed off encoding
This commit is contained in:
parent
c44288afde
commit
176ed8abc0
3 changed files with 21 additions and 24 deletions
|
@ -17,11 +17,6 @@ OggEncoder::OggEncoder(const msg::SampleFormat& format) : Encoder(format), eos(0
|
||||||
double OggEncoder::encode(msg::PcmChunk* chunk)
|
double OggEncoder::encode(msg::PcmChunk* chunk)
|
||||||
{
|
{
|
||||||
double res = 0;
|
double res = 0;
|
||||||
if (tv_sec == 0)
|
|
||||||
{
|
|
||||||
tv_sec = chunk->timestamp.sec;
|
|
||||||
tv_usec = chunk->timestamp.usec;
|
|
||||||
}
|
|
||||||
//logD << "-> pcm: " << wireChunk->length << endl;
|
//logD << "-> pcm: " << wireChunk->length << endl;
|
||||||
int bytes = chunk->payloadSize / 4;
|
int bytes = chunk->payloadSize / 4;
|
||||||
float **buffer=vorbis_analysis_buffer(&vd, bytes);
|
float **buffer=vorbis_analysis_buffer(&vd, bytes);
|
||||||
|
@ -29,10 +24,16 @@ double OggEncoder::encode(msg::PcmChunk* chunk)
|
||||||
/* uninterleave samples */
|
/* uninterleave samples */
|
||||||
for(int i=0; i<bytes; i++)
|
for(int i=0; i<bytes; i++)
|
||||||
{
|
{
|
||||||
buffer[0][i]=((chunk->payload[i*4+1]<<8)|
|
int idx = 4*i;
|
||||||
(0x00ff&(int)chunk->payload[i*4]))/32768.f;
|
/* int8_t high = chunk->payload[idx+1];
|
||||||
buffer[1][i]=((chunk->payload[i*4+3]<<8)|
|
int8_t low = chunk->payload[idx];
|
||||||
(0x00ff&(int)chunk->payload[i*4+2]))/32768.f;
|
buffer[0][i]=((high << 8) | (0x00ff&low))/32768.f;
|
||||||
|
high = chunk->payload[idx+3];
|
||||||
|
low = chunk->payload[idx+2];
|
||||||
|
buffer[1][i]=((high << 8) | (0x00ff&low))/32768.f;
|
||||||
|
*/
|
||||||
|
buffer[0][i]=((((int8_t)chunk->payload[idx+1]) << 8) | (0x00ff&((int8_t)chunk->payload[idx])))/32768.f;
|
||||||
|
buffer[1][i]=((((int8_t)chunk->payload[idx+3]) << 8) | (0x00ff&((int8_t)chunk->payload[idx+2])))/32768.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tell the library how much we actually submitted */
|
/* tell the library how much we actually submitted */
|
||||||
|
@ -70,6 +71,9 @@ double OggEncoder::encode(msg::PcmChunk* chunk)
|
||||||
pos += og.header_len;
|
pos += og.header_len;
|
||||||
memcpy(chunk->payload + pos, og.body, og.body_len);
|
memcpy(chunk->payload + pos, og.body, og.body_len);
|
||||||
pos += og.body_len;
|
pos += og.body_len;
|
||||||
|
|
||||||
|
if (ogg_page_eos(&og))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,8 +87,6 @@ double OggEncoder::encode(msg::PcmChunk* chunk)
|
||||||
lastGranulepos = os.granulepos;
|
lastGranulepos = os.granulepos;
|
||||||
chunk->payload = (char*)realloc(chunk->payload, pos);
|
chunk->payload = (char*)realloc(chunk->payload, pos);
|
||||||
chunk->payloadSize = pos;
|
chunk->payloadSize = pos;
|
||||||
tv_sec = 0;
|
|
||||||
tv_usec = 0;
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -93,9 +95,6 @@ double OggEncoder::encode(msg::PcmChunk* chunk)
|
||||||
void OggEncoder::init()
|
void OggEncoder::init()
|
||||||
{
|
{
|
||||||
/********** Encode setup ************/
|
/********** Encode setup ************/
|
||||||
tv_sec = 0;
|
|
||||||
tv_usec = 0;
|
|
||||||
|
|
||||||
vorbis_info_init(&vi);
|
vorbis_info_init(&vi);
|
||||||
|
|
||||||
/* choose an encoding mode. A few possibilities commented out, one
|
/* choose an encoding mode. A few possibilities commented out, one
|
||||||
|
@ -156,7 +155,11 @@ void OggEncoder::init()
|
||||||
make the headers, then pass them to libvorbis one at a time;
|
make the headers, then pass them to libvorbis one at a time;
|
||||||
libvorbis handles the additional Ogg bitstream constraints */
|
libvorbis handles the additional Ogg bitstream constraints */
|
||||||
|
|
||||||
vorbis_analysis_headerout(&vd,&vc,&header,&header_comm,&header_code);
|
ogg_packet header;
|
||||||
|
ogg_packet header_comm;
|
||||||
|
ogg_packet header_code;
|
||||||
|
|
||||||
|
vorbis_analysis_headerout(&vd,&vc,&header,&header_comm,&header_code);
|
||||||
ogg_stream_packetin(&os,&header);
|
ogg_stream_packetin(&os,&header);
|
||||||
ogg_stream_packetin(&os,&header_comm);
|
ogg_stream_packetin(&os,&header_comm);
|
||||||
ogg_stream_packetin(&os,&header_code);
|
ogg_stream_packetin(&os,&header_code);
|
||||||
|
|
|
@ -25,17 +25,10 @@ private:
|
||||||
vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
|
vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
|
||||||
vorbis_block vb; /* local working space for packet->PCM decode */
|
vorbis_block vb; /* local working space for packet->PCM decode */
|
||||||
|
|
||||||
ogg_packet header;
|
|
||||||
ogg_packet header_comm;
|
|
||||||
ogg_packet header_code;
|
|
||||||
|
|
||||||
ogg_int64_t lastGranulepos;
|
ogg_int64_t lastGranulepos;
|
||||||
|
|
||||||
int eos, ret;
|
int eos, ret;
|
||||||
int i, founddata;
|
int i, founddata;
|
||||||
|
|
||||||
int32_t tv_sec;
|
|
||||||
int32_t tv_usec;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,9 @@ int main(int argc, char* argv[])
|
||||||
timeval tvChunk;
|
timeval tvChunk;
|
||||||
gettimeofday(&tvChunk, NULL);
|
gettimeofday(&tvChunk, NULL);
|
||||||
long nextTick = chronos::getTickCount();
|
long nextTick = chronos::getTickCount();
|
||||||
|
|
||||||
mkfifo(fifoName.c_str(), 0777);
|
umask(0);
|
||||||
|
mkfifo(fifoName.c_str(), 0666);
|
||||||
msg::SampleFormat format(sampleFormat);
|
msg::SampleFormat format(sampleFormat);
|
||||||
size_t duration = 50;
|
size_t duration = 50;
|
||||||
//size_t chunkSize = duration*format.rate*format.frameSize / 1000;
|
//size_t chunkSize = duration*format.rate*format.frameSize / 1000;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue