Search
lxdream.org :: lxdream/src/aica/audio.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/audio.h
changeset 657:c4143facbfcb
prev643:653b0a70f173
next697:479b8c213f61
author nkeynes
date Sun May 25 20:59:29 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Update test again for ftrv change
view annotate diff log raw
     1 /**
     2  * $Id$
     3  * 
     4  * Audio engine, ie the part that does the actual work.
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    18 #ifndef dream_audio_H
    19 #define dream_audio_H 1
    21 #include <stdint.h>
    22 #include <stdio.h>
    23 #include <glib/gtypes.h>
    25 #ifdef __cplusplus
    26 extern "C" {
    27 #endif
    29 #define AUDIO_CHANNEL_COUNT 64
    31 #define AUDIO_FMT_8BIT 0
    32 #define AUDIO_FMT_16BIT 1
    33 #define AUDIO_FMT_ADPCM 2
    34 #define AUDIO_FMT_MONO 0
    35 #define AUDIO_FMT_STEREO 4
    36 #define AUDIO_FMT_SIGNED 0
    37 #define AUDIO_FMT_UNSIGNED 8
    39 #define AUDIO_FMT_16ST (AUDIO_FMT_16BIT|AUDIO_FMT_STEREO)
    41 typedef enum { LOOP_OFF = 0, LOOP_ON = 1, LOOP_LOOPED = 2 } loop_t;
    43 typedef struct audio_channel {
    44     gboolean active;
    45     uint32_t posn; /* current sample #, 0 = first sample */
    46     uint32_t posn_left;
    47     uint32_t start;
    48     uint32_t end;
    49     loop_t loop;
    50     uint32_t loop_start;
    51     int vol; /* 0..255 */
    52     int pan; /* 0 (left) .. 31 (right) */
    53     uint32_t sample_rate;
    54     int sample_format; 
    55     /* Envelope etc stuff */
    56     /* ADPCM */
    57     int adpcm_step;
    58     int adpcm_predict;
    59 } *audio_channel_t;
    62 typedef struct audio_buffer {
    63     uint32_t length; /* Bytes */
    64     uint32_t posn; /* Bytes */
    65     int status;
    66     char data[0];
    67 } *audio_buffer_t;
    69 typedef struct audio_driver {
    70     char *name;
    71     gboolean (*init)(  );
    72     gboolean (*set_output_format)( uint32_t sample_rate, uint32_t format );
    73     gboolean (*process_buffer)( audio_buffer_t buffer );
    74     gboolean (*close)(  );
    75 } *audio_driver_t;
    77 extern struct audio_driver audio_null_driver;
    78 extern struct audio_driver audio_pulse_driver;
    79 extern struct audio_driver audio_esd_driver;
    80 extern struct audio_driver audio_alsa_driver;
    82 audio_driver_t get_audio_driver_by_name( const char *name );
    84 /**
    85  * Set the output driver, sample rate and format. Also initializes the 
    86  * output buffers, flushing any current data and reallocating as 
    87  * necessary. Must be called before attempting to generate any audio.
    88  */
    89 gboolean audio_set_driver( audio_driver_t driver, uint32_t samplerate,
    90 		       int format );
    92 /**
    93  * Mark the current write buffer as full and prepare the next buffer for
    94  * writing. Returns the next buffer to write to.
    95  * If all buffers are full, returns NULL.
    96  */
    97 audio_buffer_t audio_next_write_buffer();
    99 /**
   100  * Mark the current read buffer as empty and return the next buffer for
   101  * reading. If there is no next buffer yet, returns NULL.
   102  */
   103 audio_buffer_t audio_next_read_buffer();
   105 /**
   106  * Mix a single output sample and append it to the output buffers
   107  */
   108 void audio_mix_samples( int num_samples );
   110 /**
   111  * Retrieve the channel information for the channel, numbered 0..63. 
   112  */
   113 audio_channel_t audio_get_channel( int channel );
   115 void audio_start_stop_channel( int channel, gboolean start );
   116 void audio_start_channel( int channel );
   117 void audio_stop_channel( int channel );
   119 void audio_save_state( FILE *f );
   120 int audio_load_state( FILE *f );
   122 #ifdef __cplusplus
   123 }
   124 #endif
   125 #endif
.