LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
c_sound.h
Go to the documentation of this file.
1 /*
2  * LEGO® MINDSTORMS EV3
3  *
4  * Copyright (C) 2010-2013 The LEGO Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef C_SOUND_H_
22 #define C_SOUND_H_
23 
24 #include "lms2012.h"
25 #include <stdio.h>
26 #include <string.h>
27 #include <sys/stat.h>
28 
29 #define STEP_SIZE_TABLE_ENTRIES 89
30 #define INDEX_TABLE_ENTRIES 16
31 enum
32 {
40 
41 // Percentage to SoundLevel -
42 // Adjust the percentage, if non-linear SPL response is needed
43 
44 #define SND_LEVEL_1 13 // 13% (12.5)
45 #define SND_LEVEL_2 25 // 25%
46 #define SND_LEVEL_3 38 // 38% (37.5)
47 #define SND_LEVEL_4 50 // 50%
48 #define SND_LEVEL_5 63 // 63% (62.5)
49 #define SND_LEVEL_6 75 // 75%
50 #define SND_LEVEL_7 88 // 88% (87.5)
51 
52 #define TONE_LEVEL_1 8 // 8%
53 #define TONE_LEVEL_2 16 // 16%
54 #define TONE_LEVEL_3 24 // 24%
55 #define TONE_LEVEL_4 32 // 32%
56 #define TONE_LEVEL_5 40 // 40%
57 #define TONE_LEVEL_6 48 // 48%
58 #define TONE_LEVEL_7 56 // 56%
59 #define TONE_LEVEL_8 64 // 64%
60 #define TONE_LEVEL_9 72 // 72%
61 #define TONE_LEVEL_10 80 // 80%
62 #define TONE_LEVEL_11 88 // 88%
63 #define TONE_LEVEL_12 96 // 96%
64 
65 
66 
67 
68 const SWORD StepSizeTable[STEP_SIZE_TABLE_ENTRIES] = { 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
69  19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
70  50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
71  130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
72  337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
73  876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
74  2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
75  5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
76  15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
77  };
78 
80  -1, -1, -1, -1, 2, 4, 6, 8,
81  -1, -1, -1, -1, 2, 4, 6, 8
82  };
83 
84 RESULT cSoundInit(void);
85 
86 RESULT cSoundOpen(void);
87 
88 RESULT cSoundUpdate(void);
89 
90 RESULT cSoundClose(void);
91 
92 RESULT cSoundExit(void);
93 
94 void cSoundEntry(void);
95 
96 void cSoundReady(void);
97 
98 void cSoundTest(void);
99 
100 
101 #define FILEFORMAT_RAW_SOUND 0x0100
102 #define FILEFORMAT_ADPCM_SOUND 0x0101
103 #define SOUND_MODE_ONCE 0x00
104 #define SOUND_LOOP 0x01
105 #define SOUND_ADPCM_INIT_VALPREV 0x7F
106 #define SOUND_ADPCM_INIT_INDEX 20
107 
108 typedef struct
109 {
110  //*****************************************************************************
111  // Sound Global variables
112  //*****************************************************************************
113 
116 
119  SOUND Sound;
120  SOUND *pSound;
131  char PathBuffer[MAX_FILENAME_SIZE];
132  struct stat FileStatus;
133  UBYTE SoundData[SOUND_FILE_BUFFER_SIZE + 1]; // Add up for CMD
134 }
136 
137 #if (HARDWARE == SIMULATION)
138  extern SOUND_GLOBALS * gSoundInstance;
139  #define SoundInstance (*gSoundInstance)
140 
141  void setSoundInstance(SOUND_GLOBALS * _Instance);
143 #else
145 #endif
146 
147 #endif /* C_SOUND_H_ */
int hSoundFile
Definition: c_sound.h:115
enum @37 SOUND_STATES
SOUND_GLOBALS * getSoundInstance()
Definition: c_sound.c:60
UWORD BytesLeft
Definition: c_sound.h:121
RESULT cSoundUpdate(void)
Definition: c_sound.c:199
const SWORD StepSizeTable[STEP_SIZE_TABLE_ENTRIES]
Definition: c_sound.h:68
UBYTE BytesToWrite
Definition: c_sound.h:130
UWORD SoundPlayMode
Definition: c_sound.h:125
RESULT cSoundInit(void)
Definition: c_sound.c:71
RESULT cSoundClose(void)
Definition: c_sound.c:114
#define INDEX_TABLE_ENTRIES
Definition: c_sound.h:30
SWORD Step
Definition: c_sound.h:129
RESULT cSoundExit(void)
Definition: c_sound.c:396
#define SOUND_FILE_BUFFER_SIZE
Definition: lms2012.h:536
UWORD SoundFileFormat
Definition: c_sound.h:122
void setSoundInstance(SOUND_GLOBALS *_Instance)
Definition: c_sound.c:55
UWORD SoundSampleRate
Definition: c_sound.h:124
DATA8 cSoundState
Definition: c_sound.h:118
#define SoundInstance
Definition: c_sound.h:139
SWORD Index
Definition: c_sound.h:128
SOUND Sound
Definition: c_sound.h:119
SOUND * pSound
Definition: c_sound.h:120
UWORD SoundFileLength
Definition: c_sound.h:126
unsigned char UBYTE
Basic Type used to symbolise 8 bit unsigned values.
Definition: lmstypes.h:29
UWORD SoundDataLength
Definition: c_sound.h:123
unsigned short UWORD
Basic Type used to symbolise 16 bit unsigned values.
Definition: lmstypes.h:30
void cSoundTest(void)
opSOUND_TEST byte code
Definition: c_sound.c:773
signed short SWORD
Basic Type used to symbolise 16 bit signed values.
Definition: lmstypes.h:34
RESULT cSoundOpen(void)
Definition: c_sound.c:105
SOUND_GLOBALS * gSoundInstance
Definition: c_sound.c:53
const SWORD IndexTable[INDEX_TABLE_ENTRIES]
Definition: c_sound.h:79
#define STEP_SIZE_TABLE_ENTRIES
Definition: c_sound.h:29
SBYTE DATA8
VM Type for 1 byte signed value.
Definition: lmstypes.h:61
SWORD ValPrev
Definition: c_sound.h:127
void cSoundEntry(void)
opSOUND byte code
Definition: c_sound.c:440
int SoundDriverDescriptor
Definition: c_sound.h:114
void cSoundReady(void)
opSOUND_READY byte code
Definition: c_sound.c:797
DATA8 SoundOwner
Definition: c_sound.h:117