Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MagneWave.cpp
- Committer:
- doctorura
- Date:
- 2013-10-31
- Revision:
- 2:0fc5df933021
- Parent:
- 1:a82b9af36dbf
- Child:
- 3:500b992880b3
File content as of revision 2:0fc5df933021:
#include "MagneWave.h"
#define DATA_OFFSET 44
#define DAC_CENTER 32768
MagneWave::MagneWave( SoftMCP4922 *dac )
{
m_wave_DAC = dac;
m_wave_DAC->write_u16( DAC_CENTER );
}
void MagneWave::play( FILE *wavefile )
{
#if 0
// data size check
unsiged long dataSize = 0;
seek( wavefile, 40, SEEK_SET );
dataSize = fgetc( wavefile );
dataSize |= ( fgetc( wavefile ) << 8 );
dataSize |= ( fgetc( wavefile ) << 16 );
dataSize |= ( fgetc( wavefile ) << 24 );
printf( "data size = %ld\n", dataSize );
#endif
// jump to wave data
fseek( wavefile, DATA_OFFSET, SEEK_SET );
while(1){
//16bit
/*
int tmpL = 0;
int tmpH = 0;
unsigned short dacVal16 = 0;
tmpL = fgetc( wavefile );
if( tmpL == EOF ){
break;
}
tmpH = fgetc( wavefile );
if( tmpH == EOF ){
break;
}
dacVal16 = tmpL;
dacVal16 |= ( tmpH << 8 );
m_wave_DAC->write_u16( dacVal16 );
*/
// 8bit
int dacVal8 = fgetc( wavefile );
if( dacVal8 == EOF ){
break;
}
m_wave_DAC->write_u8( ( unsigned short )dacVal8 );
// TODO: adjust cycle
wait_us( 75 );
}
}