- added wav to build system
- fixed data types git-svn-id: http://moon:8086/svn/software/trunk/libsrc/wav@959 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -6,15 +6,15 @@
|
||||
/* Datei : wav.c
|
||||
/*
|
||||
/******************************************************************************/
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "wav.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/* C definitions
|
||||
/******************************************************************************/
|
||||
void WavInit(struct _sWAV *pObj, UINT32 nSamplesPerSec, UINT16 nBits, UINT16 nChannels, UINT16 format)
|
||||
void WavInit(struct _sWAV *pObj, uint32_t nSamplesPerSec, uint16_t nBits, uint16_t nChannels, uint16_t format)
|
||||
{
|
||||
WavSetFormat(pObj, nSamplesPerSec, nBits, nChannels, format);
|
||||
pObj->m_FileType = FILETYPE_RAW;
|
||||
@@ -26,14 +26,14 @@ void WavInit(struct _sWAV *pObj, UINT32 nSamplesPerSec, UINT16 nBits, UINT16 nCh
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
UINT32 WavSetFormat(struct _sWAV *pObj, UINT32 nSamplesPerSec, UINT16 nBits, UINT16 nChannels, UINT16 format)
|
||||
uint32_t WavSetFormat(struct _sWAV *pObj, uint32_t nSamplesPerSec, uint16_t nBits, uint16_t nChannels, uint16_t format)
|
||||
{
|
||||
pObj->m_Format.wFormatTag = format;
|
||||
pObj->m_Format.nChannels = nChannels;
|
||||
pObj->m_Format.wBitsPerSample = nBits;
|
||||
pObj->m_Format.nBlockAlign = (nChannels * nBits)/ 8;
|
||||
pObj->m_Format.nSamplesPerSec = nSamplesPerSec;
|
||||
pObj->m_Format.nAvgBytesPerSec = (UINT32)pObj->m_Format.nBlockAlign * nSamplesPerSec;
|
||||
pObj->m_Format.nAvgBytesPerSec = (uint32_t)pObj->m_Format.nBlockAlign * nSamplesPerSec;
|
||||
pObj->m_Format.cbSize = 0;
|
||||
|
||||
pObj->m_nChannels = pObj->m_Format.nChannels;
|
||||
@@ -44,11 +44,11 @@ UINT32 WavSetFormat(struct _sWAV *pObj, UINT32 nSamplesPerSec, UINT16 nBits, UIN
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
UINT32 WavOpen (struct _sWAV *pObj, char* FileName)
|
||||
uint32_t WavOpen (struct _sWAV *pObj, char* FileName)
|
||||
{
|
||||
UINT32 stat;
|
||||
uint32_t stat;
|
||||
|
||||
//Wav-File öffnen
|
||||
//Wav-File �ffnen
|
||||
strcpy(pObj->m_Name, FileName);
|
||||
if (strlen(FileName) < 1)
|
||||
return -1;
|
||||
@@ -77,7 +77,7 @@ UINT32 WavOpen (struct _sWAV *pObj, char* FileName)
|
||||
return 0;
|
||||
}
|
||||
/******************************************************************************/
|
||||
UINT32 WavClose(struct _sWAV *pObj)
|
||||
uint32_t WavClose(struct _sWAV *pObj)
|
||||
{
|
||||
if (!pObj->WREAD && (pObj->m_FileType == FILETYPE_WAV))
|
||||
WriteHeader(pObj);
|
||||
@@ -87,13 +87,13 @@ UINT32 WavClose(struct _sWAV *pObj)
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
UINT32 WavCreate (struct _sWAV *pObj, char *fileName, UINT32 fileType)
|
||||
uint32_t WavCreate (struct _sWAV *pObj, char *fileName, uint32_t fileType)
|
||||
{
|
||||
pObj->m_FileType = fileType;
|
||||
|
||||
strcpy(pObj->m_Name, fileName);
|
||||
|
||||
//Wav-File öffnen
|
||||
//Wav-File �ffnen
|
||||
pObj->pHndWavFile = fopen (pObj->m_Name,"wb");
|
||||
if (pObj->pHndWavFile == 0)
|
||||
return -1;
|
||||
@@ -105,19 +105,19 @@ UINT32 WavCreate (struct _sWAV *pObj, char *fileName, UINT32 fileType)
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
UINT32 WavRead(struct _sWAV *pObj, void *data, UINT32 nSamples)
|
||||
uint32_t WavRead(struct _sWAV *pObj, void *data, uint32_t nSamples)
|
||||
{
|
||||
INT32 count;
|
||||
int32_t count;
|
||||
count = fread(data, pObj->m_Format.nBlockAlign, nSamples, pObj->pHndWavFile);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
UINT32 WavWrite(struct _sWAV *pObj, void *data, UINT32 nSamples)
|
||||
uint32_t WavWrite(struct _sWAV *pObj, void *data, uint32_t nSamples)
|
||||
{
|
||||
|
||||
UINT32 count;
|
||||
uint32_t count;
|
||||
|
||||
fseek(pObj->pHndWavFile, 0L, SEEK_END);
|
||||
count = fwrite(data, pObj->m_Format.nBlockAlign, nSamples, pObj->pHndWavFile);
|
||||
@@ -133,21 +133,21 @@ UINT32 WavWrite(struct _sWAV *pObj, void *data, UINT32 nSamples)
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
UINT32 ReadHeader (struct _sWAV *pObj)
|
||||
uint32_t ReadHeader (struct _sWAV *pObj)
|
||||
{
|
||||
char buf[80];
|
||||
INT32 err;
|
||||
int32_t err;
|
||||
|
||||
// 1. 'RIFF' abprüfen
|
||||
// 1. 'RIFF' abpr�fen
|
||||
fread(buf, sizeof(char), 4,pObj->pHndWavFile);
|
||||
buf[4]=0;
|
||||
if (strcmp (buf,"RIFF"))
|
||||
return -1;
|
||||
|
||||
// 2. FILESIZE ermitteln
|
||||
fread(&pObj->m_FileSize, sizeof(UINT32), 1,pObj->pHndWavFile);
|
||||
fread(&pObj->m_FileSize, sizeof(uint32_t), 1,pObj->pHndWavFile);
|
||||
|
||||
// 3. 'WAVEfmt' abprüfen
|
||||
// 3. 'WAVEfmt' abpr�fen
|
||||
fread(buf, sizeof(char), 8,pObj->pHndWavFile);
|
||||
buf[8]=0;
|
||||
if (strcmp (buf,"WAVEfmt "))
|
||||
@@ -159,8 +159,8 @@ UINT32 ReadHeader (struct _sWAV *pObj)
|
||||
// 4. Den ganzen Infoblock einlesen
|
||||
fread(&pObj->m_Format, pObj->m_HeaderSize, 1,pObj->pHndWavFile);
|
||||
|
||||
// 5. 'data' abprüfen
|
||||
fseek(pObj->pHndWavFile,(INT32)(pObj->m_HeaderSize+20), SEEK_SET);
|
||||
// 5. 'data' abpr�fen
|
||||
fseek(pObj->pHndWavFile,(int32_t)(pObj->m_HeaderSize+20), SEEK_SET);
|
||||
|
||||
err = -1;
|
||||
do
|
||||
@@ -168,14 +168,14 @@ UINT32 ReadHeader (struct _sWAV *pObj)
|
||||
fread(buf, sizeof(char), 4, pObj->pHndWavFile);
|
||||
buf[4]=0;
|
||||
|
||||
// 6. Datenlänge ermitteln
|
||||
// 6. Datenl�nge ermitteln
|
||||
fread(&pObj->m_DataSize, sizeof(pObj->m_DataSize), 1,pObj->pHndWavFile);
|
||||
if (!strcmp (buf,"data"))
|
||||
{
|
||||
err = 0;
|
||||
break;
|
||||
}
|
||||
fseek(pObj->pHndWavFile,(INT32)(pObj->m_DataSize), SEEK_CUR);
|
||||
fseek(pObj->pHndWavFile,(int32_t)(pObj->m_DataSize), SEEK_CUR);
|
||||
|
||||
} while (!feof(pObj->pHndWavFile));
|
||||
|
||||
@@ -187,7 +187,7 @@ UINT32 ReadHeader (struct _sWAV *pObj)
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
UINT32 WriteHeader (struct _sWAV *pObj)
|
||||
uint32_t WriteHeader (struct _sWAV *pObj)
|
||||
{
|
||||
|
||||
pObj->m_HeaderSize = bs;
|
||||
@@ -211,27 +211,27 @@ UINT32 WriteHeader (struct _sWAV *pObj)
|
||||
fwrite(&pObj->m_Format, pObj->m_HeaderSize, 1, pObj->pHndWavFile);
|
||||
|
||||
// 5. 'data' schreiben
|
||||
fseek(pObj->pHndWavFile, (INT32)(pObj->m_HeaderSize+20), SEEK_SET);
|
||||
fseek(pObj->pHndWavFile, (int32_t)(pObj->m_HeaderSize+20), SEEK_SET);
|
||||
fwrite("data",sizeof(char), 4, pObj->pHndWavFile);
|
||||
|
||||
// 6. Datenlänge schreiben
|
||||
// 6. Datenl�nge schreiben
|
||||
fwrite(&pObj->m_DataSize, sizeof(pObj->m_DataSize), 1, pObj->pHndWavFile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
UINT16 WavGetnBits(struct _sWAV *pObj)
|
||||
uint16_t WavGetnBits(struct _sWAV *pObj)
|
||||
{
|
||||
return pObj->m_Format.wBitsPerSample;
|
||||
}
|
||||
|
||||
UINT32 WavGetRate(struct _sWAV *pObj)
|
||||
uint32_t WavGetRate(struct _sWAV *pObj)
|
||||
{
|
||||
return pObj->m_Format.nSamplesPerSec;
|
||||
}
|
||||
|
||||
UINT16 WavGetnChannels(struct _sWAV *pObj)
|
||||
uint16_t WavGetnChannels(struct _sWAV *pObj)
|
||||
{
|
||||
return pObj->m_Format.nChannels;
|
||||
}
|
||||
@@ -241,10 +241,10 @@ char* WavGetFileName(struct _sWAV *pObj)
|
||||
return pObj->m_Name;
|
||||
}
|
||||
|
||||
void WavDeIlvd(struct _sWAV *pObj, INT16 *pIn, INT16 **ppOut, UINT32 len)
|
||||
void WavDeIlvd(struct _sWAV *pObj, int16_t *pIn, int16_t **ppOut, uint32_t len)
|
||||
{
|
||||
int j, nChannels;
|
||||
UINT32 i;
|
||||
uint32_t i;
|
||||
nChannels = pObj->m_Format.nChannels;
|
||||
|
||||
for (i=0; i < len; i++)
|
||||
@@ -256,10 +256,10 @@ void WavDeIlvd(struct _sWAV *pObj, INT16 *pIn, INT16 **ppOut, UINT32 len)
|
||||
}
|
||||
}
|
||||
|
||||
void WavDeIlvdDouble(struct _sWAV *pObj, INT16 *pIn, double **ppOut, UINT32 len)
|
||||
void WavDeIlvdDouble(struct _sWAV *pObj, int16_t *pIn, double **ppOut, uint32_t len)
|
||||
{
|
||||
int j, nChannels, nBits;
|
||||
UINT32 i;
|
||||
uint32_t i;
|
||||
double kNorm;
|
||||
|
||||
nChannels = pObj->m_Format.nChannels;
|
||||
@@ -275,10 +275,10 @@ void WavDeIlvdDouble(struct _sWAV *pObj, INT16 *pIn, double **ppOut, UINT32 len)
|
||||
}
|
||||
}
|
||||
|
||||
void WavDeIlvdFloat(struct _sWAV *pObj, INT16 *pIn, float **ppOut, UINT32 len)
|
||||
void WavDeIlvdFloat(struct _sWAV *pObj, int16_t *pIn, float **ppOut, uint32_t len)
|
||||
{
|
||||
int j, nChannels, nBits;
|
||||
UINT32 i;
|
||||
uint32_t i;
|
||||
float kNorm;
|
||||
|
||||
nChannels = pObj->m_Format.nChannels;
|
||||
@@ -294,10 +294,10 @@ void WavDeIlvdFloat(struct _sWAV *pObj, INT16 *pIn, float **ppOut, UINT32 len)
|
||||
}
|
||||
}
|
||||
|
||||
void WavIlvd(struct _sWAV *pObj, INT16 **ppIn, INT16 *pOut, UINT32 len)
|
||||
void WavIlvd(struct _sWAV *pObj, int16_t **ppIn, int16_t *pOut, uint32_t len)
|
||||
{
|
||||
int j, nChannels;
|
||||
UINT32 i;
|
||||
uint32_t i;
|
||||
nChannels = pObj->m_Format.nChannels;
|
||||
|
||||
for (i=0; i < len; i++)
|
||||
@@ -309,11 +309,11 @@ void WavIlvd(struct _sWAV *pObj, INT16 **ppIn, INT16 *pOut, UINT32 len)
|
||||
}
|
||||
}
|
||||
|
||||
void WavIlvdDouble(struct _sWAV *pObj, double **ppIn, INT16 *pOut, UINT32 len)
|
||||
void WavIlvdDouble(struct _sWAV *pObj, double **ppIn, int16_t *pOut, uint32_t len)
|
||||
{
|
||||
int j, nChannels, nBits;
|
||||
double kNorm;
|
||||
UINT32 i;
|
||||
uint32_t i;
|
||||
|
||||
nChannels = pObj->m_Format.nChannels;
|
||||
nBits = pObj->m_Format.wBitsPerSample;
|
||||
@@ -323,16 +323,16 @@ void WavIlvdDouble(struct _sWAV *pObj, double **ppIn, INT16 *pOut, UINT32 len)
|
||||
{
|
||||
for (j=0; j < nChannels; j++)
|
||||
{
|
||||
*(pOut++) = (INT16)(ppIn[j][i] * kNorm);
|
||||
*(pOut++) = (int16_t)(ppIn[j][i] * kNorm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WavIlvdFloat(struct _sWAV *pObj, float **ppIn, INT16 *pOut, UINT32 len)
|
||||
void WavIlvdFloat(struct _sWAV *pObj, float **ppIn, int16_t *pOut, uint32_t len)
|
||||
{
|
||||
int j, nChannels, nBits;
|
||||
float kNorm;
|
||||
UINT32 i;
|
||||
uint32_t i;
|
||||
|
||||
nChannels = pObj->m_Format.nChannels;
|
||||
nBits = pObj->m_Format.wBitsPerSample;
|
||||
@@ -342,7 +342,7 @@ void WavIlvdFloat(struct _sWAV *pObj, float **ppIn, INT16 *pOut, UINT32 len)
|
||||
{
|
||||
for (j=0; j < nChannels; j++)
|
||||
{
|
||||
*(pOut++) = (INT16)(ppIn[j][i] * kNorm);
|
||||
*(pOut++) = (int16_t)(ppIn[j][i] * kNorm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user