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 be20 * log(rms)
as I am converting amplitude to decibels (as a measure of outputted power).
原文:https://stackoverflow.com/questions/32792308
最满意答案
在按钮的方法中,创建新视图并将其添加为子视图。 将
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 ...
-
在UIViews之间拖动UIView(Drag UIView between UIViews)[2023-09-02]
调用[[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]; ...
-
Swift:动态UIView在调整大小后将UIViews推到它下面(Swift: Dynamic UIView that pushes UIViews below it after a resize)[2023-08-06]
这可能吗? 是的,这可以使用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 = ...
-
过渡UIViews(Transitioning UIViews)[2022-05-07]
以下几行解决了我的问题: #define DegreesToRadians(x) ((x) * M_PI / 180.0) CGRect screenRect = [[UIScreen mainScreen]bounds]; myViewController1.view.transform = CGAffineTransformMakeRotation(DegreesToRadians(90)); myViewController1.view.hidden = false; myViewControlle ... -
覆盖UIViews(Overlaying UIViews)[2023-03-27]
你应该使用[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 ...