#include <string.h>
#include <math.h>
#include "soundsample_yswavfile.h"
-
-//#include "app_log.h"
-#include "ico_apf_log.h"
+//#include "ico_apf_log.h"
+#include "ico_log.h"
YsWavFile::YsWavFile()
{
{
FILE *fp;
- uim_debug("Loading %s", fn);
+ ICO_DBG("Loading %s", fn);
fp = fopen(fn, "rb");
if (fp != NULL) {
if (fread(buf, 1, 4, fp) != 4) {
- uim_debug("Error in reading RIFF.");
+ ICO_DBG("Error in reading RIFF.");
goto ERREND;
}
if (strncmp((char *) buf, "RIFF", 4) != 0) {
- uim_debug("Warning: RIFF not found.");
+ ICO_DBG("Warning: RIFF not found.");
}
if (fread(buf, 1, 4, fp) != 4) {
- uim_debug("Error in reading file size.");
+ ICO_DBG("Error in reading file size.");
goto ERREND;
}
fSize = GetUnsigned(buf);
- uim_debug("File Size=%d", fSize + 8);
+ ICO_DBG("File Size=%d", fSize + 8);
if (fread(buf, 1, 8, fp) != 8) {
- uim_debug("Error in reading WAVEfmt.");
+ ICO_DBG("Error in reading WAVEfmt.");
goto ERREND;
}
if (strncmp((char *) buf, "WAVEfmt", 7) != 0) {
- uim_debug("Warning: WAVEfmt not found");
+ ICO_DBG("Warning: WAVEfmt not found");
}
if (fread(buf, 1, 4, fp) != 4) {
- uim_debug("Error in reading header size.");
+ ICO_DBG("Error in reading header size.");
goto ERREND;
}
hdrSize = GetUnsigned(buf);
- uim_debug("Header Size=%d", hdrSize);
+ ICO_DBG("Header Size=%d", hdrSize);
// WORD wFormatTag;
// WORD wBitsPerSample;
// WORD cbSize;
if (fread(buf, 1, hdrSize, fp) != hdrSize) {
- uim_debug("Error in reading header.");
+ ICO_DBG("Error in reading header.");
goto ERREND;
}
wFormatTag = GetUnsignedShort(buf);
wBitsPerSample = (hdrSize >= 16 ? GetUnsignedShort(buf + 14) : 0);
cbSize = (hdrSize >= 18 ? GetUnsignedShort(buf + 16) : 0);
- uim_debug("wFormatTag=%d", wFormatTag);
- uim_debug("nChannels=%d", nChannels);
- uim_debug("nSamplesPerSec=%d", nSamplesPerSec);
- uim_debug("nAvgBytesPerSec=%d", nAvgBytesPerSec);
- uim_debug("nBlockAlign=%d", nBlockAlign);
- uim_debug("wBitsPerSample=%d", wBitsPerSample);
- uim_debug("cbSize=%d", cbSize);
+ ICO_DBG("wFormatTag=%d", wFormatTag);
+ ICO_DBG("nChannels=%d", nChannels);
+ ICO_DBG("nSamplesPerSec=%d", nSamplesPerSec);
+ ICO_DBG("nAvgBytesPerSec=%d", nAvgBytesPerSec);
+ ICO_DBG("nBlockAlign=%d", nBlockAlign);
+ ICO_DBG("wBitsPerSample=%d", wBitsPerSample);
+ ICO_DBG("cbSize=%d", cbSize);
while (1) {
if (fread(buf, 1, 4, fp) != 4) {
- uim_debug("Error while waiting for data.");
+ ICO_DBG("Error while waiting for data.");
goto ERREND;
}
break;
}
else {
- uim_debug("Skipping %c%c%c%c", buf[0], buf[1], buf[2],
+ ICO_DBG("Skipping %c%c%c%c", buf[0], buf[1], buf[2],
buf[3]);
if (fread(buf, 1, 4, fp) != 4) {
- uim_debug("Error while skipping unknown block.");
+ ICO_DBG("Error while skipping unknown block.");
goto ERREND;
}
l = GetUnsigned(buf);
if (fread(buf, 1, l, fp) != l) {
- uim_debug("Error while skipping unknown block.");
+ ICO_DBG("Error while skipping unknown block.");
goto ERREND;
}
}
if (fread(buf, 1, 4, fp) != 4) {
- uim_debug("Error in reading data size.");
+ ICO_DBG("Error in reading data size.");
goto ERREND;
}
dataSize = GetUnsigned(buf);
- uim_debug("Data Size=%d (0x%x)", dataSize, dataSize);
+ ICO_DBG("Data Size=%d (0x%x)", dataSize, dataSize);
dat = new unsigned char[dataSize];
if ((l = fread(dat, 1, dataSize, fp)) != dataSize) {
- uim_debug("Warning: File ended before reading all data.");
- uim_debug(" %d (0x%x) bytes have been read", l, l);
+ ICO_DBG("Warning: File ended before reading all data.");
+ ICO_DBG(" %d (0x%x) bytes have been read", l, l);
}
stereo = (nChannels == 2 ? YSTRUE : YSFALSE);
return YSERR;
ERREND:
- uim_debug("Err!");
+ ICO_DBG("Err!");
if (fp != NULL) {
fclose(fp);
}
else if (bit == 8) {
if (sizeInBytes > 0 && dat != NULL) {
unsigned char *newDat = new unsigned char[sizeInBytes * 2];
-// for (int i=0; i<sizeInBytes; i++)
for (unsigned int i = 0; i < sizeInBytes; i++) {
newDat[i * 2] = dat[i];
newDat[i * 2 + 1] = dat[i];
}
else if (bit == 16) {
unsigned char *newDat = new unsigned char[sizeInBytes / 2];
-// for (int i=0; i<sizeInBytes; i+=2)
for (unsigned int i = 0; i < sizeInBytes; i += 2) {
newDat[i / 2] = dat[i];
}
else {
if (bit == 8) {
unsigned char *newDat = new unsigned char[sizeInBytes * 2];
-// for (int i=0; i<sizeInBytes; i++)
for (unsigned int i = 0; i < sizeInBytes; i++) {
newDat[i * 2] = dat[i];
newDat[i * 2 + 1] = dat[i];
}
else if (bit == 16) {
unsigned char *newDat = new unsigned char[sizeInBytes * 2];
-// for (int i=0; i<sizeInBytes; i+=2)
for (unsigned int i = 0; i < sizeInBytes; i += 2) {
newDat[i * 2] = dat[i];
newDat[i * 2 + 1] = dat[i + 1];
return YSERR;
}
-//YSRESULT YsWavFile::Resample(int newRate)
YSRESULT YsWavFile::Resample(unsigned int newRate)
{
if (rate != newRate) {
}
else {
if (bit == 8) {
-// for (int i = 0; i < sizeInBytes; i++)
for (unsigned int i = 0; i < sizeInBytes; i++) {
dat[i] -= 128;
}
}
else if (bit == 16) {
-// for (int i = 0; i < sizeInBytes-1; i+=2)
for (unsigned int i = 0; i < sizeInBytes - 1; i += 2) {
int d;
d = dat[i] + dat[i + 1] * 256;
}
else {
if (bit == 8) {
-// for (int i = 0; i < sizeInBytes; i++)
for (unsigned int i = 0; i < sizeInBytes; i++) {
dat[i] += 128;
}
}
else if (bit == 16) {
-// for (int i = 0; i < sizeInBytes-1; i+=2)
for (unsigned int i = 0; i < sizeInBytes - 1; i += 2) {
int d = dat[i] + dat[i + 1] * 256;
if (d >= 32768) {
return YSOK;
}
-//int main(int ac,char *av[])
-//{
-// YsWavFile test;
-// test.LoadWav(av[1]);
-// return 0;
-//}
-
int YsWavFile::GetNumChannel(void) const
{
return (YSTRUE == stereo ? 2 : 1);