~ubuntu-branches/ubuntu/trusty/vice/trusty

« back to all changes in this revision

Viewing changes to src/vic20/vic20sound.c

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2013-07-28 20:38:23 UTC
  • mfrom: (1.1.10) (9.2.7 sid)
  • Revision ID: package-import@ubuntu.com-20130728203823-1h8s6bcv22oundul
Tags: 2.4.dfsg-1
* New upstream release (closes: #693065, #693641).
* Drop vice-ffmpeg.patch , applied upstream.
* Disable architecture specific compilation (closes: #686400, #714136).

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include "lib.h"
36
36
#include "maincpu.h"
37
37
#include "sid.h"
 
38
#include "sidcart.h"
38
39
#include "sid-resources.h"
39
40
#include "sound.h"
40
41
#include "types.h"
41
42
#include "vic20sound.h"
42
43
#include "vic20.h"
43
44
 
 
45
/* ---------------------------------------------------------------------*/
 
46
 
 
47
/* Some prototypes are needed */
 
48
static int vic_sound_machine_init(sound_t *psid, int speed, int cycles_per_sec);
 
49
static int vic_sound_machine_calculate_samples(sound_t **psid, SWORD *pbuf, int nr, int sound_output_channels, int sound_chip_channels, int *delta_t);
 
50
static void vic_sound_machine_store(sound_t *psid, WORD addr, BYTE value);
 
51
static BYTE vic_sound_machine_read(sound_t *psid, WORD addr);
 
52
 
 
53
static int vic_sound_machine_cycle_based(void)
 
54
{
 
55
        return 1;
 
56
}
 
57
 
 
58
static int vic_sound_machine_channels(void)
 
59
{
 
60
        return 1;
 
61
}
 
62
 
 
63
static sound_chip_t vic_sound_chip = {
 
64
    NULL, /* no open */
 
65
    vic_sound_machine_init,
 
66
    NULL, /* no close */
 
67
    vic_sound_machine_calculate_samples,
 
68
    vic_sound_machine_store,
 
69
    vic_sound_machine_read,
 
70
    vic_sound_reset,
 
71
    vic_sound_machine_cycle_based,
 
72
    vic_sound_machine_channels,
 
73
    1 /* chip enabled */
 
74
};
 
75
 
 
76
static WORD vic_sound_chip_offset = 0;
 
77
 
 
78
void vic_sound_chip_init(void)
 
79
{
 
80
    vic_sound_chip_offset = sound_chip_register(&vic_sound_chip);
 
81
}
 
82
 
 
83
/* ---------------------------------------------------------------------*/
 
84
 
44
85
static BYTE noisepattern[1024] = {
45
86
      7, 30, 30, 28, 28, 62, 60, 56,120,248,124, 30, 31,143,  7,  7,193,192,224,
46
87
    241,224,240,227,225,192,224,120,126, 60, 56,224,225,195,195,135,199,  7, 30,
158
199
    return 0;
159
200
}
160
201
 
 
202
/* dummy function for now */
 
203
int machine_sid3_check_range(unsigned int sid3_adr)
 
204
{
 
205
    return 0;
 
206
}
 
207
 
161
208
void machine_sid2_enable(int val)
162
209
{
163
210
}
178
225
    int accum;
179
226
    int accum_cycles;
180
227
 
181
 
    int cycles_per_sample;
182
 
    int leftover_cycles;
 
228
    float cycles_per_sample;
 
229
    float leftover_cycles;
183
230
    int speed;
184
231
 
185
232
    float highpassbuf;
193
240
 
194
241
void vic_sound_clock(int cycles);
195
242
 
196
 
static int vic_sound_machine_calculate_samples(sound_t *psid, SWORD *pbuf, int nr,
197
 
                                    int interleave, int *delta_t)
 
243
static int vic_sound_machine_calculate_samples(sound_t **psid, SWORD *pbuf, int nr, int soc, int scc, int *delta_t)
198
244
{
199
245
    int s = 0;
 
246
    int i;
 
247
    float o;
 
248
    SWORD vicbuf;
 
249
    int samples_to_do;
200
250
 
201
251
    while (s < nr && *delta_t >= snd.cycles_per_sample - snd.leftover_cycles) {
202
 
        float o;
203
 
        SWORD vicbuf;
204
 
        int samples_to_do = snd.cycles_per_sample;
205
 
 
206
 
        if (snd.leftover_cycles) {
207
 
          samples_to_do -= snd.leftover_cycles;
208
 
          snd.leftover_cycles = 0;
209
 
        }
 
252
        samples_to_do = (int)(snd.cycles_per_sample - snd.leftover_cycles);
 
253
        snd.leftover_cycles += samples_to_do - snd.cycles_per_sample;
210
254
        vic_sound_clock(samples_to_do);
211
255
 
212
 
        o = voltagefunction[(((snd.accum*7)/snd.accum_cycles) + 1) * snd.volume];
213
 
        o = snd.lowpassbuf*snd.lowpassbeta + o*(1.0f-snd.lowpassbeta); /* 0.75f + o*0.25f; */
214
 
        snd.lowpassbuf=o;
 
256
        o = voltagefunction[(((snd.accum * 7) / snd.accum_cycles) + 1) * snd.volume];
 
257
        o = snd.lowpassbuf * snd.lowpassbeta + o * (1.0f - snd.lowpassbeta); /* 0.75f + o*0.25f; */
 
258
        snd.lowpassbuf = o;
215
259
        o -= snd.highpassbuf;
216
260
        snd.highpassbuf += o * snd.highpassbeta;
217
261
 
223
267
            vicbuf = (SWORD)o;
224
268
        }
225
269
 
226
 
        pbuf[s * interleave] = vicbuf;
 
270
        for (i = 0; i < soc; i++) {
 
271
            pbuf[(s * soc) + i] = vicbuf;
 
272
        }
227
273
        s++;
228
274
        snd.accum = 0;
229
275
        snd.accum_cycles = 0;
237
283
    return s;
238
284
}
239
285
 
240
 
void vic_sound_reset(void)
 
286
void vic_sound_reset(sound_t *psid, CLOCK cpu_clk)
241
287
{
242
288
    WORD i;
243
289
 
244
 
    sound_reset();
245
290
    for (i = 10; i < 15; i++) {
246
291
        vic_sound_store(i, 0);
247
292
    }
251
296
{
252
297
    addr &= 0x0f;
253
298
    vic20_sound_data[addr] = value;
254
 
    sound_store((WORD)(addr+0x20), value, 0);
 
299
 
 
300
    sound_store((WORD)(vic_sound_chip_offset | addr), value, 0);
255
301
}
256
302
 
257
303
 
343
389
 
344
390
    memset((unsigned char*)&snd, 0, sizeof(snd));
345
391
 
346
 
    snd.cycles_per_sample = cycles_per_sec / speed;
 
392
    snd.cycles_per_sample = (float)cycles_per_sec / speed;
 
393
    snd.leftover_cycles = 0.0f;
347
394
 
348
395
    snd.speed = speed;
349
396
 
362
409
    return 0;
363
410
}
364
411
 
365
 
sound_t *sound_machine_open(int chipno)
366
 
{
367
 
    return sid_sound_machine_open(chipno);
368
 
}
369
 
 
370
 
int sound_machine_init(sound_t *psid, int speed, int cycles_per_sec)
371
 
{
372
 
    vic_sound_machine_init(psid, speed, cycles_per_sec);
373
 
 
374
 
    if (!sidcart_clock && cycles_per_sec == VIC20_PAL_CYCLES_PER_SEC) {
375
 
        return sid_sound_machine_init(psid, (int)(speed*1.125), cycles_per_sec);
376
 
    } else {
377
 
        return sid_sound_machine_init(psid, speed, cycles_per_sec);
378
 
    }
379
 
}
380
 
 
381
 
void sound_machine_close(sound_t *psid)
382
 
{
383
 
    sid_sound_machine_close(psid);
384
 
}
385
 
 
386
 
/* for read/store 0x00 <= addr <= 0x1f is the sid
387
 
 *                0x20 <= addr <= 0x3f is the vic
388
 
 *
389
 
 * future sound devices will be able to use 0x40 and up
390
 
 */
391
 
 
392
 
BYTE sound_machine_read(sound_t *psid, WORD addr)
393
 
{
394
 
    if (addr >= 0x20 && addr <= 0x3f) {
395
 
        return vic_sound_machine_read(psid, (WORD)(addr-0x20));
396
 
    } else {
397
 
        return sid_sound_machine_read(psid, addr);
398
 
    }
399
 
}
400
 
 
401
 
void sound_machine_store(sound_t *psid, WORD addr, BYTE byte)
402
 
{
403
 
    if (addr >= 0x20 && addr <= 0x3f) {
404
 
        vic_sound_machine_store(psid, (WORD)(addr-0x20), byte);
405
 
    } else {
406
 
        sid_sound_machine_store(psid, addr, byte);
407
 
    }
408
 
}
409
 
 
410
 
void sound_machine_reset(sound_t *psid, CLOCK cpu_clk)
411
 
{
412
 
    sid_sound_machine_reset(psid, cpu_clk);
413
 
}
414
 
 
415
 
int sound_machine_calculate_samples(sound_t *psid, SWORD *pbuf, int nr,
416
 
                                    int interleave, int *delta_t)
417
 
{
418
 
    int temp;
419
 
 
420
 
    temp = vic_sound_machine_calculate_samples(psid, pbuf, nr, interleave, delta_t);
421
 
    return fastsid_calculate_samples_mix(psid, pbuf, temp, interleave, delta_t);
422
 
}
423
 
 
424
412
void sound_machine_prevent_clk_overflow(sound_t *psid, CLOCK sub)
425
413
{
426
414
    sid_sound_machine_prevent_clk_overflow(psid, sub);
431
419
    return sid_sound_machine_dump_state(psid);
432
420
}
433
421
 
434
 
int sound_machine_cycle_based(void)
435
 
{
436
 
    return 1;
437
 
}
438
 
 
439
 
int sound_machine_channels(void)
440
 
{
441
 
    return sid_sound_machine_channels();
442
 
}
443
 
 
444
422
void sound_machine_enable(int enable)
445
423
{
446
424
    sid_sound_machine_enable(enable);