Annotation of uae/src/sd-file/sound.c, revision 1.1.1.2

1.1       root        1:  /* 
                      2:   * UAE - The Un*x Amiga Emulator
                      3:   * 
                      4:   * Support for Linux/USS sound
                      5:   * 
                      6:   * Copyright 1997 Bernd Schmidt
                      7:   */
                      8: 
                      9: #include "sysconfig.h"
                     10: #include "sysdeps.h"
                     11: 
                     12: #include "config.h"
                     13: #include "options.h"
                     14: #include "memory.h"
                     15: #include "custom.h"
                     16: #include "audio.h"
                     17: #include "gensound.h"
                     18: #include "sounddep/sound.h"
                     19: 
                     20: #include <sys/ioctl.h>
                     21: #include <sys/soundcard.h>
                     22: 
                     23: int sound_fd;
                     24: static int have_sound;
                     25: static unsigned long formats;
                     26: 
                     27: unsigned long sndbuf_written;
                     28: 
                     29: uae_u16 sndbuffer[44100];
                     30: uae_u16 *sndbufpt;
                     31: int sndbufsize;
                     32: 
                     33: static int exact_log2(int v)
                     34: {
                     35:     int l = 0;
                     36:     while ((v >>= 1) != 0)
                     37:        l++;
                     38:     return l;
                     39: }
                     40: 
                     41: void close_sound(void)
                     42: {
                     43:     int t;
                     44:     uae_u32 v;
                     45:     char buf[4];
                     46:     
                     47:     if (!have_sound)
                     48:        return;
                     49:     
                     50:     t = 0;
                     51:     v = sndbuf_written;
                     52:     buf[t] = v & 255;
                     53:     buf[t+1] = (v>>8) & 255;
                     54:     buf[t+2] = (v>>16) & 255;
                     55:     buf[t+3] = (v>>24) & 255;
                     56:     lseek (sound_fd, 40, SEEK_SET);
                     57:     write (sound_fd, buf, 4);
                     58: 
                     59:     v += 36;
                     60:     buf[t] = v & 255;
                     61:     buf[t+1] = (v>>8) & 255;
                     62:     buf[t+2] = (v>>16) & 255;
                     63:     buf[t+3] = (v>>24) & 255;
                     64:     lseek (sound_fd, 4, SEEK_SET);
                     65:     write (sound_fd, buf, 4);
                     66: 
                     67:     close(sound_fd);
                     68: }
                     69: 
                     70: int setup_sound(void)
                     71: {
                     72:     sound_fd = open ("sound.output", O_CREAT|O_TRUNC|O_WRONLY, 0666);
                     73:     have_sound = !(sound_fd < 0);
                     74:     if (!have_sound)
                     75:        return 0;
                     76: 
                     77:     sound_available = 1;
                     78:     return 1;
                     79: }
                     80: 
                     81: int init_sound (void)
                     82: {
                     83:     int t;
                     84:     uae_u32 v;
                     85:     int tmp;
                     86: 
                     87:     char buf[200] = "RIFF    WAVEfmt                     data    ";
                     88: 
                     89:     /* Prepare a .WAV header */
                     90:     sndbuf_written = 44;
                     91:     t = 16; v = 16;
                     92:     buf[t] = v & 255;
                     93:     buf[t+1] = (v>>8) & 255;
                     94:     buf[t+2] = (v>>16) & 255;
                     95:     buf[t+3] = (v>>24) & 255;
                     96: 
                     97:     t = 20; v = 0x00010001 + (currprefs.stereo ? 0x10000 : 0);
                     98:     buf[t] = v & 255;
                     99:     buf[t+1] = (v>>8) & 255;
                    100:     buf[t+2] = (v>>16) & 255;
                    101:     buf[t+3] = (v>>24) & 255;
                    102: 
                    103:     t = 24; v = currprefs.sound_freq;
                    104:     buf[t] = v & 255;
                    105:     buf[t+1] = (v>>8) & 255;
                    106:     buf[t+2] = (v>>16) & 255;
                    107:     buf[t+3] = (v>>24) & 255;
                    108:     t = 32; v = ((currprefs.sound_bits == 8 ? 1 : 2)
                    109:                 * (currprefs.stereo ? 2 : 1)) + 65536*currprefs.sound_bits;
                    110:     buf[t] = v & 255;
                    111:     buf[t+1] = (v>>8) & 255;
                    112:     buf[t+2] = (v>>16) & 255;
                    113:     buf[t+3] = (v>>24) & 255;
                    114:     t = 28; v = (currprefs.sound_freq * (currprefs.sound_bits == 8 ? 1 : 2)
                    115:                 * (currprefs.stereo ? 2 : 1));
                    116:     buf[t] = v & 255;
                    117:     buf[t+1] = (v>>8) & 255;
                    118:     buf[t+2] = (v>>16) & 255;
                    119:     buf[t+3] = (v>>24) & 255;
                    120:     write (sound_fd, buf, 44);
                    121: 
                    122:     sample_evtime = (long)maxhpos * maxvpos * 50 / currprefs.sound_freq;
                    123: 
                    124:     if (currprefs.sound_bits == 16) {
                    125:        init_sound_table16 ();
1.1.1.2 ! root      126:        sample_handler = currprefs.stereo ? sample16s_handler : sample16_handler;
1.1       root      127:     } else {
                    128:        init_sound_table8 ();
1.1.1.2 ! root      129:        sample_handler = currprefs.stereo ? sample8s_handler : sample8_handler;
1.1       root      130:     }
                    131:     sound_available = 1;
                    132:     sndbufsize = 44100;
                    133:     printf ("Writing sound into \"sound.output\"; %d bits at %d Hz\n",
                    134:            currprefs.sound_bits, currprefs.sound_freq, sndbufsize);
                    135:     sndbufpt = sndbuffer;
                    136:     return 1;
                    137: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.