HRESULT TaudioCodecLibFAAD::decode(TbyteBuffer &src) { NeAACDecFrameInfo frameInfo; unsigned long size = (unsigned long)src.size(); float *outsamples = (float*)NeAACDecDecode(m_decHandle, &frameInfo, size ? &src[0] : NULL, size); src.clear(); if (frameInfo.error) { DPRINTF(_l("AAC: Error %d [%s]\n"), frameInfo.error, (const char_t*)text<char_t>(NeAACDecGetErrorMessage(frameInfo.error))); return S_OK;//S_FALSE } else if (outsamples && frameInfo.samples) { ps = !!frameInfo.ps; sbr = !!frameInfo.sbr; numframes++; bpssum += (lastbps = 8 * fmt.freq * frameInfo.bytesconsumed / (frameInfo.samples / fmt.nchannels) / 1000); if (frameInfo.channels == 2 && frameInfo.channel_position[1] == UNKNOWN_CHANNEL) { frameInfo.channel_position[0] = FRONT_CHANNEL_LEFT; frameInfo.channel_position[1] = FRONT_CHANNEL_RIGHT; } fmt = this->fmt; fmt.channelmask = 0; for (int i = 0; i < frameInfo.channels; i++) { fmt.channelmask |= chmask[frameInfo.channel_position[i]]; } int chmap[countof(frameInfo.channel_position)]; memset(chmap, 0, sizeof(chmap)); for (int i = 0; i < frameInfo.channels; i++) { unsigned int ch = 0; int mask = chmask[frameInfo.channel_position[i]]; for (int j = 0; j < 32; j++) if (fmt.channelmask & (1 << j)) { if ((1 << j) == mask) { chmap[i] = ch; break; } ch++; } } if (frameInfo.channels <= 2) { fmt.channelmask = 0; } float *dst, *dst0; dst = dst0 = (float*)getDst(frameInfo.samples * sizeof(float)); for (unsigned int j = 0; j < frameInfo.samples; j += frameInfo.channels, dst += frameInfo.channels) for (int i = 0; i < frameInfo.channels; i++) { dst[chmap[i]] = *outsamples++; } return sinkA->deliverDecodedSample(dst0, frameInfo.samples / frameInfo.channels, fmt); } else { return S_OK; } }
int main( int argc, char **argv ) { int count( 1000 ); if( argc == 2 ) { count = atoi( argv[ 1 ] ); } auto rndgen( raft::kernel::make< raft::random_variate< std::uint32_t, raft::uniform > >( 1000, 2000, count ) ); using sub = raft::lambdak< std::uint32_t >; auto l_sub( [&]( Port &input, Port &output ) { std::uint32_t a; input[ "0" ].pop( a ); output[ "0" ].push( a - 10 ); return( raft::proceed ); } ); auto kernels = raft::map.link( rndgen, raft::kernel::make< sub >( 1, 1, l_sub ) ); for( int i( 0 ); i < 50 ; i++ ) { kernels = raft::map.link( &kernels.getDst(), raft::kernel::make< sub >( 1, 1, l_sub ) ); } raft::map.link( &kernels.getDst(), raft::kernel::make< raft::print< std::uint32_t, '\n' > >() ); raft::map.exe(); return( EXIT_SUCCESS ); }
int main( int argc, char **argv ) { int count( 1000 ); if( argc == 2 ) { count = atoi( argv[ 1 ] ); } using gen = Generate< std::int64_t >; using sum = Sum< std::int64_t, std::int64_t, std::int64_t >; using p_out = raft::print< std::int64_t, '\n' >; auto linked_kernels( raft::map.link( raft::kernel::make< gen >( count ), raft::kernel::make< sum >(), "input_a" ) ); raft::map.link( raft::kernel::make< gen >( count ), &linked_kernels.getDst(), "input_b" ); raft::map.link( &linked_kernels.getDst(), raft::kernel::make< p_out >() ); raft::map.exe(); return( EXIT_SUCCESS ); }
void doAttackAttempt() { auto robots = this_step_info->robotsInfo; auto config = this_step_info->gameConfig; int max_attack_dst = config.R_max * me.V / config.L_max * me.E / config.E_max; for (auto robot : robots) { if (getDst(pair<int, int>(me.x, me.y), pair<int, int>(robot.x, robot.y)) <= max_attack_dst) //opt. range if (team.find(robot.Name) == team.end()) //not in team if (robot.E * robot.P < me.A * robot.E * 1.8) //not so strong { this_step_info->pRobotActions->addActionAttack(robot.ID); return; } } }
void doMovement(pair<int, int> dest) { auto config = this_step_info->gameConfig; int distance = getDst(pair<int, int>(me.x, me.y), dest); int max_distance = config.V_max * me.V / config.L_max * me.E / config.E_max; double dx = dest.first - me.x; double dy = dest.second - me.y; if (distance > max_distance) { double ang = atan2(dy, dx); dx = max_distance * cos(ang); //recount components dy = max_distance * sin(ang); } this_step_info->pRobotActions->addActionMove(dx, dy); }
pair<int, int> getClosestEnStation() { auto stations = this_step_info->chargingStations; int min_dst = this_step_info->gameConfig.W * this_step_info->gameConfig.H; pair<int, int> result_st; for (auto station : stations) { int dst = getDst(pair<int, int>(me.x, me.y), station); if (dst < min_dst) { min_dst = dst; result_st = station; } } return result_st; }
void VPlayer::setFrame() { if(state!=Pause){ mutex.lock(); swsctx=sws_getCachedContext(swsctx, srcSize.width(),srcSize.height(),PIX_FMT_RGB32, dstSize.width(),dstSize.height(),PIX_FMT_RGB32, SWS_FAST_BILINEAR,NULL,NULL,NULL); if(!valid){ avpicture_free (&dstFrame); avpicture_alloc(&dstFrame,PIX_FMT_RGB32,dstSize.width(),dstSize.height()); valid=true; } sws_scale(swsctx,srcFrame.data,srcFrame.linesize,0,srcSize.height(),dstFrame.data,dstFrame.linesize); QImage frame=QImage(getDst(),dstSize.width(),dstSize.height(),QImage::Format_RGB32).copy(); mutex.unlock(); emit rendered(frame); } }
int main( int argc, char **argv ) { int count( 1000 ); if( argc == 2 ) { count = atoi( argv[ 1 ] ); } using send_t = std::int64_t; using wrong_t = float; using gen = raft::test::generate< send_t >; using sum = Sum< send_t, wrong_t, send_t >; using p_out = raft::print< send_t, '\n' >; raft::map m; gen g1( count ), g2( count ); sum s; p_out p; auto linked_kernels( m += g1 >> s[ "input_a" ] ); try { /** returns std::pair of iterators **/ kernel_pair_t::kernel_iterator_type BEGIN, END; std::tie( BEGIN, END ) = linked_kernels.getDst(); m += g2 >> (*BEGIN).get()[ "input_b" ]; } catch( PortTypeMismatchException &ex ) { UNUSED( ex ); //yippy, we threw the right exception return( EXIT_SUCCESS ); } m += s >> p; m.exe(); return( EXIT_FAILURE ); }
HRESULT TaudioCodecLibDTS::decode(TbyteBuffer &src) { unsigned char *p = src.size() ? &src[0] : NULL; unsigned char *base = p; unsigned char *end = p + src.size(); while (end - p >= 14) { int size = 0, flags, sample_rate, frame_length, bit_rate; if ((size = dca_syncinfo(state, p, &flags, &sample_rate, &bit_rate, &frame_length)) > 0) { bool enoughData = p + size <= end; if (enoughData) { if (codecId == CODEC_ID_SPDIF_DTS) { bpssum += (lastbps = bit_rate / 1000); numframes++; BYTE type; switch (frame_length) { case 512: type = 0x0b; break; case 1024: type = 0x0c; break; default : type = 0x0d; break; } HRESULT hr = deciA->deliverSampleBistream(p, size, bit_rate, sample_rate, true, frame_length, 0); if (hr != S_OK) { return hr; } } else { flags |= DCA_ADJUST_LEVEL; libdca::sample_t level = 1, bias = 0; if (dca_frame(state, p, &flags, &level, bias) == 0) { bpssum += (lastbps = bit_rate / 1000); numframes++; // Dynamic range compression - Not suppored yet by libdts if (deci->getParam2(IDFF_audio_decoder_DRC)) { libdca::sample_t drcLevel = ((libdca::sample_t)deci->getParam2(IDFF_audio_decoder_DRC_Level) / 100); if (drcLevel <= 0.5) { dca_dynrng(state, NULL, NULL); } } else { dca_dynrng(state, NULL, NULL); } int scmapidx = std::min(flags & DCA_CHANNEL_MASK, int(countof(scmaps) / 2)); const Tscmap &scmap = scmaps[scmapidx + ((flags & DCA_LFE) ? (countof(scmaps) / 2) : 0)]; int blocks = dca_blocks_num(state); float *dst0, *dst; dst0 = dst = (float*)getDst(blocks * 256 * scmap.nchannels * sizeof(float)); int i = 0; for (; i < blocks && dca_block(state) == 0; i++) { libdca::sample_t* samples = dca_samples(state); for (int j = 0; j < 256; j++, samples++) for (int ch = 0; ch < scmap.nchannels; ch++) { *dst++ = float(*(samples + 256 * scmap.ch[ch]) / level); } } if (i == blocks) { fmt.sf = TsampleFormat::SF_FLOAT32; fmt.freq = sample_rate; fmt.setChannels(scmap.nchannels, scmap.channelMask); HRESULT hr = sinkA->deliverDecodedSample(dst0, blocks * 256, fmt); if (hr != S_OK) { return hr; } } } } p += size; } memmove(base, p, end - p); end = base + (end - p); p = base; if (!enoughData) { break; } } else { p++; } } src.resize(end - p); return S_OK; }
HRESULT TaudioCodecLiba52::decode(TbyteBuffer &src) { unsigned char *p=src.size() ? &src[0] : NULL; unsigned char *base=p; unsigned char *end=p+src.size(); while (end-p>7) { int size=0,flags,sample_rate,bit_rate; if ((size=a52_syncinfo(p,&flags,&sample_rate,&bit_rate))>0) { bool enoughData=p+size<=end; if (enoughData) { if (codecId==CODEC_ID_SPDIF_AC3) { bpssum+=(lastbps=bit_rate/1000); numframes++; HRESULT hr=deciA->deliverSampleSPDIF(p,size,bit_rate,sample_rate,true); if (hr!=S_OK) { return hr; } } else { flags|=A52_ADJUST_LEVEL; liba52::sample_t level=1,bias=0; if (a52_frame(state,p,&flags,&level,bias)==0) { bpssum+=(lastbps=bit_rate/1000); numframes++; // Dynamic range compression if (deci->getParam2(IDFF_audio_decoder_DRC)) { liba52::sample_t drcLevel = ((liba52::sample_t)deci->getParam2(IDFF_audio_decoder_DRC_Level) / 100); a52_dynrngsetlevel(state, drcLevel); } else { a52_dynrngsetlevel(state, 0.0); } int scmapidx=std::min(flags&A52_CHANNEL_MASK,int(countof(scmaps)/2)); const Tscmap &scmap=scmaps[scmapidx+((flags&A52_LFE)?(countof(scmaps)/2):0)]; float *dst0,*dst; dst0=dst=(float*)getDst(6*256*scmap.nchannels*sizeof(float)); int i=0; for(; i<6 && a52_block(state)==0; i++) { liba52::sample_t* samples=a52_samples(state); for (int j=0; j<256; j++,samples++) for (int ch=0; ch<scmap.nchannels; ch++) { *dst++=float(*(samples+256*scmap.ch[ch])/level); } } if (i==6) { fmt.sf=TsampleFormat::SF_FLOAT32; fmt.freq=sample_rate; fmt.setChannels(scmap.nchannels,scmap.channelMask); HRESULT hr=sinkA->deliverDecodedSample(dst0,6*256,fmt); if (hr!=S_OK) { return hr; } } } } p+=size; } memmove(base,p,end-p); end=base+(end-p); p=base; if (!enoughData) { break; } } else { p++; } } src.resize(end-p); return S_OK; }