TMS320DM642学习----第六篇(CCS中.dat文件类型详解)

摘要:
1a70c表示数据的总长度为0x1a70c(十六进制)=108300(十进制)2。创建与图像对应的.dat文件:1importcv22importglob3Path=glob.glob('*.jpg')4count=05forPicinPath:res)10fid=open(名称+“.dat”,高度=res.shape[:

1、如下为.dat文件中文件头的基本格式:

MagicNumber Format StartingAddress PageNum Length [NewFormat]

下面是分别的解释:

MagicNumber:1651.

Format:a number from 1 to 4, indicating the format of the samples in the file. This number represents a data format:

  • (1) - hexadecimal,
  • (2) - integer
  • (3) - long
  • (4) - float
  • (9) - Use new scheme 

StartingAddress:starting address of the block that was saved.

PageNum:page number the block was taken from.

Length:number of samples in the block.

NewFormat:Format (9); the new scheme. This is optional when usign the legacy formats 1 - 4

如下例子中的数据:

1 1651 2 8cc0 0 1a70c
2 79
3 74
4 74
5 67
6 ...
7 ...

第一行的数据为:1651 2 8cc0 0 1a70c

1651标志着这是TI的.dat文件的格式。

2表示了这个文件中的数据是整数格式的,比如第二行的数据79是interger的格式。

8cc0表示这段数据Load Memory到CCS软件的过程中,是加载到0x8cc0对应的地址上的。

0表示这段数据将加载到page0的位置上。

1a70c表示这段数据的总长度为0x1a70c(Hex) = 108300(Decimal)

2、创建图像对应的.dat文件:

如下的图片,转换为190*190大小的图片,并生成对应的.dat文件.

TMS320DM642学习----第六篇(CCS中.dat文件类型详解)第1张

 Code(文件名称:_dat_create.py):

 1 import cv2
 2 import glob
 3 Path = glob.glob('*.jpg')
 4 count = 0
 5 for Pic in Path:
 6         I = cv2.imread(Pic)
 7         res = cv2.resize(I,(190,190),interpolation=cv2.INTER_CUBIC)
 8         Name = "Test" + str(count)
 9         cv2.imwrite(Name + ".png",res)
10         fid = open(Name + ".dat",'w')
11         fid.write('1651 2 8cc0 0 1a70c'+'
')
12         width,height = res.shape[:2]
13         for channel in range(3):
14                 for row in range(height):
15                         for col in range(width):
16                                 fid.write(str(res[row][col][channel])+'
')
17         count += 1

将上述代码以及要处理的图片拷贝到同一个目录下,双击运行python脚本文件即可生成:

TMS320DM642学习----第六篇(CCS中.dat文件类型详解)第2张

我们可以通过修改代码中的190*190的图像尺寸来生成不同的图像数据,并生成对应的.dat文件。

3、创建音频对应的.dat文件:

如下链接中的单音音源sin.wav,生成对应的.dat文件.

https://files.cnblogs.com/files/uestc-mm/sin.7z

Code(文件名Audio2Dat.py):

 1 from scipy.io.wavfile import write, read
 2 import numpy as np
 3 import math
 4 import glob
 5 import sys
 6 import os
 7 
 8 INT16_FAC = (2**15)-1
 9 INT32_FAC = (2**31)-1
10 INT64_FAC = (2**63)-1
11 norm_fact = {'int16':INT16_FAC, 'int32':INT32_FAC, 'int64':INT64_FAC,'float32':1.0,'float64':1.0}
12 
13 def wavread(filename):
14     """
15     Read a sound file and convert it to a normalized floating point array
16     filename: name of file to read
17     returns fs: sampling rate of file, x: floating point array
18     """
19     if (os.path.isfile(filename) == False):                  # raise error if wrong input file
20             print("Input file does not exist. Make sure you computed the analysis/synthesis")
21 
22     fs, x = read(filename)
23 
24     if (len(x.shape) !=1):                                   # raise error if more than one channel
25             raise ValueError("Audio file should be mono")
26 
27     if (fs !=44100):                                         # raise error if more than one channel
28             raise ValueError("Sampling rate of input sound should be 44100")
29 
30     #scale down and convert audio into floating point number in range of -1 to 1
31     x = np.float32(x)/norm_fact[x.dtype.name]
32     return fs, x
33 
34 path = glob.glob('*.wav')
35 count = 1
36 for p in path:
37     fs, dat = wavread(str(p))
38 
39     fid = open(str(count)+'.dat','w')
40     # flie·Magic=1651 X=9 data·StartAddress=0x80000000 X=0 data·Number(Hex)=0x7a120 X=5
41     fid.write('1651 9 80000000 0 7a120 5'+'
')
42     for i in dat:
43             fid.write(str(i)+'
')
44     fid.close()
45     count += 1

将上述代码以及要处理的图片拷贝到同一个目录下,双击运行python脚本文件即可生成.dat文件:

TMS320DM642学习----第六篇(CCS中.dat文件类型详解)第3张

结果如下:

1 1651 9 80000000 0 7a120 5
2 0.0
3 0.05011866
4 0.10004042
5 0.14956915
6 0.19851027
7 ...
8 ...

参考内容:

Reference001:来自TI员工的回答,https://e2e.ti.com/support/tools/ccs/f/81/t/789759?tisearch=e2e-sitesearch&keymatch=%20user:332444

Reference002:所有代码,图片-音频打包下载(TI_dat_create.7z),https://files.cnblogs.com/files/uestc-mm/TI_dat_create.7z

免责声明:文章转载自《TMS320DM642学习----第六篇(CCS中.dat文件类型详解)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇EXCEL 如何实现下拉填充公式,保持公式部分内容不变,使用绝对引用GetWindowRect与GetClientRect 的区别 .下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

前端json数据格式化显示

1、格式化处理 1 var obj = "...";//json格式的字符串 2 var jsonPretty = JSON.stringify(JSON.parse(obj),null,2); 2、显示 只需把格式化处理后的json字符串数据放到 pre标签 中即可。 3、demo js代码(直接是对象,所以省略JSON.parse操作) 1 let...

midway日志体系

日常普通使用 首先我们学会 Midway 的日常日志使用方法。 import{Get}from'@midwayjs/decorator'; import{Inject,Controller,Provide}from'@midwayjs/decorator';   @Provide() @Controller() exportclassHelloCont...

python2.7.12操作Hbase

前置条件:您已经安装好Hbase、python2.7题外话:最好自己安装个虚拟环境,以下操作都是在虚拟环境中的(ma) hadoop@master:/usr/local/pycharm/bin$ sudo pip install thrift[sudo] password for hadoop: The directory '/home/hadoop/.c...

Unity中对注册表进行修改

问题背景: PC端软件开发,当我在Unity中的PlayerSetting中设置好分辨率,每次打包运行后会记忆上次退出时窗口的分辨率(记忆窗口状态),导致下次打开时不是PlayerSetting中的初始设置,而是读取注册表记录的数据。而我的需求时必须每次进去时都是指定的那个分辨率。 问题纠结点: 1.注册表信息是否可删,怎么获取到删除 2.也不能直接删除整...

关于winlogo.exe中了“落雪”病毒的解决方法

Windows Logon Process,Windows NT 用户登陆程序,管理用户登录和退出。该进程的正常路径应是 C:WindowsSystem32 且是以 SYSTEM 用户运行,若不是以上路径且不以 SYSTEM 用户运行,则可能是 W32.Netsky.D@mm蠕虫病毒,该病毒通过 EMail 邮件传播,当你打开病毒发送的附件时,即会被感染。...

Ajax取PHP JSON数据并显示

<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-sc...