Skip to content

Commit

Permalink
1.5.19
Browse files Browse the repository at this point in the history
Support longer streams.
Fix a bug when decoding some aac files.
Code Optimizations.
  • Loading branch information
Thomasyse committed May 28, 2020
1 parent a0da017 commit 9f8c939
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 189 deletions.
Binary file modified BDMatch/BDMatch.aps
Binary file not shown.
Binary file modified BDMatch/BDMatch.rc
Binary file not shown.
34 changes: 17 additions & 17 deletions BDMatch/MyForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma managed
#include <msclr\marshal_cppstd.h>

#define appversion "1.5.18"
#define appversion "1.5.19"
#define secpurple 45
#define setintnum 5
#define MaxdB 20.0
Expand Down Expand Up @@ -106,8 +106,8 @@ int BDMatch::MyForm::write_ass(const char* sub_path, const char* output_path)
int nb_timeline = static_cast<int>(BDMatchCoreAPI::get_nb_timeline());
//绘图相关
if (setting->draw) {
tv_draw.time_list = gcnew array<int, 2>(nb_timeline, 2);
bd_draw.time_list = gcnew array<int, 2>(nb_timeline, 2);
tv_draw.time_list = gcnew array<int64_t, 2>(nb_timeline, 2);
bd_draw.time_list = gcnew array<int64_t, 2>(nb_timeline, 2);
tv_draw.line_num = nb_timeline;
bd_draw.line_num = nb_timeline;
LineSel->Maximum = nb_timeline;
Expand Down Expand Up @@ -169,18 +169,18 @@ int BDMatch::MyForm::draw_pre(const int &re)
bd_draw.spec = BDMatchCoreAPI::get_decode_spec(Decode::Decode_File::BD_Decode);
tv_draw.num = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::FFT_Samp_Num);
bd_draw.num = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::BD_Decode, Decode::Decode_Info::FFT_Samp_Num);
tv_draw.ch = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::Channels);
bd_draw.ch = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::BD_Decode, Decode::Decode_Info::Channels);
tv_draw.ch = static_cast<int>(BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::Channels));
bd_draw.ch = static_cast<int>(BDMatchCoreAPI::get_decode_info(Decode::Decode_File::BD_Decode, Decode::Decode_Info::Channels));
tv_draw.milisec = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::Milisec);
bd_draw.milisec = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::BD_Decode, Decode::Decode_Info::Milisec);
tv_draw.fft_num = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::FFT_Num);
bd_draw.fft_num = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::BD_Decode, Decode::Decode_Info::FFT_Num);
tv_draw.fft_num = static_cast<int>(BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::FFT_Num));
bd_draw.fft_num = static_cast<int>(BDMatchCoreAPI::get_decode_info(Decode::Decode_File::BD_Decode, Decode::Decode_Info::FFT_Num));
tv_draw.ttf = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::Samp_Rate) / (static_cast<double>(tv_draw.fft_num) * 100.0);
bd_draw.ttf = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::Samp_Rate) / (static_cast<double>(bd_draw.fft_num) * 100.0);
ViewSel->SelectedIndex = 0;
ChSelect->SelectedIndex = 0;
ChSelect->Enabled = true;
TimeRoll->Maximum = max(tv_draw.milisec, bd_draw.milisec);
TimeRoll->Maximum = static_cast<int>(max(tv_draw.milisec, bd_draw.milisec));
TimeRoll->Value = 0;
TimeRoll->Enabled = true;
if (setting->match_ass)ViewSel->Enabled = true;
Expand All @@ -203,20 +203,20 @@ int BDMatch::MyForm::draw_chart()
{
using namespace System::Drawing;
Match->Enabled = false;
int maxsampnum = max(tv_draw.num, bd_draw.num);
int milisec = max(tv_draw.milisec, bd_draw.milisec);
int64_t maxsampnum = max(tv_draw.num, bd_draw.num);
int64_t milisec = max(tv_draw.milisec, bd_draw.milisec);
int offset = 0;
if (milisec < 10000) offset = 150;
else if (milisec < 100000)offset = 250;
else offset = 350;
TimeRoll->TickFrequency = offset;
TimeRoll->LargeChange = offset;
TimeRoll->SmallChange = offset / 4;
int tvstart = 0, tvend = 0, bdstart = 0;
int64_t tvstart = 0, tvend = 0, bdstart = 0;
if (ViewSel->SelectedIndex == 0) {
tvstart = static_cast<int>(round((TimeRoll->Value - offset)* tv_draw.ttf));
tvend = static_cast<int>(round((TimeRoll->Value + offset)* tv_draw.ttf));
bdstart = static_cast<int>(round((TimeRoll->Value - offset)* bd_draw.ttf));
tvstart = static_cast<int64_t>(round((TimeRoll->Value - offset)* tv_draw.ttf));
tvend = static_cast<int64_t>(round((TimeRoll->Value + offset)* tv_draw.ttf));
bdstart = static_cast<int64_t>(round((TimeRoll->Value - offset)* bd_draw.ttf));
ChartTime->Text = ms2time(TimeRoll->Value);
}
else {
Expand All @@ -237,7 +237,7 @@ int BDMatch::MyForm::draw_chart()
else ChartTime->Text = ms2time(static_cast<int>(round(tv_draw.time_list[static_cast<int>(LineSel->Value) - 1, 0] / tv_draw.ttf)) + 1)
+ "\n" + ms2time(static_cast<int>(round(bd_draw.time_list[static_cast<int>(LineSel->Value) - 1, 0] / bd_draw.ttf)));
}
int duration = tvend - tvstart + 1;
int duration = static_cast<int>(tvend - tvstart + 1);

if (ChSelect->SelectedIndex > min(tv_draw.ch, bd_draw.ch) - 1) {
ChartTime->Text = "无该声道!";
Expand Down Expand Up @@ -286,8 +286,8 @@ int BDMatch::MyForm::draw_chart()
}
}
}
int bd_spec_offset = (x + bdstart) * bd_draw.fft_num / 2 + bd_draw.fft_num - 1;
int tv_spec_offset = (x + tvstart) * tv_draw.fft_num / 2 + tv_draw.fft_num / 2 - 1;
int64_t bd_spec_offset = (x + bdstart) * bd_draw.fft_num / 2 + bd_draw.fft_num - 1;
int64_t tv_spec_offset = (x + tvstart) * tv_draw.fft_num / 2 + tv_draw.fft_num / 2 - 1;
int pos_offset = 0;
for (y = 0; y < tv_draw.fft_num; y++) {
int color = -128;
Expand Down
9 changes: 5 additions & 4 deletions BDMatch/MyForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Settings.h"
#pragma unmanaged
#include "headers/user interface.h"
#include <cstdint>
#pragma managed

namespace BDMatch {
Expand Down Expand Up @@ -40,14 +41,14 @@ namespace BDMatch {
}
}
private: ref struct drawpara {
int num = 0;
int64_t num = 0;
int ch = 0;
int milisec = 0;
int line_num = 0;
int64_t milisec = 0;
int64_t line_num = 0;
int fft_num = 0;
double ttf = 1.0;//Time to Frequency
char** spec = nullptr;
array<int, 2>^ time_list = nullptr;
array<int64_t, 2>^ time_list = nullptr;
};
private:
SettingVals ^ setting = gcnew SettingVals;
Expand Down
Binary file modified BDMatchCore/BDMatchCore.aps
Binary file not shown.
4 changes: 2 additions & 2 deletions BDMatchCore/BDMatchCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ size_t BDMatchCore::get_nb_timeline()
if (match)return match->get_nb_timeline();
else return 0;
}
int BDMatchCore::get_timeline(const int & index, const Match::Timeline_Time_Type& type)
int64_t BDMatchCore::get_timeline(const int & index, const Match::Timeline_Time_Type& type)
{
if (match)return match->get_timeline(index, type);
else return -1;
}

int BDMatchCore::get_decode_info(const Decode::Decode_File & file, const Decode::Decode_Info & type)
int64_t BDMatchCore::get_decode_info(const Decode::Decode_File & file, const Decode::Decode_Info & type)
{
Decode::Decode *decode_ptr;
if (file == Decode::Decode_File::BD_Decode)decode_ptr = bd_decode.get();
Expand Down
Binary file modified BDMatchCore/BDMatchCore.rc
Binary file not shown.
6 changes: 3 additions & 3 deletions BDMatchCore/BDMatchCoreAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// No need for platform other than Windows
#include "include/BDMatchCoreAPI.h"
#include "headers/BDMatchCore.h"
#include "include/instructionset.h"
#include "include/BDMatchCoreAPI.h"

std::unique_ptr<BDMatchCore> match_core;
const InstructionSet::InstructionSet_Internal InstructionSet::CPU_Rep;
Expand Down Expand Up @@ -65,12 +65,12 @@ BDMatchCore_API size_t BDMatchCoreAPI::get_nb_timeline()
return match_core->get_nb_timeline();
}

BDMatchCore_API int BDMatchCoreAPI::get_timeline(const int& index, const Match::Timeline_Time_Type& type)
BDMatchCore_API int64_t BDMatchCoreAPI::get_timeline(const int& index, const Match::Timeline_Time_Type& type)
{
return match_core->get_timeline(index, type);
}

BDMatchCore_API int BDMatchCoreAPI::get_decode_info(const Decode::Decode_File& file, const Decode::Decode_Info& type)
BDMatchCore_API int64_t BDMatchCoreAPI::get_decode_info(const Decode::Decode_File& file, const Decode::Decode_Info& type)
{
return match_core->get_decode_info(file, type);
}
Expand Down
4 changes: 2 additions & 2 deletions BDMatchCore/CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ A simple example of command line usage of BDMatchCore
#include <iostream>
#include "headers/BDMatchCore.h"

constexpr const char* version = "1.0.18";
constexpr const char* version = "1.0.19";

void print(const char* in, const long long len) {
void print(const char* in, const int64_t len) {
std::cout << in;
}

Expand Down
2 changes: 1 addition & 1 deletion BDMatchCore/datastruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ char * DataStruct::node::getdata()

int DataStruct::node::sum()
{
if (sumval == -2147483647) {
if (sumval == std::numeric_limits<int>::min()) {
sumval = 0;
for (int i = 0; i < count; i++) {
sumval += data[i];
Expand Down
53 changes: 27 additions & 26 deletions BDMatchCore/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int Decode::Decode::initialize(const std::string & file_name0)
else if (audio_stream == 0) {
audio_only = true;
}
milisec = static_cast<int>(ceil(ffmpeg->filefm->duration / 10000));
milisec = static_cast<int64_t>(ffmpeg->filefm->duration / 10000);
ffmpeg->codec = avcodec_find_decoder(ffmpeg->filefm->streams[audio_stream]->codecpar->codec_id);//寻找解码器
if (!ffmpeg->codec)
{
Expand Down Expand Up @@ -262,7 +262,7 @@ int Decode::Decode::decode_audio() {
if (ffmpeg->codecfm->sample_fmt == AV_SAMPLE_FMT_FLT || ffmpeg->codecfm->sample_fmt == AV_SAMPLE_FMT_FLTP) sample_type = 1;
else if (ffmpeg->codecfm->sample_fmt == AV_SAMPLE_FMT_DBL || ffmpeg->codecfm->sample_fmt == AV_SAMPLE_FMT_DBLP) sample_type = 2;
//采样变量
int samplenum = 0;
int64_t samplenum = 0;
c_min_db = 256.0 / (MaxdB - static_cast<double>(min_db));
//重采样变量2
ffmpeg->dst_data = nullptr;
Expand Down Expand Up @@ -296,9 +296,9 @@ int Decode::Decode::decode_audio() {
}
}
else {
samplenum = static_cast<int>(ceil(sample_rate / 1000.0*ffmpeg->filefm->duration / 1000.0));
samplenum = static_cast<int64_t>(ceil(sample_rate / 1000.0 * ffmpeg->filefm->duration / 1000.0));
}
e_fft_num = static_cast<int>(ceil(samplenum / float(fft_num)));//estimated_fft_num
e_fft_num = static_cast<int64_t>(ceil(samplenum / static_cast<double>(fft_num)));//estimated_fft_num
//查询音频封装格式
ffmpeg->packet = av_packet_alloc();
std::string chfmt = "Packed";
Expand All @@ -320,7 +320,7 @@ int Decode::Decode::decode_audio() {
fft_data[i] = fft_data_mem + i * size_t(e_fft_num);
fft_spec[i] = fft_spec_mem + i * size_t(e_fft_num) * spectrum_size;
char* index = fft_spec[i];
for (int j = 0; j < e_fft_num; j++, index += spectrum_size) {
for (int64_t j = 0; j < e_fft_num; j++, index += spectrum_size) {
fft_data[i][j].init_data(spectrum_size, index);
}
}
Expand Down Expand Up @@ -427,9 +427,9 @@ int Decode::Decode::decode_audio() {
}
if (vol_mode != 1) {
if (nb_fft_sample > 0) {
int fft_index = fft_samp_num;
int64_t fft_index = fft_samp_num;
if (fft_index < e_fft_num) {
if (fft_index + nb_fft_sample > e_fft_num)nb_fft_sample = e_fft_num - fft_index;
if (fft_index + nb_fft_sample > e_fft_num)nb_fft_sample = static_cast<int>(e_fft_num - fft_index);
fft_samp_num += nb_fft_sample;
pool.execute(std::bind(&Decode::Decode::FFT, this, fft_data, normalized_samples, fft_index, nb_fft_sample));
}
Expand Down Expand Up @@ -514,11 +514,11 @@ int Decode::Decode::get_return()
{
return return_val;
}
int Decode::Decode::get_fft_samp_num()
int64_t Decode::Decode::get_fft_samp_num()
{
return fft_samp_num;
}
int Decode::Decode::get_milisec()
int64_t Decode::Decode::get_milisec()
{
return milisec;
}
Expand Down Expand Up @@ -627,7 +627,7 @@ int Decode::Decode::normalize(uint8_t ** const &audiodata, double **&normalized_
transfer_audio_data_planar<int>(audiodata, normalized_samples, seqs, nb_last, nb_last_next, length);
break;
case 64:
transfer_audio_data_planar<long long>(audiodata, normalized_samples, seqs, nb_last, nb_last_next, length);
transfer_audio_data_planar<int64_t>(audiodata, normalized_samples, seqs, nb_last, nb_last_next, length);
break;
default:
break;
Expand All @@ -654,7 +654,7 @@ int Decode::Decode::normalize(uint8_t ** const &audiodata, double **&normalized_
transfer_audio_data_packed<int>(audiodata, normalized_samples, seqs, nb_last, nb_last_next, length);
break;
case 64:
transfer_audio_data_packed<long long>(audiodata, normalized_samples, seqs, nb_last, nb_last_next, length);
transfer_audio_data_packed<int64_t>(audiodata, normalized_samples, seqs, nb_last, nb_last_next, length);
break;
default:
break;
Expand Down Expand Up @@ -719,9 +719,9 @@ int Decode::Decode::FD8(double * inseq, DataStruct::node * outseq)
addx = 10.0 * log10(addx);
addx -= MaxdB;
addx *= c_min_db;
addx += 127.0;
addx = std::min(addx, 127.0);
addx = std::max(addx, -128.0);
addx += static_cast<double>(std::numeric_limits<char>::max());
addx = std::min(addx, static_cast<double>(std::numeric_limits<char>::max()));
addx = std::max(addx, static_cast<double>(std::numeric_limits<char>::min()));
addx = round(addx);
out[i] = static_cast<char>(addx);
}
Expand Down Expand Up @@ -758,8 +758,8 @@ int Decode::Decode_SSE::FD8(double * inseq, DataStruct::node * outseq)
__m128d const10 = _mm_set1_pd(10.0);
__m128d const_maxdb = _mm_set1_pd(MaxdB);
__m128d const_mindb = _mm_set1_pd(c_min_db);
__m128d const127 = _mm_set1_pd(127.0);
__m128d constm128 = _mm_set1_pd(-128.0);
__m128d const127 = _mm_set1_pd(static_cast<double>(std::numeric_limits<char>::max()));
__m128d constm128 = _mm_set1_pd(static_cast<double>(std::numeric_limits<char>::min()));
for (int i = 0; i < fft_num / 4; i++) {
__m128d seq1 = _mm_load_pd(inseq);
__m128d seq2 = _mm_load_pd(inseq + 2);
Expand Down Expand Up @@ -812,8 +812,8 @@ int Decode::Decode_AVX::FD8(double * inseq, DataStruct::node * outseq)
__m256d const10 = _mm256_set1_pd(10.0);
__m256d const_maxdb = _mm256_set1_pd(MaxdB);
__m256d const_mindb = _mm256_set1_pd(c_min_db);
__m256d const127 = _mm256_set1_pd(127.0);
__m256d constm128 = _mm256_set1_pd(-128.0);
__m256d const127 = _mm256_set1_pd(static_cast<double>(std::numeric_limits<char>::max())); // 127
__m256d constm128 = _mm256_set1_pd(static_cast<double>(std::numeric_limits<char>::min())); // -128
for (int i = 0; i < fft_num / 8; i++) {
__m256d seq1 = _mm256_load_pd(inseq);
__m256d seq2 = _mm256_load_pd(inseq + 4);
Expand Down Expand Up @@ -858,7 +858,8 @@ inline int Decode::Decode_AVX2::transfer_audio_data_planar_float(uint8_t** const
int threshold = nb_to_norm / 8;
int remainder = nb_to_norm % 8;
float* tempf = reinterpret_cast<float*>(audiodata[ch]);
double* tempd = normalized_samples[ch] + index;
double* tempd = nullptr;
if (normalized_samples)tempd = normalized_samples[ch] + index;
double* temp_seq = seqs[ch] + index2;
for (int i = 0; i < threshold; i++) {
__m256 temp256 = _mm256_load_ps(tempf);
Expand Down Expand Up @@ -1297,7 +1298,7 @@ inline int Decode::Decode_AVX2::transfer_audio_data_packed_int32(uint8_t** const
int ch = 0;
int* tempi32 = reinterpret_cast<int*>(audiodata[0]);
__m256i* temp256 = reinterpret_cast<__m256i*>(audiodata[0]);
__m256d const32 = _mm256_set1_pd(1.0 / 2147483647.0);
__m256d const32 = _mm256_set1_pd(1.0 / static_cast<double>(std::numeric_limits<int>::max()));
int avxlength = nb_samples * channels / 8;
int avx_last = (nb_samples * channels) % 8;
int nb_to_norm = std::max(length - nb_last, 0);
Expand Down Expand Up @@ -1394,14 +1395,14 @@ inline int Decode::Decode_AVX2::transfer_audio_data_packed_int32(uint8_t** const
}
for (int i = 0; i < avx_last; i++) {
if (index < length) {
normalized_samples[ch++][index] = static_cast<double>(*(tempi32++)) / 2147483647.0;
normalized_samples[ch++][index] = static_cast<double>(*(tempi32++)) / static_cast<double>(std::numeric_limits<int>::max());
if (ch == channels) {
ch = 0;
index++;
}
}
else {
seqs[ch++][index2] = static_cast<double>(*(tempi32++)) / 2147483647.0;
seqs[ch++][index2] = static_cast<double>(*(tempi32++)) / static_cast<double>(std::numeric_limits<int>::max());
if (ch == channels) {
ch = 0;
index2++;
Expand Down Expand Up @@ -1442,7 +1443,7 @@ int Decode::Decode_AVX2::normalize(uint8_t** const& audiodata, double**& normali
transfer_audio_data_planar<int>(audiodata, normalized_samples, seqs, nb_last, nb_last_next, length);
break;
case 64:
transfer_audio_data_planar<long long>(audiodata, normalized_samples, seqs, nb_last, nb_last_next, length);
transfer_audio_data_planar<int64_t>(audiodata, normalized_samples, seqs, nb_last, nb_last_next, length);
break;
default:
break;
Expand All @@ -1469,7 +1470,7 @@ int Decode::Decode_AVX2::normalize(uint8_t** const& audiodata, double**& normali
transfer_audio_data_packed_int32(audiodata, normalized_samples, seqs, nb_last, length, nb_samples);
break;
case 64:
transfer_audio_data_packed<long long>(audiodata, normalized_samples, seqs, nb_last, nb_last_next, length);
transfer_audio_data_packed<int64_t>(audiodata, normalized_samples, seqs, nb_last, nb_last_next, length);
break;
default:
break;
Expand Down Expand Up @@ -1538,8 +1539,8 @@ int Decode::Decode_AVX2::FD8(double * inseq, DataStruct::node * outseq)
__m256d const10 = _mm256_set1_pd(10.0);
__m256d const_maxdb = _mm256_set1_pd(MaxdB);
__m256d const_mindb = _mm256_set1_pd(c_min_db);
__m256d const127 = _mm256_set1_pd(127.0);
__m256d constm128 = _mm256_set1_pd(-128.0);
__m256d const127 = _mm256_set1_pd(static_cast<double>(std::numeric_limits<char>::max())); // 127
__m256d constm128 = _mm256_set1_pd(static_cast<double>(std::numeric_limits<char>::min())); // -128
for (int i = 0; i < fft_num / 8; i++) {
__m256d seq1 = _mm256_load_pd(inseq);
__m256d seq2 = _mm256_load_pd(inseq + 4);
Expand Down
6 changes: 3 additions & 3 deletions BDMatchCore/headers/BDMatchCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "language_pack.h"

typedef void(*prog_func)(int, double);
typedef void(*feedback_func)(const char*, const long long len);
typedef void(*feedback_func)(const char*, const int64_t len);

enum class Procedure { Decode = 4, Match = 6 };

Expand All @@ -25,8 +25,8 @@ class BDMatchCore {
int match_2(const char* output_path0);
int clear_match();
size_t get_nb_timeline();
int get_timeline(const int& index, const Match::Timeline_Time_Type& type);
int get_decode_info(const Decode::Decode_File& file, const Decode::Decode_Info& type);
int64_t get_timeline(const int& index, const Match::Timeline_Time_Type& type);
int64_t get_decode_info(const Decode::Decode_File& file, const Decode::Decode_Info& type);
char** get_decode_spec(const Decode::Decode_File& file);
int start_process();
int stop_process();
Expand Down
Loading

0 comments on commit 9f8c939

Please sign in to comment.