Gugen展示版
Fork of MagneWave by
MagneWave.cpp@2:0fc5df933021, 2013-10-31 (annotated)
- Committer:
- doctorura
- Date:
- Thu Oct 31 15:07:37 2013 +0000
- Revision:
- 2:0fc5df933021
- Parent:
- 1:a82b9af36dbf
- Child:
- 3:500b992880b3
adjust cycle
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
doctorura | 0:5a700113dd87 | 1 | #include "MagneWave.h" |
doctorura | 0:5a700113dd87 | 2 | |
doctorura | 2:0fc5df933021 | 3 | #define DATA_OFFSET 44 |
doctorura | 2:0fc5df933021 | 4 | #define DAC_CENTER 32768 |
doctorura | 2:0fc5df933021 | 5 | |
doctorura | 0:5a700113dd87 | 6 | MagneWave::MagneWave( SoftMCP4922 *dac ) |
doctorura | 0:5a700113dd87 | 7 | { |
doctorura | 0:5a700113dd87 | 8 | m_wave_DAC = dac; |
doctorura | 2:0fc5df933021 | 9 | m_wave_DAC->write_u16( DAC_CENTER ); |
doctorura | 0:5a700113dd87 | 10 | } |
doctorura | 0:5a700113dd87 | 11 | |
doctorura | 0:5a700113dd87 | 12 | void MagneWave::play( FILE *wavefile ) |
doctorura | 0:5a700113dd87 | 13 | { |
doctorura | 0:5a700113dd87 | 14 | #if 0 |
doctorura | 0:5a700113dd87 | 15 | // data size check |
doctorura | 0:5a700113dd87 | 16 | unsiged long dataSize = 0; |
doctorura | 0:5a700113dd87 | 17 | seek( wavefile, 40, SEEK_SET ); |
doctorura | 0:5a700113dd87 | 18 | dataSize = fgetc( wavefile ); |
doctorura | 0:5a700113dd87 | 19 | dataSize |= ( fgetc( wavefile ) << 8 ); |
doctorura | 0:5a700113dd87 | 20 | dataSize |= ( fgetc( wavefile ) << 16 ); |
doctorura | 0:5a700113dd87 | 21 | dataSize |= ( fgetc( wavefile ) << 24 ); |
doctorura | 2:0fc5df933021 | 22 | printf( "data size = %ld\n", dataSize ); |
doctorura | 0:5a700113dd87 | 23 | #endif |
doctorura | 0:5a700113dd87 | 24 | |
doctorura | 0:5a700113dd87 | 25 | // jump to wave data |
doctorura | 2:0fc5df933021 | 26 | fseek( wavefile, DATA_OFFSET, SEEK_SET ); |
doctorura | 0:5a700113dd87 | 27 | |
doctorura | 0:5a700113dd87 | 28 | while(1){ |
doctorura | 1:a82b9af36dbf | 29 | //16bit |
doctorura | 1:a82b9af36dbf | 30 | /* |
doctorura | 0:5a700113dd87 | 31 | int tmpL = 0; |
doctorura | 0:5a700113dd87 | 32 | int tmpH = 0; |
doctorura | 0:5a700113dd87 | 33 | unsigned short dacVal16 = 0; |
doctorura | 0:5a700113dd87 | 34 | tmpL = fgetc( wavefile ); |
doctorura | 0:5a700113dd87 | 35 | if( tmpL == EOF ){ |
doctorura | 0:5a700113dd87 | 36 | break; |
doctorura | 0:5a700113dd87 | 37 | } |
doctorura | 0:5a700113dd87 | 38 | tmpH = fgetc( wavefile ); |
doctorura | 0:5a700113dd87 | 39 | if( tmpH == EOF ){ |
doctorura | 0:5a700113dd87 | 40 | break; |
doctorura | 0:5a700113dd87 | 41 | } |
doctorura | 0:5a700113dd87 | 42 | dacVal16 = tmpL; |
doctorura | 0:5a700113dd87 | 43 | dacVal16 |= ( tmpH << 8 ); |
doctorura | 0:5a700113dd87 | 44 | m_wave_DAC->write_u16( dacVal16 ); |
doctorura | 1:a82b9af36dbf | 45 | */ |
doctorura | 1:a82b9af36dbf | 46 | |
doctorura | 1:a82b9af36dbf | 47 | // 8bit |
doctorura | 1:a82b9af36dbf | 48 | int dacVal8 = fgetc( wavefile ); |
doctorura | 1:a82b9af36dbf | 49 | |
doctorura | 1:a82b9af36dbf | 50 | if( dacVal8 == EOF ){ |
doctorura | 1:a82b9af36dbf | 51 | break; |
doctorura | 1:a82b9af36dbf | 52 | } |
doctorura | 1:a82b9af36dbf | 53 | m_wave_DAC->write_u8( ( unsigned short )dacVal8 ); |
doctorura | 0:5a700113dd87 | 54 | |
doctorura | 0:5a700113dd87 | 55 | // TODO: adjust cycle |
doctorura | 2:0fc5df933021 | 56 | wait_us( 75 ); |
doctorura | 0:5a700113dd87 | 57 | } |
doctorura | 0:5a700113dd87 | 58 | } |