This commit was manufactured by cvs2svn to create branch 'decode'.
[gnokii.git] / include / gsm-ringtones.h
1 /*
2
3   G N O K I I
4
5   A Linux/Unix toolset and driver for Nokia mobile phones.
6
7   Released under the terms of the GNU GPL, see file COPYING for more details.
8
9   This file provides definitions of macros from the Smart Messaging
10   Specification. It is mainly rewrite of the spec to C :-) Viva Nokia!
11
12 */
13
14 #ifndef __gsm_ringtones_h
15 #define __gsm_ringtones_h
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <ctype.h>
21 #include "misc.h"
22 #include "gsm-common.h"
23 #include "gsm-sms.h"
24
25 #define MAX_RINGTONE_NOTES 255
26
27 /* Structure to hold note of ringtone. */
28 /* NoteValue is encoded as octave(scale)*14 + note */
29 /* where for note: c=0, d=2, e=4 .... */
30 /* ie. c#=1 and 5 and 13 are invalid */
31 /* note=255 means a pause */
32 typedef struct {
33   u8 duration;
34   u8 note;
35   int tempo;
36   u8 style;
37 } GSM_RingtoneNote;
38
39 /* Structure to hold ringtones. */
40 typedef struct {
41   char name[20];
42   unsigned char Loop;
43   u8 NrNotes;
44   GSM_RingtoneNote notes[256];
45   bool allnotesscale; /* Some Nokia phones doesn't receive correctly some
46                          ringtones without it. N3310 4.02 */
47   int location;
48 } GSM_Ringtone;
49   
50 /* Structure to hold binary ringtones. */
51
52 typedef struct {
53   char name[20];
54   unsigned char frame[1000];
55   int length;
56   int location;
57 } GSM_BinRingtone;
58
59 #define GetBit(Stream,BitNr) Stream[(BitNr)/8] & 1<<(7-((BitNr)%8))
60 #define SetBit(Stream,BitNr) Stream[(BitNr)/8] |= 1<<(7-((BitNr)%8))
61 #define ClearBit(Stream,BitNr) Stream[(BitNr)/8] &= 255 - (1 << (7-((BitNr)%8)))
62
63 /* These values are from Smart Messaging Specification Revision 2.0.0 pages
64    3-23, ..., 3-29 */
65
66 /* Command-Part Encoding */
67
68 #define CancelCommand          (0x05<<1) /* binary 0000 101 */
69 #define RingingToneProgramming (0x25<<1) /* binary 0100 101 */
70 #define Sound                  (0x1d<<1) /* binary 0011 101 */
71 /* MW: I didn't find phone, which can unpack ringtone with Unicode
72    command. Tested 3310, 6150 */
73 #define Unicode                (0x22<<1) /* binary 0100 010 */
74
75 /* Song-Type Encoding */
76
77 #define BasicSongType     (0x01<<5) /* binary 001 */
78 #define TemporarySongType (0x02<<5) /* binary 010 */
79 #define MidiSongType      (0x03<<5) /* binary 011 */
80 #define DigitizedSongType (0x04<<5) /* binary 100 */
81
82 /* Instruction ID Encoding */
83
84 #define PatternHeaderId      (0x00<<5) /* binary 000 */
85 #define NoteInstructionId    (0x01<<5) /* binary 001 */
86 #define ScaleInstructionId   (0x02<<5) /* binary 010 */
87 #define StyleInstructionId   (0x03<<5) /* binary 011 */
88 #define TempoInstructionId   (0x04<<5) /* binary 100 */
89 #define VolumeInstructionId  (0x05<<5) /* binary 101 */
90
91 /* Style-Value Encoding*/
92
93 #define NaturalStyle    (0x00<<6) /* binary 00 */
94 #define ContinuousStyle (0x01<<6) /* binary 01 */
95 #define StaccatoStyle   (0x02<<6) /* binary 10 */
96
97 /* Note-Scale Encoding  */
98
99 #define Scale1 (0x00<<6) /* binary 00 */
100 #define Scale2 (0x01<<6) /* binary 01 */
101 #define Scale3 (0x02<<6) /* binary 10 */
102 #define Scale4 (0x03<<6) /* binary 11 */
103
104 /* Note-Value Encoding */
105
106 #define Note_Pause (0x00<<4) /* binary 0000 */
107 #define Note_C     (0x01<<4) /* binary 0001 */
108 #define Note_Cis   (0x02<<4) /* binary 0010 */
109 #define Note_D     (0x03<<4) /* binary 0011 */
110 #define Note_Dis   (0x04<<4) /* binary 0100 */
111 #define Note_E     (0x05<<4) /* binary 0101 */
112 #define Note_F     (0x06<<4) /* binary 0110 */
113 #define Note_Fis   (0x07<<4) /* binary 0111 */
114 #define Note_G     (0x08<<4) /* binary 1000 */
115 #define Note_Gis   (0x09<<4) /* binary 1001 */
116 #define Note_A     (0x0a<<4) /* binary 1010 */
117 #define Note_Ais   (0x0b<<4) /* binary 1011 */
118 #define Note_H     (0x0c<<4) /* binary 1100 */
119
120 /* Note-Duration Encoding */
121
122 #define Duration_Full (0x00<<5) /* binary 000 */
123 #define Duration_1_2  (0x01<<5) /* binary 001 */
124 #define Duration_1_4  (0x02<<5) /* binary 010 */
125 #define Duration_1_8  (0x03<<5) /* binary 011 */
126 #define Duration_1_16 (0x04<<5) /* binary 100 */
127 #define Duration_1_32 (0x05<<5) /* binary 101 */
128
129 /* Note-Duration-Specifier Encoding */
130
131 #define NoSpecialDuration (0x00<<6) /* binary 00 */
132 #define DottedNote        (0x01<<6) /* binary 01 */
133 #define DoubleDottedNote  (0x02<<6) /* binary 10 */
134 #define Length_2_3        (0x03<<6) /* binary 11 */
135
136 /* Pattern ID Encoding */
137 #define A_part (0x00<<6) /* binary 00 */
138 #define B_part (0x01<<6) /* binary 01 */
139 #define C_part (0x02<<6) /* binary 10 */
140 #define D_part (0x03<<6) /* binary 11 */
141
142 /* Command-End */
143 #define CommandEnd (0x00) /* binary 00000000 */
144
145 u8 GSM_PackRingtone(GSM_Ringtone *ringtone, unsigned char *package, int *maxlength);
146 GSM_Error GSM_UnPackRingtone(GSM_Ringtone *ringtone, char *package, int maxlength);
147
148 int GSM_GetDuration(int number, unsigned char *spec);
149 int GSM_GetNote(int number);
150 int GSM_GetScale(int number);
151 int GSM_GetTempo(int Beats);
152
153 void GSM_PlayOneNote (GSM_RingtoneNote note);
154 void GSM_PlayRingtone (GSM_Ringtone *ringtone);
155
156 int GSM_GetFrequency(int number);
157
158 GSM_Error GSM_ReadRingtone(GSM_SMSMessage *message, GSM_Ringtone *ringtone);
159
160 int GSM_SaveRingtoneToSMS(GSM_MultiSMSMessage *SMS,
161                           GSM_Ringtone *ringtone,bool profilestyle);
162
163 /* FIXME: For each phone probaby different */
164 #define FB61_MAX_RINGTONE_FRAME_LENGTH 200
165
166 /* Smart Messaging 3.0 says: 16*9=144 bytes,
167    but on 3310 4.02 it was possible to save about 196 chars (without cutting) */
168 #define SM30_MAX_RINGTONE_FRAME_LENGTH 196
169
170 /* Like PC Composer help say */
171 #define FB61_MAX_RINGTONE_NOTES 130
172
173 /* Nokia ringtones codes. */
174
175 struct OneRingtone {
176   char name[30];
177   int menu;
178   int code;
179 };
180
181 void PrepareRingingTones(char model[64], char rev[64]);
182
183 /* returns names from code or number in menu */
184 char *RingingToneName(int code, int menu);
185
186 /* returns code from number in menu */
187 int RingingToneCode(int menu);
188
189 /* returns number in menu from code */
190 int RingingToneMenu(int code);
191
192 int NumberOfRingtones();
193
194 GSM_Error GSM_GetPhoneRingtone(GSM_BinRingtone *ringtone,GSM_Ringtone *SMringtone);
195
196 #endif  /* __gsm_ringtones_h */