BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
risoundlib2.c File Reference
#include "blitzlib.h"
#include "blitzobj.h"
#include "blitzexec.h"
#include <exec/io.h>
#include <exec/memory.h>
#include <utility/tagitem.h>
#include <devices/ahi.h>

Data Structures

struct  reqtags

Macros

#define ID(a, b, c, d)
#define LONGAT(p)
#define WORDAT(p)
#define MAXBODY   131071
#define LVO_OpenDevice   (-444)
#define LVO_DoIO   (-456)
#define LVO_SendIO   (-462)
#define LVO_AHI_AllocAudioRequestA   (-120)
#define LVO_AHI_AudioRequestA   (-126)
#define LVO_AHI_FreeAudioRequest   (-132)
#define MIN_AHI_VERSION   4
#define AHI_TAGBASE   0x80000000UL
#define AHIR_SCREEN   (AHI_TAGBASE + 201)
#define AHIR_INITIALLEFTEDGE   (AHI_TAGBASE + 240)
#define AHIR_INITIALTOPEDGE   (AHI_TAGBASE + 241)
#define AHIR_INITIALWIDTH   (AHI_TAGBASE + 242)
#define AHIR_INITIALHEIGHT   (AHI_TAGBASE + 243)
#define AHIR_INITIALAUDIOID   (AHI_TAGBASE + 244)
#define AHIR_INITIALMIXFREQ   (AHI_TAGBASE + 245)
#define AHIR_DOMIXFREQ   (AHI_TAGBASE + 260)
#define reqcall(lvo, req)

Functions

void risoundlib2_loadsounds (void)
void risoundlib2_libinit (void)
void risoundlib2_libfinit (void)
void _OpenAHI (void)
void _OpenAHI2 (void)
void _CloseAHI (void)
void _PlaySoundAHI (void)
void _PlaySoundAHI1 (void)
void _PlaySoundAHI2 (void)
void _PlayRawAHI (void)
void _PlayRawAHI1 (void)
void _PlayRawAHI2 (void)
void _AHIOutputRequest1 (void)
void _AHIOutputRequest2 (void)
void _AHIOutputRequest3 (void)
void _AHIOutputRequest4 (void)
void _AHIOutputRequest5 (void)
void _AHIOutputRequest6 (void)
void _AHIRequestedID (void)
void _AHIRequestedFreq (void)
static ULONG periodfreq (UWORD period)
 The playing frequency of a sound object: 3579545 / its period (+4).
static ULONG c_libinit (void)
 init: create the message port and the AHI request.
static void ahitakeback (void)
 Take back the sound PlaySoundAHI sent: abort it if it still plays, then WaitIO (which also removes its reply from the port).
static void c_closeahi (void)
 CloseAHI: stop a running sound, close ahi.device; the request and the port stay.
static void c_libfinit (void)
 finit: close the device (c_closeahi()), delete the request and the port.
BB_BOOL c_openahi2 (ULONG unit, ULONG id)
 OpenAHI unit,deviceID: open ahi.device with the library's request.
BB_BOOL c_openahi (ULONG unit)
 OpenAHI unit: c_openahi2() with the device ID AHI_DEFAULT_ID.
ULONG c_playsound2 (ULONG vol, ULONG bal, struct bb_sound *obj)
 PlaySoundAHI sound,volume,balance: play a sound object through ahi.device.
ULONG c_playsound1 (ULONG vol, struct bb_sound *obj)
 PlaySoundAHI sound,volume: c_playsound2() with the balance centred (0x8000).
ULONG c_playsound (struct bb_sound *obj)
 PlaySoundAHI sound: c_playsound2() with full volume (0x10000), centred.
ULONG c_playraw2 (ULONG data, ULONG len, ULONG freq, ULONG vol, ULONG bal)
 PlayRawAHI address,length,frequency,volume,balance: play raw 8 bit data through ahi.device.
ULONG c_playraw1 (ULONG data, ULONG len, ULONG freq, ULONG vol)
 PlayRawAHI address,length,frequency,volume: c_playraw2() centred (0x8000).
ULONG c_playraw (ULONG data, ULONG len, ULONG freq)
 PlayRawAHI address,length,frequency: c_playraw2() at full volume, centred.
ULONG c_outreq6 (ULONG x, ULONG y, ULONG w, ULONG h, ULONG id, ULONG freq, const ULONG *scr)
 AHIOutputRequest x,y,width,height,modeid,frequency: AHI's audio mode requester.
ULONG c_outreq1 (const ULONG *scr)
 AHIOutputRequest: c_outreq6() with x, y, width, height -1 and mode id, frequency 0.
ULONG c_outreq2 (ULONG id, const ULONG *scr)
 AHIOutputRequest modeid: c_outreq6() with x, y, width, height -1, frequency 0.
ULONG c_outreq3 (ULONG id, ULONG freq, const ULONG *scr)
 AHIOutputRequest modeid,frequency: c_outreq6() with x, y, width, height -1.
ULONG c_outreq4 (ULONG x, ULONG y, ULONG w, ULONG h, const ULONG *scr)
 AHIOutputRequest x,y,width,height: c_outreq6() with mode id and frequency 0.
ULONG c_outreq5 (ULONG x, ULONG y, ULONG w, ULONG h, ULONG id, const ULONG *scr)
 AHIOutputRequest x,y,width,height,modeid: c_outreq6() with frequency 0.
ULONG c_requestedid (void)
 AHIRequestedID: the audio mode id chosen in AHIOutputRequest.
ULONG c_requestedfreq (void)
 AHIRequestedFreq: the mixing frequency chosen in AHIOutputRequest.
static BB_BOOL loadsounds_c (ULONG sound, UBYTE *sram, struct bb_sound *saddr)
 CludgeSound sound#,address: make a sound object of an 8SVX file in memory.

Variables

static struct reqtags ahireqtags
static ULONG reqaudioid = (ULONG)-1
static ULONG reqmixfreq
static ULONG deviceunit
static ULONG deviceid
static struct MsgPort * ahimsgport
static struct AHIRequest * ahiiorequest
static ULONG ahidevice
static BOOL ahisent
static struct Device * ahibase
static char ahiname [] = "ahi.device"

Macro Definition Documentation

◆ AHI_TAGBASE

#define AHI_TAGBASE   0x80000000UL

◆ AHIR_DOMIXFREQ

#define AHIR_DOMIXFREQ   (AHI_TAGBASE + 260)

◆ AHIR_INITIALAUDIOID

#define AHIR_INITIALAUDIOID   (AHI_TAGBASE + 244)

◆ AHIR_INITIALHEIGHT

#define AHIR_INITIALHEIGHT   (AHI_TAGBASE + 243)

◆ AHIR_INITIALLEFTEDGE

#define AHIR_INITIALLEFTEDGE   (AHI_TAGBASE + 240)

◆ AHIR_INITIALMIXFREQ

#define AHIR_INITIALMIXFREQ   (AHI_TAGBASE + 245)

◆ AHIR_INITIALTOPEDGE

#define AHIR_INITIALTOPEDGE   (AHI_TAGBASE + 241)

◆ AHIR_INITIALWIDTH

#define AHIR_INITIALWIDTH   (AHI_TAGBASE + 242)

◆ AHIR_SCREEN

#define AHIR_SCREEN   (AHI_TAGBASE + 201)

◆ ID

#define ID ( a,
b,
c,
d )
Value:
((ULONG)(a) << 24 | (ULONG)(b) << 16 | (c) << 8 | (d))
ULONG WORD UWORD c
Definition 2dlib.c:2491
static struct @065163037313156332013005143365272036211065172003 d

◆ LONGAT

#define LONGAT ( p)
Value:
(*(ULONG *)(p))

◆ LVO_AHI_AllocAudioRequestA

#define LVO_AHI_AllocAudioRequestA   (-120)

◆ LVO_AHI_AudioRequestA

#define LVO_AHI_AudioRequestA   (-126)

◆ LVO_AHI_FreeAudioRequest

#define LVO_AHI_FreeAudioRequest   (-132)

◆ LVO_DoIO

#define LVO_DoIO   (-456)

◆ LVO_OpenDevice

#define LVO_OpenDevice   (-444)

◆ LVO_SendIO

#define LVO_SendIO   (-462)

◆ MAXBODY

#define MAXBODY   131071

◆ MIN_AHI_VERSION

#define MIN_AHI_VERSION   4

◆ reqcall

#define reqcall ( lvo,
req )
Value:
({ \
struct bl_regs r_ = { .a1 = (ULONG)(req) }; \
BLITZ_BASEJSR(SysBase, lvo, r_); })
#define SysBase
Definition blitzexec.h:15
Definition blitzlib.h:537

◆ WORDAT

#define WORDAT ( p)
Value:
(*(UWORD *)(p))

Function Documentation

◆ _AHIOutputRequest1()

void _AHIOutputRequest1 ( void )

◆ _AHIOutputRequest2()

void _AHIOutputRequest2 ( void )

◆ _AHIOutputRequest3()

void _AHIOutputRequest3 ( void )

◆ _AHIOutputRequest4()

void _AHIOutputRequest4 ( void )

◆ _AHIOutputRequest5()

void _AHIOutputRequest5 ( void )

◆ _AHIOutputRequest6()

void _AHIOutputRequest6 ( void )

◆ _AHIRequestedFreq()

void _AHIRequestedFreq ( void )

◆ _AHIRequestedID()

void _AHIRequestedID ( void )

◆ _CloseAHI()

void _CloseAHI ( void )

◆ _OpenAHI()

void _OpenAHI ( void )

◆ _OpenAHI2()

void _OpenAHI2 ( void )

◆ _PlayRawAHI()

void _PlayRawAHI ( void )

◆ _PlayRawAHI1()

void _PlayRawAHI1 ( void )

◆ _PlayRawAHI2()

void _PlayRawAHI2 ( void )

◆ _PlaySoundAHI()

void _PlaySoundAHI ( void )

◆ _PlaySoundAHI1()

void _PlaySoundAHI1 ( void )

◆ _PlaySoundAHI2()

void _PlaySoundAHI2 ( void )

◆ ahitakeback()

void ahitakeback ( void )
static

Take back the sound PlaySoundAHI sent: abort it if it still plays, then WaitIO (which also removes its reply from the port).

Fixed (#933): the original sent its one request again without waiting for the one before or removing its reply, and finit left everything open while it was in use. Only a request this library sent with SendIO is waited for, so it never blocks on one the device never had.

◆ c_closeahi()

void c_closeahi ( void )
static

CloseAHI: stop a running sound, close ahi.device; the request and the port stay.

Fixed (#927): the original's CloseAHI was finit, which deleted the request and the port, so that a later OpenAHI used request 0. Nothing without a request. A sound that plays is aborted (fixed: #933, the original left everything open while the request was in use); CloseDevice if ahidevice is set (fixed: #924, never set in the original); then ahibase = 0.

◆ c_libfinit()

void c_libfinit ( void )
static

finit: close the device (c_closeahi()), delete the request and the port.

Nothing without the port; without a request (init could not make it) no CheckIO (fixed: #927, the original's CheckIO of address 0). A sound that plays is aborted first (fixed: #933). Then DeleteIORequest, DeleteMsgPort.

◆ c_libinit()

ULONG c_libinit ( void )
static

init: create the message port and the AHI request.

CreateMsgPort, then CreateIORequest of a struct AHIRequest (80 bytes) on that port. Both are exec V36 calls: below exec V36 (Kickstart 1.x) port and request stay 0, and the commands fail (OpenAHI 0); fixed (#1139), the original called them there (offsets behind exec's jump table: a crash at the program's start). Port and request made before and not deleted by finit (CloseAHI keeps them, fixed: #927) stay.

Returns
d0: the request, 0 if the port or the request could not be made (a port made stays) or exec is older than V36

◆ c_openahi()

BB_BOOL c_openahi ( ULONG unit)

OpenAHI unit: c_openahi2() with the device ID AHI_DEFAULT_ID.

Parameters
unitd0: the AHI unit
Returns
d0: BB_TRUE if ahi.device opened, else BB_FALSE

◆ c_openahi2()

BB_BOOL c_openahi2 ( ULONG unit,
ULONG id )

OpenAHI unit,deviceID: open ahi.device with the library's request.

Sets ahir_Version to 4 (MIN_AHI_VERSION) and calls OpenDevice ("ahi.device", unit, request, 0); on success io_Device becomes the library base for the requester calls. The device ID is stored but not used. A second OpenAHI while it is open returns 0 (fixed: #924, the original never set ahidevice and opened the open request again). Fixed (#927): without a request (init could not make it) the result is 0; the original wrote ahir_Version to address 48 and passed request 0 to OpenDevice (also after CloseAHI, which deleted the request).

Parameters
unitd0: the AHI unit
idd1: the device (audio mode) ID, unused
Returns
d0: BB_TRUE if ahi.device opened, else BB_FALSE

◆ c_outreq1()

ULONG c_outreq1 ( const ULONG * scr)

AHIOutputRequest: c_outreq6() with x, y, width, height -1 and mode id, frequency 0.

Parameters
scra0: the used screen object of screenslib (its first long the struct Screen), 0 without one (!libs screenslib,ua0)
Returns
d0: as c_outreq6()

◆ c_outreq2()

ULONG c_outreq2 ( ULONG id,
const ULONG * scr )

AHIOutputRequest modeid: c_outreq6() with x, y, width, height -1, frequency 0.

The entry "AudioID" of the original, for the form with 1 argument (fixed: #928; the original gave it to the form with 4 arguments, x, y, width and height replaced by -1, the mode id whatever d4 held).

Parameters
idd0: the mode id
scra0: the used screen object of screenslib (its first long the struct Screen), 0 without one (!libs screenslib,ua0)
Returns
d0: as c_outreq6()

◆ c_outreq3()

ULONG c_outreq3 ( ULONG id,
ULONG freq,
const ULONG * scr )

AHIOutputRequest modeid,frequency: c_outreq6() with x, y, width, height -1.

The entry "AudioID, Frequency" of the original, for the form with 2 arguments (fixed: #928; the original gave it to the form with 1 argument, which was lost, mode id and frequency whatever d4/d5 held).

Parameters
idd0: the mode id
freqd1: the frequency
scra0: the used screen object of screenslib (its first long the struct Screen), 0 without one (!libs screenslib,ua0)
Returns
d0: as c_outreq6()

◆ c_outreq4()

ULONG c_outreq4 ( ULONG x,
ULONG y,
ULONG w,
ULONG h,
const ULONG * scr )

AHIOutputRequest x,y,width,height: c_outreq6() with mode id and frequency 0.

The entry "X,Y,WIDTH,HEIGHT" of the original, for the form with 4 arguments (fixed: #928; the original gave it to the form with 2 arguments, width and height whatever d2/d3 held).

Parameters
xd0: the left edge
yd1: the top edge
wd2: the width
hd3: the height
scra0: the used screen object of screenslib (its first long the struct Screen), 0 without one (!libs screenslib,ua0)
Returns
d0: as c_outreq6()

◆ c_outreq5()

ULONG c_outreq5 ( ULONG x,
ULONG y,
ULONG w,
ULONG h,
ULONG id,
const ULONG * scr )

AHIOutputRequest x,y,width,height,modeid: c_outreq6() with frequency 0.

Parameters
xd0: the left edge
yd1: the top edge
wd2: the width
hd3: the height
idd4: the mode id
scra0: the used screen object of screenslib (its first long the struct Screen), 0 without one (!libs screenslib,ua0)
Returns
d0: as c_outreq6()

◆ c_outreq6()

ULONG c_outreq6 ( ULONG x,
ULONG y,
ULONG w,
ULONG h,
ULONG id,
ULONG freq,
const ULONG * scr )

AHIOutputRequest x,y,width,height,modeid,frequency: AHI's audio mode requester.

Writes the arguments into the data of the tag list's initial left edge, top edge, width, height, audio id and mix frequency (offsets 4, 12, 20, 28, 36, 44; fixed: #931, the original wrote the last four to 16, 20, 24, 28, over the tag ids of width and height), then AHIR_Screen = the struct Screen of the used screen object (its first long; 0 without one: AHI's default; fixed: #929, the original never set it), then AHI_AllocAudioRequestA and AHI_AudioRequestA (no tags). A confirmed requester's choice (ahiam_AudioID, ahiam_MixFreq) is kept for AHIRequestedID/AHIRequestedFreq (fixed: #934), and the requester is freed again (AHI_FreeAudioRequest; fixed: #930, the original allocated one per call and never freed one).

Parameters
xd0: the initial left edge
yd1: the initial top edge
wd2: the initial width
hd3: the initial height
idd4: the initial audio mode id
freqd5: the initial mixing frequency
scra0: the used screen object of screenslib (its first long the struct Screen), 0 without one (!libs screenslib,ua0)
Returns
d0: AHI_AudioRequestA's result (0 when cancelled), 0 without ahi.device or when the requester could not be allocated

◆ c_playraw()

ULONG c_playraw ( ULONG data,
ULONG len,
ULONG freq )

PlayRawAHI address,length,frequency: c_playraw2() at full volume, centred.

Parameters
datad0: the sample data
lend1: its length in bytes
freqd2: the frequency
Returns
d0: as c_playraw2()

◆ c_playraw1()

ULONG c_playraw1 ( ULONG data,
ULONG len,
ULONG freq,
ULONG vol )

PlayRawAHI address,length,frequency,volume: c_playraw2() centred (0x8000).

Parameters
datad0: the sample data
lend1: its length in bytes
freqd2: the frequency
vold3: the volume (Fixed 16.16)
Returns
d0: as c_playraw2()

◆ c_playraw2()

ULONG c_playraw2 ( ULONG data,
ULONG len,
ULONG freq,
ULONG vol,
ULONG bal )

PlayRawAHI address,length,frequency,volume,balance: play raw 8 bit data through ahi.device.

Without ahi.device (ahidevice, fixed: #924 - the original never set it and never played) returns 0. Takes back a sound of PlaySoundAHI (fixed: #933), then CMD_WRITE as AHIST_M8S with ahir_Link 0 and priority 0 (fixed: #924) through DoIO: it returns when the data has been played (the data may be a temporary buffer).

Parameters
datad0: the sample data
lend1: its length in bytes
freqd2: the frequency
vold3: the volume (Fixed 16.16)
bald4: the stereo position (Fixed)
Returns
d0: 0, or DoIO's d0

◆ c_playsound()

ULONG c_playsound ( struct bb_sound * obj)

PlaySoundAHI sound: c_playsound2() with full volume (0x10000), centred.

Parameters
obja0: audiolib's sound object
Returns
d0: as c_playsound2()

◆ c_playsound1()

ULONG c_playsound1 ( ULONG vol,
struct bb_sound * obj )

PlaySoundAHI sound,volume: c_playsound2() with the balance centred (0x8000).

Parameters
vold1: the volume (Fixed 16.16)
obja0: audiolib's sound object
Returns
d0: as c_playsound2()

◆ c_playsound2()

ULONG c_playsound2 ( ULONG vol,
ULONG bal,
struct bb_sound * obj )

PlaySoundAHI sound,volume,balance: play a sound object through ahi.device.

Without ahi.device (ahidevice, fixed: #924 - the original never set it and never played) returns 0. Takes back the sound sent before (abort if it still plays, WaitIO; fixed: #933), then CMD_WRITE of the sample as 8 bit mono (AHIST_M8S), the length in bytes = the object's length in words (+6) x 2 (fixed: #932), the frequency 3579545 / the object's period (fixed: #926), ahir_Link 0 and priority 0 (set for every write: the device trashes them, fixed: #924), through SendIO.

Parameters
vold1: the volume (Fixed 16.16, 0x10000 = full)
bald2: the stereo position (Fixed, 0x8000 = centre)
obja0: audiolib's sound object (!libs audiolib,ia0|pd0)
Returns
d0: 0, or SendIO's d0

◆ c_requestedfreq()

ULONG c_requestedfreq ( void )

AHIRequestedFreq: the mixing frequency chosen in AHIOutputRequest.

The ahiam_MixFreq of the last confirmed requester, 0 before one (fixed: #934; the original returned the data of the initial tag AHIR_InitialMixFreq).

Returns
d0: the chosen frequency, 0 before a choice or without ahi.device

◆ c_requestedid()

ULONG c_requestedid ( void )

AHIRequestedID: the audio mode id chosen in AHIOutputRequest.

The ahiam_AudioID of the last confirmed requester, -1 before one (fixed: #934; the original returned the data of the initial tag AHIR_InitialAudioID).

Returns
d0: the chosen mode id, -1 before a choice, 0 without ahi.device

◆ loadsounds_c()

BB_BOOL loadsounds_c ( ULONG sound,
UBYTE * sram,
struct bb_sound * saddr )
static

CludgeSound sound#,address: make a sound object of an 8SVX file in memory.

risoundlib's routine: checks "8SVX" at +8 and "VHDR" at +12, takes the rate from the VHDR, the period 3579545 / rate, finds the BODY among the first seven chunks, frees the object's old sample (memlib globfree; not DecodeSound's in-place "cL" data, fixed: #945; after the checks, the pointer cleared, fixed: #831) and copies the BODY to chip memory (memlib globalloc). Fixed (#926): nothing is written behind the 16 byte object (the original's rate at +16). Fixed (#925): mark (+14) is cleared again, as in risoundlib; Fixed (#832): the rate is samplesPerSec (VHDR data + 12); Fixed (#830): rate 0 gives 0; Fixed (#828): the chunk walk skips the pad bytes and stays inside the FORM; Fixed (#829): the whole BODY is copied, an empty one or one of 131072 bytes or more gives 0.

Parameters
soundd0: sound# (its upper word goes into globfree's d0)
sramd1: the 8SVX file in memory
saddra0: audiolib's sound object
Returns
d0: BB_TRUE if the sound was made, BB_FALSE if the file is no 8SVX with a VHDR, its rate is 0, it has no BODY among the first seven chunks of the FORM, the BODY is empty or 131072 bytes or longer (the sound unchanged), or no chip memory (the sound then has no sample)

◆ periodfreq()

ULONG periodfreq ( UWORD period)
static

The playing frequency of a sound object: 3579545 / its period (+4).

Fixed (#926): the original read the word +16 that CludgeSound wrote behind the object; the period works for every sound object (LoadSound, DecodeSound, InitSound, CludgeSound) and gives the pitch Sound plays. Two DIVU.w steps (a library cannot link the division of libgcc).

Parameters
periodthe object's period
Returns
the frequency in Hz, 0 for a period of 0

◆ risoundlib2_libfinit()

void risoundlib2_libfinit ( void )

◆ risoundlib2_libinit()

void risoundlib2_libinit ( void )

◆ risoundlib2_loadsounds()

void risoundlib2_loadsounds ( void )

Variable Documentation

◆ ahibase

struct Device* ahibase
static

◆ ahidevice

ULONG ahidevice
static

◆ ahiiorequest

struct AHIRequest* ahiiorequest
static

◆ ahimsgport

struct MsgPort* ahimsgport
static

◆ ahiname

char ahiname[] = "ahi.device"
static

◆ ahireqtags

struct reqtags ahireqtags
static
Initial value:
= {
{ AHIR_INITIALLEFTEDGE, (ULONG)-1 }, { AHIR_INITIALTOPEDGE, (ULONG)-1 },
{ AHIR_INITIALWIDTH, (ULONG)-1 }, { AHIR_INITIALHEIGHT, (ULONG)-1 },
{ AHIR_INITIALAUDIOID, (ULONG)-1 }, { AHIR_INITIALMIXFREQ, 0 },
{ AHIR_SCREEN, 0 }, { AHIR_DOMIXFREQ, 1 }, TAG_END
}
#define AHIR_INITIALMIXFREQ
Definition risoundlib2.c:258
#define AHIR_INITIALLEFTEDGE
Definition risoundlib2.c:253
#define AHIR_INITIALWIDTH
Definition risoundlib2.c:255
#define AHIR_INITIALHEIGHT
Definition risoundlib2.c:256
#define AHIR_INITIALTOPEDGE
Definition risoundlib2.c:254
#define AHIR_SCREEN
Definition risoundlib2.c:252
#define AHIR_DOMIXFREQ
Definition risoundlib2.c:259
#define AHIR_INITIALAUDIOID
Definition risoundlib2.c:257

◆ ahisent

BOOL ahisent
static

◆ deviceid

ULONG deviceid
static

◆ deviceunit

ULONG deviceunit
static

◆ reqaudioid

ULONG reqaudioid = (ULONG)-1
static

◆ reqmixfreq

ULONG reqmixfreq
static