Added initial support for Dreamcast (thanks HERO!)
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40510
This commit is contained in:
parent
148a1a64f4
commit
3ee2de057f
43 changed files with 2847 additions and 4 deletions
|
@ -6,7 +6,7 @@ noinst_LTLIBRARIES = libaudio.la
|
|||
# Define which subdirectories need to be built
|
||||
SUBDIRS = @AUDIO_SUBDIRS@
|
||||
DIST_SUBDIRS = alsa arts baudio dma dmedia dsp esd macrom nas nto openbsd \
|
||||
paudio sun ums windib windx5 disk mint
|
||||
paudio sun ums windib windx5 disk mint dc
|
||||
|
||||
DRIVERS = @AUDIO_DRIVERS@
|
||||
|
||||
|
|
|
@ -88,6 +88,9 @@ static AudioBootStrap *bootstrap[] = {
|
|||
#endif
|
||||
#ifdef DISKAUD_SUPPORT
|
||||
&DISKAUD_bootstrap,
|
||||
#endif
|
||||
#ifdef ENABLE_DC
|
||||
&DCAUD_bootstrap,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
|
|
@ -153,6 +153,9 @@ extern AudioBootStrap MINTAUDIO_bootstrap;
|
|||
#ifdef DISKAUD_SUPPORT
|
||||
extern AudioBootStrap DISKAUD_bootstrap;
|
||||
#endif
|
||||
#ifdef ENABLE_DC
|
||||
extern AudioBootStrap DCAUD_bootstrap;
|
||||
#endif
|
||||
|
||||
/* This is the current audio device */
|
||||
extern SDL_AudioDevice *current_audio;
|
||||
|
|
6
src/audio/dc/.cvsignore
Normal file
6
src/audio/dc/.cvsignore
Normal file
|
@ -0,0 +1,6 @@
|
|||
Makefile.in
|
||||
Makefile
|
||||
.libs
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
11
src/audio/dc/Makefile.am
Normal file
11
src/audio/dc/Makefile.am
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
## Makefile.am for SDL on the Dreamcast console
|
||||
|
||||
noinst_LTLIBRARIES = libaudio_dc.la
|
||||
libaudio_dc_la_SOURCES = $(SRCS)
|
||||
|
||||
# The SDL audio driver sources
|
||||
SRCS = SDL_dcaudio.c \
|
||||
SDL_dcaudio.h \
|
||||
aica.c \
|
||||
aica.h
|
245
src/audio/dc/SDL_dcaudio.c
Normal file
245
src/audio/dc/SDL_dcaudio.c
Normal file
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
BERO <bero@geocities.co.jp>
|
||||
based on SDL_diskaudio.c by Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
*/
|
||||
|
||||
#ifdef SAVE_RCSID
|
||||
static char rcsid =
|
||||
"@(#) $Id$";
|
||||
#endif
|
||||
|
||||
/* Output dreamcast aica */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
#include "SDL_audio.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_audiomem.h"
|
||||
#include "SDL_audio_c.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audiodev_c.h"
|
||||
#include "SDL_dcaudio.h"
|
||||
|
||||
#include "aica.h"
|
||||
#include <dc/spu.h>
|
||||
|
||||
/* Audio driver functions */
|
||||
static int DCAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
|
||||
static void DCAUD_WaitAudio(_THIS);
|
||||
static void DCAUD_PlayAudio(_THIS);
|
||||
static Uint8 *DCAUD_GetAudioBuf(_THIS);
|
||||
static void DCAUD_CloseAudio(_THIS);
|
||||
|
||||
/* Audio driver bootstrap functions */
|
||||
static int DCAUD_Available(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void DCAUD_DeleteDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
free(device->hidden);
|
||||
free(device);
|
||||
}
|
||||
|
||||
static SDL_AudioDevice *DCAUD_CreateDevice(int devindex)
|
||||
{
|
||||
SDL_AudioDevice *this;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
|
||||
if ( this ) {
|
||||
memset(this, 0, (sizeof *this));
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
malloc((sizeof *this->hidden));
|
||||
}
|
||||
if ( (this == NULL) || (this->hidden == NULL) ) {
|
||||
SDL_OutOfMemory();
|
||||
if ( this ) {
|
||||
free(this);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
/* Set the function pointers */
|
||||
this->OpenAudio = DCAUD_OpenAudio;
|
||||
this->WaitAudio = DCAUD_WaitAudio;
|
||||
this->PlayAudio = DCAUD_PlayAudio;
|
||||
this->GetAudioBuf = DCAUD_GetAudioBuf;
|
||||
this->CloseAudio = DCAUD_CloseAudio;
|
||||
|
||||
this->free = DCAUD_DeleteDevice;
|
||||
|
||||
spu_init();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
AudioBootStrap DCAUD_bootstrap = {
|
||||
"dcaudio", "Dreamcast AICA audio",
|
||||
DCAUD_Available, DCAUD_CreateDevice
|
||||
};
|
||||
|
||||
/* This function waits until it is possible to write a full sound buffer */
|
||||
static void DCAUD_WaitAudio(_THIS)
|
||||
{
|
||||
if (this->hidden->playing) {
|
||||
/* wait */
|
||||
while(aica_get_pos(0)/this->spec.samples == this->hidden->nextbuf) {
|
||||
thd_pass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define SPU_RAM_BASE 0xa0800000
|
||||
|
||||
static void spu_memload_stereo8(int leftpos,int rightpos,void *src0,size_t size)
|
||||
{
|
||||
uint8 *src = src0;
|
||||
uint32 *left = (uint32*)(leftpos +SPU_RAM_BASE);
|
||||
uint32 *right = (uint32*)(rightpos+SPU_RAM_BASE);
|
||||
size = (size+7)/8;
|
||||
while(size--) {
|
||||
unsigned lval,rval;
|
||||
lval = *src++;
|
||||
rval = *src++;
|
||||
lval|= (*src++)<<8;
|
||||
rval|= (*src++)<<8;
|
||||
lval|= (*src++)<<16;
|
||||
rval|= (*src++)<<16;
|
||||
lval|= (*src++)<<24;
|
||||
rval|= (*src++)<<24;
|
||||
g2_write_32(left++,lval);
|
||||
g2_write_32(right++,rval);
|
||||
g2_fifo_wait();
|
||||
}
|
||||
}
|
||||
|
||||
static void spu_memload_stereo16(int leftpos,int rightpos,void *src0,size_t size)
|
||||
{
|
||||
uint16 *src = src0;
|
||||
uint32 *left = (uint32*)(leftpos +SPU_RAM_BASE);
|
||||
uint32 *right = (uint32*)(rightpos+SPU_RAM_BASE);
|
||||
size = (size+7)/8;
|
||||
while(size--) {
|
||||
unsigned lval,rval;
|
||||
lval = *src++;
|
||||
rval = *src++;
|
||||
lval|= (*src++)<<16;
|
||||
rval|= (*src++)<<16;
|
||||
g2_write_32(left++,lval);
|
||||
g2_write_32(right++,rval);
|
||||
g2_fifo_wait();
|
||||
}
|
||||
}
|
||||
|
||||
static void DCAUD_PlayAudio(_THIS)
|
||||
{
|
||||
SDL_AudioSpec *spec = &this->spec;
|
||||
unsigned int offset;
|
||||
|
||||
if (this->hidden->playing) {
|
||||
/* wait */
|
||||
while(aica_get_pos(0)/spec->samples == this->hidden->nextbuf) {
|
||||
thd_pass();
|
||||
}
|
||||
}
|
||||
|
||||
offset = this->hidden->nextbuf*spec->size;
|
||||
this->hidden->nextbuf^=1;
|
||||
/* Write the audio data, checking for EAGAIN on broken audio drivers */
|
||||
if (spec->channels==1) {
|
||||
spu_memload(this->hidden->leftpos+offset,this->hidden->mixbuf,this->hidden->mixlen);
|
||||
} else {
|
||||
offset/=2;
|
||||
if ((this->spec.format&255)==8) {
|
||||
spu_memload_stereo8(this->hidden->leftpos+offset,this->hidden->rightpos+offset,this->hidden->mixbuf,this->hidden->mixlen);
|
||||
} else {
|
||||
spu_memload_stereo16(this->hidden->leftpos+offset,this->hidden->rightpos+offset,this->hidden->mixbuf,this->hidden->mixlen);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->hidden->playing) {
|
||||
int mode;
|
||||
this->hidden->playing = 1;
|
||||
mode = (spec->format==AUDIO_S8)?SM_8BIT:SM_16BIT;
|
||||
if (spec->channels==1) {
|
||||
aica_play(0,mode,this->hidden->leftpos,0,spec->samples*2,spec->freq,255,128,1);
|
||||
} else {
|
||||
aica_play(0,mode,this->hidden->leftpos ,0,spec->samples*2,spec->freq,255,0,1);
|
||||
aica_play(1,mode,this->hidden->rightpos,0,spec->samples*2,spec->freq,255,255,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Uint8 *DCAUD_GetAudioBuf(_THIS)
|
||||
{
|
||||
return(this->hidden->mixbuf);
|
||||
}
|
||||
|
||||
static void DCAUD_CloseAudio(_THIS)
|
||||
{
|
||||
aica_stop(0);
|
||||
if (this->spec.channels==2) aica_stop(1);
|
||||
if ( this->hidden->mixbuf != NULL ) {
|
||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||
this->hidden->mixbuf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int DCAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
|
||||
{
|
||||
switch(spec->format&0xff) {
|
||||
case 8: spec->format = AUDIO_S8; break;
|
||||
case 16: spec->format = AUDIO_S16LSB; break;
|
||||
default:
|
||||
SDL_SetError("Unsupported audio format");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Update the fragment size as size in bytes */
|
||||
SDL_CalculateAudioSpec(spec);
|
||||
|
||||
/* Allocate mixing buffer */
|
||||
this->hidden->mixlen = spec->size;
|
||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||
if ( this->hidden->mixbuf == NULL ) {
|
||||
return(-1);
|
||||
}
|
||||
memset(this->hidden->mixbuf, spec->silence, spec->size);
|
||||
this->hidden->leftpos = 0x11000;
|
||||
this->hidden->rightpos = 0x11000+spec->size;
|
||||
this->hidden->playing = 0;
|
||||
this->hidden->nextbuf = 0;
|
||||
|
||||
/* We're ready to rock and roll. :-) */
|
||||
return(0);
|
||||
}
|
45
src/audio/dc/SDL_dcaudio.h
Normal file
45
src/audio/dc/SDL_dcaudio.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
BERO <bero@geocities.co.jp>
|
||||
based on SDL_diskaudio.h by Sam Lantinga <slouken@libsdl.org>
|
||||
*/
|
||||
|
||||
#ifdef SAVE_RCSID
|
||||
static char rcsid =
|
||||
"@(#) $Id$";
|
||||
#endif
|
||||
|
||||
#ifndef _SDL_diskaudio_h
|
||||
#define _SDL_diskaudio_h
|
||||
|
||||
#include "SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the video functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData {
|
||||
/* The file descriptor for the audio device */
|
||||
Uint8 *mixbuf;
|
||||
Uint32 mixlen;
|
||||
int playing;
|
||||
int leftpos,rightpos;
|
||||
int nextbuf;
|
||||
};
|
||||
|
||||
#endif /* _SDL_diskaudio_h */
|
267
src/audio/dc/aica.c
Normal file
267
src/audio/dc/aica.c
Normal file
|
@ -0,0 +1,267 @@
|
|||
/* This file is part of the Dreamcast function library.
|
||||
* Please see libdream.c for further details.
|
||||
*
|
||||
* (c)2000 Dan Potter
|
||||
* modify BERO
|
||||
*/
|
||||
#include "aica.h"
|
||||
|
||||
/* #define dc_snd_base ((volatile unsigned char *)0x00800000) */ /* arm side */
|
||||
#define dc_snd_base ((volatile unsigned char *)0xa0700000) /* dc side */
|
||||
|
||||
/* Some convienence macros */
|
||||
#define SNDREGADDR(x) (0xa0700000 + (x))
|
||||
#define CHNREGADDR(ch,x) SNDREGADDR(0x80*(ch)+(x))
|
||||
|
||||
|
||||
#define SNDREG32(x) (*(volatile unsigned long *)SNDREGADDR(x))
|
||||
#define SNDREG8(x) (*(volatile unsigned char *)SNDREGADDR(x))
|
||||
#define CHNREG32(ch, x) (*(volatile unsigned long *)CHNREGADDR(ch,x))
|
||||
#define CHNREG8(ch, x) (*(volatile unsigned long *)CHNREGADDR(ch,x))
|
||||
|
||||
#define G2_LOCK(OLD) \
|
||||
do { \
|
||||
if (!irq_inside_int()) \
|
||||
OLD = irq_disable(); \
|
||||
/* suspend any G2 DMA here... */ \
|
||||
while((*(volatile unsigned int *)0xa05f688c) & 0x20) \
|
||||
; \
|
||||
} while(0)
|
||||
|
||||
#define G2_UNLOCK(OLD) \
|
||||
do { \
|
||||
/* resume any G2 DMA here... */ \
|
||||
if (!irq_inside_int()) \
|
||||
irq_restore(OLD); \
|
||||
} while(0)
|
||||
|
||||
|
||||
void aica_init() {
|
||||
int i, j, old;
|
||||
|
||||
/* Initialize AICA channels */
|
||||
G2_LOCK(old);
|
||||
SNDREG32(0x2800) = 0x0000;
|
||||
|
||||
for (i=0; i<64; i++) {
|
||||
for (j=0; j<0x80; j+=4) {
|
||||
if ((j&31)==0) g2_fifo_wait();
|
||||
CHNREG32(i, j) = 0;
|
||||
}
|
||||
g2_fifo_wait();
|
||||
CHNREG32(i,0) = 0x8000;
|
||||
CHNREG32(i,20) = 0x1f;
|
||||
}
|
||||
|
||||
SNDREG32(0x2800) = 0x000f;
|
||||
g2_fifo_wait();
|
||||
G2_UNLOCK(old);
|
||||
}
|
||||
|
||||
/* Translates a volume from linear form to logarithmic form (required by
|
||||
the AICA chip */
|
||||
/* int logs[] = {
|
||||
|
||||
0, 40, 50, 58, 63, 68, 73, 77, 80, 83, 86, 89, 92, 94, 97, 99, 101, 103,
|
||||
105, 107, 109, 111, 112, 114, 116, 117, 119, 120, 122, 123, 125, 126, 127,
|
||||
129, 130, 131, 133, 134, 135, 136, 137, 139, 140, 141, 142, 143, 144, 145,
|
||||
146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 156, 157, 158, 159,
|
||||
160, 161, 162, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 170, 171,
|
||||
172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, 180, 180, 181, 182,
|
||||
182, 183, 183, 184, 185, 185, 186, 187, 187, 188, 188, 189, 190, 190, 191,
|
||||
191, 192, 193, 193, 194, 194, 195, 196, 196, 197, 197, 198, 198, 199, 199,
|
||||
200, 201, 201, 202, 202, 203, 203, 204, 204, 205, 205, 206, 206, 207, 207,
|
||||
208, 208, 209, 209, 210, 210, 211, 211, 212, 212, 213, 213, 214, 214, 215,
|
||||
215, 216, 216, 217, 217, 217, 218, 218, 219, 219, 220, 220, 221, 221, 222,
|
||||
222, 222, 223, 223, 224, 224, 225, 225, 225, 226, 226, 227, 227, 228, 228,
|
||||
228, 229, 229, 230, 230, 230, 231, 231, 232, 232, 232, 233, 233, 234, 234,
|
||||
234, 235, 235, 236, 236, 236, 237, 237, 238, 238, 238, 239, 239, 240, 240,
|
||||
240, 241, 241, 241, 242, 242, 243, 243, 243, 244, 244, 244, 245, 245, 245,
|
||||
246, 246, 247, 247, 247, 248, 248, 248, 249, 249, 249, 250, 250, 250, 251,
|
||||
251, 251, 252, 252, 252, 253, 253, 253, 254, 254, 254, 255
|
||||
|
||||
}; */
|
||||
|
||||
const static unsigned char logs[] = {
|
||||
0, 15, 22, 27, 31, 35, 39, 42, 45, 47, 50, 52, 55, 57, 59, 61,
|
||||
63, 65, 67, 69, 71, 73, 74, 76, 78, 79, 81, 82, 84, 85, 87, 88,
|
||||
90, 91, 92, 94, 95, 96, 98, 99, 100, 102, 103, 104, 105, 106,
|
||||
108, 109, 110, 111, 112, 113, 114, 116, 117, 118, 119, 120, 121,
|
||||
122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
|
||||
135, 136, 137, 138, 138, 139, 140, 141, 142, 143, 144, 145, 146,
|
||||
146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 156,
|
||||
157, 158, 159, 160, 160, 161, 162, 163, 164, 164, 165, 166, 167,
|
||||
167, 168, 169, 170, 170, 171, 172, 173, 173, 174, 175, 176, 176,
|
||||
177, 178, 178, 179, 180, 181, 181, 182, 183, 183, 184, 185, 185,
|
||||
186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194,
|
||||
195, 195, 196, 197, 197, 198, 199, 199, 200, 200, 201, 202, 202,
|
||||
203, 204, 204, 205, 205, 206, 207, 207, 208, 209, 209, 210, 210,
|
||||
211, 212, 212, 213, 213, 214, 215, 215, 216, 216, 217, 217, 218,
|
||||
219, 219, 220, 220, 221, 221, 222, 223, 223, 224, 224, 225, 225,
|
||||
226, 227, 227, 228, 228, 229, 229, 230, 230, 231, 232, 232, 233,
|
||||
233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 239, 239, 240,
|
||||
240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246,
|
||||
247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, 254, 255
|
||||
};
|
||||
|
||||
/* For the moment this is going to have to suffice, until we really
|
||||
figure out what these mean. */
|
||||
#define AICA_PAN(x) ((x)==0x80?(0):((x)<0x80?(0x1f):(0x0f)))
|
||||
#define AICA_VOL(x) (0xff - logs[128 + (((x) & 0xff) / 2)])
|
||||
//#define AICA_VOL(x) (0xff - logs[x&255])
|
||||
|
||||
static inline unsigned AICA_FREQ(unsigned freq) {
|
||||
unsigned long freq_lo, freq_base = 5644800;
|
||||
int freq_hi = 7;
|
||||
|
||||
/* Need to convert frequency to floating point format
|
||||
(freq_hi is exponent, freq_lo is mantissa)
|
||||
Formula is ferq = 44100*2^freq_hi*(1+freq_lo/1024) */
|
||||
while (freq < freq_base && freq_hi > -8) {
|
||||
freq_base >>= 1;
|
||||
--freq_hi;
|
||||
}
|
||||
while (freq < freq_base && freq_hi > -8) {
|
||||
freq_base >>= 1;
|
||||
freq_hi--;
|
||||
}
|
||||
freq_lo = (freq<<10) / freq_base;
|
||||
return (freq_hi << 11) | (freq_lo & 1023);
|
||||
}
|
||||
|
||||
/* Sets up a sound channel completely. This is generally good if you want
|
||||
a quick and dirty way to play notes. If you want a more comprehensive
|
||||
set of routines (more like PC wavetable cards) see below.
|
||||
|
||||
ch is the channel to play on (0 - 63)
|
||||
smpptr is the pointer to the sound data; if you're running off the
|
||||
SH4, then this ought to be (ptr - 0xa0800000); otherwise it's just
|
||||
ptr. Basically, it's an offset into sound ram.
|
||||
mode is one of the mode constants (16 bit, 8 bit, ADPCM)
|
||||
nsamp is the number of samples to play (not number of bytes!)
|
||||
freq is the sampling rate of the sound
|
||||
vol is the volume, 0 to 0xff (0xff is louder)
|
||||
pan is a panning constant -- 0 is left, 128 is center, 255 is right.
|
||||
|
||||
This routine (and the similar ones) owe a lot to Marcus' sound example --
|
||||
I hadn't gotten quite this far into dissecting the individual regs yet. */
|
||||
void aica_play(int ch,int mode,unsigned long smpptr,int loopst,int loopend,int freq,int vol,int pan,int loopflag) {
|
||||
int i;
|
||||
int val;
|
||||
int old;
|
||||
|
||||
/* Stop the channel (if it's already playing) */
|
||||
aica_stop(ch);
|
||||
/* doesn't seem to be needed, but it's here just in case */
|
||||
/*
|
||||
for (i=0; i<256; i++) {
|
||||
asm("nop");
|
||||
asm("nop");
|
||||
asm("nop");
|
||||
asm("nop");
|
||||
}
|
||||
*/
|
||||
G2_LOCK(old);
|
||||
/* Envelope setup. The first of these is the loop point,
|
||||
e.g., where the sample starts over when it loops. The second
|
||||
is the loop end. This is the full length of the sample when
|
||||
you are not looping, or the loop end point when you are (though
|
||||
storing more than that is a waste of memory if you're not doing
|
||||
volume enveloping). */
|
||||
CHNREG32(ch, 8) = loopst & 0xffff;
|
||||
CHNREG32(ch, 12) = loopend & 0xffff;
|
||||
|
||||
/* Write resulting values */
|
||||
CHNREG32(ch, 24) = AICA_FREQ(freq);
|
||||
|
||||
/* Set volume, pan, and some other things that we don't know what
|
||||
they do =) */
|
||||
CHNREG32(ch, 36) = AICA_PAN(pan) | (0xf<<8);
|
||||
/* Convert the incoming volume and pan into hardware values */
|
||||
/* Vol starts at zero so we can ramp */
|
||||
vol = AICA_VOL(vol);
|
||||
CHNREG32(ch, 40) = 0x24 | (vol<<8);
|
||||
/* Convert the incoming volume and pan into hardware values */
|
||||
/* Vol starts at zero so we can ramp */
|
||||
|
||||
/* If we supported volume envelopes (which we don't yet) then
|
||||
this value would set that up. The top 4 bits determine the
|
||||
envelope speed. f is the fastest, 1 is the slowest, and 0
|
||||
seems to be an invalid value and does weird things). The
|
||||
default (below) sets it into normal mode (play and terminate/loop).
|
||||
CHNREG32(ch, 16) = 0xf010;
|
||||
*/
|
||||
CHNREG32(ch, 16) = 0x1f; /* No volume envelope */
|
||||
|
||||
|
||||
/* Set sample format, buffer address, and looping control. If
|
||||
0x0200 mask is set on reg 0, the sample loops infinitely. If
|
||||
it's not set, the sample plays once and terminates. We'll
|
||||
also set the bits to start playback here. */
|
||||
CHNREG32(ch, 4) = smpptr & 0xffff;
|
||||
val = 0xc000 | 0x0000 | (mode<<7) | (smpptr >> 16);
|
||||
if (loopflag) val|=0x200;
|
||||
|
||||
CHNREG32(ch, 0) = val;
|
||||
|
||||
G2_UNLOCK(old);
|
||||
|
||||
/* Enable playback */
|
||||
/* CHNREG32(ch, 0) |= 0xc000; */
|
||||
g2_fifo_wait();
|
||||
|
||||
#if 0
|
||||
for (i=0xff; i>=vol; i--) {
|
||||
if ((i&7)==0) g2_fifo_wait();
|
||||
CHNREG32(ch, 40) = 0x24 | (i<<8);;
|
||||
}
|
||||
|
||||
g2_fifo_wait();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Stop the sound on a given channel */
|
||||
void aica_stop(int ch) {
|
||||
g2_write_32(CHNREGADDR(ch, 0),(g2_read_32(CHNREGADDR(ch, 0)) & ~0x4000) | 0x8000);
|
||||
g2_fifo_wait();
|
||||
}
|
||||
|
||||
|
||||
/* The rest of these routines can change the channel in mid-stride so you
|
||||
can do things like vibrato and panning effects. */
|
||||
|
||||
/* Set channel volume */
|
||||
void aica_vol(int ch,int vol) {
|
||||
// g2_write_8(CHNREGADDR(ch, 41),AICA_VOL(vol));
|
||||
g2_write_32(CHNREGADDR(ch, 40),(g2_read_32(CHNREGADDR(ch, 40))&0xffff00ff)|(AICA_VOL(vol)<<8) );
|
||||
g2_fifo_wait();
|
||||
}
|
||||
|
||||
/* Set channel pan */
|
||||
void aica_pan(int ch,int pan) {
|
||||
// g2_write_8(CHNREGADDR(ch, 36),AICA_PAN(pan));
|
||||
g2_write_32(CHNREGADDR(ch, 36),(g2_read_32(CHNREGADDR(ch, 36))&0xffffff00)|(AICA_PAN(pan)) );
|
||||
g2_fifo_wait();
|
||||
}
|
||||
|
||||
/* Set channel frequency */
|
||||
void aica_freq(int ch,int freq) {
|
||||
g2_write_32(CHNREGADDR(ch, 24),AICA_FREQ(freq));
|
||||
g2_fifo_wait();
|
||||
}
|
||||
|
||||
/* Get channel position */
|
||||
int aica_get_pos(int ch) {
|
||||
#if 1
|
||||
/* Observe channel ch */
|
||||
g2_write_32(SNDREGADDR(0x280c),(g2_read_32(SNDREGADDR(0x280c))&0xffff00ff) | (ch<<8));
|
||||
g2_fifo_wait();
|
||||
/* Update position counters */
|
||||
return g2_read_32(SNDREGADDR(0x2814)) & 0xffff;
|
||||
#else
|
||||
/* Observe channel ch */
|
||||
g2_write_8(SNDREGADDR(0x280d),ch);
|
||||
/* Update position counters */
|
||||
return g2_read_32(SNDREGADDR(0x2814)) & 0xffff;
|
||||
#endif
|
||||
}
|
17
src/audio/dc/aica.h
Normal file
17
src/audio/dc/aica.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef _AICA_H_
|
||||
#define _AICA_H_
|
||||
|
||||
#define AICA_MEM 0xa0800000
|
||||
|
||||
#define SM_8BIT 1
|
||||
#define SM_16BIT 0
|
||||
#define SM_ADPCM 2
|
||||
|
||||
void aica_play(int ch,int mode,unsigned long smpptr,int looptst,int loopend,int freq,int vol,int pan,int loopflag);
|
||||
void aica_stop(int ch);
|
||||
void aica_vol(int ch,int vol);
|
||||
void aica_pan(int ch,int pan);
|
||||
void aica_freq(int ch,int freq);
|
||||
int aica_get_pos(int ch);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue