请选择 进入手机版 | 继续访问电脑版

 找回密码
 立即注册
查看: 494|回复: 3

[求助] 结构体的定义

[复制链接]

4

主题

6

帖子

8

积分
交易币
0

新手入门

Rank: 1

发表于 2021-1-13 22:22:07 | 显示全部楼层 |阅读模式
求问如下这种结构体的定义应该怎么写?

这是我的代码,怎么写都不对,  
[aardio] 纯文本查看 复制代码
	TStreamTime = class {
    int sec;
    int ms;
    int samples;
    union hms = {
        int hour;
        int minute ;
        int second ;
        int millisecond;
    };
	};


原来本身应该是这样的
typedef struct {  unsigned int sec;  unsigned int ms;  unsigned int samples;  TStreamHMSTime hms;} TStreamTime;

typedef struct {  unsigned int hour;  unsigned int minute;  unsigned int second;  unsigned int millisecond;} TStreamHMSTime;
回复

使用道具 举报

0

主题

4

帖子

3

积分
交易币
0

新手入门

Rank: 1

发表于 2021-1-14 00:51:27 | 显示全部楼层
本帖最后由 or1 于 2021-1-14 00:52 编辑

[aardio] 纯文本查看 复制代码
class TStreamTime{
	INT sec;
	INT ms;
	INT samples;
	struct hms = {
    	INT hour;
    	INT minute ;
    	INT second ;
    	INT millisecond;
	};
};


你为什么要把 struct 改为 union ?
另外无符号数在 aardio 里要大写类型名,看看文档里有写。
回复 支持 反对

使用道具 举报

4

主题

6

帖子

8

积分
交易币
0

新手入门

Rank: 1

 楼主| 发表于 2021-1-14 02:09:18 | 显示全部楼层
谢谢指点,我已经改了下,
他里面的是结构体有嵌套

        TStreamHMSTime = class  {
                INT hour;
                INT minute ;
                INT second ;
                INT millisecond;
        }
我的本意是想嵌套进去的,减少代码篇幅, 易于维护,但是不知道怎么嵌套进去.现在改成这样貌似也能用.

        TStreamTime = class {
                INT sec;
                INT ms;
                INT samples;
                struct hms=  {
                        int hour;
                        int minute ;
                        int second ;
                        int millisecond;
                }
        };

另外一个问题 ,
函数参数声明如下,后面是按址传递参数的.

[aardio] 纯文本查看 复制代码
ZPLAY_HANDLE handle  ZPLAY handle. Get this handle with zplay_CreateZPlay.  
int nFFTPoints  Set this value to specify FFT size. This value must be power of 2.  
TFFTWindow nFFTWindow  Set this value to specify FFT window.  
int * pnHarmonicNumber  Pointer to variable receiving number of harmonics returned from FFT analysis. NumberOfHarmonics = (nFFTPoints/2 + 1)  
int * pnHarmonicFreq  Pointer to integer array receiving frequency of each harmonic. User must to allocate memory for this array. Use returned pnHarmonicNumber value to get number of harmonics. If you don't need this information, set this parameter to NULL.
  
int * pnLeftAmplitude  Pointer to integer array receiving amplitude of each harmonic for left channel. Amplitude range is from 0 to about 120 dB. User needs to allocate memory for this array. If you don't need this information, set this parameter to NULL.  
int * pnRightAmplitude  Pointer to integer array receiving amplitude of each harmonic for right channel. Amplitude range is from 0 to about 120 dB. User needs to allocate memory for this array. If you don't need this information, set this parameter to NULL.
  
int * pnLeftPhase  Pointer to integer array receiving phase of each harmonic for left channel. Phase range is from -90 to 90 degrees. User needs to allocate memory for this array. If you don't need this information, set this parameter to NULL.
  
int * pnRightPhase  Pointer to integer array receiving phase of each harmonic for right channel. Phase range is from -90 to 90 degrees. User needs to allocate memory for this array. If you don't need this information, set this parameter to NULL.


我改写两种方式都闪退

第一种
GetFFTData = ::libzplay.api("zplay_GetFFTData","int(int handle, int nFFTPoints, int nFFTWindow, pointer &pnHarmonicNumber, float &pnHarmonicFreq, pointer &pnLeftAmplitude, pointer &pnRightAmplitude, pointer &pnLeftPhase, int[] &pnRightPhase)" );
第二种
[aardio] 纯文本查看 复制代码
   
GetFFTData = function(size=256,t=1){
        var asize = size/2+1;
        
		var pnHarmonicNumber = { INT values = 0 }
		var pnHarmonicFreq = { INT values[]={ length=asize } }
		
		var pnLeftAmplitude = { INT values[]={ length=asize } }
		var pnRightAmplitude = { INT values[]={ length=asize } }
		 
		var pnLeftPhase = { INT values[]={ length=asize } }
		var pnRightPhase = { INT values[]={ length=asize } }
		
        ret = libzplay.zplay_GetFFTData(this.handle,size,t,pnHarmonicNumber,pnHarmonicFreq,pnLeftAmplitude,pnRightAmplitude,pnLeftPhase,pnRightPhase);
		
		return pnHarmonicNumber,pnHarmonicFreq,pnLeftAmplitude,pnRightAmplitude,pnLeftPhase,pnRightPhase;
    };
回复 支持 反对

使用道具 举报

0

主题

4

帖子

3

积分
交易币
0

新手入门

Rank: 1

发表于 2021-1-14 22:51:16 | 显示全部楼层
简单的结构体类型都不看文档,答了一个问题马上还有另一个问题,有问题都不先去搜索一下,libzplay的库别人6年前就写好了 http://bbs.aardio.com/forum.php? ... amp;highlight=zplay

浪费自己时间又浪费别人时间,动个手几秒钟的事。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



GMT+8, 2021-3-8 10:35 , Processed in 0.095841 second(s), 25 queries .

© 2001-2011 Powered by Discuz! X3.2.

快速回复 返回顶部 返回列表