aud_test.c

#include "aud_media.h"
#include "aud_app.h"
/******************************测试接口****************************************/
/*
测试用例:
	2:start_audio_app()调用测试接口
*/


/*录音本地测试:    传入需要录制文件的大小,录制完成后自动播放,测试本地录音的功能性*/
/*测试结果:   录制完成后,可以正常播放录音*/

struct t_pcm_file  g_rec_pcm_file = { 0 };
static void  create_rec_file(void);
u32  test_media_size = 0;

BOOL recorder_test_mode = FALSE;

void record_test(u32 vp_rec_size_kByte)
{

	BOOL ret = FALSE;
	recorder_test_mode = TRUE;
	/*创建录音存储文件*/
	test_media_size = vp_rec_size_kByte;
	create_rec_file();
	ret = pfv_StartRec(1, 8000, 16, "D9A");
	if (ret)
	{
		printf("start test record  success...............\r\n");
	}
	else
	{
		pfv_StopRec();
		fclose(g_rec_pcm_file.m_fp);
		remove(g_rec_pcm_file.m_filename);
		memset(&g_rec_pcm_file, 0, sizeof(struct  t_pcm_file));
		printf("start test record  failed...............\r\n");

		recorder_test_mode = FALSE;
		
	}
}


base_EEventResult Frm_OnRecData_testMode(const u8 *pp_Pcm_Data, u32 vp_DataLen, t_ywCbContext vp_Ctx)
{
	u32 writesize = 0;
	if (g_rec_pcm_file.m_fp)
	{
		writesize = fwrite(pp_Pcm_Data, 1, vp_DataLen, g_rec_pcm_file.m_fp);
		g_rec_pcm_file.m_FileSize = writesize;
		g_rec_pcm_file.m_FileTotalSize += g_rec_pcm_file.m_FileSize;
		printf("record data rev:%uByte  write: %uByte    mFileTotalSize = %uByte \r\n", vp_DataLen, g_rec_pcm_file.m_FileSize, g_rec_pcm_file.m_FileTotalSize);
		if (g_rec_pcm_file.m_FileTotalSize >= (u32)(test_media_size * 1024))
		{
			printf("mFileTotalSize > %u kByte \r\n",test_media_size);
			pfv_StopRec();

			/*播放录音文件*/
			aud_amp_poweron();
			printf(">>>>>>>>>>>>>>>>>>>g_rec_pcm_file  mFileTotalSize = %uByte<<<<<<<<<<<<<<<<<<<<< \r\n", g_rec_pcm_file.m_FileTotalSize);
			pfv_PlayPcmFile(g_rec_pcm_file.m_filename, 1, 8000, 16);
			fclose(g_rec_pcm_file.m_fp);
			remove(g_rec_pcm_file.m_filename);
			memset(&g_rec_pcm_file, 0, sizeof(struct  t_pcm_file));

			recorder_test_mode = FALSE;
		}
	}

	return base_cbrOk;
}

static void  create_rec_file(void)
{
	/*创建音频文件*/
	g_rec_pcm_file.m_filename = "rec_media";
	g_rec_pcm_file.m_FileTotalSize = 0;
	g_rec_pcm_file.m_Crc = 0;
	g_rec_pcm_file.m_MediaId = 0;
	g_rec_pcm_file.m_Format = PCM_FMT;
	int pcm_ret = pcmfile_create(&g_rec_pcm_file, PCM_FMT);
	if (pcm_ret == 0)
	{
		printf("rec_media file create success. \r\n");
	}
	else
	{
		printf("rec_media file create failed. \r\n");
	}

}

 

import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader, TensorDataset import numpy as np import os # 设置随机种子以保证可重复性 torch.manual_seed(42) np.random.seed(42) # 定义扩散模型的参数 NUM_STEPS = 1000 # 扩散步数 BETA_START = 0.0001 BETA_END = 0.02 BETA_SCHEDULE = "linear" # 计算扩散过程中的β值 betas = torch.linspace(BETA_START, BETA_END, NUM_STEPS) alphas = 1 - betas alpha_bar = torch.cumprod(alphas, dim=0) # 数据加载类 class LoadData: def __init__(self, sub): self.features_path = "/home/C/wwx/xc/EAV/EAV-main/EAV-main/features_extract" self.x1 = np.load(os.path.join(self.features_path, f"EEG/features_eeg_sub{sub:02d}.npy")) # 400*60 self.x2 = np.load(os.path.join(self.features_path, f"Audio/features_aud_sub{sub:02d}.npy")) # 400*768 self.x3 = np.load(os.path.join(self.features_path, f"Vision/features_vis_sub{sub:02d}.npy")) # 400*19200 self.labels = np.load(os.path.join(self.features_path, f"labels/features_labels_sub{sub:02d}.npy")) self.x3 = self.downsample_vis() print(self.x3.shape) def downsample_vis(self): selected_x3 = [] for i in range(0, len(self.x3), 25): group = self.x3[i:i + 25] # 提取当前组 sample = np.concatenate(group, axis=0) selected_x3.append(sample) selected_x3 = np.array(selected_x3) assert selected_x3.shape[0] == self.x1.shape[0] == self.x2.shape[0] == self.labels.shape[0] return selected_x3.astype(np.float32) # 数据划分函数 def split_data(x1, x2, x3, y, h_idx=40): y = y.flatten() features1, features2, features3, labels = [], [], [], [] for class_idx in range(5): # Assuming there are 5 classes class_mask = np.where(y == class_idx)[0] class_features1 = x1[class_mask] class_features2 = x2[class_mask] class_features3 = x3[class_mask] class_labels = y[class_mask] features1.append(class_features1) features2.ap另外我发现一点:你没有把模型和数据传到GPU
03-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值