Search
lxdream.org :: lxdream/src/aica/audio.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/audio.h
changeset 755:ab873907b00e
prev736:a02d1475ccfd
next759:f16975739abc
author nkeynes
date Mon Jul 21 00:08:34 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Add gettext.h and build sanely without libintl if it's not available
Remove x86dasm's config.h & opintl.h (no longer needed and actually wrong)
file annotate diff log raw
nkeynes@66
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@66
     3
 * 
nkeynes@66
     4
 * Audio engine, ie the part that does the actual work.
nkeynes@66
     5
 *
nkeynes@66
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@66
     7
 *
nkeynes@66
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@66
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@66
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@66
    11
 * (at your option) any later version.
nkeynes@66
    12
 *
nkeynes@66
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@66
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@66
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@66
    16
 * GNU General Public License for more details.
nkeynes@66
    17
 */
nkeynes@736
    18
#ifndef lxdream_audio_H
nkeynes@736
    19
#define lxdream_audio_H 1
nkeynes@66
    20
nkeynes@66
    21
#include <stdint.h>
nkeynes@465
    22
#include <stdio.h>
nkeynes@66
    23
#include <glib/gtypes.h>
nkeynes@755
    24
#include "gettext.h"
nkeynes@700
    25
nkeynes@66
    26
#ifdef __cplusplus
nkeynes@66
    27
extern "C" {
nkeynes@66
    28
#endif
nkeynes@66
    29
nkeynes@465
    30
#define AUDIO_CHANNEL_COUNT 64
nkeynes@465
    31
nkeynes@66
    32
#define AUDIO_FMT_8BIT 0
nkeynes@66
    33
#define AUDIO_FMT_16BIT 1
nkeynes@66
    34
#define AUDIO_FMT_ADPCM 2
nkeynes@697
    35
#define AUDIO_FMT_FLOAT 3  // 32-bit -1.0 to 1.0
nkeynes@66
    36
#define AUDIO_FMT_MONO 0
nkeynes@66
    37
#define AUDIO_FMT_STEREO 4
nkeynes@66
    38
#define AUDIO_FMT_SIGNED 0
nkeynes@66
    39
#define AUDIO_FMT_UNSIGNED 8
nkeynes@697
    40
    
nkeynes@697
    41
#define AUDIO_FMT_SAMPLE_MASK 3
nkeynes@66
    42
nkeynes@106
    43
#define AUDIO_FMT_16ST (AUDIO_FMT_16BIT|AUDIO_FMT_STEREO)
nkeynes@697
    44
#define AUDIO_FMT_FLOATST (AUDIO_FMT_FLOAT|AUDIO_FMT_STEREO)
nkeynes@66
    45
nkeynes@697
    46
#define DEFAULT_SAMPLE_RATE 44100
nkeynes@697
    47
#define DEFAULT_SAMPLE_FORMAT AUDIO_FMT_16ST
nkeynes@697
    48
    
nkeynes@463
    49
typedef enum { LOOP_OFF = 0, LOOP_ON = 1, LOOP_LOOPED = 2 } loop_t;
nkeynes@463
    50
nkeynes@66
    51
typedef struct audio_channel {
nkeynes@66
    52
    gboolean active;
nkeynes@434
    53
    uint32_t posn; /* current sample #, 0 = first sample */
nkeynes@66
    54
    uint32_t posn_left;
nkeynes@66
    55
    uint32_t start;
nkeynes@66
    56
    uint32_t end;
nkeynes@463
    57
    loop_t loop;
nkeynes@66
    58
    uint32_t loop_start;
nkeynes@82
    59
    int vol; /* 0..255 */
nkeynes@82
    60
    int pan; /* 0 (left) .. 31 (right) */
nkeynes@66
    61
    uint32_t sample_rate;
nkeynes@66
    62
    int sample_format; 
nkeynes@66
    63
    /* Envelope etc stuff */
nkeynes@66
    64
    /* ADPCM */
nkeynes@66
    65
    int adpcm_step;
nkeynes@66
    66
    int adpcm_predict;
nkeynes@66
    67
} *audio_channel_t;
nkeynes@66
    68
nkeynes@66
    69
nkeynes@66
    70
typedef struct audio_buffer {
nkeynes@73
    71
    uint32_t length; /* Bytes */
nkeynes@73
    72
    uint32_t posn; /* Bytes */
nkeynes@66
    73
    int status;
nkeynes@66
    74
    char data[0];
nkeynes@66
    75
} *audio_buffer_t;
nkeynes@66
    76
nkeynes@91
    77
typedef struct audio_driver {
nkeynes@74
    78
    char *name;
nkeynes@700
    79
    char *description;
nkeynes@697
    80
    uint32_t sample_rate;
nkeynes@697
    81
    uint32_t sample_format;
nkeynes@697
    82
    gboolean (*init)( );
nkeynes@697
    83
    void (*start)( );
nkeynes@66
    84
    gboolean (*process_buffer)( audio_buffer_t buffer );
nkeynes@697
    85
    void (*stop)( );
nkeynes@697
    86
    gboolean (*shutdown)(  );
nkeynes@91
    87
} *audio_driver_t;
nkeynes@66
    88
nkeynes@700
    89
nkeynes@700
    90
/**
nkeynes@700
    91
 * Print the configured audio drivers to the output stream, one to a line.
nkeynes@700
    92
 */
nkeynes@700
    93
void print_audio_drivers( FILE *out );
nkeynes@700
    94
nkeynes@531
    95
audio_driver_t get_audio_driver_by_name( const char *name );
nkeynes@531
    96
nkeynes@66
    97
/**
nkeynes@66
    98
 * Set the output driver, sample rate and format. Also initializes the 
nkeynes@66
    99
 * output buffers, flushing any current data and reallocating as 
nkeynes@66
   100
 * necessary. Must be called before attempting to generate any audio.
nkeynes@66
   101
 */
nkeynes@697
   102
gboolean audio_set_driver( audio_driver_t driver );
nkeynes@66
   103
nkeynes@66
   104
/**
nkeynes@66
   105
 * Mark the current write buffer as full and prepare the next buffer for
nkeynes@66
   106
 * writing. Returns the next buffer to write to.
nkeynes@66
   107
 * If all buffers are full, returns NULL.
nkeynes@66
   108
 */
nkeynes@66
   109
audio_buffer_t audio_next_write_buffer();
nkeynes@66
   110
nkeynes@66
   111
/**
nkeynes@66
   112
 * Mark the current read buffer as empty and return the next buffer for
nkeynes@66
   113
 * reading. If there is no next buffer yet, returns NULL.
nkeynes@66
   114
 */
nkeynes@66
   115
audio_buffer_t audio_next_read_buffer();
nkeynes@66
   116
nkeynes@66
   117
/**
nkeynes@66
   118
 * Mix a single output sample and append it to the output buffers
nkeynes@66
   119
 */
nkeynes@73
   120
void audio_mix_samples( int num_samples );
nkeynes@66
   121
nkeynes@66
   122
/**
nkeynes@66
   123
 * Retrieve the channel information for the channel, numbered 0..63. 
nkeynes@66
   124
 */
nkeynes@66
   125
audio_channel_t audio_get_channel( int channel );
nkeynes@66
   126
nkeynes@434
   127
void audio_start_stop_channel( int channel, gboolean start );
nkeynes@66
   128
void audio_start_channel( int channel );
nkeynes@66
   129
void audio_stop_channel( int channel );
nkeynes@66
   130
nkeynes@465
   131
void audio_save_state( FILE *f );
nkeynes@465
   132
int audio_load_state( FILE *f );
nkeynes@66
   133
nkeynes@66
   134
#ifdef __cplusplus
nkeynes@66
   135
}
nkeynes@66
   136
#endif
nkeynes@736
   137
nkeynes@736
   138
#endif /* !lxdream_audio_H */
.