Search
lxdream.org :: lxdream/src/aica/audio.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/audio.h
changeset 463:0655796f9bb5
prev434:8af49a412d92
next465:3bd7be575792
author nkeynes
date Wed Oct 24 21:24:09 2007 +0000 (15 years ago)
permissions -rw-r--r--
last change Implement channel position readback
view annotate diff log raw
     1 /**
     2  * $Id: audio.h,v 1.9 2007-10-24 21:24:09 nkeynes Exp $
     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 <glib/gtypes.h>
    24 #ifdef __cplusplus
    25 extern "C" {
    26 #endif
    28 #define AUDIO_FMT_8BIT 0
    29 #define AUDIO_FMT_16BIT 1
    30 #define AUDIO_FMT_ADPCM 2
    31 #define AUDIO_FMT_MONO 0
    32 #define AUDIO_FMT_STEREO 4
    33 #define AUDIO_FMT_SIGNED 0
    34 #define AUDIO_FMT_UNSIGNED 8
    36 #define AUDIO_FMT_16ST (AUDIO_FMT_16BIT|AUDIO_FMT_STEREO)
    38 typedef enum { LOOP_OFF = 0, LOOP_ON = 1, LOOP_LOOPED = 2 } loop_t;
    40 typedef struct audio_channel {
    41     gboolean active;
    42     uint32_t posn; /* current sample #, 0 = first sample */
    43     uint32_t posn_left;
    44     uint32_t start;
    45     uint32_t end;
    46     loop_t loop;
    47     uint32_t loop_start;
    48     int vol; /* 0..255 */
    49     int pan; /* 0 (left) .. 31 (right) */
    50     uint32_t sample_rate;
    51     int sample_format; 
    52     /* Envelope etc stuff */
    53     /* ADPCM */
    54     int adpcm_step;
    55     int adpcm_predict;
    56 } *audio_channel_t;
    59 typedef struct audio_buffer {
    60     uint32_t length; /* Bytes */
    61     uint32_t posn; /* Bytes */
    62     int status;
    63     char data[0];
    64 } *audio_buffer_t;
    66 typedef struct audio_driver {
    67     char *name;
    68     gboolean (*set_output_format)( uint32_t sample_rate, uint32_t format );
    69     gboolean (*process_buffer)( audio_buffer_t buffer );
    70 } *audio_driver_t;
    72 extern struct audio_driver audio_null_driver;
    73 extern struct audio_driver audio_esd_driver;
    75 /**
    76  * Set the output driver, sample rate and format. Also initializes the 
    77  * output buffers, flushing any current data and reallocating as 
    78  * necessary. Must be called before attempting to generate any audio.
    79  */
    80 gboolean audio_set_driver( audio_driver_t driver, uint32_t samplerate,
    81 		       int format );
    83 /**
    84  * Mark the current write buffer as full and prepare the next buffer for
    85  * writing. Returns the next buffer to write to.
    86  * If all buffers are full, returns NULL.
    87  */
    88 audio_buffer_t audio_next_write_buffer();
    90 /**
    91  * Mark the current read buffer as empty and return the next buffer for
    92  * reading. If there is no next buffer yet, returns NULL.
    93  */
    94 audio_buffer_t audio_next_read_buffer();
    96 /**
    97  * Mix a single output sample and append it to the output buffers
    98  */
    99 void audio_mix_samples( int num_samples );
   101 /**
   102  * Retrieve the channel information for the channel, numbered 0..63. 
   103  */
   104 audio_channel_t audio_get_channel( int channel );
   106 void audio_start_stop_channel( int channel, gboolean start );
   107 void audio_start_channel( int channel );
   108 void audio_stop_channel( int channel );
   111 #ifdef __cplusplus
   112 }
   113 #endif
   114 #endif
.