Gugen展示版
Fork of MagneWave by
MagneWave.cpp@0:5a700113dd87, 2013-10-29 (annotated)
- Committer:
- doctorura
- Date:
- Tue Oct 29 06:49:27 2013 +0000
- Revision:
- 0:5a700113dd87
- Child:
- 1:a82b9af36dbf
MagneWave (16bit PCM only player) is added.
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 | 0:5a700113dd87 | 3 | MagneWave::MagneWave( SoftMCP4922 *dac ) |
doctorura | 0:5a700113dd87 | 4 | { |
doctorura | 0:5a700113dd87 | 5 | m_wave_DAC = dac; |
doctorura | 0:5a700113dd87 | 6 | m_wave_DAC->write_u16( 32768 ); |
doctorura | 0:5a700113dd87 | 7 | } |
doctorura | 0:5a700113dd87 | 8 | |
doctorura | 0:5a700113dd87 | 9 | void MagneWave::play( FILE *wavefile ) |
doctorura | 0:5a700113dd87 | 10 | { |
doctorura | 0:5a700113dd87 | 11 | #if 0 |
doctorura | 0:5a700113dd87 | 12 | // data size check |
doctorura | 0:5a700113dd87 | 13 | unsiged long dataSize = 0; |
doctorura | 0:5a700113dd87 | 14 | seek( wavefile, 40, SEEK_SET ); |
doctorura | 0:5a700113dd87 | 15 | dataSize = fgetc( wavefile ); |
doctorura | 0:5a700113dd87 | 16 | dataSize |= ( fgetc( wavefile ) << 8 ); |
doctorura | 0:5a700113dd87 | 17 | dataSize |= ( fgetc( wavefile ) << 16 ); |
doctorura | 0:5a700113dd87 | 18 | dataSize |= ( fgetc( wavefile ) << 24 ); |
doctorura | 0:5a700113dd87 | 19 | printf("data size = %ld\n", dataSize ); |
doctorura | 0:5a700113dd87 | 20 | #endif |
doctorura | 0:5a700113dd87 | 21 | |
doctorura | 0:5a700113dd87 | 22 | // jump to wave data |
doctorura | 0:5a700113dd87 | 23 | fseek( wavefile, 44, SEEK_SET ); |
doctorura | 0:5a700113dd87 | 24 | |
doctorura | 0:5a700113dd87 | 25 | while(1){ |
doctorura | 0:5a700113dd87 | 26 | int tmpL = 0; |
doctorura | 0:5a700113dd87 | 27 | int tmpH = 0; |
doctorura | 0:5a700113dd87 | 28 | unsigned short dacVal16 = 0; |
doctorura | 0:5a700113dd87 | 29 | tmpL = fgetc( wavefile ); |
doctorura | 0:5a700113dd87 | 30 | if( tmpL == EOF ){ |
doctorura | 0:5a700113dd87 | 31 | break; |
doctorura | 0:5a700113dd87 | 32 | } |
doctorura | 0:5a700113dd87 | 33 | tmpH = fgetc( wavefile ); |
doctorura | 0:5a700113dd87 | 34 | if( tmpH == EOF ){ |
doctorura | 0:5a700113dd87 | 35 | break; |
doctorura | 0:5a700113dd87 | 36 | } |
doctorura | 0:5a700113dd87 | 37 | dacVal16 = tmpL; |
doctorura | 0:5a700113dd87 | 38 | dacVal16 |= ( tmpH << 8 ); |
doctorura | 0:5a700113dd87 | 39 | m_wave_DAC->write_u16( dacVal16 ); |
doctorura | 0:5a700113dd87 | 40 | |
doctorura | 0:5a700113dd87 | 41 | // TODO: adjust cycle |
doctorura | 0:5a700113dd87 | 42 | wait( 0.005 ); |
doctorura | 0:5a700113dd87 | 43 | } |
doctorura | 0:5a700113dd87 | 44 | } |