bool FStructureEditorUtils::Change3dWidgetEnabled(UUserDefinedStruct* Struct, FGuid VarGuid, bool bIsEnabled) { auto VarDesc = GetVarDescByGuid(Struct, VarGuid); const auto PropertyStruct = VarDesc ? Cast<const UStruct>(VarDesc->SubCategoryObject.Get()) : NULL; if (FEdMode::CanCreateWidgetForStructure(PropertyStruct) && (VarDesc->bEnable3dWidget != bIsEnabled)) { const FScopedTransaction Transaction(LOCTEXT("Change3dWidgetEnabled", "Change 3d Widget Enabled")); ModifyStructData(Struct); VarDesc->bEnable3dWidget = bIsEnabled; auto Property = FindField<UProperty>(Struct, VarDesc->VarName); if (Property) { if (VarDesc->bEnable3dWidget) { Property->SetMetaData(FEdMode::MD_MakeEditWidget, TEXT("true")); } else { Property->RemoveMetaData(FEdMode::MD_MakeEditWidget); } } return true; } return false; }
bool CFlacDec::GetMetaData(FILE *in, const bool /*nice*/, CAudioMetaData* m) { FLAC__StreamDecoder *vf; vf = FLAC__stream_decoder_new(); FLAC__stream_decoder_set_metadata_ignore_all(vf); // we need streaminfo (default on) and FLAC__METADATA_TYPE_VORBIS_COMMENT (default off) for ID3 tags FLAC__stream_decoder_set_metadata_respond(vf, FLAC__METADATA_TYPE_STREAMINFO); FLAC__stream_decoder_set_metadata_respond(vf, FLAC__METADATA_TYPE_VORBIS_COMMENT); if (!Open(in, vf)) { return false; } if (FLAC__stream_decoder_process_until_end_of_metadata(vf)) { // if the metadata callback was called mMetadata should be filled with infos if (mMetadata) { SetMetaData(mMetadata, m); } } // clean up stuff, the mMetadata may be used later again so let the decoder free it FLAC__stream_decoder_finish(vf); FLAC__stream_decoder_delete(vf); return true; }
bool FStructureEditorUtils::ChangeMultiLineTextEnabled(UUserDefinedStruct* Struct, FGuid VarGuid, bool bIsEnabled) { auto VarDesc = GetVarDescByGuid(Struct, VarGuid); if (CanEnableMultiLineText(Struct, VarGuid) && VarDesc->bEnableMultiLineText != bIsEnabled) { const FScopedTransaction Transaction(LOCTEXT("ChangeMultiLineTextEnabled", "Change Multi-line Text Enabled")); ModifyStructData(Struct); VarDesc->bEnableMultiLineText = bIsEnabled; auto Property = FindField<UProperty>(Struct, VarDesc->VarName); if (Property) { if (VarDesc->bEnableMultiLineText) { Property->SetMetaData("MultiLine", TEXT("true")); } else { Property->RemoveMetaData("MultiLine"); } } OnStructureChanged(Struct); return true; } return false; }
bool COggDec::GetMetaData(FILE *in, const bool /*nice*/, CAudioMetaData* m) { OggVorbis_File vf; if (!Open(in, &vf)) { return false; } SetMetaData(&vf, m); ov_clear(&vf); return true; }
void UUserDefinedStruct::PostDuplicate(bool bDuplicateForPIE) { Super::PostDuplicate(bDuplicateForPIE); if (!bDuplicateForPIE) { Guid = FGuid::NewGuid(); } if (!bDuplicateForPIE && (GetOuter() != GetTransientPackage())) { SetMetaData(TEXT("BlueprintType"), TEXT("true")); FStructureEditorUtils::OnStructureChanged(this); } }
bool FStructureEditorUtils::ChangeVariableTooltip(UUserDefinedStruct* Struct, FGuid VarGuid, const FString& InTooltip) { auto VarDesc = GetVarDescByGuid(Struct, VarGuid); if (VarDesc && (InTooltip != VarDesc->ToolTip)) { const FScopedTransaction Transaction(LOCTEXT("ChangeVariableTooltip", "Change UDS Variable Tooltip")); ModifyStructData(Struct); VarDesc->ToolTip = InTooltip; auto Property = FindField<UProperty>(Struct, VarDesc->VarName); if (Property) { Property->SetMetaData(FBlueprintMetadata::MD_Tooltip, *VarDesc->ToolTip); } return true; } return false; }
int main(int argc, char *argv[]) { /**********************************************************/ /* */ /* Initializing the problem */ /* */ /**********************************************************/ double L; // Length of simulation cell (assumed to be a cube) int n; // Number of Chebyshev nodes per dimension doft dof; int Ns; // Number of sources in simulation cell int Nf; // Number of field points in simulation cell int m; int level; double eps; int use_chebyshev = 1; SetMetaData(L, n, dof, Ns, Nf, m, level, eps); vector3* source = new vector3[Ns]; // Position array for the source points vector3* field = new vector3[Nf]; // Position array for the field points double *q = new double[Ns*dof.s*m]; // Source array SetSources(field,Nf,source,Ns,q,m,&dof,L); double err; double *stress = new double[Nf*dof.f*m];// Field array (BBFMM calculation) double *stress_dir = new double[Nf*dof.f*m];// Field array (direct O(N^2) calculation) /**********************************************************/ /* */ /* Fast matrix vector product */ /* */ /**********************************************************/ /***** Pre Computation ******/ clock_t t0 = clock(); myKernel Atree(&dof,L,level, n, eps, use_chebyshev); Atree.buildFMMTree(); clock_t t1 = clock(); double tPre = t1 - t0; /***** FMM Computation *******/ t0 = clock(); H2_3D_Compute<myKernel> compute(&Atree, field, source, Ns, Nf, q,m, stress); t1 = clock(); double tFMM = t1 - t0; /***** output result to binary file ******/ // string outputfilename = "../output/stress.bin"; // write_Into_Binary_File(outputfilename, stress, m*Nf*dof.f); /**********************************************************/ /* */ /* Exact matrix vector product */ /* */ /**********************************************************/ t0 = clock(); DirectCalc3D(&Atree, field, Nf, source, q, m, Ns, &dof,0 , L, stress_dir); t1 = clock(); double tExact = t1 - t0; cout << "Pre-computation time: " << double(tPre) / double(CLOCKS_PER_SEC) << endl; cout << "FMM computing time: " << double(tFMM) / double(CLOCKS_PER_SEC) << endl; cout << "FMM total time: " << double(tFMM+tPre) / double(CLOCKS_PER_SEC) << endl; cout << "Exact computing time: " << double(tExact) / double(CLOCKS_PER_SEC) << endl; //Compute the 2-norm error err = ComputeError(stress,stress_dir,Nf,&dof,m); cout << "Relative Error: " << err << endl; /******* Clean Up *******/ delete []stress; delete []stress_dir; delete []q; delete []source; delete []field; return 0; }
CBaseDec::RetCode COggDec::Decoder(FILE *in, const int OutputFd, State* const state, CAudioMetaData* meta_data, time_t* const time_played, unsigned int* const secondsToSkip) { OggVorbis_File vf; int bitstream, rval; ogg_int64_t jumptime=0; Status=OK; mOutputFd = OutputFd; mState = state; mTimePlayed=time_played; if (!Open(in, &vf)) { Status=DATA_ERR; return Status; } SetMetaData(&vf, meta_data); #if __BYTE_ORDER == __LITTLE_ENDIAN || USE_TREMOR audioDecoder->PrepareClipPlay(ov_info(&vf,0)->channels, ov_info(&vf,0)->rate, 16, 1); #else audioDecoder->PrepareClipPlay(ov_info(&vf,0)->channels, ov_info(&vf,0)->rate, 16, 0); #endif /* up and away ... */ mSlotSize = MAX_OUTPUT_SAMPLES * 2 * ov_info(&vf,0)->channels; for(int i = 0 ; i < DECODE_SLOTS ; i++) { if ((mPcmSlots[i] = (char*) malloc(mSlotSize)) == NULL) { for (int j = i - 1; j >= 0; j--) { free(mPcmSlots[j]); } Status=INTERNAL_ERR; return Status; } mSlotTime[i]=0; } mReadSlot=mWriteSlot=0; pthread_t OutputThread; if (pthread_create (&OutputThread, 0, OutputDsp, (void *) this) != 0 ) { for(int i = 0 ; i < DECODE_SLOTS ; i++) free(mPcmSlots[i]); Status=INTERNAL_ERR; return Status; } int bytes; State oldstate=*state; do { // clear buffer on state change if(oldstate!=*state) { if(*state!=PAUSE && (*state!=PLAY || oldstate!=PAUSE)) { mWriteSlot=mReadSlot=0; oldstate=*state; } } while((mWriteSlot+1)%DECODE_SLOTS == mReadSlot) { usleep(10000); } bytes=0; if(mSeekable) #ifdef USE_TREMOR mSlotTime[mWriteSlot] = ov_time_tell(&vf); #else mSlotTime[mWriteSlot] = (ogg_int64_t)(1000 * ov_time_tell(&vf)); #endif do { #ifdef USE_TREMOR rval = ov_read(&vf, mPcmSlots[mWriteSlot]+bytes, mSlotSize-bytes, &bitstream); #else rval = ov_read(&vf, mPcmSlots[mWriteSlot]+bytes, mSlotSize-bytes, 0, 2, 1, &bitstream); #endif bytes+=rval; //printf("Ogg: read buf 0x%x size %d / %d done %d\n", mPcmSlots[mWriteSlot]+bytes, rval, mSlotSize, bytes); } while (rval > 0 && bytes !=mSlotSize); //printf("\n"); int actMSecsToSkip = (*secondsToSkip != 0) ? *secondsToSkip * 1000 : MSECS_TO_SKIP; if((*state==FF || *state==REV) && mSeekable ) { if((std::abs((long int)( mSlotTime[mWriteSlot]-jumptime))) > MSECS_TO_PLAY) { if(*state==FF) { ov_time_seek_page(&vf, mSlotTime[mWriteSlot] + actMSecsToSkip); jumptime=mSlotTime[mWriteSlot]+actMSecsToSkip; } else { if(mSlotTime[mWriteSlot] < actMSecsToSkip) { ov_time_seek(&vf, 0); *state=PLAY; } else { ov_time_seek_page(&vf, mSlotTime[mWriteSlot] - actMSecsToSkip); jumptime=mSlotTime[mWriteSlot]-actMSecsToSkip; } } } if (*secondsToSkip != 0) { *state=PLAY; } } if(bytes == mSlotSize) mWriteSlot=(mWriteSlot+1) % DECODE_SLOTS; } while (rval != 0 && *state!=STOP_REQ && Status==OK); //printf("COggDec::Decoder: read loop stop, rval %d state %d status %d\n", rval, *state, Status); // let buffer run dry while(rval==0 && *state!=STOP_REQ && Status==OK && mReadSlot != mWriteSlot) usleep(100000); //pthread_cancel(OutputThread); //printf("COggDec::Decoder: OutputThread join\n"); Status = WRITE_ERR; pthread_join(OutputThread, NULL); //printf("COggDec::Decoder: OutputThread join done\n"); audioDecoder->StopClip(); for(int i = 0 ; i < DECODE_SLOTS ; i++) free(mPcmSlots[i]); /* clean up the junk from the party */ ov_clear(&vf); /* and drive home ;) */ return Status; }
CBaseDec::RetCode CWavDec::Decoder(FILE *in, int OutputFd, State* state, CAudioMetaData* meta_data, time_t* time_played, unsigned int* secondsToSkip) { char* buffer; RetCode Status=OK; if (!SetMetaData(in, meta_data)) { Status=DATA_ERR; return Status; } fseek(in, header_size, SEEK_SET); int fmt; switch(mBitsPerSample) { case 8 : fmt = AFMT_U8; break; case 16 : fmt = header_size == 0 ? AFMT_S16_BE : AFMT_S16_LE; break; default: printf("%s: wrong bits per sample (%d)\n", ProgName, mBitsPerSample); Status=DATA_ERR; return Status; } if (SetDSP(OutputFd, fmt, meta_data->samplerate , mChannels)) { Status=DSPSET_ERR; return Status; } int actSecsToSkip = (*secondsToSkip != 0) ? *secondsToSkip : MSECS_TO_SKIP / 1000; unsigned int oldSecsToSkip = *secondsToSkip; int jumppos=0; int bytes; int bytes_to_play = (int) (1.0 * MSECS_TO_PLAY / 1000 * meta_data->bitrate / 8); int bytes_to_skip = (int) (1.0 * actSecsToSkip * meta_data->bitrate / 8); int buffersize = MAX_OUTPUT_SAMPLES * mChannels * mBitsPerSample / 8; buffer = (char*) malloc (buffersize); do { while(*state==PAUSE) usleep(10000); if(*state==FF || *state==REV) { if (oldSecsToSkip != *secondsToSkip) { actSecsToSkip = (*secondsToSkip != 0) ? *secondsToSkip : MSECS_TO_SKIP / 1000; bytes_to_skip = (int) (1.0 * actSecsToSkip * meta_data->bitrate / 8); oldSecsToSkip = *secondsToSkip; } //printf("skipping %d secs and %d bytes\n",actSecsToSkip,bytes_to_skip); if(std::abs(ftell(in)-jumppos) > bytes_to_play) { if(*state==FF) { fseek(in, bytes_to_skip, SEEK_CUR); jumppos=ftell(in); } else { if(ftell(in) < bytes_to_skip) { fseek(in, header_size, SEEK_SET); *state=PLAY; } else { fseek(in, -bytes_to_skip, SEEK_CUR); jumppos=ftell(in); } } } // if a custom value was set we only jump once if (*secondsToSkip != 0) { *state=PLAY; } } bytes = fread(buffer, 1, buffersize, in); if (write(OutputFd, buffer, bytes) != bytes) { fprintf(stderr,"%s: PCM write error (%s).\n", ProgName, strerror(errno)); Status=WRITE_ERR; } *time_played = (meta_data->bitrate!=0) ? (ftell(in)-header_size)*8/meta_data->bitrate : 0; } while (bytes > 0 && *state!=STOP_REQ && Status==OK); free(buffer); return Status; }
bool CWavDec::GetMetaData(FILE *in, const bool nice, CAudioMetaData* m) { return SetMetaData(in, m); }
int main(int argc, char *argv[]) { /**********************************************************/ /* */ /* Initializing the problem */ /* */ /**********************************************************/ double L; // Length of simulation cell (assumed to be a cube) int n; // Number of Chebyshev nodes per dimension doft dof; int Ns; // Number of sources in simulation cell int Nf; // Number of field points in simulation cell int m; int level; double eps; int use_chebyshev = 1; SetMetaData(L, n, dof, Ns, Nf, m, level, eps); vector3* source = new vector3[Ns]; // Position array for the source points vector3* field = new vector3[Nf]; // Position array for the field points double *q = new double[Ns*dof.s*m]; // Source array SetSources(field,Nf,source,Ns,q,m,&dof,L); double err; double *stress = new double[Nf*dof.f*m];// Field array (BBFMM calculation) double *stress_dir = new double[Nf*dof.f*m];// Field array (direct O(N^2) calculation)*/ /**********************************************************/ /* */ /* Fast matrix vector product */ /* */ /**********************************************************/ /***** Pre Computation ******/ clock_t t0 = clock(); kernel_Gaussian Atree(&dof,L,level, n, eps, use_chebyshev); Atree.buildFMMTree(); clock_t t1 = clock(); double tPre = t1 - t0; /***** FMM Computation *******/ t0 = clock(); H2_3D_Compute<kernel_Gaussian> compute(&Atree, field, source, Ns, Nf, q,m, stress); t1 = clock(); double tFMM = t1 - t0; /***** You can repeat this part with different source, field points and charges *****/ /*vector3* source1 = new vector3[Ns]; // Position array for the source points vector3* field1 = new vector3[Nf]; // Position array for the field points double *q1 = new double[Ns*dof.s*m]; // Source array SetSources(field1,Nf,source1,Ns,q1,m,&dof,L); double *stress1 = new double[Nf*dof.f*m];// Field array (BBFMM calculation) H2_3D_Compute<kernel_LaplacianForce> compute1(&Atree, field1, source1, Ns, Nf, q1,m, stress1);*/ /**** Test interplation error *****/ // kernel_Gaussian testTree(&dof,1.0/4 ,2, n, eps, use_chebyshev); // double errtest = testInterplationErr(&testTree, 100, 100); /***** output result to binary file ******/ // string outputfilename = "../output/stress.bin"; // write_Into_Binary_File(outputfilename, stress, m*Nf*dof.f); /**********************************************************/ /* */ /* Exact matrix vector product */ /* */ /**********************************************************/ // string inputfilename = "../output/stress_dir05gaussian.bin"; // read_Stress(inputfilename, stress_dir, Nf*dof.f*m); t0 = clock(); DirectCalc3D(&Atree, field, Nf, source, q, m, Ns, &dof,0 , L, stress_dir); t1 = clock(); double tExact = t1 - t0; string outputfilename = "../output/stress_dir06gaussian.bin"; write_Into_Binary_File(outputfilename, stress, m*Nf*dof.f); cout << "Pre-computation time: " << double(tPre) / double(CLOCKS_PER_SEC) << endl; cout << "FMM computing time: " << double(tFMM) / double(CLOCKS_PER_SEC) << endl; cout << "FMM total time: " << double(tPre+tFMM) / double(CLOCKS_PER_SEC) << endl; cout << "Exact computing time: " << double(tExact) / double(CLOCKS_PER_SEC) << endl; // Compute the 2-norm error err = ComputeError(stress,stress_dir,Nf,&dof,m); cout << "Relative Error: " << err << endl; /******* Clean Up *******/ delete []stress; delete []stress_dir; delete []source; delete []field; delete []q; //delete []stress1; return 0; }
bool CFfmpegDec::GetMetaData(FILE *_in, const bool /*nice*/, CAudioMetaData* m) { return SetMetaData(_in, m); }
CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State* state, CAudioMetaData* _meta_data, time_t* time_played, unsigned int* secondsToSkip) { in = _in; RetCode Status=OK; is_stream = fseek((FILE *)in, 0, SEEK_SET); if (!SetMetaData((FILE *)in, _meta_data, true)) { DeInit(); Status=DATA_ERR; return Status; } AVCodecContext *c = avc->streams[best_stream]->codec; mutex.lock(); int r = avcodec_open2(c, codec, NULL); mutex.unlock(); if (r) { DeInit(); Status=DATA_ERR; return Status; } SwrContext *swr = swr_alloc(); if (!swr) { mutex.lock(); avcodec_close(c); mutex.unlock(); DeInit(); Status=DATA_ERR; return Status; } mSampleRate = samplerate; mChannels = av_get_channel_layout_nb_channels(AV_CH_LAYOUT_STEREO); #if __BYTE_ORDER == __LITTLE_ENDIAN audioDecoder->PrepareClipPlay(mChannels, mSampleRate, 16, 1); #else audioDecoder->PrepareClipPlay(mChannels, mSampleRate, 16, 0); #endif AVFrame *frame = NULL; AVPacket rpacket; av_init_packet(&rpacket); av_opt_set_int(swr, "in_channel_layout", c->channel_layout, 0); //av_opt_set_int(swr, "out_channel_layout", c->channel_layout, 0); av_opt_set_int(swr, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0); av_opt_set_int(swr, "in_sample_rate", c->sample_rate, 0); av_opt_set_int(swr, "out_sample_rate", c->sample_rate, 0); av_opt_set_int(swr, "in_sample_fmt", c->sample_fmt, 0); av_opt_set_int(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); swr_init(swr); uint8_t *outbuf = NULL; int outsamples = 0; int outsamples_max = 0; int64_t pts = 0, start_pts = 0, next_skip_pts = 0; uint64_t skip = 0; int seek_flags = 0; do { int actSecsToSkip = *secondsToSkip; if (!is_stream && (actSecsToSkip || *state==FF || *state==REV) && avc->streams[best_stream]->time_base.num) { if (!next_skip_pts || pts >= next_skip_pts) { skip = avc->streams[best_stream]->time_base.den / avc->streams[best_stream]->time_base.num; if (actSecsToSkip) skip *= actSecsToSkip; if (*state == REV) { next_skip_pts = pts - skip; pts = next_skip_pts - skip/4; seek_flags = AVSEEK_FLAG_BACKWARD; if (pts < start_pts) { pts = start_pts; *state = PAUSE; } } else { pts += skip; next_skip_pts = pts + skip/4; seek_flags = 0; } av_seek_frame(avc, best_stream, pts, seek_flags); skip = 0; // if a custom value was set we only jump once if (actSecsToSkip != 0) { *state=PLAY; *secondsToSkip = 0; } } } while(*state==PAUSE && !is_stream) usleep(10000); if (av_read_frame(avc, &rpacket)) { Status=DATA_ERR; break; } if (rpacket.stream_index != best_stream) { av_free_packet(&rpacket); continue; } AVPacket packet = rpacket; while (packet.size > 0) { int got_frame = 0; if (!frame) { if (!(frame = avcodec_alloc_frame())) { Status=DATA_ERR; break; } } else avcodec_get_frame_defaults(frame); int len = avcodec_decode_audio4(c, frame, &got_frame, &packet); if (len < 0) { // skip frame packet.size = 0; avcodec_flush_buffers(c); mutex.lock(); avcodec_close(c); avcodec_open2(c, codec, NULL); mutex.unlock(); continue; } if (got_frame && *state!=PAUSE) { int out_samples; outsamples = av_rescale_rnd(swr_get_delay(swr, c->sample_rate) + frame->nb_samples, c->sample_rate, c->sample_rate, AV_ROUND_UP); if (outsamples > outsamples_max) { av_free(outbuf); if (av_samples_alloc(&outbuf, &out_samples, mChannels, //c->channels, frame->nb_samples, AV_SAMPLE_FMT_S16, 1) < 0) { Status=WRITE_ERR; packet.size = 0; break; } outsamples_max = outsamples; } outsamples = swr_convert(swr, &outbuf, outsamples, (const uint8_t **) &frame->data[0], frame->nb_samples); int outbuf_size = av_samples_get_buffer_size(&out_samples, mChannels, //c->channels, outsamples, AV_SAMPLE_FMT_S16, 1); if(audioDecoder->WriteClip((unsigned char*) outbuf, outbuf_size) != outbuf_size) { fprintf(stderr,"%s: PCM write error (%s).\n", ProgName, strerror(errno)); Status=WRITE_ERR; } pts = av_frame_get_best_effort_timestamp(frame); if (!start_pts) start_pts = pts; } packet.size -= len; packet.data += len; } if (time_played && avc->streams[best_stream]->time_base.den) *time_played = (pts - start_pts) * avc->streams[best_stream]->time_base.num / avc->streams[best_stream]->time_base.den; av_free_packet(&rpacket); } while (*state!=STOP_REQ && Status==OK); audioDecoder->StopClip(); meta_data_valid = false; swr_free(&swr); av_free(outbuf); av_free_packet(&rpacket); avcodec_free_frame(&frame); avcodec_close(c); //av_free(avcc); DeInit(); if (_meta_data->cover_temporary && !_meta_data->cover.empty()) { _meta_data->cover_temporary = false; unlink(_meta_data->cover.c_str()); } return Status; }