小编Jac*_*man的帖子

复制方法 IMP 以进行多个方法混合

我设置了一个类,理想情况下将读取传入的任何类的方法,然后在运行时将它们全部映射到单个选择器,然后将它们转发到原始选择器。

这现在确实有效,但我一次只能使用一种方法。问题似乎是,一旦我调整第一个方法,我用于捕获和转发该方法的 IMP 现在已与其他方法 IMP 交换。任何进一步的尝试都会搞砸,因为他们使用新交换的 IMP 来替换其他 IMP。

1)所以我有MethodA、MethodB和CustomCatchAllMethod。

2)我将 MethodA 与 CustomCatchAllMethod 交换。方法A->自定义CatchAll方法,自定义CatchAll方法->方法A

3)现在我尝试用CustomCatchAllMethod交换到MethodB,但是由于CustomCatchAllMethod现在= MethodA,MethodB变成MethodA和MethodA->MethodB。

那么,如何为每个我想要拦截的新选择器获取/复制 IMP 的新实例呢?

这是上述流程的粗略模型:

void swizzle(Class classImCopying, SEL orig){
 SEL new = @selector(catchAll:);
 Method origMethod = class_getInstanceMethod(classImCopying, orig);
 Method newMethod = class_getInstanceMethod(catchAllClass,new);
 method_exchangeImplementations(origMethod, newMethod);
}

//In some method elsewhere

//I want this to make both methodA and methodB point to catchAll:
swizzle(someClass, @selector(methodA:));
swizzle(someClass, @selector(methodB:));
Run Code Online (Sandbox Code Playgroud)

objective-c objective-c-runtime swizzling ios

5
推荐指数
1
解决办法
1341
查看次数

从覆盆子pi上的ADC芯片读取原始音频值

我将MCP3008 ADC芯片连接到驻极体麦克风和我的pi.我在python中使用bit-banging读取输入,我得到一个0-1024的整数.

我按照本教程进行了比特操作:https://learn.adafruit.com/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi/connecting-the-cobbler -to-A-mcp3008

我的问题是如何取这个整数并将其转换为有意义的东西?我可以以某种方式将这些字节写入python中的文件,以获取Audacity可以播放的原始音频数据吗?现在,当我尝试写入值时,它们只显示为整数而不是二进制.我是python的新手,我发现这个链接用于转换原始数据,但是我在生成原始数据时遇到了麻烦:Python打开原始音频数据文件

我甚至不确定这些值代表什么,他们是PCM数据,我必须做与时间有关的数学?

python audio adc raspberry-pi

5
推荐指数
1
解决办法
2543
查看次数