Add ability to read in samples.
This commit is contained in:
126
proto/Main.cpp
126
proto/Main.cpp
@@ -7,12 +7,25 @@
|
||||
#include <common/string.hpp>
|
||||
|
||||
|
||||
void DumpSamplesWORD(PureSampleEx &pureSample);
|
||||
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 wavePathFileName3="f:\\AudioBounce.wav";
|
||||
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
|
||||
@@ -21,7 +34,8 @@ void main()
|
||||
// length = sizeof(WORD); // 2 BYTES 16 BITS
|
||||
|
||||
|
||||
SmartPointer<WaveForm> waveForm(::new WaveForm(wavePathFileName3),PointerDisposition::Delete);
|
||||
// Load the WAV file
|
||||
SmartPointer<WaveForm> waveForm(::new WaveForm(wavePathFileName),PointerDisposition::Delete);
|
||||
::OutputDebugString((*waveForm).toString());
|
||||
|
||||
PureSampleEx &pureSample=waveForm->getPureSample();
|
||||
@@ -29,6 +43,38 @@ void main()
|
||||
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 :
|
||||
@@ -36,26 +82,76 @@ void main()
|
||||
case PureSampleEx::Bit8 :
|
||||
break;
|
||||
case PureSampleEx::Bit16 :
|
||||
DumpSamplesWORD(pureSample);
|
||||
returnCode=LoadSamplesWORD(samplePathInputFileName,pureSample);
|
||||
break;
|
||||
case PureSampleEx::Bit32 :
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
SmartPointer<PureWave> pureWave(new PureWave(),PointerDisposition::Delete);
|
||||
pureWave->play(*waveForm);
|
||||
|
||||
|
||||
|
||||
::OutputDebugString("Here");
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
void DumpSamplesWORD(PureSampleEx &pureSample)
|
||||
|
||||
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("c:\\work\\proto\\debug\\samples.csv",FileHandle::Access::Write,FileHandle::Share::ShareNone,FileHandle::Mode::Create), PointerDisposition::Delete);
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user