pythonint函数的参数_向嵌入的Python函数传递两个参数(int和array)

我需要从我的模块中调用Python函数并为其设置两个参数:int和array。在

现在我在调用这个函数的时候遇到了segfault,我不知道我做错了什么。有人能指出我的错误在哪里吗?在

函数在我的Python模块中应用程序副本. 如果我从Python代码调用它,它会起作用:def get_model(rate, signal):

mfcc_train = MFCC().compute(rate, signal)

with open('mfcc_test', 'wb') as f:

pickle.dump(mfcc_train, f)

return clf()._fit(mfcc_train)

调用上面函数的C代码。最后一个春天是“打电话前”

^{pr2}$

UPD:更新代码,其中一个问题已修复。但另一个问题仍然存在。它在PyObject* pSamples = PyArray_SimpleNewFromData(1, dims, NPY_INT8, (void*)samples);行。我也不知道是怎么回事。在

和wav.h以防万一:#include

#include

#include

#include

#include

#include

typedef struct {

char chunk_id[4];

uint32_t chunk_size;

char format[4];

char fmtchunk_id[4];

uint32_t fmtchunk_size;

uint16_t audio_format;

uint16_t num_channels;

uint32_t sample_rate;

uint32_t byte_rate;

uint16_t block_align;

uint16_t bps;

char datachunk_id[4];

uint32_t datachunk_size;

}WavHeader;

WavHeader *header;

void wavread(char *file_name, int16_t **samples)

{

int fd;

if (!file_name)

errx(1, "Filename not specified");

if ((fd = open(file_name, O_RDONLY)) < 1)

errx(1, "Error opening file");

if (!header)

header = (WavHeader*)malloc(sizeof(WavHeader));

if (read(fd, header, sizeof(WavHeader)) < sizeof(WavHeader))

errx(1, "File broken: header");

if (strncmp(header->chunk_id, "RIFF", 4) ||

strncmp(header->format, "WAVE", 4))

errx(1, "Not a wav file");

if (header->audio_format != 1)

errx(1, "Only PCM encoding supported");

if (*samples) free(*samples);

*samples = (int16_t*)malloc(header->datachunk_size);

if (!*samples)

errx(1, "Error allocating memory");

if (read(fd, *samples, header->datachunk_size) < header->datachunk_size)

errx(1, "File broken: samples");

close(fd);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值