Search
lxdream.org :: lxdream/src/aica/audio.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/audio.h
changeset 66:2ec5b6eb75e5
next73:0bb57e51ac9e
author nkeynes
date Tue Jan 10 13:56:54 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Go go gadget audio!
Slow, but it works :)
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/aica/audio.h Tue Jan 10 13:56:54 2006 +0000
1.3 @@ -0,0 +1,113 @@
1.4 +/**
1.5 + * $Id: audio.h,v 1.1 2006-01-10 13:56:54 nkeynes Exp $
1.6 + *
1.7 + * Audio engine, ie the part that does the actual work.
1.8 + *
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +#ifndef dream_audio_H
1.22 +#define dream_audio_H 1
1.23 +
1.24 +#include <stdint.h>
1.25 +#include <glib/gtypes.h>
1.26 +
1.27 +#ifdef __cplusplus
1.28 +extern "C" {
1.29 +#endif
1.30 +
1.31 +#define AUDIO_FMT_8BIT 0
1.32 +#define AUDIO_FMT_16BIT 1
1.33 +#define AUDIO_FMT_ADPCM 2
1.34 +#define AUDIO_FMT_MONO 0
1.35 +#define AUDIO_FMT_STEREO 4
1.36 +#define AUDIO_FMT_SIGNED 0
1.37 +#define AUDIO_FMT_UNSIGNED 8
1.38 +
1.39 +
1.40 +typedef struct audio_channel {
1.41 + gboolean active;
1.42 + uint32_t posn;
1.43 + uint32_t posn_left;
1.44 + uint32_t start;
1.45 + uint32_t end;
1.46 + uint32_t loop_start;
1.47 + uint32_t loop_end;
1.48 + int loop_count; /* 0 = no loop, -1 = loop forever */
1.49 + int vol_left; /* 0..255 */
1.50 + int vol_right; /* 0..255 */
1.51 + uint32_t sample_rate;
1.52 + int sample_format;
1.53 + /* Envelope etc stuff */
1.54 + /* ADPCM */
1.55 + int adpcm_nibble; /* 0 = low nibble, 1 = high nibble */
1.56 + int adpcm_step;
1.57 + int adpcm_predict;
1.58 +} *audio_channel_t;
1.59 +
1.60 +
1.61 +typedef struct audio_buffer {
1.62 + uint32_t length; /* Samples */
1.63 + uint32_t posn; /* Samples */
1.64 + int status;
1.65 + char data[0];
1.66 +} *audio_buffer_t;
1.67 +
1.68 +struct audio_driver {
1.69 + gboolean (*set_output_format)( uint32_t sample_rate, uint32_t format );
1.70 + gboolean (*process_buffer)( audio_buffer_t buffer );
1.71 +};
1.72 +
1.73 +typedef struct audio_driver *audio_driver_t;
1.74 +
1.75 +extern struct audio_driver null_audio_driver;
1.76 +extern struct audio_driver esd_audio_driver;
1.77 +
1.78 +/**
1.79 + * Set the output driver, sample rate and format. Also initializes the
1.80 + * output buffers, flushing any current data and reallocating as
1.81 + * necessary. Must be called before attempting to generate any audio.
1.82 + */
1.83 +void audio_set_output( audio_driver_t driver, uint32_t samplerate,
1.84 + int format );
1.85 +
1.86 +/**
1.87 + * Mark the current write buffer as full and prepare the next buffer for
1.88 + * writing. Returns the next buffer to write to.
1.89 + * If all buffers are full, returns NULL.
1.90 + */
1.91 +audio_buffer_t audio_next_write_buffer();
1.92 +
1.93 +/**
1.94 + * Mark the current read buffer as empty and return the next buffer for
1.95 + * reading. If there is no next buffer yet, returns NULL.
1.96 + */
1.97 +audio_buffer_t audio_next_read_buffer();
1.98 +
1.99 +/**
1.100 + * Mix a single output sample and append it to the output buffers
1.101 + */
1.102 +void audio_mix_sample( void );
1.103 +
1.104 +/**
1.105 + * Retrieve the channel information for the channel, numbered 0..63.
1.106 + */
1.107 +audio_channel_t audio_get_channel( int channel );
1.108 +
1.109 +void audio_start_channel( int channel );
1.110 +void audio_stop_channel( int channel );
1.111 +
1.112 +
1.113 +#ifdef __cplusplus
1.114 +}
1.115 +#endif
1.116 +#endif
.