首页 \ 问答 \ gstreamer从缓冲区读取分贝(gstreamer read decibel from buffer)

gstreamer从缓冲区读取分贝(gstreamer read decibel from buffer)

我试图获得传入音频样本的dB级别。 在每个视频帧上,我更新dB级别并绘制一个代表0 - 100%值的条形(0%是任意的,例如-20.0dB,100%是0dB)。

gdouble sum, rms;
sum = 0.0;
guint16 *data_16 = (guint16 *)amap.data;
for (gint i = 0; i < amap.size; i = i + 2)
{
    gdouble sample = ((guint16)data_16[i]) / 32768.0;
    sum += (sample * sample);
}
rms = sqrt(sum / (amap.size / 2));
dB = 10 * log10(rms);

这是从代码示例中修改为C,标记为答案,从这里开始 。 我想知道我从这个非常简单的等式中遗漏了什么。

回答 :夹克是关于失去标志的代码是正确的,所以一切都结果是积极的。 代码10 * log(rms)也不正确。 它应该是20 * log(rms)因为我将幅度转换为分贝(作为输出功率的度量)。


I am trying to get the dB level of incoming audio samples. On every video frame, I update the dB level and draw a bar representing a 0 - 100% value (0% being something arbitrary such as -20.0dB and 100% being 0dB.)

gdouble sum, rms;
sum = 0.0;
guint16 *data_16 = (guint16 *)amap.data;
for (gint i = 0; i < amap.size; i = i + 2)
{
    gdouble sample = ((guint16)data_16[i]) / 32768.0;
    sum += (sample * sample);
}
rms = sqrt(sum / (amap.size / 2));
dB = 10 * log10(rms);

This was adapted to C from a code sample, marked as the answer, from here. I am wondering what it is that I am missing from this very simple equation.

Answered: jacket was correct about the code loosing the sign, so everything ended up being positive. Also the code 10 * log(rms) is incorrect. It should be 20 * log(rms) as I am converting amplitude to decibels (as a measure of outputted power).


原文:https://stackoverflow.com/questions/32792308
更新时间:2023-07-01 10:07

最满意答案

在按钮的方法中,创建新视图并将其添加为子视图。 将frame.origin.x设置为0减去视图的宽度(如果您希望它从左侧推动),使其不可见并将该值更改为您希望它在内部的位置[UIView animateWithDuration:animations:]

[UIView animateWithDuration:1.0 animations:^(void){
    [newView setFrame:({
        CGRect frame = newView.frame;
        frame.origin.x = 150; // If you want it to start at x = 150
        frame;
    })];

    // If you want to move other views too, just add them in this block
}];

如果你没有得到我正在做的设置框架,请查看本文中的第一个提示。


In the method of the button create the new view and add it as a subview. Set the frame.origin.x to 0 minus the width of the view (if you want it to push from the left) so it is not visible and change that value to where you want it to be inside [UIView animateWithDuration:animations:].

[UIView animateWithDuration:1.0 animations:^(void){
    [newView setFrame:({
        CGRect frame = newView.frame;
        frame.origin.x = 150; // If you want it to start at x = 150
        frame;
    })];

    // If you want to move other views too, just add them in this block
}];

If you don't get what I'm doing to set the frame, check out the first tip in this post.

相关问答

更多
  • 在按钮的方法中,创建新视图并将其添加为子视图。 将frame.origin.x设置为0减去视图的宽度(如果您希望它从左侧推动),使其不可见并将该值更改为您希望它在内部的位置[UIView animateWithDuration:animations:] 。 [UIView animateWithDuration:1.0 animations:^(void){ [newView setFrame:({ CGRect frame = newView.frame; fram ...
  • 调用[[touches anyObject] locationInView: self.superview]获取容器视图中手指下的点。 然后发送self.superview -hitTest:withEvent:找出视图X在里面。 请注意,它将始终返回X,因此您必须在拖动时重写-pointIsInside:withEvent:或-hitTest:withEvent:以返回nil。 这种kludge是我在容器视图中实现这种跟踪的原因,而不是在拖动视图中。 Call [[touches anyObject] l ...
  • 您可以在touchesMoved:方法中获取触摸的位置,然后询问主UIView触摸了哪个视图: - (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event { UIView *subview = [masterView hitTest:[[touches anyObject] locationInView:masterView] withEvent:nil]; ... } You can get the location of ...
  • 如果将阵列init更改为以下内容, self.viewArray = [[NSMutableArray alloc] init]; 在将视图添加到阵列之前初始化视图, _question1View = [[UIView alloc] init]; _question2View = [[UIView alloc] init]; _question3View = [[UIView alloc] init]; [viewArray insertObject: _question1View atIndex:0]; ...
  • 这可能吗? 是的,这可以使用autolayout。 这是一个关于如何开始使用autolayout的精彩教程。 这是关于动画自动布局约束更改的简要教程。 如果你正确设置了约束,你应该可以做一些简单的事情: myLabel.sizeToFit() 并且会发生所请求的更改。 我需要导入库吗? 不需要外部库。 然而,你可以在这里看看是否存在类似的东西。 Is this possible? Yes this is possible using autolayout. Here is a great tutorial ...
  • 我通过以下一些基本步骤达到了相同的要求。 //Declare the view which is going to be added as header view let requiredView = UIView() //Add your required view as subview of uicollectionview backgroundView view like as collectionView.backgroundView = UIView() collectionView. ...
  • 首先,创建一些数组来存储所有UIViews及其相关引用的帧。 然后,可能在后台线程中,可以使用阵列中的内容运行一些碰撞测试。 对于仅用于矩形的一些简单碰撞测试,请查看此SO问题: 矩形的简单碰撞算法 希望有所帮助! First, create some array that stores the frames of all of your UIViews and their associated reference. Then, potentially in a background thread, you ...
  • 在这种方法中,你应该写下如下的内容: [view removeFromSuperview]; [scrollView2 addSubview:view]; 编辑 : 对于动画移动,您应该尝试如下所示: CGPoint originalCenter = [self.view convertPoint:view.center fromView:scrollView1]; [view removeFromSuperView]; [self.view addSubview:view]; view.center = ...
  • 以下几行解决了我的问题: #define DegreesToRadians(x) ((x) * M_PI / 180.0) CGRect screenRect = [[UIScreen mainScreen]bounds]; myViewController1.view.transform = CGAffineTransformMakeRotation(DegreesToRadians(90)); myViewController1.view.hidden = false; myViewControlle ...
  • 你应该使用[existingView addSubview:newView]; 将视图添加到现有视图。 newView将出现在existingView的顶部。 因此,从概念上讲,您可以在existingView上创建一个按钮,将其连接到调用如下方法的IBAction: CGRect newSize = CGRectMake(0.0f ,0.0f, 320.f, 400.0f); UIView *newView = [[UIView alloc] initWithFrame:newSize]; [existi ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)