void gooda::gcov_file::write_section_header(gcov_unsigned_t tag, unsigned int length){ //The header of the section write_unsigned(tag); //The size of the section, skipped by AFDO, but important to make a GCOV-valid file write_unsigned(length); }
void UmlCom::send_cmd(const void * id, OnInstanceCmd cmd, const QVector<UmlClass> & l1, const QVector<UmlClass> & l2, const QVector<UmlClass> & l3) { #ifdef TRACE cout << "UmlCom::send_cmd(id, " << cmd << ", const QVector<UmlClass> & l1, const QVector<UmlClass> & l2, const QVector<UmlClass> & l3)\n"; #endif write_char(onInstanceCmd); write_id(id); write_char(cmd); unsigned n; unsigned i; n = l1.count(); write_unsigned(n); for (i = 0; i != n; i += 1) write_id(((UmlBaseItem *) l1[i])->_identifier); n = l2.count(); write_unsigned(n); for (i = 0; i != n; i += 1) write_id(((UmlBaseItem *) l2[i])->_identifier); n = l3.count(); write_unsigned(n); for (i = 0; i != n; i += 1) write_id(((UmlBaseItem *) l3[i])->_identifier); flush(); }
void gooda::gcov_file::write_header(){ write_unsigned(GCOV_DATA_MAGIC); write_unsigned(GCOV_VERSION); //The stamp is not important for AFDO write_unsigned(0); }
bool UmlCom::connect(unsigned int port) { sock = new QTcpSocket(/*QTcpSocket::Stream*/0); #ifdef habip //sock->setAddressReusable(TRUE); #endif buffer_in_size = 1024; buffer_in = new char[buffer_in_size]; buffer_in_end = p_buffer_in = 0; buffer_out_size = 1024; buffer_out = new char[buffer_out_size]; p_buffer_out = buffer_out + 4/*bytes for length*/; QHostAddress ha; ha.setAddress("127.0.0.1"); sock->connectToHost(ha, port); if (sock->waitForConnected()) { // send API version write_unsigned(25); flush(); return TRUE; } else return FALSE; }
bool UmlCom::connect(unsigned int port) { sock = new Q3SocketDevice(Q3SocketDevice::Stream); sock->setAddressReusable(TRUE); buffer_in_size = 1024; buffer_in = new char[buffer_in_size]; buffer_in_end = p_buffer_in = 0; buffer_out_size = 1024; buffer_out = new char[buffer_out_size]; p_buffer_out = buffer_out + 4/*bytes for length*/; QHostAddress ha; ha.setAddress("127.0.0.1"); if (sock->connect(ha, port)) { // send API version write_unsigned(55); flush(); return TRUE; } else return FALSE; }
void UmlCom::send_cmd(const void * id, OnInstanceCmd cmd, unsigned int arg1, char arg2, const char * arg3, const char * arg4, const UmlTypeSpec & arg5) { #ifdef TRACE cout << "UmlCom::send_cmd(id, " << cmd << ", " << arg1 << ", " << (int) arg2 << ", " << ((arg3) ? arg3 : "") << ", " << ((arg4) ? arg4 : "") << ", UmlTypeSpec)\n"; #endif write_char(onInstanceCmd); write_id(id); write_char(cmd); write_unsigned(arg1); write_char(arg2); write_string(arg3); write_string(arg4); if (arg5.type) { write_id(arg5.type->_identifier); write_string(""); } else { write_id(0); write_string(arg5.explicit_type); } flush(); }
void UmlCom::send_cmd(CmdFamily f, unsigned int cmd, int arg, const char *) { #ifdef TRACE cout << "UmlCom::send_cmd((CmdFamily) " << f << ", " << cmd << ", " << arg << ", dummy)\n"; #endif write_char(f); write_char(cmd); write_unsigned(arg); flush(); }
void UmlCom::send_cmd(const void * id, OnInstanceCmd cmd, unsigned int arg) { #ifdef TRACE cout << "UmlCom::send_cmd(id, " << cmd << ", " << arg << '\n'; #endif write_char(onInstanceCmd); write_id(id); write_char(cmd); write_unsigned(arg); flush(); }
void UmlCom::send_cmd(const void * id, OnInstanceCmd cmd, const Q3PtrVector<UmlClass> & l) { #ifdef TRACE cout << "UmlCom::send_cmd(id, " << cmd << ", const Q3PtrVector<UmlClass> & l)\n"; #endif write_char(onInstanceCmd); write_id(id); write_char(cmd); unsigned n = l.count(); write_unsigned(n); for (unsigned i = 0; i != n; i += 1) write_id(((UmlBaseItem *) l[i])->_identifier); flush(); }
void gooda::gcov_file::write_string (const std::string& value){ log::emit<log::Trace>() << "Write string \"" << value << "\"" << log::endl; const char* string = value.c_str(); unsigned int length = strlen (string); unsigned int alloc = (length + 4) >> 2; write_unsigned(alloc); char* buffer = new char[alloc * 4]; std::fill(buffer, buffer+(alloc*4), 0); memcpy (&buffer[0], string, length); gcov_file_w.write(buffer, alloc * 4); delete[] buffer; }
void UmlCom::send_cmd(const void * id, OnInstanceCmd cmd, unsigned int arg1, const UmlTypeSpec & arg2) { #ifdef TRACE qDebug() << "UmlCom::send_cmd(id, " << cmd << ", " << arg1 << ", UmlTypeSpec)\n"; #endif write_char(onInstanceCmd); write_id(id); write_char(cmd); write_unsigned(arg1); if (arg2.type) { write_id(arg2.type->_identifier); write_string(""); } else { write_id(0); write_string(arg2.explicit_type); } flush(); }
PyObject* encoders_encode_shn(PyObject *dummy, PyObject *args, PyObject *keywds) { static char *kwlist[] = {"filename", "pcmreader", "is_big_endian", "signed_samples", "header_data", "footer_data", "block_size", NULL}; char *filename; FILE *output_file; BitstreamWriter* writer; pcmreader* pcmreader; int is_big_endian = 0; int signed_samples = 0; char* header_data; #ifdef PY_SSIZE_T_CLEAN Py_ssize_t header_size; #else int header_size; #endif char* footer_data = NULL; #ifdef PY_SSIZE_T_CLEAN Py_ssize_t footer_size = 0; #else int footer_size = 0; #endif unsigned block_size = 256; unsigned bytes_written = 0; unsigned i; /*fetch arguments*/ if (!PyArg_ParseTupleAndKeywords(args, keywds, "sO&iis#|s#I", kwlist, &filename, pcmreader_converter, &pcmreader, &is_big_endian, &signed_samples, &header_data, &header_size, &footer_data, &footer_size, &block_size)) return NULL; /*ensure PCMReader is compatible with Shorten*/ if ((pcmreader->bits_per_sample != 8) && (pcmreader->bits_per_sample != 16)) { pcmreader->del(pcmreader); PyErr_SetString(PyExc_ValueError, "unsupported bits per sample"); return NULL; } /*open given filename for writing*/ if ((output_file = fopen(filename, "wb")) == NULL) { PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename); pcmreader->del(pcmreader); return NULL; } else { writer = bw_open(output_file, BS_BIG_ENDIAN); } /*write magic number and version*/ writer->build(writer, "4b 8u", "ajkg", 2); bw_add_callback(writer, byte_counter, &bytes_written); /*write Shorten header*/ write_header(writer, pcmreader->bits_per_sample, is_big_endian, signed_samples, pcmreader->channels, block_size); /*issue initial VERBATIM command with header data*/ write_unsigned(writer, COMMAND_SIZE, FN_VERBATIM); write_unsigned(writer, VERBATIM_SIZE, header_size); for (i = 0; i < header_size; i++) write_unsigned(writer, VERBATIM_BYTE_SIZE, (uint8_t)header_data[i]); /*process PCM frames*/ if (encode_audio(writer, pcmreader, signed_samples, block_size)) goto error; /*if there's footer data, issue a VERBATIM command for it*/ if ((footer_data != NULL) && (footer_size > 0)) { write_unsigned(writer, COMMAND_SIZE, FN_VERBATIM); write_unsigned(writer, VERBATIM_SIZE, footer_size); for (i = 0; i < footer_size; i++) write_unsigned(writer, VERBATIM_BYTE_SIZE, (uint8_t)footer_data[i]); } /*issue QUIT command*/ write_unsigned(writer, COMMAND_SIZE, FN_QUIT); /*pad output (not including header) to a multiple of 4 bytes*/ writer->byte_align(writer); while ((bytes_written % 4) != 0) { writer->write(writer, 8, 0); } /*deallocate temporary buffers and close files*/ pcmreader->del(pcmreader); writer->close(writer); Py_INCREF(Py_None); return Py_None; error: pcmreader->del(pcmreader); writer->close(writer); return NULL; }
static int encode_audio(BitstreamWriter* bs, pcmreader* pcmreader, int signed_samples, unsigned block_size) { unsigned left_shift = 0; int sign_adjustment; /*allocate some temporary buffers*/ array_ia* frame = array_ia_new(); array_ia* wrapped_samples = array_ia_new(); array_i* shifted = array_i_new(); array_ia* deltas = array_ia_new(); array_i* residuals = array_i_new(); unsigned c; unsigned i; for (i = 0; i < pcmreader->channels; i++) wrapped_samples->append(wrapped_samples); if (!signed_samples) { sign_adjustment = 1 << (pcmreader->bits_per_sample - 1); } else { sign_adjustment = 0; } if (pcmreader->read(pcmreader, block_size, frame)) goto error; while (frame->_[0]->len > 0) { #ifndef STANDALONE Py_BEGIN_ALLOW_THREADS #endif if (frame->_[0]->len != block_size) { /*PCM frame count has changed, so issue BLOCKSIZE command*/ block_size = frame->_[0]->len; write_unsigned(bs, COMMAND_SIZE, FN_BLOCKSIZE); write_long(bs, block_size); } for (c = 0; c < frame->len; c++) { array_i* channel = frame->_[c]; array_i* wrapped = wrapped_samples->_[c]; /*convert signed samples to unsigned, if necessary*/ if (sign_adjustment != 0) for (i = 0; i < channel->len; i++) channel->_[i] += sign_adjustment; if (all_zero(channel)) { /*write ZERO command and wrap channel for next set*/ write_unsigned(bs, COMMAND_SIZE, FN_ZERO); wrapped->extend(wrapped, channel); wrapped->tail(wrapped, SAMPLES_TO_WRAP, wrapped); } else { unsigned diff = 1; unsigned energy = 0; unsigned wasted_BPS = wasted_bits(channel); if (wasted_BPS != left_shift) { /*issue BITSHIFT comand*/ left_shift = wasted_BPS; write_unsigned(bs, COMMAND_SIZE, FN_BITSHIFT); write_unsigned(bs, BITSHIFT_SIZE, left_shift); } /*apply left shift to channel data*/ if (left_shift > 0) { shifted->reset_for(shifted, channel->len); for (i = 0; i < channel->len; i++) a_append(shifted, channel->_[i] >> left_shift); } else { channel->copy(channel, shifted); } /*calculate best DIFF, energy and residuals for shifted data*/ calculate_best_diff(shifted, wrapped, deltas, &diff, &energy, residuals); /*issue DIFF command*/ write_unsigned(bs, COMMAND_SIZE, diff); write_unsigned(bs, ENERGY_SIZE, energy); for (i = 0; i < residuals->len; i++) write_signed(bs, energy, residuals->_[i]); /*wrap shifted channel data for next set*/ wrapped->extend(wrapped, shifted); wrapped->tail(wrapped, SAMPLES_TO_WRAP, wrapped); } }