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@1:a82b9af36dbf, 2013-10-29 (annotated)
- Committer:
- doctorura
- Date:
- Tue Oct 29 15:58:06 2013 +0000
- Revision:
- 1:a82b9af36dbf
- Parent:
- 0:5a700113dd87
- Child:
- 2:0fc5df933021
8bit version
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 | 1:a82b9af36dbf | 26 | //16bit |
| doctorura | 1:a82b9af36dbf | 27 | /* |
| doctorura | 0:5a700113dd87 | 28 | int tmpL = 0; |
| doctorura | 0:5a700113dd87 | 29 | int tmpH = 0; |
| doctorura | 0:5a700113dd87 | 30 | unsigned short dacVal16 = 0; |
| doctorura | 0:5a700113dd87 | 31 | tmpL = fgetc( wavefile ); |
| doctorura | 0:5a700113dd87 | 32 | if( tmpL == EOF ){ |
| doctorura | 0:5a700113dd87 | 33 | break; |
| doctorura | 0:5a700113dd87 | 34 | } |
| doctorura | 0:5a700113dd87 | 35 | tmpH = fgetc( wavefile ); |
| doctorura | 0:5a700113dd87 | 36 | if( tmpH == EOF ){ |
| doctorura | 0:5a700113dd87 | 37 | break; |
| doctorura | 0:5a700113dd87 | 38 | } |
| doctorura | 0:5a700113dd87 | 39 | dacVal16 = tmpL; |
| doctorura | 0:5a700113dd87 | 40 | dacVal16 |= ( tmpH << 8 ); |
| doctorura | 0:5a700113dd87 | 41 | m_wave_DAC->write_u16( dacVal16 ); |
| doctorura | 1:a82b9af36dbf | 42 | */ |
| doctorura | 1:a82b9af36dbf | 43 | |
| doctorura | 1:a82b9af36dbf | 44 | // 8bit |
| doctorura | 1:a82b9af36dbf | 45 | int dacVal8 = fgetc( wavefile ); |
| doctorura | 1:a82b9af36dbf | 46 | |
| doctorura | 1:a82b9af36dbf | 47 | if( dacVal8 == EOF ){ |
| doctorura | 1:a82b9af36dbf | 48 | break; |
| doctorura | 1:a82b9af36dbf | 49 | } |
| doctorura | 1:a82b9af36dbf | 50 | m_wave_DAC->write_u8( ( unsigned short )dacVal8 ); |
| doctorura | 0:5a700113dd87 | 51 | |
| doctorura | 0:5a700113dd87 | 52 | // TODO: adjust cycle |
| doctorura | 1:a82b9af36dbf | 53 | wait_us(100); |
| doctorura | 0:5a700113dd87 | 54 | } |
| doctorura | 0:5a700113dd87 | 55 | } |