CAMLprim value caml_ml_flush_partial(value vchannel) { CAMLparam1 (vchannel); struct channel * channel = Channel(vchannel); int res; if (channel->fd == -1) CAMLreturn(Val_true); Lock(channel); res = caml_flush_partial(channel); Unlock(channel); CAMLreturn (Val_bool(res)); }
CAMLprim value caml_ml_output_partial(value vchannel, value buff, value start, value length) { CAMLparam4 (vchannel, buff, start, length); struct channel * channel = Channel(vchannel); int res; Lock(channel); res = caml_putblock(channel, &Byte(buff, Long_val(start)), Long_val(length)); Unlock(channel); CAMLreturn (Val_int(res)); }
void MainWindow::onAddChannelButtonPressed() { if (m_session.isValid()) { QString name = ui->channelNameEdit->text(); QString description = ui->channelDescriptionEdit->text(); QString url = ui->channelUrlEdit->text(); m_applyChannelQuery->setQuery(Channel(name,description,url),m_session); m_applyChannelQuery->doRequest(); } }
int main(void) { int i, j; unsigned short CRC_Xmit; unsigned short CRC_Recv; int Detected_Count = 0; int Okay_Count = 0; /* Initialize. */ for (i = 0; i < 1024; i++) { Raw_Data[i] = (unsigned char)i; } CRC_Xmit = CRC_Clear(); Initialize_Noise(1.0e-5); /* Compute the CRC checksum. */ for (i = 0; i < 1024; i++) { CRC_Xmit = CRC_Update(CRC_Xmit, Raw_Data[i]); } CRC_Xmit = CRC_Finish(CRC_Xmit); /* Now loop many times sending the block of data through the channel. */ for (i = 0; i < 1024; i++) { CRC_Recv = CRC_Clear(); for (j = 0; j < 1024; j++) { CRC_Recv = CRC_Update(CRC_Recv, Channel(Raw_Data[j])); } CRC_Recv = CRC_Update(CRC_Recv, Channel((CRC_Xmit & 0xFF00) >> 8)); CRC_Recv = CRC_Update(CRC_Recv, Channel(CRC_Xmit & 0x00FF)); if (CRC_Recv != 0) Detected_Count++; else Okay_Count++; } printf("Blocks with detected errors: %d\n", Detected_Count); printf("Blocks okay: %d\n", Okay_Count); return 0; }
SensorDataSet SensorDB::ExecuteSQL_SelectFromSensorDataTable(std::string sqlcommand) { SensorDataSet ds; ChannelList channelist; int channel_num; int datatype_id; int operator_id; int device_id; int position_id; int activity_id; int activitybeginframe_id; int activityendframe_id; double samplerate; QDateTime createtime; if(db.isOpen()){ QSqlQuery query; QString sqlcmd = string2qstring(sqlcommand); if(query.exec(sqlcmd)){ while(query.next()){ datatype_id = query.value("DataTypeID").toInt(); activity_id = query.value("ActivityID").toInt(); device_id = query.value("DeviceID").toInt(); operator_id = query.value("OperatorID").toInt(); position_id = query.value("PositionID").toInt(); activitybeginframe_id = query.value("ActivityBeginFrameID").toInt(); activityendframe_id = query.value("ActivityEndFrameID").toInt(); samplerate = query.value("SampleRate").toDouble(); createtime = query.value("CreateTime").toDateTime(); channel_num = query.value("TotalChannelNum").toInt(); channelist.clear(); for(int i=1;i<=channel_num;i++){ if(query.value(i).isNull()){ break; } string ch = "channel_"+int2string(i); //qDebug() << query.value(string2qstring(ch.c_str())).toString(); channelist.push_back(Channel(query.value(string2qstring(ch.c_str())).toString().toStdString())); //qDebug() << string2qstring((channelist[channelist.size()-1].ToString())); } ds.PushBackSensorData(SensorData(channelist,channel_num,datatype_id,operator_id,device_id,position_id, activity_id,activitybeginframe_id,activityendframe_id, samplerate,createtime)); } } else{ qDebug()<<query.lastError(); } } else{ qDebug()<<"DataBase is not opened"; } return ds; }
/* converts a Caml channel to a C FILE* stream */ static FILE * stream_of_channel(value chan, const char * mode) { int des; FILE * res ; struct channel *c_chan = Channel(chan) ; if(c_chan==NULL) return NULL; des = dup(c_chan->fd) ; res = fdopen(des, mode) ; if (des < 0 || res == NULL) { caml_failwith("failed to duplicate caml channel"); } return res ; }
CAMLprim value caml_ml_input_int(value vchannel) { CAMLparam1 (vchannel); struct channel * channel = Channel(vchannel); intnat i; Lock(channel); i = caml_getword(channel); Unlock(channel); #ifdef ARCH_SIXTYFOUR i = (i << 32) >> 32; /* Force sign extension */ #endif CAMLreturn (Val_long(i)); }
void OutgoingResourceLimiter::ForwardMessage(string_t type, uint160 hash) { if (type == "tx") return ForwardTransaction(hash); string_t channel = Channel(type); with_msg_as_instance_of_(type, hash, if (channel == "trade") flexnode.tradehandler.BroadcastMessage(msg); else if (channel == "relay") flexnode.relayhandler.BroadcastMessage(msg); else if (channel == "deposit") flexnode.deposit_handler.BroadcastMessage(msg); ) }
// returns a status message regarding the successful or unsuccesful // creation of a channel std::string IRCCommandHandler::createChannel() { // CREATECHANNEL channelname username std::string channel {arguments[0]}; std::string user {arguments[1]}; std::string result; if (channels.count(channel) || channel == "server") { result = "Error: Channel '"+channel+"' already exists"; } else { channels.emplace(channel, Channel(channel)); channels.at(channel).addUser(user); result = "Successfully created channel '"+channel+"'"; } return result; }
boost::system::error_code RtspService::createChannel(uint32_t uiChannelId, const std::string& sChannelName, const AudioChannelDescriptor& audioDescriptor) { VLOG(2) << "createChannel: " << uiChannelId; boost::mutex::scoped_lock l(m_channelLock); ChannelMap_t::iterator it = m_mChannels.find(uiChannelId); if (it != m_mChannels.end()) { return boost::system::error_code(boost::system::errc::file_exists, boost::system::get_generic_category()); } else { m_qChannelsToBeAdded.push_back(Channel(uiChannelId, sChannelName, audioDescriptor)); return boost::system::error_code(); } return boost::system::error_code(); }
string SimulateRead(const SequencingParameters& p, const std::string& tpl, RandomNumberGenerator& rng) { std::string read; read.reserve(tpl.length() * 2); int pos = 0; while (pos < (int)tpl.length()) { char base = tpl[pos]; char prevBase = pos > 0 ? tpl[pos-1] : 'N'; int channel = Channel(base); // // Tabulate the different possible move probabilities, then choose one // bool canMerge = base == prevBase; vector<double> errorProbs = ErrorProbs(p, channel, canMerge); int choice = rng.RandomChoice(errorProbs); if (choice == (int) errorProbs.size() - 1) { // Match read.push_back(base); pos++; } else if (choice < 4) { // Insert vector<double> insertProbs = vector<double>(errorProbs.begin(), errorProbs.begin() + 4); int eChannel = rng.RandomChoice(insertProbs); char eBase = "TGAC"[eChannel]; read.push_back(eBase); } else if (choice == 4) { // Dark pos++; } else if (choice == 5) { // Miscall read.push_back(rng.RandomBase()); pos++; } else { // Merge assert (canMerge); pos++; } } return read; }
CAMLprim value win_filedescr_of_channel(value vchan) { CAMLparam1(vchan); CAMLlocal1(fd); struct channel * chan; HANDLE h; chan = Channel(vchan); if (chan->fd == -1) uerror("descr_of_channel", Nothing); h = (HANDLE) _get_osfhandle(chan->fd); if (chan->flags & CHANNEL_FLAG_FROM_SOCKET) fd = win_alloc_socket((SOCKET) h); else fd = win_alloc_handle(h); CRT_fd_val(fd) = chan->fd; CAMLreturn(fd); }
void TransportStreamFilter::SetStatus(bool On) { cFilter::SetStatus(On); #if VDRVERSNUM <= 10327 #error "Unfortunately, VDR versions up to 1.3.27 contain a bug that prevents this code from working properly. Please use VDR version 1.3.28 or later." #endif //printf("TransportStreamFilter::SetStatus , status is %d, On is %d\n", status, On); TransportStreamID currentTs=TransportStream(Channel()).GetTransportStreamID(); if (On) { switch (status) { case TransportStreamUnknown: ts=currentTs; status=Active; AddFilterData(); break; case Active: break; // should not happen case Inactive: case OnOtherTransportStream: if (currentTs == ts) { status=Active; AddFilterData(); } else { status=OnOtherTransportStream; OtherTransportStream(currentTs); } break; case Deactivated: break; } } else { switch (status) { case TransportStreamUnknown: break; case Active: status=Inactive; RemoveFilterData(); break; case Inactive: case OnOtherTransportStream: break; case Deactivated: break; } } //printf("TransportStreamFilter::SetStatus, leaving, status is %d\n", status); }
CAMLprim value caml_ml_output(value vchannel, value buff, value start, value length) { CAMLparam4 (vchannel, buff, start, length); struct channel * channel = Channel(vchannel); intnat pos = Long_val(start); intnat len = Long_val(length); Lock(channel); while (len > 0) { int written = caml_putblock(channel, &Byte(buff, pos), len); pos += written; len -= written; } Unlock(channel); CAMLreturn (Val_unit); }
Channel Channel::downsampleEnergy(unsigned factor) const { if(factor>0) { unsigned newSize=data.size()/factor; std::vector<float> target=std::vector<float>(newSize); float acc; for(unsigned i=0,j=0;j<newSize;j++) { acc=0; for(unsigned k=0;k<factor && i<data.size();k++) acc+=sqr(data[i++]); target[j]=sqrt(acc/factor); } return Channel(rate/factor,target); } else return *this; }
void ZFnEXR::saveCameraNZ(float* data, M44f mat, float fov, const char* filename, int width, int height) { Header header (width, height); header.insert ("fov", DoubleAttribute (fov)); header.insert ("cameraTransform", M44fAttribute (mat)); header.channels().insert ("R", Channel (FLOAT)); OutputFile file (filename, header); FrameBuffer frameBuffer; frameBuffer.insert ("R", Slice (FLOAT, (char *) data, sizeof (*data) * 1, sizeof (*data) * width)); file.setFrameBuffer (frameBuffer); file.writePixels (height); }
Channel Channel::resampleTo(unsigned newRate) const { unsigned newSize=(data.size()*newRate)/rate; std::vector<float> target=std::vector<float>(newSize); LOG(logDEBUG) << "Old rate "<< rate << " New Rate: " << newRate << std::endl; LOG(logDEBUG) << "Old size " << data.size() << " New Size: " << newSize << std::endl; unsigned oldSize=data.size(); // TODO: Only nearest "interpolation"... for(unsigned i=0;i<newSize;i++) { int j=(long(i)*oldSize)/newSize; target[i]=data[j]; } LOG(logDEBUG) << "done"<< std::endl; return Channel(newRate,target); }
CAMLprim value caml_ml_close_channel(value vchannel) { int result; /* For output channels, must have flushed before */ struct channel * channel = Channel(vchannel); if (channel->fd != -1){ result = close(channel->fd); channel->fd = -1; }else{ result = 0; } /* Ensure that every read or write on the channel will cause an immediate caml_flush_partial or caml_refill, thus raising a Sys_error exception */ channel->curr = channel->max = channel->end; if (result == -1) caml_sys_error (NO_ARG); return Val_unit; }
bool Box::createdChannel(const string& name) { bool found = false; for (int i = 0; i < channels.size(); i++) if (channels[i].getName() == name) { found = true; break; } if (found) return false; else { Channel ctemp = Channel(name); this->channels.push_back(ctemp); sort(channels.begin(), channels.end()); return true; } }
CAMLprim value ml_gsl_monte_vegas_set_params(value state, value params) { gsl_monte_vegas_state *s = GSLVEGASSTATE_VAL(state); s->alpha = Double_val(Field(params, 0)); s->iterations = Int_val(Field(params, 1)); s->stage = Int_val(Field(params, 2)); s->mode = Int_val(Field(params, 3)) - 1; s->verbose = Int_val(Field(params, 4)); { value vchan = Field(params, 5); if(Is_block(vchan)) { struct channel *chan=Channel(Field(vchan, 0)); if(s->ostream != stdout && s->ostream != stderr) fclose(s->ostream); flush(chan); s->ostream = fdopen(dup(chan->fd), "w"); GSLVEGASSTREAM_VAL(state) = vchan; } } return Val_unit; }
void ModuleTouch::Update(Stream* stream) { bool send = false; for (int n = 0; n < 4; n++) { bool state = m_buttons[n].IsPressed(); if (m_prevStates[n] != state) { m_prevStates[n] = state; send = true; } } if (send) { stream->print("u "); stream->print(Channel()); stream->print("/"); stream->print(Name()); stream->print(m_prevStates[0] ? " 1," : " 0,"); stream->print(m_prevStates[1] ? "1," : "0,"); stream->print(m_prevStates[2] ? "1," : "0,"); stream->print(m_prevStates[3] ? "1\r\n" : "0\r\n"); } }
// Add a channel to the timer with a given period int MuxTimer::add_channel(long period) { // Check if this period is already registered for (Channel& channel : getChannels()) { if (channel.period == period) { // Timer fot his period has already been registered, return the associated id INFO_PF("Timer channel with %u ms period already registered", period); // Return the associated id return channel.id; } } // Check if the timer is not currently running if (getStatus()) { // Dump a log ERROR_LG("Timer cannot add new channel in timer, currently running"); // Return negative result return -1; } else { // Dump a log INFO_PF("Timer, add new channel to timer with %u ms period", period); // Get the new id int id = getChannels().size() + 1; // Add a new channel to this timer getChannels().push_back(Channel(id, period)); // Return new channel id return id; } }
TEST(Recording_test, constructors) { Recording rec0; EXPECT_EQ( rec0.size(), 0 ); std::vector<Section> sec_list(16, Section(32768)); Channel ch(sec_list); Recording rec1(ch); EXPECT_EQ( rec1.size(), 1 ); EXPECT_EQ( rec1[0].size(), 16 ); EXPECT_EQ( rec1[0][0].size(), 32768 ); std::vector<Channel> ch_list(4, Channel(16, 32768)); Recording rec2(ch_list); EXPECT_EQ( rec2.size(), 4 ); EXPECT_EQ( rec2[rec2.size()-1].size(), 16 ); EXPECT_EQ( rec2[rec2.size()-1][rec2[rec2.size()-1].size()-1].size(), 32768 ); Recording rec3(4, 16, 32768); EXPECT_EQ( rec3.size(), 4 ); EXPECT_EQ( rec3[rec3.size()-1].size(), 16 ); EXPECT_EQ( rec3[rec3.size()-1][rec3[rec3.size()-1].size()-1].size(), 32768 ); }
void operator () (Channel c) const { // @todo: need to do a “channel_convert” too, in case the channel types aren't the same? get_color (dst_, Channel()) = channel_multiply(get_color(src_,Channel()), alpha_or_max(src_)); }
void EXRImageFileWriter::write( const char* filename, const ICanvas& image, const ImageAttributes& image_attributes) { try { // Retrieve canvas properties. const CanvasProperties& props = image.properties(); // todo: lift this limitation. assert(props.m_channel_count <= 4); // Figure out the pixel type, based on the pixel format of the image. PixelType pixel_type = FLOAT; switch (props.m_pixel_format) { case PixelFormatUInt32: pixel_type = UINT; break; case PixelFormatHalf: pixel_type = HALF; break; case PixelFormatFloat: pixel_type = FLOAT; break; default: throw ExceptionUnsupportedImageFormat(); } // Construct TileDescription object. const TileDescription tile_desc( static_cast<unsigned int>(props.m_tile_width), static_cast<unsigned int>(props.m_tile_height), ONE_LEVEL); // Construct ChannelList object. ChannelList channels; for (size_t c = 0; c < props.m_channel_count; ++c) channels.insert(ChannelName[c], Channel(pixel_type)); // Construct Header object. Header header( static_cast<int>(props.m_canvas_width), static_cast<int>(props.m_canvas_height)); header.setTileDescription(tile_desc); header.channels() = channels; // Add image attributes to the Header object. add_attributes(image_attributes, header); // Create the output file. TiledOutputFile file(filename, header, m_thread_count); // Write tiles. for (size_t y = 0; y < props.m_tile_count_y; ++y) { for (size_t x = 0; x < props.m_tile_count_x; ++x) { const int ix = static_cast<int>(x); const int iy = static_cast<int>(y); const Box2i range = file.dataWindowForTile(ix, iy); const Tile& tile = image.tile(x, y); const size_t channel_size = Pixel::size(tile.get_pixel_format()); const size_t stride_x = channel_size * props.m_channel_count; const size_t stride_y = stride_x * tile.get_width(); const size_t tile_origin = range.min.x * stride_x + range.min.y * stride_y; const char* tile_base = reinterpret_cast<const char*>(tile.pixel(0, 0)) - tile_origin; // Construct FrameBuffer object. FrameBuffer framebuffer; for (size_t c = 0; c < props.m_channel_count; ++c) { const char* base = tile_base + c * channel_size; framebuffer.insert( ChannelName[c], Slice( pixel_type, const_cast<char*>(base), stride_x, stride_y)); } // Write tile. file.setFrameBuffer(framebuffer); file.writeTile(ix, iy); } } } catch (const BaseExc& e) { // I/O error. throw ExceptionIOError(e.what()); } }
YUVCS::YUVCS(ColorSpace::Identifier id) : ColorSpace(id) { addChannel(Channel(Channel::YUV_Y, new YFilter())); addChannel(Channel(Channel::YUV_U, new UFilter())); addChannel(Channel(Channel::YUV_V, new VFilter())); }
Channel JsonSerializer::getChannel() const { return m_channels.isEmpty() ? Channel() : m_channels.at(0); }
QSizeF GChannelGraphicsItem::sizeHint( Qt::SizeHint which, const QSizeF & constraint /*= QSizeF() */ ) const { QSizeF sizeToReturn(Channel()->Sequence()->Length(), CHANNEL_GRAPHICS_ITEM_VERTICAL_SIZE); return sizeToReturn; }
CAMLprim value caml_ml_pos_in_64(value vchannel) { return Val_file_offset(caml_pos_in(Channel(vchannel))); }
// The CALLER of this method must ensure that the status byte's MIDI Command matches!!! bool CAAUMIDIMap::MIDI_Matches (UInt8 inChannel, UInt8 inData1, UInt8 inData2, Float32 &outLinear) const { // see if the channels match first SInt8 chan = Channel(); // channel matches (if chan is less than zero, "Any Channel" flag is set) if (chan >= 0 && chan != inChannel) return false; // match the special cases first if (IsKeyEvent()) { // we're using this key event as an on/off type switch if (IsBipolar()) { if (IsKeyPressure()){ if (IsBipolar_OnValue()) { if (inData2 > 63) { outLinear = 1; return true; } } else { if (inData2 < 64) { outLinear = 0; return true; } } return false; } else { if (IsBipolar_OnValue()) { if (inData1 > 63) { outLinear = 1; return true; } } else { if (inData1 < 64) { outLinear = 0; return true; } } return false; } } if (IsAnyNote()) { // not quite sure how to interpret this... if (IsKeyPressure()) outLinear = inData2 / 127.0; else outLinear = inData1 / 127.0; return true; } if (mData1 == inData1) { if (IsKeyPressure()) outLinear = inData2 / 127.0; else outLinear = 1; return true; } return false; } else if (IsControlChange()) { // controller ID matches if (mData1 == inData1) { if (IsBipolar()) { if (IsBipolar_OnValue()) { if (inData2 > 63) { outLinear = 1; return true; } } else { if (inData2 < 64) { outLinear = 0; return true; } } return false; } //printf("this in midi matches %X with ", this); outLinear = inData2 / 127.; return true; } return false; } // this just matches on the patch change value itself... if (IsPatchChange()) { if (mData1 == inData1) { outLinear = 1; return true; } return false; } // finally, for the other two, just check the bi-polar matching conditions // pitch bend and after touch if (IsBipolar()) { if (IsBipolar_OnValue()) { if (inData1 > 63) { outLinear = 1; return true; } } else { if (inData1 < 64) { outLinear = 0; return true; } } return false; } if (IsPitchBend()) { UInt16 value = (inData2 << 7) | inData1; outLinear = value / 16383.; } else if (IsChannelPressure()) { outLinear = inData1 / 127.0; } return true; }