217 lines
5.4 KiB
C++
217 lines
5.4 KiB
C++
#include <windows.h>
|
|
#include <stdio.h>
|
|
#include <sample/wave.hpp>
|
|
#include <sample/purewave.hpp>
|
|
#include <common/pointer.hpp>
|
|
#include <common/StringBuffer.hpp>
|
|
#include <common/string.hpp>
|
|
|
|
|
|
void DumpSamplesWORD(String &wavePathOuputFileName,PureSampleEx &pureSample);
|
|
void DumpSamples(String &wavePathOuputFileName, PureSampleEx &pureSample);
|
|
|
|
bool LoadSamples(String &samplePathInputFileName,PureSampleEx &pureSample);
|
|
bool LoadSamplesWORD(String &samplePathInputFileName,PureSampleEx &pureSample);
|
|
|
|
|
|
void PlaySample(SmartPointer<WaveForm> &waveForm);
|
|
|
|
|
|
|
|
void main()
|
|
{
|
|
String wavePathFileName="f:\\AudioBounce.wav";
|
|
String wavePathOutputFileName="f:\\AudioBounce_AI.wav";
|
|
|
|
String samplePathOuputFileName = "c:\\work\\proto\\debug\\samples.csv";
|
|
String samplePathInputFileName="f:\\samples.audio.out.csv";
|
|
|
|
|
|
// int length = sizeof(SampleData);
|
|
// length = sizeof(int); // 4 BYTES 32 BITS
|
|
// length = sizeof(BYTE); // 1 BYTE 8 BITS
|
|
// length = sizeof(DWORD); // 4 BYTES 32 BITS
|
|
// length = sizeof(WORD); // 2 BYTES 16 BITS
|
|
|
|
|
|
// Load the WAV file
|
|
SmartPointer<WaveForm> waveForm(::new WaveForm(wavePathFileName),PointerDisposition::Delete);
|
|
::OutputDebugString((*waveForm).toString());
|
|
|
|
PureSampleEx &pureSample=waveForm->getPureSample();
|
|
DWORD sizeBytes=pureSample.getSizeBytes();
|
|
DWORD numSamples=pureSample.getNumSamples();
|
|
PureSampleEx::BitsPerSample bitsPerSample=pureSample.getBitsPerSample();
|
|
|
|
// DumpSamples(samplePathOuputFileName,pureSample)
|
|
|
|
// PlaySample(waveForm);
|
|
|
|
LoadSamples(samplePathInputFileName,pureSample);
|
|
waveForm->save(wavePathOutputFileName);
|
|
|
|
|
|
// SmartPointer<PureWave> pureWave(new PureWave(),PointerDisposition::Delete);
|
|
// pureWave->play(*waveForm);
|
|
|
|
|
|
|
|
::OutputDebugString("Here");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlaySample(SmartPointer<WaveForm> &waveForm)
|
|
{
|
|
SmartPointer<PureWave> pureWave(new PureWave(),PointerDisposition::Delete);
|
|
pureWave->play(*waveForm);
|
|
|
|
}
|
|
|
|
bool LoadSamples(String &samplePathInputFileName, PureSampleEx &pureSample)
|
|
{
|
|
bool returnCode(false);
|
|
PureSampleEx::BitsPerSample bitsPerSample=pureSample.getBitsPerSample();
|
|
|
|
switch(bitsPerSample)
|
|
{
|
|
case PureSampleEx::Bit4 :
|
|
break;
|
|
case PureSampleEx::Bit8 :
|
|
break;
|
|
case PureSampleEx::Bit16 :
|
|
returnCode=LoadSamplesWORD(samplePathInputFileName,pureSample);
|
|
break;
|
|
case PureSampleEx::Bit32 :
|
|
break;
|
|
}
|
|
return returnCode;
|
|
}
|
|
|
|
|
|
bool LoadSamplesWORD(String &samplePathInputFileName,PureSampleEx &pureSample)
|
|
{
|
|
SmartPointer<FileIO> inFile(::new FileIO(samplePathInputFileName), PointerDisposition::Delete);
|
|
SmartPointer<String> strLine(:: new String(), PointerDisposition::Delete);
|
|
WORD *pSampleDataWORD=(WORD*)pureSample.getSampleData();
|
|
DWORD numSamples=pureSample.getNumSamples();
|
|
DWORD sampleIndex(0);
|
|
int lineCount=0;
|
|
|
|
while(inFile->readLine(*strLine))lineCount++;
|
|
lineCount--;
|
|
|
|
if(lineCount!=numSamples)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
inFile->rewind();
|
|
lineCount=0;
|
|
while(inFile->readLine(*strLine))
|
|
{
|
|
if(0==lineCount)
|
|
{
|
|
lineCount++;
|
|
continue;
|
|
}
|
|
String strSampleNo=strLine->betweenString(0,',');
|
|
String strSample=strLine->betweenString(',',0);
|
|
WORD sample = strSample.toUShort();
|
|
pSampleDataWORD[sampleIndex++]=sample;
|
|
lineCount++;
|
|
}
|
|
::OutputDebugString(String().fromInt(lineCount-1));
|
|
inFile->close();
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
void DumpSamples(String &wavePathOuputFileName, PureSampleEx &pureSample)
|
|
{
|
|
PureSampleEx::BitsPerSample bitsPerSample=pureSample.getBitsPerSample();
|
|
|
|
switch(bitsPerSample)
|
|
{
|
|
case PureSampleEx::Bit4 :
|
|
break;
|
|
case PureSampleEx::Bit8 :
|
|
break;
|
|
case PureSampleEx::Bit16 :
|
|
DumpSamplesWORD(wavePathOuputFileName,pureSample);
|
|
break;
|
|
case PureSampleEx::Bit32 :
|
|
break;
|
|
}
|
|
}
|
|
|
|
void DumpSamplesWORD(String &wavePathOuputFileName, PureSampleEx &pureSample)
|
|
{
|
|
String crlf("\r\n");
|
|
SmartPointer<FileHandle> outFile(::new FileHandle(wavePathOuputFileName,FileHandle::Access::Write,FileHandle::Share::ShareNone,FileHandle::Mode::Create), PointerDisposition::Delete);
|
|
outFile.disposition(PointerDisposition::Disposition::Delete);
|
|
outFile->disposition(FileHandle::Disposition::CloseHandle);
|
|
|
|
WORD *pSampleDataWORD=(WORD*)pureSample.getSampleData();
|
|
DWORD numSamples=pureSample.getNumSamples();
|
|
|
|
outFile->write("Index,Sample");
|
|
outFile->write(crlf);
|
|
|
|
for(long index=0;index<numSamples;index++)
|
|
{
|
|
SmartPointer<StringBuffer> sb(::new StringBuffer(),PointerDisposition::Delete);
|
|
|
|
sb->append(String().fromInt(index+1));
|
|
sb->append(",");
|
|
sb->append(String().fromUShort(pSampleDataWORD[index]));
|
|
sb->append(crlf);
|
|
outFile->write(sb->toString());
|
|
}
|
|
|
|
|
|
outFile->flush();
|
|
outFile->close();
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
// (*waveForm).save("c:\\work\\exe\\DSPDIEHI_2.WAV");
|
|
|
|
|
|
|
|
// WaveForm *pWaveForm = new WaveForm(wavePathFileName);
|
|
// PureWave *pPureWave = new PureWave();
|
|
|
|
// pPureWave->play(*pWaveForm);
|
|
|
|
|
|
|
|
|
|
// ::delete[] pWaveForm;
|
|
// ::delete[] pPureWave;
|
|
|
|
// String wavePathFileName="c:\\work\\exe\\DSPDIEHI.WAV";
|
|
// String wavePathFileName2="C:\\Program Files\\Activision\\A-10Cuba\\Media\\Afterburner.wav";
|
|
|
|
// SmartPointer<WaveForm> waveForm(new WaveForm(wavePathFileName),PointerDisposition::Delete);
|
|
// ::OutputDebugString((*waveForm).toString());
|
|
// waveForm.destroy();
|
|
|
|
// waveForm=new WaveForm(wavePathFileName2);
|
|
// waveForm.disposition(PointerDisposition::Delete);
|
|
// waveForm->save("c:\\work\\exe\\Afterburner.WAV");
|
|
// ::OutputDebugString((*waveForm).toString());
|
|
|
|
// SimpleObject *pSimpleObject;
|
|
// pSimpleObject=::new SimpleObject(vector3D,(Ship<<16)|pureObjects.size());
|
|
*/
|
|
|
|
|
|
|