示例#1
0
void DataFlash_Block::WriteBlock(const void *pBuffer, uint16_t size)
{
    if (!CardInserted() || !log_write_started || !_writes_enabled) {
        return;
    }
    while (size > 0) {
        uint16_t n = df_PageSize - df_BufferIdx;
        if (n > size) {
            n = size;
        }

        if (df_BufferIdx == 0) {
            // if we are at the start of a page we need to insert a
            // page header
            if (n > df_PageSize - sizeof(struct PageHeader)) {
                n = df_PageSize - sizeof(struct PageHeader);
            }
            struct PageHeader ph = { df_FileNumber, df_FilePage };
            BlockWrite(df_BufferNum, df_BufferIdx, &ph, sizeof(ph), pBuffer, n);
            df_BufferIdx += n + sizeof(ph);
        } else {
            BlockWrite(df_BufferNum, df_BufferIdx, NULL, 0, pBuffer, n);
            df_BufferIdx += n;
        }

        size -= n;
        pBuffer = (const void *)(n + (uintptr_t)pBuffer);

        if (df_BufferIdx == df_PageSize) {
            FinishWrite();
            df_FilePage++;
        }
    }
}
示例#2
0
文件: Text1.c 项目: super-1943/MCU
void drawline(UINT sx, UINT ex, UINT sy, UINT ey,UINT linecolor)
{
	unsigned long int a,b;
	UINT diffx,diffy;
	diffx=ex-sx;
	diffy=ey-sy;
	if(diffx==0)
	{
		for(b=sy;b<=ey;b++)
		{
			BlockWrite(sx,sx,b,b);
			W_DATA(linecolor);
		}		
	}
	else if(diffy==0)
	{
		for(a=sx;a<ex;a++)
		{
			BlockWrite(a,a,sy,sy);
			W_DATA(linecolor);		
		}
	}
	else
	{
		for(a=sx;a<=ex;a++)
		{
			b=(a-sx)*diffy/diffx;
			BlockWrite(a,a,b,b);
			W_DATA(linecolor);
		}
	}
}
示例#3
0
文件: super.c 项目: d33tah/whitix
/* Update the freeClusters in the FsInfo sector on FAT32 */
int FatWriteSuper(struct VfsSuperBlock* superBlock)
{
	struct FatSbInfo* sbInfo;
	struct FatFsInfo* info;
	struct Buffer* buff;
	DWORD prevSize = superBlock->sDevice->softBlockSize;
	
	sbInfo = FatGetSbPriv(superBlock);

	if (sbInfo->fatType != 32)
		return 0;
	
	/* Need this to write the correct FsInfo sector. It will throw all blocks
	 * out of cache, but if we're calling this, we're either syncing or
	 * freeing the super typically.
	 */
	 
	BlockSetSize(superBlock->sDevice, superBlock->sDevice->blockSize);
	
	buff = BlockRead(superBlock->sDevice, sbInfo->fsInfoSector);
	
	info = (struct FatFsInfo*)(buff->data + 0x1E0);
	info->freeClusters = sbInfo->freeClusters;
	
	BlockWrite(buff->device, buff);
	
	BlockSetSize(superBlock->sDevice, prevSize);
	
	return 0;
}
示例#4
0
int GptBlockWrite(HGPT hGPT, QWORD qwSector, WORD wNum, void FAR *pBuf)
    {
    QWORD qw = qwSector;
    qw *= hGPT->iSectPerSect;

    return BlockWrite(hGPT->hBlockDev, qw, (WORD)(wNum*hGPT->iSectPerSect), pBuf);
    }
bool DataFlash_Block::WritePrioritisedBlock(const void *pBuffer, uint16_t size,
    bool is_critical)
{
    // is_critical is ignored - we're a ring buffer and never run out
    // of space.  possibly if we do more complicated bandwidth
    // limiting we can reservice bandwidth based on is_critical
    if (!CardInserted() || !log_write_started || !_writes_enabled) {
        return false;
    }

    if (! WriteBlockCheckStartupMessages()) {
        return false;
    }

    while (size > 0) {
        uint16_t n = df_PageSize - df_BufferIdx;
        if (n > size) {
            n = size;
        }

        if (df_BufferIdx == 0) {
            // if we are at the start of a page we need to insert a
            // page header
            if (n > df_PageSize - sizeof(struct PageHeader)) {
                n = df_PageSize - sizeof(struct PageHeader);
            }
            struct PageHeader ph = { df_FileNumber, df_FilePage };
            BlockWrite(df_BufferNum, df_BufferIdx, &ph, sizeof(ph), pBuffer, n);
            df_BufferIdx += n + sizeof(ph);
        } else {
            BlockWrite(df_BufferNum, df_BufferIdx, NULL, 0, pBuffer, n);
            df_BufferIdx += n;
        }

        size -= n;
        pBuffer = (const void *)(n + (uintptr_t)pBuffer);

        if (df_BufferIdx == df_PageSize) {
            FinishWrite();
            df_FilePage++;
        }
    }

    return true;
}
示例#6
0
/*
绘制一个像素点
*/
void PutPixel(unsigned int x, unsigned int y, unsigned int color)
{
    BlockWrite(x, x, y, y);
    CS_CLEAR;
    RS_SET;
    SendDataSPI(color >> 8);
    SendDataSPI(color);
    CS_SET;
}
示例#7
0
文件: Tiky_LCD.c 项目: ash-liu/IST
/**********************************************
函数名:Lcd块选函数
功能:选定Lcd上指定的矩形区域

注意:xStart和 yStart随着屏幕的旋转而改变,位置是矩形框的四个角

入口参数:xStart x方向的起始点
          ySrart y方向的终止点
          xLong 要选定矩形的x方向长度
          yLong  要选定矩形的y方向长度
返回值:无
***********************************************/
void Lcd_ColorBox(u16 xStart,u16 yStart,u16 xLong,u16 yLong,u16 Color)
{
	u32 temp;

	BlockWrite(xStart,xStart+xLong-1,yStart,yStart+yLong-1);
	for (temp=0; temp<xLong*yLong; temp++)
	{
		*(__IO u16 *) (Bank1_LCD_D) = Color;
	}
}
示例#8
0
文件: Text1.c 项目: super-1943/MCU
void Show(UINT sx, UINT ex, UINT sy, UINT ey, UINT dat)
{
	UINT x, y, i, j;
	BlockWrite(sx, ex, sy, ey);
	
	x = ex - sx;
	y = ey - sy;
	
	for ( i = 0; i <= y; i++ )
		for ( j = 0; j <= x; j++ )
			W_DATA(dat);
}
示例#9
0
文件: Text1.c 项目: super-1943/MCU
void show_pic(unsigned char * table,UINT x0,UINT y0,UINT width,UINT height)
{
	UINT x;
	UINT temp;
	BlockWrite(x0,x0+width-1,y0,y0+height-1);
	for(x=0;x<width*height*2;x+=2)
	{
		temp=table[x]<<8;
		temp+=table[x+1];
		W_DATA(temp);
	}
}
示例#10
0
文件: Text1.c 项目: super-1943/MCU
/*******************kkk*****************/
void sin(void)
{
	unsigned int x,y;
	for(y=0;y<4;y++)
	{
		for(x=0;x<400;x++)
		{	
			BlockWrite(sintable[x]+119,sintable[x]+119,x+y,x+y);
			W_DATA(0xf800);
		}
		Delay(100);
	}
}
示例#11
0
/*
LCD显示颜色(颜色已在.h文件中定义)
*/
void DispColor(unsigned int color)
{
    unsigned int i, j;
    BlockWrite(0, COL - 1, 0, ROW - 1);

    CS_CLEAR;
    RS_SET;
    for(i = 0; i < ROW; i++)
    {
        for(j = 0; j < COL; j++)
        {
            SendDataSPI(color >> 8);
            SendDataSPI(color);
        }
    }
    CS_SET;
}
示例#12
0
文件: Tiky_LCD.c 项目: ash-liu/IST
/******************************************
函数名:Lcd图像填充100*100
功能:向Lcd指定位置填充图像
入口参数:Index 要寻址的寄存器地址
          ConfigTemp 写入的数据或命令值
******************************************/
void LCD_Fill_Pic(u16 x, u16 y,u16 pic_H, u16 pic_V, const unsigned char* pic)
{
  unsigned long i;
	unsigned int j;

// 	WriteComm(0x3600); //Set_address_mode
// 	WriteData(0x00); //横屏,从左下角开始,从左到右,从下到上
	BlockWrite(x,x+pic_H-1,y,y+pic_V-1);
	for (i = 0; i < pic_H*pic_V*2; i+=2)
	{
		j=pic[i];
		j=j<<8;
		j=j+pic[i+1];
		*(__IO u16 *) (Bank1_LCD_D) = j;
	}
// 	WriteComm(0x3600); //Set_address_mode
// 	WriteData(0xA0);
}
示例#13
0
文件: Text1.c 项目: super-1943/MCU
void ShowCharWithColor(UCHAR sx, UINT sy, UCHAR index, UINT CharColor, UINT BkColor)
{
	UCHAR i, j;
	UCHAR mask;

	if ( index > 95 )
		return;

	BlockWrite(sx, sx+7, sy, sy+15);	
	for ( i = 0; i < 16; i++ )
	{
		mask = 0x80;
		for ( j = 0; j < 8; j++ )
		{
			W_DATA((ascii_font[index][i] & mask) ? CharColor : BkColor);
			mask >>= 1;
		}
	}
}
示例#14
0
文件: voix-classic.c 项目: nkfly/MSAR
int main(int argc, char *argv[]){

    FILE *infile, *outfile;
    char infilename[260], outfilename[260];
    char WaveId[4];
    wHeader infileHeader;
    fmtChunk infileChunk;
    unsigned long Count, DataSize, tmpDataSize, FilePos;
	unsigned int tmpRIFFSize;

    float LPCutoff, HPCutoff, Invert, VocalPan, Gain;
    float ChMix[4];
    double a1[3],b1[3],a2[3],b2[3];
    double LP_L_In[3], LP_L_Out[3], HP_L_In[3], HP_L_Out[3];
    double LP_R_In[3], LP_R_Out[3], HP_R_In[3], HP_R_Out[3];    
    double Left, Right, NewLeft, NewRight;
    unsigned long i, j, k;
    short percentage = 0;
    
    /* Display version and usage */
    printf("VoiX Version %s\n(http://vocaleliminator.sourceforge.net)\n", VERSION);

    if (argc==1) {printf("\nUsage: %s <infile> [outfile] [options]\n", argv[0]);
                  printf("\nOptions: <lowpass> <highpass> <invert> <pan> <gain>\n");
                  printf("\n<lowpass>: Cutoff frequency (in Hz) for low-pass filter\n");
                  printf("<highpass>: Cutoff frequency (in Hz) for high-pass filter\n");
                  printf("<invert>: Invert right channel to make it mono, 0=off 1=on\n");                  
                  printf("<pan>: Pan for Vocal Track: 0=center -100=left 100=right\n");
                  printf("<gain>: Gain (in dB) for output file\n");                  
                  printf("\nExample: %s input.wav output.wav 200 8000\n", argv[0]);
                  return(0);}
    strcpy(infilename,argv[1]); /* Copy input filename from first parameter */
    
    /* For Windows Drag & Drop*/
    char *FileExt = ".voix.wav";
    if (argc==2) {
                 strcpy(outfilename, infilename); strcat(outfilename,FileExt); 
                 } else strcpy(outfilename,argv[2]);
    /* Windows Drag & Drop End*/
    
    printf("Input: %s ", infilename);
    if (argc>=4) LPCutoff = atof(argv[3]); else LPCutoff = 200.0;
    if (argc>=5) HPCutoff = atof(argv[4]); else HPCutoff = 8000.0;
    if (argc>=6) Invert = atof(argv[5]); else Invert = 0.0;
    if (argc>=7) VocalPan = atof(argv[6]); else VocalPan = 0.0;
    if ((VocalPan<=-100.0)||(VocalPan>=100.0)) VocalPan = 0.0;
    if (argc>=8) Gain = atof(argv[7]); else Gain = 0.0;
    if ((Gain<-20.0)||(Gain>20.0)) Gain = 0.0;

    /* Read Header from Input Wave File*/
    if ((infile = fopen(infilename,"rb+")) == NULL) {
        printf("\n\nError(1): Could not open input file \"%s\".\n",infilename); return(1);}
    
    fread(&infileHeader, sizeof(infileHeader), 1, infile);
    if ((infileHeader.ID[0]!='R')||(infileHeader.ID[1]!='I')
       ||(infileHeader.ID[2]!='F')||(infileHeader.ID[3]!='F')) {
         printf("\n\nError(3): \"%s\" is not a standrad RIFF file.\n",infilename);
           fclose(infile); return(3);}

    fread(&WaveId, sizeof(WaveId), 1, infile);
    if ((WaveId[0]!='W')||(WaveId[1]!='A')||(WaveId[2]!='V')||(WaveId[3]!='E')) {
        printf("\n\nError(4): Could not find correct WAVE header form \"%s\".\n", infilename);
           fclose(infile); return(4);}

    fread(&infileHeader, sizeof(infileHeader), 1, infile);
    if ((infileHeader.ID[0]!='f')||(infileHeader.ID[1]!='m')
      ||(infileHeader.ID[2]!='t')||(infileHeader.ID[3]!=' ')) {
        printf("\n\nError(5): Could not find correct chunk header form \"%s\".\n", infilename);
           fclose(infile); return(5);}
    
    fread(&infileChunk, sizeof(infileChunk), 1, infile);
    fseek(infile, ftell(infile) + infileHeader.Length - 16, 0);
    /* Display the input file format*/
    if (infileChunk.FormatTag == 1) printf("(Windows PCM");
    if (infileChunk.FormatTag == 3) printf("(IEEE float");
    printf(", %d Hz, %d bit, ", infileChunk.SampleRate, infileChunk.Bits);
    if (infileChunk.Channels == 1) printf("mono)\n"); else
    if (infileChunk.Channels == 2) printf("stereo)\n"); else
    printf("%d channels)\n", infileChunk.Channels);
    /* end */
    if ((infileChunk.FormatTag!=0x0001)&&(infileChunk.FormatTag!=0x0003)) {
        printf("\nError(6): \"%s\" is not a PCM or IEEE float wave file.\n",infilename);
          fclose(infile); return(6);}
    if (infileChunk.Channels!=2) {
        printf("\nError(7): \"%s\" is not stereo.\n",infilename);
          fclose(infile); return(7);}
    if ((infileChunk.Bits!=8)&&(infileChunk.Bits!=16)&&(infileChunk.Bits!=24)&&(infileChunk.Bits!=32))
        { printf("\nError(8): VoiX could not process %d bit wave files.\n", infileChunk.Bits);
          fclose(infile); return(8);}
    if (infileChunk.Bits/8*infileChunk.Channels!=infileChunk.BlockAlign)
        { printf("\nError(9): VoiX could not process non-standrad wave files.\n");
          fclose(infile); return(9);}
    fread(&infileHeader, sizeof(infileHeader), 1, infile);
    while (((infileHeader.ID[0]!='d')||(infileHeader.ID[1]!='a')||
          (infileHeader.ID[2]!='t')||(infileHeader.ID[3]!='a'))
    &&(!feof(infile))) {
    fseek(infile, ftell(infile) + infileHeader.Length, 0); 
    fread(&infileHeader, sizeof(infileHeader), 1, infile);
    }
    if (feof(infile)) {
       printf("\nError(10): Could not find correct data header form \"%s\".\n", infilename);
         fclose(infile); return(10);}
    printf("Output: %s\n", outfilename);
    if ((outfile = fopen(outfilename,"wb+")) == NULL) {
        printf("\nError(2): Could not open output file \"%s\".\n",outfilename);
          fclose(infile); return(2);}
    
    /* Write Header to Output Wave File*/
    DataSize = infileHeader.Length;
    tmpDataSize = 0;
    strcpy(infileHeader.ID,"RIFF"); infileHeader.Length = tmpDataSize+36;
    fwrite(&infileHeader,sizeof(infileHeader),1,outfile);
    strcpy(WaveId,"WAVE"); fwrite(WaveId,sizeof(WaveId),1,outfile);
    strcpy(infileHeader.ID,"fmt "); infileHeader.Length = 16;
    fwrite(&infileHeader,sizeof(infileHeader),1,outfile);
    fwrite(&infileChunk,sizeof(infileChunk),1,outfile);
    strcpy(infileHeader.ID,"data"); infileHeader.Length = tmpDataSize;
    fwrite(&infileHeader,sizeof(infileHeader),1,outfile);    
    
    if ((LPCutoff < 1.00) || (LPCutoff > infileChunk.SampleRate/2 - 1)) LPCutoff = 1.00;
    if ((HPCutoff < 1.00) || (HPCutoff > infileChunk.SampleRate/2 - 1)) HPCutoff = infileChunk.SampleRate/2 - 1;
    if (HPCutoff < LPCutoff) HPCutoff = LPCutoff;
    printf("(i)Lowpass: %.1f Hz, Highpass: %.1f Hz\n", LPCutoff, HPCutoff);
    SetLP(infileChunk.SampleRate,LPCutoff,a1,b1);
    SetHP(infileChunk.SampleRate,HPCutoff,a2,b2);
    for (i=0;i<=2;i++) {
      LP_L_In[i]=0; LP_L_Out[i]=0;
      HP_L_In[i]=0; HP_L_Out[i]=0;
      LP_R_In[i]=0; LP_R_Out[i]=0;
      HP_R_In[i]=0; HP_R_Out[i]=0;
    }
    printf("(i)Invert: ");
    if (Invert == 1.00) printf("On"); else printf("Off");
    printf(" Vocal Pan: "); printf("%.1f", VocalPan);
    VocalPan = (VocalPan+100.00)/2.00;
    printf(" Gain: %.1f dB\n", Gain);
    Gain = pow(10.0,Gain/20.0);
    
    if (VocalPan <= 50.0) {
    ChMix[0] = 1.0;
    ChMix[1] = -(VocalPan/(100.0-VocalPan));
    ChMix[2] = 1.0;
    ChMix[3] = -(VocalPan/(100.0-VocalPan));
    }
    if (VocalPan > 50.0) {
    ChMix[0] = -((100.0-VocalPan)/VocalPan);
    ChMix[1] = 1.0;
    ChMix[2] = -((100.0-VocalPan)/VocalPan);
    ChMix[3] = 1.0;
    }
    if (Invert == 0.00) {
      if (VocalPan<=50.00) {
         ChMix[2] = -ChMix[2]; ChMix[3] = -ChMix[3];
      }else {
         ChMix[0] = -ChMix[0]; ChMix[1] = -ChMix[1];         
      }         
    }

    printf("(!)Press [Ctrl+C] to exit\n(i)Process: ");
    Count = 0;
    for (i = 1; i <= DataSize/infileChunk.BlockAlign; i++) {
        
        if (feof(infile)) {
                        printf("\nError(11): EOF(End of file) of input file detected.\n");
                        fclose(infile); fclose(outfile); return(11);
                        }
        BlockRead(&Left, infileChunk.Bits, infileChunk.FormatTag, infile);
        BlockRead(&Right, infileChunk.Bits, infileChunk.FormatTag, infile);      
      
        
        if (percentage<i*20/(DataSize/infileChunk.BlockAlign)) {
          tmpDataSize = Count*infileChunk.BlockAlign;
          FilePos = ftell(outfile);
          tmpRIFFSize = tmpDataSize + 36;
          fseek(outfile,4,0); fwrite(&tmpRIFFSize,sizeof(tmpRIFFSize),1,outfile);
          fseek(outfile,40,0); fwrite(&tmpDataSize,sizeof(tmpDataSize),1,outfile);        
          fseek(outfile,FilePos,0);
          percentage= i*20/(DataSize/infileChunk.BlockAlign);
          printf("."); if (percentage%5==0) printf("%d%c",percentage*5,'%');

        }
        
        Count++;
        LP_L_In[2]=Left; LP_R_In[2]=Right;
        LP_L_Out[2]=(b1[0]/a1[0])*LP_L_In[2]+(b1[1]/a1[0])*LP_L_In[1]+(b1[2]/a1[0])*LP_L_In[0]-(a1[1]/a1[0])*LP_L_Out[1]-(a1[2]/a1[0])*LP_L_Out[0];
        LP_R_Out[2]=(b1[0]/a1[0])*LP_R_In[2]+(b1[1]/a1[0])*LP_R_In[1]+(b1[2]/a1[0])*LP_R_In[0]-(a1[1]/a1[0])*LP_R_Out[1]-(a1[2]/a1[0])*LP_R_Out[0];

        HP_L_In[2]=Left; HP_R_In[2]=Right;
        HP_L_Out[2]=(b2[0]/a2[0])*HP_L_In[2]+(b2[1]/a2[0])*HP_L_In[1]+(b2[2]/a2[0])*HP_L_In[0]-(a2[1]/a2[0])*HP_L_Out[1]-(a2[2]/a2[0])*HP_L_Out[0];
        HP_R_Out[2]=(b2[0]/a2[0])*HP_R_In[2]+(b2[1]/a2[0])*HP_R_In[1]+(b2[2]/a2[0])*HP_R_In[0]-(a2[1]/a2[0])*HP_R_Out[1]-(a2[2]/a2[0])*HP_R_Out[0];
           
        NewLeft=(ChMix[0]*(Left-LP_L_Out[2]-HP_L_Out[2])+ChMix[1]*(Right-LP_R_Out[2]-HP_R_Out[2]))*Gain+LP_L_Out[2]+HP_L_Out[2];
        NewRight=(ChMix[2]*(Left-LP_L_Out[2]-HP_L_Out[2])+ChMix[3]*(Right-LP_R_Out[2]-HP_R_Out[2]))*Gain+LP_R_Out[2]+HP_R_Out[2];
      
        LP_L_In[0]=LP_L_In[1]; LP_L_In[1]=LP_L_In[2];
        LP_R_In[0]=LP_R_In[1]; LP_R_In[1]=LP_R_In[2];
        LP_L_Out[0]=LP_L_Out[1]; LP_L_Out[1]=LP_L_Out[2];
        LP_R_Out[0]=LP_R_Out[1]; LP_R_Out[1]=LP_R_Out[2]; 
      
        HP_L_In[0]=HP_L_In[1]; HP_L_In[1]=HP_L_In[2];
        HP_R_In[0]=HP_R_In[1]; HP_R_In[1]=HP_R_In[2];
        HP_L_Out[0]=HP_L_Out[1]; HP_L_Out[1]=HP_L_Out[2];
        HP_R_Out[0]=HP_R_Out[1]; HP_R_Out[1]=HP_R_Out[2];  
      
        BlockWrite(NewLeft, infileChunk.Bits, infileChunk.FormatTag, outfile);
        BlockWrite(NewRight,infileChunk.Bits, infileChunk.FormatTag, outfile);       
    }
    tmpDataSize = DataSize;
    FilePos = ftell(outfile);
    tmpRIFFSize = tmpDataSize + 36;
    fseek(outfile,4,0); fwrite(&tmpRIFFSize,sizeof(tmpRIFFSize),1,outfile);
    fseek(outfile,40,0); fwrite(&tmpDataSize,sizeof(tmpDataSize),1,outfile);        
    fseek(outfile,FilePos,0);    
    printf("\n(i)Done processing file!\n");
    fclose(infile); fclose(outfile); return(0);
}
示例#15
0
文件: Tiky_LCD.c 项目: ash-liu/IST
//在指定座标上打一个点
void DrawPixel(u16 x, u16 y, int Color)
{
	BlockWrite(x,x,y,y);

	*(__IO u16 *) (Bank1_LCD_D) = Color;
}