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

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: 
1.1.1.5 ! root       96:     t = 20; v = 0x00010001 + (/* currprefs.stereo */ 1 ? 0x10000 : 0);
1.1       root       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;
1.1.1.5 ! root      107:     t = 32; v = (2 * 2) + 65536 * 16;
1.1       root      108:     buf[t] = v & 255;
                    109:     buf[t+1] = (v>>8) & 255;
                    110:     buf[t+2] = (v>>16) & 255;
                    111:     buf[t+3] = (v>>24) & 255;
1.1.1.5 ! root      112:     t = 28; v = (currprefs.sound_freq * 2 * 2);
1.1       root      113:     buf[t] = v & 255;
                    114:     buf[t+1] = (v>>8) & 255;
                    115:     buf[t+2] = (v>>16) & 255;
                    116:     buf[t+3] = (v>>24) & 255;
                    117:     write (sound_fd, buf, 44);
                    118: 
1.1.1.4   root      119:     obtained_freq = currprefs.sound_freq;
1.1       root      120: 
1.1.1.5 ! root      121:     init_sound_table16 ();
        !           122:     sample_handler = sample16s_handler;
1.1       root      123:     sound_available = 1;
                    124:     sndbufsize = 44100;
1.1.1.5 ! root      125:     printf ("Writing sound into \"sound.output\"; 16 bits at %d Hz\n",
        !           126:            currprefs.sound_freq, sndbufsize);
1.1       root      127:     sndbufpt = sndbuffer;
                    128:     return 1;
                    129: }

unix.superglobalmegacorp.com

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