跳转至内容

General Discussion | 综合讨论

A place to talk about whatever you want

32 主题 178 帖子
  • 此主题已被删除!

    1
    0 赞同
    1 帖子
    9 浏览
    尚无回复
  • 此主题已被删除!

    1
    0 赞同
    1 帖子
    6 浏览
    尚无回复
  • 此主题已被删除!

    1
    0 赞同
    1 帖子
    6 浏览
    尚无回复
  • 此主题已被删除!

    1
    0 赞同
    1 帖子
    6 浏览
    尚无回复
  • 此主题已被删除!

    1
    0 赞同
    1 帖子
    17 浏览
    尚无回复
  • 此主题已被删除!

    1
    0 赞同
    1 帖子
    7 浏览
    尚无回复
  • 此主题已被删除!

    1
    0 赞同
    1 帖子
    7 浏览
    尚无回复
  • 此主题已被删除!

    1
    0 赞同
    1 帖子
    16 浏览
    尚无回复
  • 此主题已被删除!

    1
    0 赞同
    1 帖子
    9 浏览
    尚无回复
  • 此主题已被删除!

    1
    0 赞同
    1 帖子
    10 浏览
    尚无回复
  • 吃太飽生了個無需黑箱的高精度π計算方法

    1
    1 赞同
    1 帖子
    90 浏览
    尚无回复
  • 使用自编C++Web框架搭建的个人博客

    5
    0 赞同
    5 帖子
    268 浏览
    MineCodeM

    @unamed-coder 看https://glwebsite.us.ci/about下边的小字,我真不是福瑞

  • 快速十六进制转八进制

    2
    1 赞同
    2 帖子
    126 浏览
    StehsaerS
    改进

    经过@yyq252517提醒并测试,直接使用12bit的查找表可以更快:

    consteval std::array<std::array<char, 4>, 4096> hex_to_oct_lookup() noexcept { std::array<std::array<char, 4>, 4096> lookup{}; for (size_t i = 0; i < 4096; ++i) { lookup[i][0] = '0' + ((i >> 0) & 0b111); lookup[i][1] = '0' + ((i >> 3) & 0b111); lookup[i][2] = '0' + ((i >> 6) & 0b111); lookup[i][3] = '0' + ((i >> 9) & 0b111); } return lookup; } // ... std::string hex_to_oct(const std::string& hex) noexcept { const auto hex_length = hex.length(); if (hex_length == 0) return "0"; const auto groups = (hex_length + 2) / 3; const auto oct_digits = groups * 4; std::string res(oct_digits, '0'); for (size_t i = hex_length % 3; i < hex_length; i += 3) { const size_t curr_group = (i + 2) / 3; const uint16_t h0 = hex_lookup[std::bit_cast<uint8_t>(hex[i + 2])]; // [3:0] const uint16_t h1 = hex_lookup[std::bit_cast<uint8_t>(hex[i + 1])]; // [7:4] const uint16_t h2 = hex_lookup[std::bit_cast<uint8_t>(hex[i + 0])]; // [11:8] const uint16_t idx = (h2 << 8) | (h1 << 4) | h0; // [11:0] const auto [o1, o2, o3, o4] = hex_to_oct_lookup_table[idx]; res[curr_group * 4 + 3] = o1; res[curr_group * 4 + 2] = o2; res[curr_group * 4 + 1] = o3; res[curr_group * 4 + 0] = o4; } if (hex_length % 3 != 0) { std::array<uint16_t, 3> h{0, 0, 0}; if (hex_length % 3 == 1) { h[0] = hex_lookup[std::bit_cast<uint8_t>(hex[0])]; } else // hex_length % 3 == 2 { h[1] = hex_lookup[std::bit_cast<uint8_t>(hex[0])]; h[0] = hex_lookup[std::bit_cast<uint8_t>(hex[1])]; } const uint16_t idx = (h[2] << 8) | (h[1] << 4) | h[0]; const auto [o1, o2, o3, o4] = hex_to_oct_lookup_table[idx]; res[3] = o1; res[2] = o2; res[1] = o3; res[0] = o4; } const auto first_non_zero = res.find_first_not_of('0'); if (first_non_zero == std::string::npos) return "0"; return res.substr(first_non_zero); }

    使用和此前一致的测试环境,可以得到:

    Optimized version: 72.16 ms (stddev: 0.45 ms), 1385897448.4948883 hex chars/sec

    比此前快了15%!此前低估了现代CPU的L1缓存系统的能力,看来它处理4096*4byte = 16KiB的查找表也不在话下

    感谢@yyq252517

  • 小白学习给点建议 - C语言学习

    5
    1 赞同
    5 帖子
    348 浏览
    SPeakS

    @johanvx 这个也是非常经典的公开课 中国大学Mooc和B站上应该都能找到视频

  • 第一个文件注释掉D2X_wait后直接报错退出

    2
    0 赞同
    2 帖子
    149 浏览
    SPeakS

    这个之前有个类似情况, 程序遇到死循环这个就可能发生. 重新运行每次都会这样吗

  • 0 赞同
    3 帖子
    362 浏览
    SPeakS

    @SPeak 在 调完字体大小后光标位置不对啊,有没有大佬看看(用xlings下的文字也有问题) 中说:

    http://forum.d2learn.org/post/418

    问题1: 界面乱码问题

    A1: xlings已经更新解决(增加了utf8编码的支持, 重装即可

    问题2: 代码输入光标位置问题

    解决方法1: 代码中不要包含中文内容
    解决方法2: 取消beta/utf8编码选项, 然后卸载重新安装devcpp

    xlings remove devcpp xlings install devcpp

    6c34d5cd-b1eb-4c7f-8181-1ca3ca6c673b-image.png

    中/英文切换: https://forum.d2learn.org/topic/134

  • 项目代码在gtest单元测试中崩溃的问题

    4
    0 赞同
    4 帖子
    380 浏览
    SPeakS

    chain对象104, 3个对象中间asan插入了红区保护
    通过内存布局看 [00] 的访问(size_)是在104最后32字节的, 但依然报错

    image.png

    821b2e52-ffc5-4751-a9f8-306ac05b66ef-image.png

    并且非常奇怪的是, 插入crash代码(减少使用printf/cout 造成代码生成变化带来的干扰) 92可以执行到, 95行无法执行到

    14502bf3-0652-4f95-8779-5e65c987d49a-image.png

    怀疑的地方

    分配器内存对齐问题? operator=的实现是否正确处理基类? 哪里的代码造成UB, 导致代码生成出现问题?
  • 关于sonic实现音频变速不变调的问题

    11
    0 赞同
    11 帖子
    887 浏览
    Cat-GuijunC

    hi,友友有解决这个情况吗,我也是当speed不为一时就报错了,我完全不知道如何查找崩溃,找了一天了,下面是我的代码:
    void AudioDecodeThread::run()
    {
    // 加入sonic
    // 初始化部分:先创建一个流
    sonicStream stream = sonicCreateStream(m_videoPlayControl->m_audioCodecCtx->sample_rate, 2);
    if (!stream)
    {
    m_videoPlayControl->m_eventHandler->onVideoPlayerError(0, "sonicCreateStream error!");
    }

    if (!initSwrCtx()) { m_videoPlayControl->m_eventHandler->onVideoPlayerError(0, "initSwrCtx error"); return; } while (true) { if (m_videoPlayControl->m_currentState == State::STOP) { break; } else if (m_videoPlayControl->m_currentState == State::PAUSE) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); continue; } AVPacket *pkt = m_videoPlayControl->m_audioPacketQueue.pop(); if (pkt == nullptr) { if (m_videoPlayControl->m_isReadFinished) { break; } continue; } if (memcmp(pkt->data, FLUSHDATA, strlen(FLUSHDATA)) == 0) { avcodec_flush_buffers(m_videoPlayControl->m_audioCodecCtx); av_packet_free(&pkt); continue; } int ret = avcodec_send_packet(m_videoPlayControl->m_audioCodecCtx, pkt); if (ret < 0) { char errbuf[1024] = { 0 }; av_strerror(ret, errbuf, sizeof(errbuf)); fprintf(stderr, "avcodec_send_packet: %s (error pts: %d)\n", errbuf, pkt->pts); av_packet_free(&pkt); continue; } AVFrame *frame = av_frame_alloc(); while (avcodec_receive_frame(m_videoPlayControl->m_audioCodecCtx, frame) == 0) { // 读取frame, swr转换, 放到frameQueue里面去 int inSamples = frame->nb_samples; // int outSamples = av_rescale_rnd(inSamples, 1, 1, AV_ROUND_UP); // 废除手动分配的 audioBuffer,改用 resampleFrame 内部缓冲区 AVFrame *resampleFrame = av_frame_alloc(); resampleFrame->format = AV_SAMPLE_FMT_S16; av_channel_layout_default(&resampleFrame->ch_layout, 2); // 双声道 resampleFrame->sample_rate = frame->sample_rate; // 正确设置采样率 resampleFrame->nb_samples = inSamples; // 让 FFmpeg 自动分配缓冲区(确保地址和大小正确) if (av_frame_get_buffer(resampleFrame, 0) < 0) { av_frame_free(&resampleFrame); continue; } int len = swr_convert(m_swrCtx, resampleFrame->data, resampleFrame->nb_samples, (const uint8_t **)frame->data, inSamples); // 加入sonic sonicSetSpeed(stream, m_videoPlayControl->m_speed); // 4. 写入音频数据到Sonic ,这里的bug short *valid_audio_data = (short *)resampleFrame->data[0]; int total_samples = len; // 单声道总样本数 std::cout << len << std::endl; ret = sonicWriteShortToStream(stream, valid_audio_data, total_samples); if (ret == 0) { m_videoPlayControl->m_eventHandler->onVideoPlayerError(0, "sonicWriteShortToStream error"); continue; } int availableSamples = sonicSamplesAvailable(stream); // if (availableSamples <= 0) { continue; } // 根据实际需要的样本数分配缓冲区 short *output_pcm = new short[availableSamples * 2]; int samples = sonicReadShortFromStream(stream, output_pcm, availableSamples); if (samples <= 0) { delete[] output_pcm; av_frame_free(&resampleFrame); continue; } std::cout << inSamples << "---" << len << "---" << availableSamples << "---" << samples << std::endl; PCMFrame *pcm = new PCMFrame(); pcm->setBuffer((uint8_t *)output_pcm, samples * 4); pcm->setPts(frame->pts); pcm->setSampleRate(frame->sample_rate); m_videoPlayControl->m_audioFrameQueue.push(pcm); delete[] output_pcm; av_frame_free(&resampleFrame); } av_frame_free(&frame); av_packet_free(&pkt); } sonicDestroyStream(stream); }
  • Linux & Win 游戏性能随手记录

    16
    1 赞同
    16 帖子
    2k 浏览
    MoYingJiM

    我用错驱动了...
    理论上 上述linux的测试结果还能再提升?

    图片.png

  • 关于 GitHub 中的 Fork 仓库的简单问题

    4
    0 赞同
    4 帖子
    513 浏览
    johanvxJ

    为方便描述,称上游 GitHub 仓库为 upstream,自己 fork 的 GitHub 仓库为 origin。如果没有理解错的话,你应该是遇到下面这个场景并想做到 Step 4:

    = Step 1: Fork * aaaaaa (HEAD -> main, origin/main, upstream/main) ... = Step 2: Make local changes and push them to origin * bbbbbb (HEAD -> main, origin/main) * aaaaaa (upstream/main) ... = Step 3: Check (fetch) upstream's update * bbbbbb (HEAD -> main, origin/main) | * cccccc (upstream/main) |/ * aaaaaa ... = Step 4: Rebase (but how?) * bbbbbb (HEAD -> main, origin/main) * cccccc (upstream/main) * aaaaaa ...

    如果是这样的话,我通常的做法是在本地进行这样的操作:

    git pull -r upstream main # Resolve conflict git rebase --continue

    至于 GitHub 有没有一键(或者几键)的做法,我没有找到。

    参考阅读:https://gitolite.com/git-pull--rebase