BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
audiolib.c File Reference
#include "blitzlib.h"
#include "blitzobj.h"

Data Structures

struct  vhdr
struct  opened

Macros

#define TOK_iffchunk   TOK_ifffind /* "iffchunk" in audiolib */
#define AUD(ch, off)
#define CIAAPRA   (*(volatile UBYTE *)0xbfe001)
#define VHPOSR_B   (*(volatile UBYTE *)0xdff006)
#define IFFCALL(tok, r)
#define SND_START(ch, bit)
#define SND_REPEAT(ch, bit)

Functions

void dodplay2 (void)
void dodplay (void)
void dodiskbuff (void)
void dofilter (void)
void dovolume (void)
void dosdata (void)
 SoundData Sound#,Offset,Data: write a byte of the sample (inline MOVE.l (a3),a0:MOVE.b d2,0(a0,d1.l), as in the original).
void dopsound (void)
 PeekSound(Sound#,Offset): a byte of the sample, sign extended to a word (inline, as in the original).
void audiolib_codeinit (void)
void audiolib_codefinit (void)
void dofreesound (void)
void sndchk (void)
void dpchk (void)
void vchk (void)
void ischk1 (void)
void ischk2 (void)
void sdatachk (void)
void setpchk (void)
void doisound2 (void)
void doisound3 (void)
void doisound (void)
static UBYTE * alloc (ULONG size, ULONG flags)
static void dealloc (void *mem, ULONG size)
static void dofilter_c (UWORD on)
 Filter On|Off: the audio low pass filter (the power LED bit, BCLR/BSET #1,$BFE001).
 BLITZ_ALIAS (dofilter, dofilter_c)
static void dodiskbuff_c (ULONG len)
 DiskBuffer Bufferlen: the length of each half of DiskPlay's chip buffer (default 1024).
 BLITZ_ALIAS (dodiskbuff, dodiskbuff_c)
static BLITZ_ENTRYPOINT void dovolume_c (UWORD mask, const UBYTE *args)
 Volume Channelmask,Vol1[,Vol2...]: set the volume of the channels of the mask.
 BLITZ_ALIAS_EP (dovolume, dovolume_c)
static void freesound (struct bb_sound *s)
static void dofreesound_c (void)
 Free Sound (the object's _free nullsub): free the sample of the sound in a3 (not for "cL" data of DecodeSound).
static int opensound (const UBYTE *name, struct opened *o, UBYTE *buf)
void doloadsound (const UBYTE *name)
 LoadSound Sound#,Filename$: load an IFF 8SVX file into the sound.
void _cludgesound (ULONG *p)
 DecodeSound Sound#,MemoryLocation: a sound from an 8SVX FORM in memory.
void _setperiod (UWORD period)
 SetPeriod Sound#,Period: set the sound's period.
static void initsound (ULONG len, UWORD period, ULONG rep)
static void doisound2_c (ULONG len)
 InitSound Sound#,Length: an empty sound of Length bytes in chip memory (cleared), period 428, repeat from the start.
static void doisound3_c (ULONG len, UWORD period)
 InitSound Sound#,Length,Period: InitSound with a period.
static void doisound_c (ULONG len, UWORD period, ULONG rep)
 InitSound Sound#,Length,Period,Repeat: InitSound with a period and a repeat offset.
BL_ALWAYS_INLINE void wait12 (void)
static UWORD chansoff (UWORD mask)
BL_ALWAYS_INLINE void playsound (UWORD mask, WORD nvol, int loop, const UBYTE *args)
static BLITZ_ENTRYPOINT void dosound2_c (UWORD mask)
 Sound Sound#,Channelmask: play the sound once on the channels.
 BLITZ_ALIAS_EP (dosound2, dosound2_c)
static BLITZ_ENTRYPOINT void dosound_c (UWORD mask, WORD nvol, const UBYTE *args)
 Sound Sound#,Channelmask,Vol1[,Vol2...]: Sound with volumes.
 BLITZ_ALIAS_EP (dosound, dosound_c)
static BLITZ_ENTRYPOINT void dosoundl2_c (UWORD mask)
 LoopSound Sound#,Channelmask: play the sound and repeat its repeat part.
 BLITZ_ALIAS_EP (dosoundl2, dosoundl2_c)
static BLITZ_ENTRYPOINT void dosoundl_c (UWORD mask, WORD nvol, const UBYTE *args)
 LoopSound Sound#,Channelmask,Vol1[,Vol2...]: LoopSound with volumes.
 BLITZ_ALIAS_EP (dosoundl, dosoundl_c)
static void intwait (UWORD bits)
static LONG loadbuff (UBYTE **pp, UWORD dma)
static void diskplay (const UBYTE *name, UWORD mask, WORD nvol, const UBYTE *args)
static void dodplay2_c (const UBYTE *name, UWORD mask, const UBYTE *args)
 DiskPlay Filename$,Channelmask: stream an 8SVX file from disk.
 BLITZ_ALIAS (dodplay2, dodplay2_c)
static void dodplay_c (const UBYTE *name, UWORD mask, WORD nvol, const UBYTE *args)
 DiskPlay Filename$,Channelmask,Vol1[,Vol2...]: DiskPlay with volumes.
 BLITZ_ALIAS (dodplay, dodplay_c)
static void codeinit_c (void)
 init: audio DMA and interrupts off, DiskBuffer 1024, a zero word in chip memory (memlib globalloc).
static void codefinit_c (void)
 finit: audio DMA off, the volume of all channels 0.
static void dpchk_c (UWORD mask)
static void sndchk_c (UWORD mask)
static void setpchk_c (void)
static void vchk_c (UWORD mask)
static void ischk1_c (ULONG len)
static void ischk2_c (ULONG len, ULONG rep)
static void sdatachk_c (ULONG off)

Variables

static ULONG dbufflen = 1024
static LONG dlen
static UBYTE * dbuffat
static UBYTE * dbuffend
static UWORD * chzero
static const char mess1 [] = "Illegal Sound file"
static const char mess2 [] = "Can't Find VHDR"
static const char mess3 [] = "Error Reading File"
static const char mess4 [] = "Sound too long"
static const char mess5 [] = "Uninitialized Sound"
const char mess6 []
const char mess7 []
const char mess8 []
const char mess9 []
const char messa []

Macro Definition Documentation

◆ AUD

#define AUD ( ch,
off )
Value:
(0xdff0a0 + 16 * (ch) + (off))
static void ch(struct out *o, char c)
Definition xtra_ab3.c:487

◆ CIAAPRA

#define CIAAPRA   (*(volatile UBYTE *)0xbfe001)

◆ IFFCALL

#define IFFCALL ( tok,
r )
Value:
BLITZ_ALIBJSR_CCR(tok, r, "ne")
#define BLITZ_ALIBJSR_CCR(tok, r, cc)
Definition blitzlib.h:702

◆ SND_REPEAT

#define SND_REPEAT ( ch,
bit )
Value:
if (mask & (bit)) { \
*(volatile UWORD *)AUD(ch, 4) = len; \
*(volatile ULONG *)AUD(ch, 0) = ptr; \
}
ULONG len
Definition asllib.c:158
#define AUD(ch, off)
Definition audiolib.c:70
static ULONG bit(ULONG flags, int n)
Definition gtlib.c:620

◆ SND_START

#define SND_START ( ch,
bit )
Value:
if (mask & (bit)) { \
*(volatile UWORD *)AUD(ch, 8) = 0; \
*(volatile ULONG *)AUD(ch, 0) = (ULONG)s->data; \
*(volatile UWORD *)AUD(ch, 6) = s->period; \
*(volatile UWORD *)AUD(ch, 4) = s->len; \
*(volatile UWORD *)AUD(ch, 8) = 64; \
if (--nvol >= 0) /* SUBQ #1,d7:BMI */ \
*(volatile UWORD *)AUD(ch, 8) = BL_POPW(sp); \
}
#define BL_POPW(sp)
Definition blitzhelp.h:156

◆ TOK_iffchunk

#define TOK_iffchunk   TOK_ifffind /* "iffchunk" in audiolib */

◆ VHPOSR_B

#define VHPOSR_B   (*(volatile UBYTE *)0xdff006)

Function Documentation

◆ _cludgesound()

void _cludgesound ( ULONG * p)

DecodeSound Sound#,MemoryLocation: a sound from an 8SVX FORM in memory.

Looks for VHDR and BODY; chip data (below 2 MB) is used in place ("cL", never freed), other data copied to chip memory. Fixed (#68): freeing the sound clears the "cL" mark, so a later copy of fast memory is freed again. Errors: "Illegal Sound file" (no FORM/8SVX, no VHDR/BODY before the end of the FORM), "Sound too long" (>= 128K). The Sound object comes in a3 (!libs {audiolib,$1380}, from Sound# in d0).

Parameters
pd1: the address of the FORM

◆ _setperiod()

void _setperiod ( UWORD period)

SetPeriod Sound#,Period: set the sound's period.

Without a sound: runtime error "Uninitialized Sound" (err5, in the normal code; the original branches into the error check area, fixed: #70). Fixed (#66): the error check (setpchk) tests the sound only; the original's sndchk went on into dpchk and tested the period as channel mask: a period > 15 was "Illegal Chanel Mask" with the debugger. The Sound object comes in a3 (!libs {audiolib,$1380}, from Sound# in d0).

Parameters
periodd1.w: the period

◆ alloc()

UBYTE * alloc ( ULONG size,
ULONG flags )
static

◆ audiolib_codefinit()

void audiolib_codefinit ( void )

◆ audiolib_codeinit()

void audiolib_codeinit ( void )

◆ BLITZ_ALIAS() [1/4]

BLITZ_ALIAS ( dodiskbuff ,
dodiskbuff_c  )

◆ BLITZ_ALIAS() [2/4]

BLITZ_ALIAS ( dodplay ,
dodplay_c  )

◆ BLITZ_ALIAS() [3/4]

BLITZ_ALIAS ( dodplay2 ,
dodplay2_c  )

◆ BLITZ_ALIAS() [4/4]

BLITZ_ALIAS ( dofilter ,
dofilter_c  )

◆ BLITZ_ALIAS_EP() [1/5]

BLITZ_ALIAS_EP ( dosound ,
dosound_c  )

◆ BLITZ_ALIAS_EP() [2/5]

BLITZ_ALIAS_EP ( dosound2 ,
dosound2_c  )

◆ BLITZ_ALIAS_EP() [3/5]

BLITZ_ALIAS_EP ( dosoundl ,
dosoundl_c  )

◆ BLITZ_ALIAS_EP() [4/5]

BLITZ_ALIAS_EP ( dosoundl2 ,
dosoundl2_c  )

◆ BLITZ_ALIAS_EP() [5/5]

BLITZ_ALIAS_EP ( dovolume ,
dovolume_c  )

◆ chansoff()

UWORD chansoff ( UWORD mask)
static

◆ codefinit_c()

void codefinit_c ( void )
static

finit: audio DMA off, the volume of all channels 0.

◆ codeinit_c()

void codeinit_c ( void )
static

init: audio DMA and interrupts off, DiskBuffer 1024, a zero word in chip memory (memlib globalloc).

◆ dealloc()

void dealloc ( void * mem,
ULONG size )
static

◆ diskplay()

void diskplay ( const UBYTE * name,
UWORD mask,
WORD nvol,
const UBYTE * args )
static

◆ dodiskbuff()

void dodiskbuff ( void )

◆ dodiskbuff_c()

void dodiskbuff_c ( ULONG len)
static

DiskBuffer Bufferlen: the length of each half of DiskPlay's chip buffer (default 1024).

Parameters
lend0: the length in bytes

◆ dodplay()

void dodplay ( void )

◆ dodplay2()

void dodplay2 ( void )

◆ dodplay2_c()

void dodplay2_c ( const UBYTE * name,
UWORD mask,
const UBYTE * args )
static

DiskPlay Filename$,Channelmask: stream an 8SVX file from disk.

Through two halves of a chip buffer (DiskBuffer, default 1024 bytes each), waiting for the audio interrupt bits in INTREQR (busy wait, as in the original). Fixed (#69): a BODY whose length is a multiple of the buffer length (or 0) ends; the original never returned. Errors: as LoadSound (no file, no VHDR, read error); (debugger, dpchk) "Illegal Chanel Mask". Fixed (#950): on those errors the chip buffer is freed (the original kept it).

Parameters
named0: the file name
maskd1.w: the channel mask
argsa2: the compiler's stack (its string length is dropped)

◆ dodplay_c()

void dodplay_c ( const UBYTE * name,
UWORD mask,
WORD nvol,
const UBYTE * args )
static

DiskPlay Filename$,Channelmask,Vol1[,Vol2...]: DiskPlay with volumes.

As DiskPlay Filename$,Channelmask.

Parameters
named0: the file name
maskd1.w: the channel mask
nvold7.w: the number of volumes
argsa2: the compiler's stack with the string length and the volumes (words)

◆ dofilter()

void dofilter ( void )

◆ dofilter_c()

void dofilter_c ( UWORD on)
static

Filter On|Off: the audio low pass filter (the power LED bit, BCLR/BSET #1,$BFE001).

Fixed (#985): bit 1 of CIAAPRA is the active-low /LED output (0 = LED bright, filter on; Amiga Hardware Reference Manual): On clears it, Off sets it. The original set it for On (BSET) and so switched the filter off, and Off switched it on.

Parameters
ond0.w: not 0 = on

◆ dofreesound()

void dofreesound ( void )

◆ dofreesound_c()

void dofreesound_c ( void )
static

Free Sound (the object's _free nullsub): free the sample of the sound in a3 (not for "cL" data of DecodeSound).

◆ doisound()

void doisound ( void )

◆ doisound2()

void doisound2 ( void )

◆ doisound2_c()

void doisound2_c ( ULONG len)
static

InitSound Sound#,Length: an empty sound of Length bytes in chip memory (cleared), period 428, repeat from the start.

Errors (debugger, ischk1): "Sound too long" (>= 128K), "Sound Length MUST be even". The Sound object comes in a3 (!libs {audiolib,$1380}, from Sound# in d0).

Parameters
lend1: the length in bytes

◆ doisound3()

void doisound3 ( void )

◆ doisound3_c()

void doisound3_c ( ULONG len,
UWORD period )
static

InitSound Sound#,Length,Period: InitSound with a period.

Errors (debugger, ischk1): as InitSound Sound#,Length. The Sound object comes in a3 (!libs {audiolib,$1380}, from Sound# in d0).

Parameters
lend1: the length in bytes
periodd2.w: the period

◆ doisound_c()

void doisound_c ( ULONG len,
UWORD period,
ULONG rep )
static

InitSound Sound#,Length,Period,Repeat: InitSound with a period and a repeat offset.

Errors (debugger, ischk2): as InitSound Sound#,Length, and "Repeat offset MUST be even", "Repeat MUST be less than Length". The Sound object comes in a3 (!libs {audiolib,$1380}, from Sound# in d0).

Parameters
lend1: the length in bytes
periodd2.w: the period
repd3: the repeat offset in bytes

◆ doloadsound()

void doloadsound ( const UBYTE * name)

LoadSound Sound#,Filename$: load an IFF 8SVX file into the sound.

Through iffiolib: VHDR (repeat start and length, period = 3579440 / samplesPerSec, DIVU: overflow below 55 Hz leaves 3579440), then BODY into chip memory. Errors: "Illegal Sound file" (no file), "Can't Find VHDR", "Error Reading File", "Sound too long" (>= 128K). Fixed (#67): the file is closed before the last three (the original left it open). The Sound object comes in a3 (!libs {audiolib,$1380}, from Sound# in d0).

Parameters
named1: the file name

◆ dopsound()

void dopsound ( void )

PeekSound(Sound#,Offset): a byte of the sample, sign extended to a word (inline, as in the original).

a3 = the Sound object (!libs {audiolib,$1380}), d1 = the offset; d0.w = the byte. Fixed (#46): a3 is left as it is; inside a string expression the compiler saves a3 (the end of the string) around the call (eval.c libfunction). Errors (debugger, sdatachk): as SoundData.

◆ dosdata()

void dosdata ( void )

SoundData Sound#,Offset,Data: write a byte of the sample (inline MOVE.l (a3),a0:MOVE.b d2,0(a0,d1.l), as in the original).

a3 = the Sound object (!libs {audiolib,$1380}), d1 = the offset, d2 = the byte. Errors (debugger, sdatachk): "Uninitialized Sound", "Data offset too large".

◆ dosound2_c()

BLITZ_ENTRYPOINT void dosound2_c ( UWORD mask)
static

Sound Sound#,Channelmask: play the sound once on the channels.

Switches the channels' DMA off, waits for 12 changes of the VHPOSR line byte, starts the sound on every channel of the mask (volume 64 or the next given one) and after another 12 lines sets a zero word in chip memory as the repeat part. Errors (debugger, sndchk): "Uninitialized Sound", "Illegal Chanel Mask" (mask > 15). The Sound object comes in a3 (!libs {audiolib,$1380}, from Sound# in d0). The four entries are __entrypoint routines (they save nothing and change d0-d6, with volumes d7, and a2; the original changes d0, d2-d4, d6, d7 and a0).

Parameters
maskd1.w: the channel mask

◆ dosound_c()

BLITZ_ENTRYPOINT void dosound_c ( UWORD mask,
WORD nvol,
const UBYTE * args )
static

Sound Sound#,Channelmask,Vol1[,Vol2...]: Sound with volumes.

As Sound Sound#,Channelmask, with the volumes from the a2 stack, one per channel of the mask (channel 0 first).

Parameters
maskd1.w: the channel mask
nvold7.w: the number of volumes
argsa2: the compiler's stack with the volumes (words)

◆ dosoundl2_c()

BLITZ_ENTRYPOINT void dosoundl2_c ( UWORD mask)
static

LoopSound Sound#,Channelmask: play the sound and repeat its repeat part.

As Sound, but after the second wait the repeat part of the sound is set as the channels' location and length.

Parameters
maskd1.w: the channel mask

◆ dosoundl_c()

BLITZ_ENTRYPOINT void dosoundl_c ( UWORD mask,
WORD nvol,
const UBYTE * args )
static

LoopSound Sound#,Channelmask,Vol1[,Vol2...]: LoopSound with volumes.

As LoopSound Sound#,Channelmask, with the volumes as Sound.

Parameters
maskd1.w: the channel mask
nvold7.w: the number of volumes
argsa2: the compiler's stack with the volumes (words)

◆ dovolume()

void dovolume ( void )

◆ dovolume_c()

BLITZ_ENTRYPOINT void dovolume_c ( UWORD mask,
const UBYTE * args )
static

Volume Channelmask,Vol1[,Vol2...]: set the volume of the channels of the mask.

The volumes from the a2 stack, one per set bit (channel 0 first). Errors (debugger, vchk): "Illegal Chanel Mask" (mask > 15). The four channels unrolled: one bit test and one write to an absolute AUDxVOL each, no loop counter and no address step (the original's LSR/BCC/LEA/DBF loop costs 196 cycles for one channel without the call, this 130).

Parameters
maskd0.w: the channel mask
argsa2: the compiler's stack with the volumes (words)

◆ dpchk()

void dpchk ( void )

◆ dpchk_c()

void dpchk_c ( UWORD mask)
static

◆ freesound()

void freesound ( struct bb_sound * s)
static

◆ initsound()

void initsound ( ULONG len,
UWORD period,
ULONG rep )
static

◆ intwait()

void intwait ( UWORD bits)
static

◆ ischk1()

void ischk1 ( void )

◆ ischk1_c()

void ischk1_c ( ULONG len)
static

◆ ischk2()

void ischk2 ( void )

◆ ischk2_c()

void ischk2_c ( ULONG len,
ULONG rep )
static

◆ loadbuff()

LONG loadbuff ( UBYTE ** pp,
UWORD dma )
static

◆ opensound()

int opensound ( const UBYTE * name,
struct opened * o,
UBYTE * buf )
static

◆ playsound()

BL_ALWAYS_INLINE void playsound ( UWORD mask,
WORD nvol,
int loop,
const UBYTE * args )

◆ sdatachk()

void sdatachk ( void )

◆ sdatachk_c()

void sdatachk_c ( ULONG off)
static

◆ setpchk()

void setpchk ( void )

◆ setpchk_c()

void setpchk_c ( void )
static

◆ sndchk()

void sndchk ( void )

◆ sndchk_c()

void sndchk_c ( UWORD mask)
static

◆ vchk()

void vchk ( void )

◆ vchk_c()

void vchk_c ( UWORD mask)
static

◆ wait12()

BL_ALWAYS_INLINE void wait12 ( void )

Variable Documentation

◆ chzero

UWORD* chzero
static

◆ dbuffat

UBYTE* dbuffat
static

◆ dbuffend

UBYTE* dbuffend
static

◆ dbufflen

ULONG dbufflen = 1024
static

◆ dlen

LONG dlen
static

◆ mess1

const char mess1[] = "Illegal Sound file"
static

◆ mess2

const char mess2[] = "Can't Find VHDR"
static

◆ mess3

const char mess3[] = "Error Reading File"
static

◆ mess4

const char mess4[] = "Sound too long"
static

◆ mess5

const char mess5[] = "Uninitialized Sound"
static

◆ mess6

const char mess6[]
extern

◆ mess7

const char mess7[]

◆ mess8

const char mess8[]

◆ mess9

const char mess9[]

◆ messa

const char messa[]