Skip to content

Commit

Permalink
Merge pull request #535 from ElderOrb/yaxis
Browse files Browse the repository at this point in the history
Scriptable min/max for y-axis
  • Loading branch information
dericed authored Apr 25, 2018
2 parents cc4e181 + 1f15222 commit a69596c
Show file tree
Hide file tree
Showing 19 changed files with 237 additions and 115 deletions.
10 changes: 5 additions & 5 deletions Source/Core/AudioCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct per_group AudioPerGroup [Group_AudioMax]=
{
//R128
{
Item_R128M, 1, -70, 0, 3, "R.128", false,
Item_R128M, 1, "-70", "0", 3, "R.128", false,
"R 128 refers to a European Broadcasting Union (EBU) specification\n"
"document governing several loudness parameters, including momentary,\n"
"integrated, and short-term loudness. QCTools specifically examines momentary\n"
Expand All @@ -23,15 +23,15 @@ struct per_group AudioPerGroup [Group_AudioMax]=
},
//aphasemeter
{
Item_aphasemeter, 1, -1, 1, 3, "Audio Phase", false,
Item_aphasemeter, 1, "-1", "1", 3, "Audio Phase", false,
"The audio phase value represents the mean phase of current audio frame. Value is\n"
"in range [-1, 1]. The -1 means left and right channels are completely out of\n"
"phase and 1 means channels are in phase.",
ActiveFilter_Audio_aphasemeter,
},
//astats levels
{
Item_DC_offset, 3, -1, 1, 3, "Levels", true,
Item_DC_offset, 3, "-1", "1", 3, "Levels", true,
"For selected audio tracks this graph plots the DC offset (mean\n"
"amplitude displacement from zero), minimal sample level, and \n"
"maximum sample level. Note that this value is plotted per audio\n"
Expand All @@ -40,7 +40,7 @@ struct per_group AudioPerGroup [Group_AudioMax]=
},
//astats diff
{
Item_Min_difference, 3, 0, 1, 3, "Aud Diffs", false,
Item_Min_difference, 3, "0", "1", 3, "Aud Diffs", false,
"For selected audio tracks this graph plots the minimal difference\n"
"between two consecutive samples, maximal difference between two\n"
"consecutive samples. and the mean difference between two consecutive\n"
Expand All @@ -52,7 +52,7 @@ struct per_group AudioPerGroup [Group_AudioMax]=
},
//astats rms
{
Item_Peak_level, 3, -70, 0, 3, "RMS", false,
Item_Peak_level, 3, "-70", "0", 3, "RMS", false,
"For selected audio tracks this graph plots the Standard peak and RMS\n"
"level measured in dBFS and the Peak and trough values for RMS level\n"
"measured over a short window. Note that this value is plotted per\n"
Expand Down
51 changes: 22 additions & 29 deletions Source/Core/AudioStreamStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ using namespace tinyxml2;
AudioStreamStats::AudioStreamStats(XMLElement *streamElement) : CommonStreamStats(streamElement),
sample_rate(0),
channels(0),
bits_per_sample(0),
bits_per_raw_sample(0)
bits_per_sample(0)
{
codec_type = "audio";
stream_type = AVMEDIA_TYPE_AUDIO;

const char* sample_fmt_value = streamElement->Attribute("sample_fmt");
if(sample_fmt_value)
sample_fmt = sample_fmt_value;
if(sample_fmt_value) {
sample_fmt = av_get_sample_fmt(sample_fmt_value);
sample_fmt_string = sample_fmt_value;
}

const char* sample_rate_value = streamElement->Attribute("sample_rate");
if(sample_rate_value)
Expand All @@ -59,31 +61,28 @@ AudioStreamStats::AudioStreamStats(XMLElement *streamElement) : CommonStreamStat
const char* bits_per_sample_value = streamElement->Attribute("bits_per_sample");
if(bits_per_sample_value)
bits_per_sample = std::stoi(bits_per_sample_value);

const char* bits_per_raw_sample_value = streamElement->Attribute("bits_per_raw_sample");
if(bits_per_raw_sample_value)
bits_per_raw_sample = std::stoi(bits_per_raw_sample_value);
}

AudioStreamStats::AudioStreamStats(AVStream* stream, AVFormatContext *context) : CommonStreamStats(stream),
sample_fmt(""),
sample_fmt_string(""),
sample_rate(stream != NULL ? stream->codecpar->sample_rate : 0),
channels(stream != NULL ? stream->codecpar->channels : 0),
channel_layout(""),
bits_per_sample(stream != NULL ? av_get_bits_per_sample(stream->codecpar->codec_id) : 0),
bits_per_raw_sample(stream != NULL ? stream->codecpar->bits_per_raw_sample : 0)
bits_per_sample(stream != NULL ? av_get_bits_per_sample(stream->codecpar->codec_id) : 0)
{
Q_UNUSED(context);

codec_type = "audio";
stream_type = AVMEDIA_TYPE_AUDIO;

if(stream)
{
const char* s = av_get_sample_fmt_name((AVSampleFormat) stream->codecpar->format);
sample_fmt = stream->codecpar->format;
const char* s = av_get_sample_fmt_name((AVSampleFormat) sample_fmt);
if (s)
sample_fmt = s;
sample_fmt_string = s;
else
sample_fmt = "unknown";
sample_fmt_string = "unknown";

AVBPrint pbuf;
av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
Expand All @@ -106,7 +105,7 @@ void AudioStreamStats::writeStreamInfoToXML(QXmlStreamWriter *writer)

assert(writer);

writer->writeAttribute("sample_fmt", QString::fromStdString(getSample_fmt()));
writer->writeAttribute("sample_fmt", QString::fromStdString(getSample_fmt_string()));
writer->writeAttribute("sample_rate", QString::number(getSample_rate()));
writer->writeAttribute("channels", QString::number(getChannels()));
writer->writeAttribute("channel_layout", QString::fromStdString(getChannel_layout()));
Expand All @@ -116,20 +115,24 @@ void AudioStreamStats::writeStreamInfoToXML(QXmlStreamWriter *writer)
writer->writeAttribute("time_base", QString::fromStdString(getTime_base()));
writer->writeAttribute("start_pts", QString::fromStdString(getStart_pts()));
writer->writeAttribute("start_time", QString::fromStdString(getStart_time()));
writer->writeAttribute("bits_per_raw_sample", QString::number(getBits_per_raw_sample()));

CommonStreamStats::writeDispositionInfoToXML(writer);
CommonStreamStats::writeMetadataToXML(writer);
}

std::string AudioStreamStats::getSample_fmt() const
int AudioStreamStats::getSample_fmt() const
{
return sample_fmt;
}

void AudioStreamStats::setSample_fmt(const std::string &value)
std::string AudioStreamStats::getSample_fmt_string() const
{
return sample_fmt_string;
}

void AudioStreamStats::setSample_fmt_string(const std::string &value)
{
sample_fmt = value;
sample_fmt_string = value;
}

int AudioStreamStats::getSample_rate() const
Expand Down Expand Up @@ -171,13 +174,3 @@ void AudioStreamStats::setBits_per_sample(int value)
{
bits_per_sample = value;
}

int AudioStreamStats::getBits_per_raw_sample() const
{
return bits_per_raw_sample;
}

void AudioStreamStats::setBits_per_raw_sample(int value)
{
bits_per_raw_sample = value;
}
13 changes: 6 additions & 7 deletions Source/Core/AudioStreamStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class AudioStreamStats : public CommonStreamStats

virtual void writeStreamInfoToXML(QXmlStreamWriter* writer);

std::string getSample_fmt() const;
void setSample_fmt(const std::string &value);
int getSample_fmt() const;

std::string getSample_fmt_string() const;
void setSample_fmt_string(const std::string &value);

int getSample_rate() const;
void setSample_rate(const int &value);
Expand All @@ -41,16 +43,13 @@ class AudioStreamStats : public CommonStreamStats
int getBits_per_sample() const;
void setBits_per_sample(int value);

int getBits_per_raw_sample() const;
void setBits_per_raw_sample(int value);

private:
std::string sample_fmt;
std::string sample_fmt_string;
int sample_fmt;
int sample_rate;
int channels;
std::string channel_layout;
int bits_per_sample;
int bits_per_raw_sample;
};

#endif // AudioStreamStats_H
5 changes: 5 additions & 0 deletions Source/Core/CommonStreamStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ std::string CommonStreamStats::getCodec_Type() const
return codec_type;
}

int CommonStreamStats::getType() const
{
return stream_type;
}

std::string CommonStreamStats::getCodec_Time_Base() const
{
return codec_time_base;
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/CommonStreamStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CommonStreamStats
std::string getCodec_Name() const;
std::string getCodec_Long_Name() const;
std::string getCodec_Type() const;
int getType() const;
std::string getCodec_Time_Base() const;
std::string getCodec_TagString() const;

Expand Down Expand Up @@ -75,6 +76,7 @@ class CommonStreamStats
std::string codec_name;
std::string codec_long_name;
std::string codec_type;
int stream_type;
std::string codec_time_base;
int codec_tag;

Expand Down
9 changes: 3 additions & 6 deletions Source/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,15 @@ struct per_group
{
const std::size_t Start; //Item
const std::size_t Count;
const double Min;
const double Max;
const char* MinFormula;
const char* MaxFormula;
const double StepsCount;
const char* Name;
const bool CheckedByDefault;
const char* Description;
activefilter ActiveFilterGroup;

void setMax(double value) {
(const_cast<double&> (Max)) = value;
}
};

struct per_item
{
const std::size_t Group1; //Group
Expand Down
51 changes: 48 additions & 3 deletions Source/Core/FFmpeg_Glue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2408,11 +2408,11 @@ string FFmpeg_Glue::ColorRange_Get()
}
}

int FFmpeg_Glue::BitsPerRawSample_Get()
int FFmpeg_Glue::BitsPerRawSample_Get(int streamType)
{
inputdata* InputData=NULL;
for (size_t Pos=0; Pos<InputDatas.size(); Pos++)
if (InputDatas[Pos] && InputDatas[Pos]->Type==AVMEDIA_TYPE_VIDEO)
if (InputDatas[Pos] && InputDatas[Pos]->Type==streamType)
{
InputData=InputDatas[Pos];
break;
Expand Down Expand Up @@ -2470,7 +2470,23 @@ string FFmpeg_Glue::SampleFormat_Get()
case AV_SAMPLE_FMT_NB: return "number of sample formats";
default: return string();
}
}
}

int FFmpeg_Glue::sampleFormat()
{
inputdata* InputData=NULL;
for (size_t Pos=0; Pos<InputDatas.size(); Pos++)
if (InputDatas[Pos] && InputDatas[Pos]->Type==AVMEDIA_TYPE_AUDIO)
{
InputData=InputDatas[Pos];
break;
}

if (InputData==NULL || InputData->Stream==NULL || InputData->Stream->codec==NULL)
return AV_SAMPLE_FMT_NONE;

return InputData->Stream->codec->sample_fmt;
}

//---------------------------------------------------------------------------
int FFmpeg_Glue::SamplingRate_Get()
Expand Down Expand Up @@ -2775,6 +2791,35 @@ int FFmpeg_Glue::guessBitsPerRawSampleFromFormat(int pixelFormat)
}
}

int FFmpeg_Glue::bitsPerAudioSample(int audioFormat)
{
return av_get_bytes_per_sample((AVSampleFormat) audioFormat);
}

bool FFmpeg_Glue::isFloatAudioSampleFormat(int audioFormat)
{
return audioFormat == AV_SAMPLE_FMT_FLT
|| audioFormat == AV_SAMPLE_FMT_FLTP
|| audioFormat == AV_SAMPLE_FMT_DBL
|| audioFormat == AV_SAMPLE_FMT_DBLP;
}

bool FFmpeg_Glue::isSignedAudioSampleFormat(int audioFormat)
{
return audioFormat == AV_SAMPLE_FMT_S16
|| audioFormat == AV_SAMPLE_FMT_S16P
|| audioFormat == AV_SAMPLE_FMT_S32
|| audioFormat == AV_SAMPLE_FMT_S32P
|| audioFormat == AV_SAMPLE_FMT_S64
|| audioFormat == AV_SAMPLE_FMT_S64P;
}

bool FFmpeg_Glue::isUnsignedAudioSampleFormat(int audioFormat)
{
return audioFormat == AV_SAMPLE_FMT_U8
|| audioFormat == AV_SAMPLE_FMT_U8P;
}

FFmpeg_Glue::Image::Image()
{

Expand Down
7 changes: 6 additions & 1 deletion Source/Core/FFmpeg_Glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ class FFmpeg_Glue
string PixFormat_Get();
string ColorSpace_Get();
string ColorRange_Get();
int BitsPerRawSample_Get();
int BitsPerRawSample_Get(int streamType = Type_Video);

// Audio information
string AudioFormat_Get();
string SampleFormat_Get();
int sampleFormat();
int SamplingRate_Get();
string ChannelLayout_Get();
int ABitDepth_Get();
Expand All @@ -153,6 +154,10 @@ class FFmpeg_Glue

static QByteArray getAttachment(const QString& fileName, QString& attachmentFileName);
static int guessBitsPerRawSampleFromFormat(int pixelFormat);
static int bitsPerAudioSample(int audioFormat);
static bool isFloatAudioSampleFormat(int audioFormat);
static bool isSignedAudioSampleFormat(int audioFormat);
static bool isUnsignedAudioSampleFormat(int audioFormat);

// Actions
void AddInput_Video(size_t FrameCount, int time_base_num, int time_base_den, int Width, int Height, int BitDepth, bool Compression, int TimecodeBCD=-1);
Expand Down
Loading

0 comments on commit a69596c

Please sign in to comment.