Update to version 2
This commit is contained in:
@@ -27,158 +27,181 @@
|
||||
namespace Gempa {
|
||||
namespace CAPS {
|
||||
|
||||
template<typename T> Steim1Encoder<T>::~Steim1Encoder() {
|
||||
if ( format != NULL ) delete format;
|
||||
template<typename T>
|
||||
Steim1Encoder<T>::~Steim1Encoder() {
|
||||
if ( _format ) {
|
||||
delete _format;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> void Steim1Encoder<T>::update_spw(int bp) {
|
||||
template<typename T>
|
||||
void Steim1Encoder<T>::updateSpw(int bp) {
|
||||
int spw1 = 4;
|
||||
|
||||
assert(bp < 4);
|
||||
if(buf[bp] < -32768 || buf[bp] > 32767) spw1 = 1;
|
||||
else if(buf[bp] < -128 || buf[bp] > 127) spw1 = 2;
|
||||
if(spw1 < spw) spw = spw1;
|
||||
if ( _buf[bp] < -32768 || _buf[bp] > 32767 ) spw1 = 1;
|
||||
else if ( _buf[bp] < -128 || _buf[bp] > 127 ) spw1 = 2;
|
||||
if ( spw1 < _spw ) _spw = spw1;
|
||||
}
|
||||
|
||||
template<typename T> void Steim1Encoder<T>::store(int32_t value) {
|
||||
assert(bp < 4);
|
||||
buf[bp] = value - last_sample;
|
||||
last_sample = value;
|
||||
update_spw(bp);
|
||||
++bp;
|
||||
template<typename T>
|
||||
void Steim1Encoder<T>::store(int32_t value) {
|
||||
assert(_bp < 4);
|
||||
_buf[_bp] = value - _lastSample;
|
||||
_lastSample = value;
|
||||
updateSpw(_bp);
|
||||
++_bp;
|
||||
}
|
||||
|
||||
template<typename T> void Steim1Encoder<T>::init_packet() {
|
||||
template<typename T>
|
||||
void Steim1Encoder<T>::initPacket() {
|
||||
int i;
|
||||
int32_t begin_sample = last_sample;
|
||||
int32_t beginSample = _lastSample;
|
||||
|
||||
for(i = 1; i < bp; ++i) {
|
||||
begin_sample -= buf[i];
|
||||
for ( i = 1; i < _bp; ++i ) {
|
||||
beginSample -= _buf[i];
|
||||
}
|
||||
|
||||
reset();
|
||||
current_packet.data[0].sample_word[0] = htonl(begin_sample);
|
||||
frame_count = 0;
|
||||
nibble_word = 0;
|
||||
fp = 2;
|
||||
_currentPacket.data[0].sampleWord[0] = htonl(beginSample);
|
||||
_frameCount = 0;
|
||||
_nibbleWord = 0;
|
||||
_fp = 2;
|
||||
}
|
||||
|
||||
template<typename T> void Steim1Encoder<T>::finish_packet() {
|
||||
template<typename T>
|
||||
void Steim1Encoder<T>::finishPacket() {
|
||||
int i;
|
||||
int32_t end_sample = last_sample;
|
||||
int32_t endSample = _lastSample;
|
||||
|
||||
for(i = 0; i < bp; ++i) {
|
||||
end_sample -= buf[i];
|
||||
for ( i = 0; i < _bp; ++i ) {
|
||||
endSample -= _buf[i];
|
||||
}
|
||||
|
||||
current_packet.data[0].sample_word[1] = htonl(end_sample);
|
||||
_currentPacket.data[0].sampleWord[1] = htonl(endSample);
|
||||
}
|
||||
|
||||
template<typename T> void Steim1Encoder<T>::update_packet() {
|
||||
template<typename T>
|
||||
void Steim1Encoder<T>::updatePacket() {
|
||||
unsigned int nibble = 0;
|
||||
u_int32_t sample_word = 0;
|
||||
u_int32_t sampleWord = 0;
|
||||
|
||||
assert(bp < 5);
|
||||
assert(_bp < 5);
|
||||
|
||||
int used = bp;
|
||||
int used = _bp;
|
||||
|
||||
while(used > spw) {
|
||||
while ( used > _spw ) {
|
||||
--used;
|
||||
spw = 4;
|
||||
for(int i = 0; i < used; ++i) update_spw(i);
|
||||
_spw = 4;
|
||||
for ( int i = 0; i < used; ++i ) {
|
||||
updateSpw(i);
|
||||
}
|
||||
}
|
||||
|
||||
while(used < spw) spw >>= 1;
|
||||
while ( used < _spw ) {
|
||||
_spw >>= 1;
|
||||
}
|
||||
|
||||
used = spw;
|
||||
used = _spw;
|
||||
|
||||
switch(spw) {
|
||||
switch ( _spw ) {
|
||||
case 4:
|
||||
nibble = 1;
|
||||
sample_word = ((buf[0] & 0xff) << 24) | ((buf[1] & 0xff) << 16) |
|
||||
((buf[2] & 0xff) << 8) | (buf[3] & 0xff);
|
||||
sampleWord = ((_buf[0] & 0xff) << 24) | ((_buf[1] & 0xff) << 16) |
|
||||
((_buf[2] & 0xff) << 8) | (_buf[3] & 0xff);
|
||||
break;
|
||||
case 2:
|
||||
nibble = 2;
|
||||
sample_word = ((buf[0] & 0xffff) << 16) | (buf[1] & 0xffff);
|
||||
sampleWord = ((_buf[0] & 0xffff) << 16) | (_buf[1] & 0xffff);
|
||||
break;
|
||||
case 1:
|
||||
nibble = 3;
|
||||
sample_word = buf[0];
|
||||
sampleWord = _buf[0];
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
nibble_word |= (nibble << (30 - ((fp + 1) << 1)));
|
||||
_nibbleWord |= (nibble << (30 - ((_fp + 1) << 1)));
|
||||
|
||||
spw = 4;
|
||||
for(int i = 0; i < bp - used; ++i) {
|
||||
buf[i] = buf[i + used];
|
||||
update_spw(i);
|
||||
_spw = 4;
|
||||
for ( int i = 0; i < _bp - used; ++i ) {
|
||||
_buf[i] = _buf[i + used];
|
||||
updateSpw(i);
|
||||
}
|
||||
|
||||
bp -= used;
|
||||
_bp -= used;
|
||||
_sampleCount += used;
|
||||
|
||||
current_packet.data[frame_count].nibble_word = htonl(nibble_word);
|
||||
current_packet.data[frame_count].sample_word[fp] = htonl(sample_word);
|
||||
if(++fp < 15) return;
|
||||
_currentPacket.data[_frameCount].nibbleWord = htonl(_nibbleWord);
|
||||
_currentPacket.data[_frameCount].sampleWord[_fp] = htonl(sampleWord);
|
||||
|
||||
if ( ++_fp < 15 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
_nibbleWord = 0;
|
||||
_fp = 0;
|
||||
++_frameCount;
|
||||
|
||||
nibble_word = 0;
|
||||
fp = 0;
|
||||
++frame_count;
|
||||
return;
|
||||
}
|
||||
|
||||
template<typename T> void Steim1Encoder<T>::queue_packet(MSEEDEncoderPacket<Steim1Frame> &pckt) {
|
||||
format->updateBuffer(pckt.record, _sampleCount, frame_count + (fp > 0));
|
||||
template<typename T>
|
||||
void Steim1Encoder<T>::queuePacket(MSEEDEncoderPacket<Steim1Frame> &pckt) {
|
||||
_format->updateBuffer(pckt.record, _sampleCount, _frameCount + (_fp > 0));
|
||||
|
||||
Packet *packet = new Packet(DataRecordPtr(pckt.record), format->networkCode, format->stationCode,
|
||||
format->locationCode, format->channelCode);
|
||||
Packet *packet = new Packet(DataRecordPtr(pckt.record),
|
||||
_format->networkCode,
|
||||
_format->stationCode,
|
||||
_format->locationCode,
|
||||
_format->channelCode);
|
||||
_packetQueue.push_back(PacketPtr(packet));
|
||||
pckt.reset();
|
||||
reset();
|
||||
}
|
||||
|
||||
template<typename T> void Steim1Encoder<T>::push(void *value) {
|
||||
template<typename T>
|
||||
void Steim1Encoder<T>::push(void *value) {
|
||||
int32_t sample_val = *static_cast<T*>(value);
|
||||
store(sample_val);
|
||||
_clk.tick();
|
||||
|
||||
while(bp >= spw) {
|
||||
if(!current_packet.valid()) {
|
||||
current_packet = get_packet();
|
||||
init_packet();
|
||||
while ( _bp >= _spw ) {
|
||||
if ( !_currentPacket.valid() ) {
|
||||
_currentPacket = getPacket();
|
||||
initPacket();
|
||||
}
|
||||
|
||||
update_packet();
|
||||
if(frame_count == number_of_frames(current_packet)) {
|
||||
finish_packet();
|
||||
queue_packet(current_packet);
|
||||
updatePacket();
|
||||
if ( _frameCount == numberOfFrames(_currentPacket) ) {
|
||||
finishPacket();
|
||||
queuePacket(_currentPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> void Steim1Encoder<T>::flush() {
|
||||
while(bp) {
|
||||
if(!current_packet.valid()) {
|
||||
current_packet = get_packet();
|
||||
init_packet();
|
||||
template<typename T>
|
||||
void Steim1Encoder<T>::flush() {
|
||||
while ( _bp ) {
|
||||
if ( !_currentPacket.valid() ) {
|
||||
_currentPacket = getPacket();
|
||||
initPacket();
|
||||
}
|
||||
|
||||
update_packet();
|
||||
if(frame_count == number_of_frames(current_packet)) {
|
||||
finish_packet();
|
||||
queue_packet(current_packet);
|
||||
updatePacket();
|
||||
if ( _frameCount == numberOfFrames(_currentPacket) ) {
|
||||
finishPacket();
|
||||
queuePacket(_currentPacket);
|
||||
}
|
||||
}
|
||||
|
||||
if(current_packet.valid()) {
|
||||
finish_packet();
|
||||
queue_packet(current_packet);
|
||||
if ( _currentPacket.valid() ) {
|
||||
finishPacket();
|
||||
queuePacket(_currentPacket);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user