~ubuntu-branches/ubuntu/quantal/vice/quantal

« back to all changes in this revision

Viewing changes to src/sound.c

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2006-07-30 19:15:59 UTC
  • mto: (9.1.1 lenny) (1.1.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20060730191559-g31ymd2mk102kzff
Tags: upstream-1.19
ImportĀ upstreamĀ versionĀ 1.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#include "maincpu.h"
46
46
#include "resources.h"
47
47
#include "sound.h"
 
48
#ifdef HAS_TRANSLATION
 
49
#include "translate.h"
 
50
#endif
48
51
#include "types.h"
49
52
#include "ui.h"
50
53
#include "util.h"
212
215
 
213
216
/* ------------------------------------------------------------------------- */
214
217
 
215
 
static const cmdline_option_t cmdline_options[] = {
216
 
    { "-sound", SET_RESOURCE, 0, NULL, NULL, "Sound", (resource_value_t)1,
217
 
      NULL, "Enable sound playback" },
218
 
    { "+sound", SET_RESOURCE, 0, NULL, NULL, "Sound", (resource_value_t)0,
219
 
      NULL, "Disable sound playback" },
220
 
    { "-soundrate", SET_RESOURCE, 1, NULL, NULL, "SoundSampleRate", NULL,
221
 
      "<value>", "Set sound sample rate to <value> Hz" },
222
 
    { "-soundbufsize", SET_RESOURCE, 1, NULL, NULL, "SoundBufferSize", NULL,
223
 
      "<value>", "Set sound buffer size to <value> msec" },
224
 
    { "-sounddev", SET_RESOURCE, 1, NULL, NULL, "SoundDeviceName", NULL,
225
 
      "<name>", "Specify sound driver" },
226
 
    { "-soundarg", SET_RESOURCE, 1, NULL, NULL, "SoundDeviceArg", NULL,
227
 
      "<args>", "Specify initialization parameters for sound driver" },
228
 
    { "-soundrecdev", SET_RESOURCE, 1, NULL, NULL, "SoundRecordDeviceName",
229
 
      NULL, "<name>", "Specify recording sound driver" },
230
 
    { "-soundrecarg", SET_RESOURCE, 1, NULL, NULL, "SoundRecordDeviceArg", NULL,
231
 
      "<args>", "Specify initialization parameters for recording sound driver" },
232
 
    { "-soundsync", SET_RESOURCE, 1, NULL, NULL, "SoundSpeedAdjustment", NULL,
233
 
      "<sync>", "Set sound speed adjustment (0: flexible, 1: adjusting, 2: exact)" },
234
 
    { NULL }
235
 
};
 
218
#ifdef HAS_TRANSLATION
 
219
static const cmdline_option_t cmdline_options[] = {
 
220
    { "-sound", SET_RESOURCE, 0, NULL, NULL, "Sound", (resource_value_t)1,
 
221
      0, IDCLS_ENABLE_SOUND_PLAYBACK },
 
222
    { "+sound", SET_RESOURCE, 0, NULL, NULL, "Sound", (resource_value_t)0,
 
223
      0, IDCLS_DISABLE_SOUND_PLAYBACK },
 
224
    { "-soundrate", SET_RESOURCE, 1, NULL, NULL, "SoundSampleRate", NULL,
 
225
      IDCLS_P_VALUE, IDCLS_SET_SAMPLE_RATE_VALUE_HZ },
 
226
    { "-soundbufsize", SET_RESOURCE, 1, NULL, NULL, "SoundBufferSize", NULL,
 
227
      IDCLS_P_VALUE, IDCLS_SET_SOUND_BUFFER_SIZE_MSEC },
 
228
    { "-sounddev", SET_RESOURCE, 1, NULL, NULL, "SoundDeviceName", NULL,
 
229
      IDCLS_P_NAME, IDCLS_SPECIFY_SOUND_DRIVER },
 
230
    { "-soundarg", SET_RESOURCE, 1, NULL, NULL, "SoundDeviceArg", NULL,
 
231
      IDCLS_P_ARGS, IDCLS_SPECIFY_SOUND_DRIVER_PARAM },
 
232
    { "-soundrecdev", SET_RESOURCE, 1, NULL, NULL, "SoundRecordDeviceName",
 
233
      NULL, IDCLS_P_NAME, IDCLS_SPECIFY_RECORDING_SOUND_DRIVER },
 
234
    { "-soundrecarg", SET_RESOURCE, 1, NULL, NULL, "SoundRecordDeviceArg", NULL,
 
235
      IDCLS_P_ARGS, IDCLS_SPECIFY_REC_SOUND_DRIVER_PARAM },
 
236
    { "-soundsync", SET_RESOURCE, 1, NULL, NULL, "SoundSpeedAdjustment", NULL,
 
237
      IDCLS_P_SYNC, IDCLS_SET_SOUND_SPEED_ADJUST },
 
238
    { NULL }
 
239
};
 
240
#else
 
241
static const cmdline_option_t cmdline_options[] = {
 
242
    { "-sound", SET_RESOURCE, 0, NULL, NULL, "Sound", (resource_value_t)1,
 
243
      NULL, N_("Enable sound playback") },
 
244
    { "+sound", SET_RESOURCE, 0, NULL, NULL, "Sound", (resource_value_t)0,
 
245
      NULL, N_("Disable sound playback") },
 
246
    { "-soundrate", SET_RESOURCE, 1, NULL, NULL, "SoundSampleRate", NULL,
 
247
      N_("<value>"), N_("Set sound sample rate to <value> Hz") },
 
248
    { "-soundbufsize", SET_RESOURCE, 1, NULL, NULL, "SoundBufferSize", NULL,
 
249
      N_("<value>"), N_("Set sound buffer size to <value> msec") },
 
250
    { "-sounddev", SET_RESOURCE, 1, NULL, NULL, "SoundDeviceName", NULL,
 
251
      N_("<name>"), N_("Specify sound driver") },
 
252
    { "-soundarg", SET_RESOURCE, 1, NULL, NULL, "SoundDeviceArg", NULL,
 
253
      N_("<args>"), N_("Specify initialization parameters for sound driver") },
 
254
    { "-soundrecdev", SET_RESOURCE, 1, NULL, NULL, "SoundRecordDeviceName",
 
255
      NULL, N_("<name>"), N_("Specify recording sound driver") },
 
256
    { "-soundrecarg", SET_RESOURCE, 1, NULL, NULL, "SoundRecordDeviceArg", NULL,
 
257
      N_("<args>"), N_("Specify initialization parameters for recording sound driver") },
 
258
    { "-soundsync", SET_RESOURCE, 1, NULL, NULL, "SoundSpeedAdjustment", NULL,
 
259
      N_("<sync>"), N_("Set sound speed adjustment (0: flexible, 1: adjusting, 2: exact)") },
 
260
    { NULL }
 
261
};
 
262
#endif
236
263
 
237
264
int sound_cmdline_options_init(void)
238
265
{
320
347
/* device registration code */
321
348
static sound_device_t *sound_devices[32];
322
349
 
 
350
static char *devlist;
 
351
 
323
352
int sound_register_device(sound_device_t *pdevice)
324
353
{
 
354
    const int max = sizeof(sound_devices) / sizeof(sound_devices[0]);
325
355
    int i;
326
 
 
327
 
    for (i = 0; sound_devices[i]; i++);
328
 
    sound_devices[i] = pdevice;
 
356
    char *tmplist;
 
357
 
 
358
    for (i = 0; sound_devices[i] && i < max; i++);
 
359
 
 
360
    if (i < max) {
 
361
        sound_devices[i] = pdevice;
 
362
        tmplist = lib_msprintf("%s %s", devlist, pdevice->name);
 
363
        lib_free(devlist);
 
364
        devlist = tmplist;
 
365
    } else {
 
366
        log_error(sound_log, "available sound devices exceed VICEs storage");
 
367
    }
 
368
 
329
369
    return 0;
330
370
}
331
371
 
409
449
    lib_free(p);
410
450
 
411
451
    if (i)
 
452
#ifdef HAS_TRANSLATION
 
453
        sound_error(translate_text(IDGS_WRITE_TO_SOUND_DEVICE_FAILED));
 
454
#else
412
455
        sound_error(_("write to sound device failed."));
 
456
#endif
413
457
}
414
458
 
415
459
 
420
464
 
421
465
    for (c = 0; c < snddata.channels; c++) {
422
466
        if (!(snddata.psid[c] = sound_machine_open(c))) {
 
467
#ifdef HAS_TRANSLATION
 
468
            return sound_error(translate_text(IDGS_CANNOT_OPEN_SID_ENGINE));
 
469
#else
423
470
            return sound_error(_("Cannot open SID engine"));
 
471
#endif
424
472
        }
425
473
    }
426
474
 
455
503
 
456
504
    for (c = 0; c < snddata.channels; c++) {
457
505
        if (!sound_machine_init(snddata.psid[c], speed, cycles_per_sec)) {
 
506
#ifdef HAS_TRANSLATION
 
507
            return sound_error(translate_text(IDGS_CANNOT_INIT_SID_ENGINE));
 
508
#else
458
509
            return sound_error(_("Cannot initialize SID engine"));
 
510
#endif
459
511
        }
460
512
    }
461
513
 
557
609
            int channels_cap = snddata.channels;
558
610
            if (pdev->init(playparam, &speed, &fragsize, &fragnr, &channels_cap)) {
559
611
                char *err;
 
612
#ifdef HAS_TRANSLATION
 
613
                err = lib_msprintf(translate_text(IDGS_INIT_FAILED_FOR_DEVICE_S),
 
614
                                   pdev->name);
 
615
#else
560
616
                err = lib_msprintf(_("initialization failed for device `%s'."),
561
617
                                   pdev->name);
 
618
#endif
562
619
                sound_error(err);
563
620
                lib_free(err);
564
621
                return 1;
611
668
            }
612
669
        }
613
670
    } else {
 
671
#ifdef HAS_TRANSLATION
 
672
        char *err = lib_msprintf(translate_text(IDGS_DEVICE_S_NOT_FOUND_SUPPORT),
 
673
                                 playname);
 
674
#else
614
675
        char *err = lib_msprintf(_("device '%s' not found or not supported."),
615
676
                                 playname);
 
677
#endif
616
678
        sound_error(err);
617
679
        lib_free(err);
618
680
        return 1;
628
690
    }
629
691
 
630
692
    if (recname && rdev == NULL)
 
693
#ifdef HAS_TRANSLATION
 
694
        ui_error(translate_text(IDGS_RECORD_DEVICE_S_NOT_EXIST), recname);
 
695
#else
631
696
        ui_error(_("Recording device %s doesn't exist!"), recname);
 
697
#endif
632
698
 
633
699
    if (rdev) {
634
700
        if (rdev == pdev) {
 
701
#ifdef HAS_TRANSLATION
 
702
            ui_error(translate_text(IDGS_RECORD_DIFFERENT_PLAYBACK));
 
703
#else
635
704
            ui_error(_("Recording device must be different from playback device"));
 
705
#endif
636
706
            resources_set_value("SoundRecordDeviceName", "");
637
707
            return 0;
638
708
        }
639
709
 
640
710
        if (rdev->bufferspace != NULL) {
 
711
#ifdef HAS_TRANSLATION
 
712
            ui_error(translate_text(IDGS_WARNING_RECORDING_REALTIME));
 
713
#else
641
714
            ui_error(_("Warning! Recording device %s seems to be a realtime device!"));
 
715
#endif
642
716
        }
643
717
 
644
718
        if (rdev->init) {
645
719
            int channels_cap = snddata.channels;
646
720
            if (rdev->init(recparam, &speed, &fragsize, &fragnr, &channels_cap)) {
 
721
#ifdef HAS_TRANSLATION
 
722
                ui_error(translate_text(IDGS_INIT_FAILED_FOR_DEVICE_S),
 
723
                                   rdev->name);
 
724
#else
647
725
                ui_error(_("Initialization failed for device `%s'."),
648
726
                                   rdev->name);
 
727
#endif
649
728
                resources_set_value("SoundRecordDeviceName", "");
650
729
                return 0;
651
730
            }
655
734
                || snddata.fragnr != fragnr
656
735
                || snddata.channels != channels_cap)
657
736
            {
 
737
#ifdef HAS_TRANSLATION
 
738
                ui_error(translate_text(IDGS_RECORD_NOT_SUPPORT_SOUND_PAR));
 
739
#else
658
740
                ui_error(_("The recording device doesn't support current sound parameters"));
 
741
#endif
659
742
                rdev->close();
660
743
                resources_set_value("SoundRecordDeviceName", "");
661
744
            } else {
732
815
                                                 snddata.channels,
733
816
                                                 &delta_t);
734
817
            if (delta_t) {
 
818
#ifdef HAS_TRANSLATION
 
819
                return sound_error(translate_text(IDGS_SOUND_BUFFER_OVERFLOW_CYCLE));
 
820
#else
735
821
                return sound_error(_("Sound buffer overflow (cycle based)"));
 
822
#endif
736
823
            }
737
824
        }
738
825
    } else {
742
829
        if (!nr)
743
830
            return 0;
744
831
        if (snddata.bufptr + nr > BUFSIZE) {
 
832
#ifdef HAS_TRANSLATION
 
833
            return sound_error(translate_text(IDGS_SOUND_BUFFER_OVERFLOW));
 
834
#else
745
835
            return sound_error(_("Sound buffer overflow."));
 
836
#endif
746
837
        }
747
838
        for (c = 0; c < snddata.channels; c++) {
748
839
            sound_machine_calculate_samples(snddata.psid[c],
864
955
        i = snddata.playdev->flush(state);
865
956
        lib_free(state);
866
957
        if (i) {
 
958
#ifdef HAS_TRANSLATION
 
959
            sound_error(translate_text(IDGS_CANNOT_FLUSH));
 
960
#else
867
961
            sound_error(_("cannot flush."));
 
962
#endif
868
963
            return 0;
869
964
        }
870
965
    }
909
1004
            log_warning(sound_log, "fragment problems %d %d",
910
1005
                 space, snddata.bufsize);
911
1006
 
 
1007
#ifdef HAS_TRANSLATE
 
1008
            sound_error(translate_text(IDGS_FRAGMENT_PROBLEMS));
 
1009
#else
912
1010
            sound_error(_("fragment problems."));
 
1011
#endif
913
1012
            return 0;
914
1013
        }
915
1014
        used = snddata.bufsize - space;
974
1073
            if (suspend_time > 0)
975
1074
                suspendsound("running too slow");
976
1075
            else {
 
1076
#ifdef HAS_TRANSLATION
 
1077
                sound_error(translate_text(IDGS_RUNNING_TOO_SLOW));
 
1078
#else
977
1079
                sound_error(_("running too slow."));
 
1080
#endif
978
1081
            }
979
1082
            return 0;
980
1083
        }
986
1089
 
987
1090
    /* Flush buffer, all channels are already mixed into it. */
988
1091
    if (snddata.playdev->write(snddata.buffer, nr * snddata.channels)) {
 
1092
#ifdef HAS_TRANSLATION
 
1093
        sound_error(translate_text(IDGS_WRITE_TO_SOUND_DEVICE_FAILED));
 
1094
#else
989
1095
        sound_error(_("write to sounddevice failed."));
 
1096
#endif
990
1097
        return 0;
991
1098
    }
992
1099
 
993
1100
    if (snddata.recdev) {
994
1101
        if (snddata.recdev->write(snddata.buffer, nr * snddata.channels)) {
 
1102
#ifdef HAS_TRANSLATION
 
1103
            sound_error(translate_text(IDGS_WRITE_TO_SOUND_DEVICE_FAILED));
 
1104
#else
995
1105
            sound_error(_("write to sounddevice failed."));
 
1106
#endif
996
1107
            return 0;
997
1108
        }
998
1109
    }
1107
1218
    clk_guard_add_callback(maincpu_clk_guard, prevent_clk_overflow_callback,
1108
1219
                           NULL);
1109
1220
 
 
1221
    devlist = lib_stralloc("");
 
1222
 
1110
1223
#if defined(USE_ARTS)
1111
1224
    sound_init_arts_device();
1112
1225
#endif
 
1226
#if defined(HAVE_ALSA_ASOUNDLIB_H)
 
1227
    sound_init_alsa_device();
 
1228
#endif
 
1229
#ifdef USE_COREAUDIO
 
1230
    sound_init_coreaudio_device();
 
1231
#endif
1113
1232
#if defined(HAVE_LINUX_SOUNDCARD_H) || defined(HAVE_MACHINE_SOUNDCARD_H) || defined(HAVE_SYS_SOUNDCARD_H)
 
1233
 
 
1234
/* don't use uss for FreeBSD or BSDI */
 
1235
 
 
1236
#if !defined(__FreeBSD__) && !defined(__bsdi__)
1114
1237
    sound_init_uss_device();
1115
1238
#endif
 
1239
#endif
1116
1240
#if defined(HAVE_ESD_H) && defined(HAVE_LIBESD)
1117
1241
    sound_init_esd_device();
1118
1242
#endif
1119
1243
#if defined(HAVE_DMEDIA_AUDIO_H)
1120
1244
    sound_init_sgi_device();
1121
1245
#endif
1122
 
#if defined(HAVE_SYS_AUDIOIO_H)
 
1246
 
 
1247
/* Don't use the NetBSD/SUN sound driver for OpenBSD */
 
1248
#if defined(HAVE_SYS_AUDIOIO_H) && !defined(__OpenBSD__)
1123
1249
    sound_init_sun_device();
1124
1250
#endif
1125
1251
#if defined(HAVE_SYS_AUDIO_H)
1176
1302
#if 0
1177
1303
    sound_init_test_device();   /* XXX: missing */
1178
1304
#endif
 
1305
 
 
1306
    log_message(sound_log, "Available sound devices:%s", devlist);
 
1307
 
 
1308
    lib_free(devlist);
1179
1309
}
1180
1310
 
1181
1311
long sound_sample_position(void)
1216
1346
    snddata.wclk = maincpu_clk;
1217
1347
 
1218
1348
    if (i)
 
1349
#ifdef HAS_TRANSLATION
 
1350
        sound_error(translate_text(IDGS_STORE_SOUNDDEVICE_FAILED));
 
1351
#else
1219
1352
        sound_error(_("store to sounddevice failed."));
 
1353
#endif
1220
1354
}
1221
1355
 
1222
1356