~ubuntu-branches/ubuntu/karmic/xmame/karmic

« back to all changes in this revision

Viewing changes to src/sound/votrax.c

  • Committer: Bazaar Package Importer
  • Author(s): Bruno Barrera C.
  • Date: 2007-02-16 10:06:54 UTC
  • mfrom: (2.1.5 edgy)
  • Revision ID: james.westby@ubuntu.com-20070216100654-iztas2cl47k5j039
Tags: 0.106-2
* Added Italian debconf templates translation. (closes: #382672)
* Added German debconf templates translation. (closes: #396610)
* Added Japanese debconf templates translation. (closes: #400011)
* Added Portuguese debconf templates translation. (closes: #409960)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**************************************************************************
2
2
 
3
 
        Votrax SC-01 Emulator
 
3
    Votrax SC-01 Emulator
4
4
 
5
 
        Mike@Dissfulfils.co.uk
 
5
    Mike@Dissfulfils.co.uk
6
6
 
7
7
**************************************************************************
8
8
 
9
9
sh_votrax_start  - Start emulation, load samples from Votrax subdirectory
10
10
sh_votrax_stop   - End emulation, free memory used for samples
11
 
votrax_w                 - Write data to votrax port
 
11
votrax_w         - Write data to votrax port
12
12
votrax_status    - Return busy status (-1 = busy)
13
13
 
14
14
If you need to alter the base frequency (i.e. Qbert) then just alter
16
16
 
17
17
**************************************************************************/
18
18
 
19
 
#include "driver.h"
20
 
 
21
 
int             VotraxBaseFrequency;            /* Some games (Qbert) change this */
22
 
int     VotraxBaseVolume;
23
 
int     VotraxChannel;
24
 
 
25
 
struct  GameSamples *VotraxSamples;
 
19
#include "sndintrf.h"
 
20
#include "streams.h"
 
21
#include "samples.h"
 
22
 
 
23
 
 
24
struct votrax_info
 
25
{
 
26
        int             stream;
 
27
        int             frequency;              /* Some games (Qbert) change this */
 
28
        int     volume;
 
29
        sound_stream *  channel;
 
30
 
 
31
        struct loaded_sample *sample;
 
32
        UINT32          pos;
 
33
        UINT32          frac;
 
34
        UINT32          step;
 
35
 
 
36
        struct  loaded_samples *samples;
 
37
};
 
38
 
 
39
#define FRAC_BITS               24
 
40
#define FRAC_ONE                (1 << FRAC_BITS)
 
41
#define FRAC_MASK               (FRAC_ONE - 1)
 
42
 
26
43
 
27
44
/****************************************************************************
28
45
 * 64 Phonemes - currently 1 sample per phoneme, will be combined sometime!
41
58
 0
42
59
};
43
60
 
44
 
void sh_votrax_start(int Channel)
45
 
{
46
 
        VotraxSamples = readsamples(VotraxTable,"votrax");
47
 
    VotraxBaseFrequency = 8000;
48
 
    VotraxBaseVolume = 230;
49
 
    VotraxChannel = Channel;
50
 
}
51
 
 
52
 
void sh_votrax_stop(void)
53
 
{
54
 
}
 
61
static void votrax_update_sound(void *param, stream_sample_t **inputs, stream_sample_t **_buffer, int length)
 
62
{
 
63
        struct votrax_info *info = param;
 
64
        stream_sample_t *buffer = _buffer[0];
 
65
 
 
66
        if (info->sample)
 
67
        {
 
68
                /* load some info locally */
 
69
                UINT32 pos = info->pos;
 
70
                UINT32 frac = info->frac;
 
71
                UINT32 step = info->step;
 
72
                UINT32 length = info->sample->length;
 
73
                INT16 *sample = info->sample->data;
 
74
 
 
75
                while (length--)
 
76
                {
 
77
                        /* do a linear interp on the sample */
 
78
                        INT32 sample1 = sample[pos];
 
79
                        INT32 sample2 = sample[(pos + 1) % length];
 
80
                        INT32 fracmult = frac >> (FRAC_BITS - 14);
 
81
                        *buffer++ = ((0x4000 - fracmult) * sample1 + fracmult * sample2) >> 14;
 
82
 
 
83
                        /* advance */
 
84
                        frac += step;
 
85
                        pos += frac >> FRAC_BITS;
 
86
                        frac = frac & ((1 << FRAC_BITS) - 1);
 
87
 
 
88
                        /* handle looping/ending */
 
89
                        if (pos >= length)
 
90
                        {
 
91
                                info->sample = NULL;
 
92
                                break;
 
93
                        }
 
94
                }
 
95
 
 
96
                /* push position back out */
 
97
                info->pos = pos;
 
98
                info->frac = frac;
 
99
        }
 
100
}
 
101
 
 
102
 
 
103
static void *votrax_start(int sndindex, int clock, const void *config)
 
104
{
 
105
        struct votrax_info *votrax;
 
106
 
 
107
        votrax = auto_malloc(sizeof(*votrax));
 
108
        memset(votrax, 0, sizeof(*votrax));
 
109
 
 
110
        votrax->samples = readsamples(VotraxTable,"votrax");
 
111
    votrax->frequency = 8000;
 
112
    votrax->volume = 230;
 
113
 
 
114
    votrax->channel = stream_create(0, 1, Machine->sample_rate, votrax, votrax_update_sound);
 
115
 
 
116
        votrax->sample = NULL;
 
117
        votrax->step = 0;
 
118
 
 
119
        return votrax;
 
120
}
 
121
 
55
122
 
56
123
void votrax_w(int data)
57
124
{
 
125
        struct votrax_info *info = sndti_token(SOUND_VOTRAX, 0);
58
126
        int Phoneme,Intonation;
59
127
 
 
128
        stream_update(info->channel, 0);
 
129
 
60
130
    Phoneme = data & 0x3F;
61
131
    Intonation = data >> 6;
62
132
 
63
133
        logerror("Speech : %s at intonation %d\n",VotraxTable[Phoneme],Intonation);
64
134
 
65
135
    if(Phoneme==63)
66
 
                mixer_stop_sample(VotraxChannel);
 
136
        info->sample = NULL;
67
137
 
68
 
    if(VotraxSamples->sample[Phoneme])
 
138
    if(info->samples->sample[Phoneme].data)
69
139
        {
70
 
                mixer_set_volume(VotraxChannel,VotraxBaseVolume+(8*Intonation)*100/255);
71
 
                mixer_play_sample(VotraxChannel,VotraxSamples->sample[Phoneme]->data,
72
 
                                  VotraxSamples->sample[Phoneme]->length,
73
 
                                  VotraxBaseFrequency+(256*Intonation),
74
 
                                  0);
 
140
                info->sample = &info->samples->sample[Phoneme];
 
141
                info->pos = 0;
 
142
                info->frac = 0;
 
143
                info->step = ((INT64)(info->sample->frequency + (256*Intonation)) << FRAC_BITS) / Machine->sample_rate;
 
144
                stream_set_output_gain(info->channel, 0, (info->volume + (8*Intonation)*100/255) / 100.0);
75
145
        }
76
146
}
77
147
 
78
148
int votrax_status_r(void)
79
149
{
80
 
    return mixer_is_sample_playing(VotraxChannel);
 
150
        struct votrax_info *info = sndti_token(SOUND_VOTRAX, 0);
 
151
        stream_update(info->channel, 0);
 
152
    return (info->sample != NULL);
 
153
}
 
154
 
 
155
 
 
156
 
 
157
/**************************************************************************
 
158
 * Generic get_info
 
159
 **************************************************************************/
 
160
 
 
161
static void votrax_set_info(void *token, UINT32 state, sndinfo *info)
 
162
{
 
163
        switch (state)
 
164
        {
 
165
                /* no parameters to set */
 
166
        }
 
167
}
 
168
 
 
169
 
 
170
void votrax_get_info(void *token, UINT32 state, sndinfo *info)
 
171
{
 
172
        switch (state)
 
173
        {
 
174
                /* --- the following bits of info are returned as 64-bit signed integers --- */
 
175
 
 
176
                /* --- the following bits of info are returned as pointers to data or functions --- */
 
177
                case SNDINFO_PTR_SET_INFO:                                              info->set_info = votrax_set_info;               break;
 
178
                case SNDINFO_PTR_START:                                                 info->start = votrax_start;                             break;
 
179
                case SNDINFO_PTR_STOP:                                                  /* Nothing */                                                   break;
 
180
                case SNDINFO_PTR_RESET:                                                 /* Nothing */                                                   break;
 
181
 
 
182
                /* --- the following bits of info are returned as NULL-terminated strings --- */
 
183
                case SNDINFO_STR_NAME:                                                  info->s = "Votrax SC-01";                               break;
 
184
                case SNDINFO_STR_CORE_FAMILY:                                   info->s = "Votrax speech";                              break;
 
185
                case SNDINFO_STR_CORE_VERSION:                                  info->s = "1.0";                                                break;
 
186
                case SNDINFO_STR_CORE_FILE:                                             info->s = __FILE__;                                             break;
 
187
                case SNDINFO_STR_CORE_CREDITS:                                  info->s = "Copyright (c) 2004, The MAME Team"; break;
 
188
        }
81
189
}
82
190