diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..823073d --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +include ./config.mk + +NAME := Wav + +GCC_SRCS := $(LIBSRC_PATH)/wav/wav.c + +INCLUDES += -I $(LIBSRC_PATH) + +include $(MAKE_HOME)/compile.mk diff --git a/Wav.h b/Wav.h deleted file mode 100755 index 60c0505..0000000 --- a/Wav.h +++ /dev/null @@ -1,83 +0,0 @@ -/*************************************************************************/ -/* Speicher, Laden und Erzeugen von WAV und PCM Dateien -/* -/* Datum : 27.03.2002 -/* Autor : Jens Ahrensfeld -/* Datei : wav.h -/* -/*************************************************************************/ -#ifndef AVWAV_H -#define AVWAV_H - -#include -#define INT8 char -#define INT16 short -#define INT32 long -#define UINT8 unsigned char -#define UINT16 unsigned short -#define UINT32 unsigned long - -#define bs 18 -#define WAVE_FORMAT_PCM 1 -#define FILETYPE_RAW 0 -#define FILETYPE_WAV 1 - -/******************************************************************************/ -typedef struct _sWAVEHEADER -{ - UINT16 wFormatTag; - UINT16 nChannels; - UINT32 nSamplesPerSec; - UINT32 nAvgBytesPerSec; - UINT16 nBlockAlign; - UINT16 wBitsPerSample; - UINT16 cbSize; - -} WAVEHEADER; - - -/******************************************************************************/ -typedef struct _sWAV -{ - char m_Name[257]; - WAVEHEADER m_Format; - UINT32 m_DataSize, m_FileSize, m_HeaderSize, m_FileType, m_numSamples; - FILE *pHndWavFile; - UINT32 WREAD; - UINT16 m_nChannels; - UINT32 m_SampleRate; - UINT16 m_nBits; - -} WAV; -/******************************************************************************/ -/* Global Functions -/******************************************************************************/ -#ifdef __cplusplus -extern "C" { -#endif - -void WavInit(struct _sWAV*, UINT32 nSamplesPerSec, UINT16 nBits, UINT16 nChannels, UINT16 format); -UINT32 WavSetFormat(struct _sWAV*, UINT32, UINT16, UINT16, UINT16 format); -UINT32 WavOpen (struct _sWAV*, char*); -UINT32 WavCreate(struct _sWAV*, char*, UINT32); -UINT32 WavClose(struct _sWAV*); -UINT32 WavRead(struct _sWAV*, void*, UINT32); -UINT32 WavWrite(struct _sWAV*, void*, UINT32); -UINT32 ReadHeader(struct _sWAV*); -UINT32 WriteHeader(struct _sWAV*); -UINT16 WavGetnBits(struct _sWAV *pObj); -UINT32 WavGetRate(struct _sWAV *pObj); -UINT16 WavGetnChannels(struct _sWAV *pObj); -char* WavGetFileName(struct _sWAV *pObj); - -void WavDeIlvd(struct _sWAV *pObj, INT16 *pIn, INT16 **ppOut, UINT32 len); -void WavDeIlvdDouble(struct _sWAV *pObj, INT16 *pIn, double **ppOut, UINT32 len); -void WavDeIlvdFloat(struct _sWAV *pObj, INT16 *pIn, float **ppOut, UINT32 len); -void WavIlvd(struct _sWAV *pObj, INT16 **ppIn, INT16 *pOut, UINT32 len); -void WavIlvdDouble(struct _sWAV *pObj, double **ppIn, INT16 *pOut, UINT32 len); -void WavIlvdFloat(struct _sWAV *pObj, float **ppIn, INT16 *pOut, UINT32 len); - -#ifdef __cplusplus -} -#endif -#endif /* AVWAV_H */ diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..bf77a39 --- /dev/null +++ b/config.mk @@ -0,0 +1,6 @@ +MAKE_HOME ?= /home/jens/work/software/make +CONFIG ?= debug +BUILD_DIR ?= ./build/${CONFIG} +MAKEFLAGS += --no-print-directory + +LIBSRC_PATH ?= $(realpath ../../libsrc) diff --git a/wav.c b/wav.c index bb2ea1c..d72493e 100755 --- a/wav.c +++ b/wav.c @@ -6,15 +6,15 @@ /* Datei : wav.c /* /******************************************************************************/ -#include "stdio.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include #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); } } } diff --git a/wav.h b/wav.h new file mode 100755 index 0000000..646eb93 --- /dev/null +++ b/wav.h @@ -0,0 +1,77 @@ +/*************************************************************************/ +/* Speicher, Laden und Erzeugen von WAV und PCM Dateien +/* +/* Datum : 27.03.2002 +/* Autor : Jens Ahrensfeld +/* Datei : wav.h +/* +/*************************************************************************/ +#ifndef AVWAV_H +#define AVWAV_H + +#include + +#define bs 18 +#define WAVE_FORMAT_PCM 1 +#define FILETYPE_RAW 0 +#define FILETYPE_WAV 1 + +/******************************************************************************/ +typedef struct _sWAVEHEADER +{ + uint16_t wFormatTag; + uint16_t nChannels; + uint32_t nSamplesPerSec; + uint32_t nAvgBytesPerSec; + uint16_t nBlockAlign; + uint16_t wBitsPerSample; + uint16_t cbSize; + +} WAVEHEADER; + + +/******************************************************************************/ +typedef struct _sWAV +{ + char m_Name[257]; + WAVEHEADER m_Format; + uint32_t m_DataSize, m_FileSize, m_HeaderSize, m_FileType, m_numSamples; + FILE *pHndWavFile; + uint32_t WREAD; + uint16_t m_nChannels; + uint32_t m_SampleRate; + uint16_t m_nBits; + +} WAV; +/******************************************************************************/ +/* Global Functions +/******************************************************************************/ +#ifdef __cplusplus +extern "C" { +#endif + +void WavInit(struct _sWAV*, uint32_t nSamplesPerSec, uint16_t nBits, uint16_t nChannels, uint16_t format); +uint32_t WavSetFormat(struct _sWAV*, uint32_t, uint16_t, uint16_t, uint16_t format); +uint32_t WavOpen (struct _sWAV*, char*); +uint32_t WavCreate(struct _sWAV*, char*, uint32_t); +uint32_t WavClose(struct _sWAV*); +uint32_t WavRead(struct _sWAV*, void*, uint32_t); +uint32_t WavWrite(struct _sWAV*, void*, uint32_t); +uint32_t ReadHeader(struct _sWAV*); +uint32_t WriteHeader(struct _sWAV*); +uint16_t WavGetnBits(struct _sWAV *pObj); +uint32_t WavGetRate(struct _sWAV *pObj); +uint16_t WavGetnChannels(struct _sWAV *pObj); +char* WavGetFileName(struct _sWAV *pObj); + +void WavDeIlvd(struct _sWAV *pObj, int16_t *pIn, int16_t **ppOut, uint32_t len); +void WavDeIlvdDouble(struct _sWAV *pObj, int16_t *pIn, double **ppOut, uint32_t len); +void WavDeIlvdFloat(struct _sWAV *pObj, int16_t *pIn, float **ppOut, uint32_t len); +void WavIlvd(struct _sWAV *pObj, int16_t **ppIn, int16_t *pOut, uint32_t len); +void WavIlvdDouble(struct _sWAV *pObj, double **ppIn, int16_t *pOut, uint32_t len); +void WavIlvdFloat(struct _sWAV *pObj, float **ppIn, int16_t *pOut, uint32_t len); + +#ifdef __cplusplus +} +#endif +#endif /* AVWAV_H */