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

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

unix.superglobalmegacorp.com

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