日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ccs读取dat文件c语言程序,TMS320DM642学习----第六篇(CCS中.dat文件类型详解)

發(fā)布時間:2024/9/27 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ccs读取dat文件c语言程序,TMS320DM642学习----第六篇(CCS中.dat文件类型详解) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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

如下例子中的數(shù)據(jù):

1 1651 2 8cc0 0 1a70c2 793 744 745 676 ...7 ...

第一行的數(shù)據(jù)為:1651 2 8cc0 0 1a70c

1651標志著這是TI的.dat文件的格式。

2表示了這個文件中的數(shù)據(jù)是整數(shù)格式的,比如第二行的數(shù)據(jù)79是interger的格式。

8cc0表示這段數(shù)據(jù)Load Memory到CCS軟件的過程中,是加載到0x8cc0對應的地址上的。

0表示這段數(shù)據(jù)將加載到page0的位置上。

1a70c表示這段數(shù)據(jù)的總長度為0x1a70c(Hex) = 108300(Decimal)

2、創(chuàng)建圖像對應的.dat文件:

如下的圖片,轉(zhuǎn)換為190*190大小的圖片,并生成對應的.dat文件.

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

1 importcv22 importglob3 Path = glob.glob('*.jpg')4 count =05 for Pic inPath: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'+'\n')12 width,height = res.shape[:2]13 for channel in range(3):14 for row inrange(height):15 for col inrange(width):16 fid.write(str(res[row][col][channel])+'\n')17 count += 1

將上述代碼以及要處理的圖片拷貝到同一個目錄下,雙擊運行python腳本文件即可生成:

我們可以通過修改代碼中的190*190的圖像尺寸來生成不同的圖像數(shù)據(jù),并生成對應的.dat文件。

3、創(chuàng)建音頻對應的.dat文件:

如下鏈接中的單音音源sin.wav,生成對應的.dat文件.

Code(文件名Audio2Dat.py):

1 from scipy.io.wavfile importwrite, read2 importnumpy as np3 importmath4 importglob5 importsys6 importos7

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 defwavread(filename):14 """

15 Read a sound file and convert it to a normalized floating point array16 filename: name of file to read17 returns fs: sampling rate of file, x: floating point array18 """

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 returnfs, x33

34 path = glob.glob('*.wav')35 count = 1

36 for p inpath: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'+'\n')42 for i indat:43 fid.write(str(i)+'\n')44 fid.close()45 count += 1

將上述代碼以及要處理的圖片拷貝到同一個目錄下,雙擊運行python腳本文件即可生成.dat文件:

結果如下:

1 1651 9 80000000 0 7a120 5

2 0.0

3 0.05011866

4 0.10004042

5 0.14956915

6 0.19851027

7 ...8 ...

參考內(nèi)容:

總結

以上是生活随笔為你收集整理的ccs读取dat文件c语言程序,TMS320DM642学习----第六篇(CCS中.dat文件类型详解)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。