mirror of
https://github.com/stevenhowes/CTheEscape.git
synced 2026-05-27 00:03:27 +01:00
Very WIP PCM sound support
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include "Graphics.h"
|
||||
|
||||
#define SKIP_INTRO
|
||||
#define SKIP_MISSION1
|
||||
//#define SKIP_MISSION1
|
||||
//#define SKIP_MISSION2
|
||||
|
||||
// SWI Registers
|
||||
@@ -51,6 +51,10 @@ void exitfunc () {
|
||||
free(buffer);
|
||||
free(fontbuffer);
|
||||
free(tilebuffer);
|
||||
|
||||
inreg.r[0] = 4;
|
||||
inreg.r[1] = 0;
|
||||
_kernel_swi (DataVox_Unset, &inreg, &outreg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
||||
+37
-1
@@ -1,4 +1,7 @@
|
||||
#include "Graphics.h"
|
||||
#include "Sound.h"
|
||||
#include "swis.h"
|
||||
#include <kernel.h>
|
||||
|
||||
#define PLAYER_Y_START 100
|
||||
#define PLAYER_X_SPEED 10
|
||||
@@ -11,6 +14,9 @@
|
||||
extern sound_composition_save(char *filename);
|
||||
extern sound_composition_load(char *filename);
|
||||
|
||||
extern _kernel_swi_regs inreg;
|
||||
extern _kernel_swi_regs outreg;
|
||||
|
||||
enum sprite_e{player_ship, durno_ship, ship_trgt, durno_ship2, ship2_trgt, player_shipl,player_shipr,explode_start,explode_shp2,explode_shp3,explode_end,photon1,photon2,plasma1,plasma2};
|
||||
char *sprites[] = {"player_ship","durno_ship","ship_trgt","durno_ship2","ship2_trgt","player_shipl","player_shipr","explode_shp1","explode_shp2","explode_shp3","explode_shp4","photon1","photon2","plasma1","plasma2"};
|
||||
|
||||
@@ -140,6 +146,12 @@ void game_spawn_projectile(int id, int Px, int Py, int Vx, int Vy, enum sprite_e
|
||||
Projectiles[id].nextframe = tick + 10;
|
||||
Projectiles[id].damage = damage;
|
||||
Projectiles[id].collidable = 1;
|
||||
// Play it
|
||||
inreg.r[0] = 4;
|
||||
inreg.r[1] = -15;
|
||||
inreg.r[2] = 1;
|
||||
inreg.r[3] = 1;
|
||||
_kernel_swi (Sound_Control, &inreg, &outreg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -785,7 +797,31 @@ void game_setup_audio()
|
||||
sound_set_voice(1,"WaveSynth-Beep");
|
||||
sound_set_voice(2,"Percussion-Noise");
|
||||
sound_set_voice(3,"Percussion-Soft");
|
||||
sound_set_voice(4,"Percussion-Noise");
|
||||
sound_set_voice(4,"DataVox-Voice");
|
||||
sound_pcm_loadsample("sounds.torpedo");
|
||||
|
||||
|
||||
inreg.r[0] = 4;
|
||||
inreg.r[1] = (int) audiobuffer;
|
||||
inreg.r[2] = (int) audiobuffer + 20000;
|
||||
_kernel_swi (DataVox_SetMemory, &inreg, &outreg);
|
||||
|
||||
// Unsigned 8-bit PCM
|
||||
inreg.r[0] = 4;
|
||||
inreg.r[1] = 1;
|
||||
_kernel_swi (DataVox_Type, &inreg, &outreg);
|
||||
|
||||
// Not timed
|
||||
inreg.r[0] = 4;
|
||||
inreg.r[1] = 0;
|
||||
_kernel_swi (DataVox_Timed, &inreg, &outreg);
|
||||
|
||||
// Bitrate
|
||||
inreg.r[0] = 4;
|
||||
inreg.r[1] = 4000; // I was expecting this to be 125 to 8KHz but.... No idea
|
||||
_kernel_swi (DataVox_Pitch, &inreg, &outreg);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void game_draw_hud()
|
||||
|
||||
@@ -266,6 +266,7 @@ void game2_setup()
|
||||
game2_loadmap("m2_map");
|
||||
game2_loadsmarttiles("m2_smart");
|
||||
game2_loadareanames("m2_areas");
|
||||
|
||||
game2_fillmap(TilePlayer.mapoffset.X,TilePlayer.mapoffset.Y);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ int composition_startcent = -1;
|
||||
|
||||
struct CompositionElement composition[COMPOSITION_MAX];
|
||||
|
||||
unsigned char audiobuffer[20000];
|
||||
|
||||
char *notes[] = {"AX","A#","BX","CX","C#","DX","D#","EX","FX","F#","GX","G#"};
|
||||
|
||||
void sound_on()
|
||||
@@ -195,3 +197,36 @@ int sound_composition_incomplete()
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
void sound_pcm_loadsample(char* filename)
|
||||
{
|
||||
int length;
|
||||
|
||||
memset(audiobuffer,0x00,20000);
|
||||
|
||||
// Attempt to get file info
|
||||
inreg.r[0] = 5;
|
||||
inreg.r[1] = (int) filename;
|
||||
_kernel_swi(OS_File,&inreg,&outreg);
|
||||
|
||||
// Length will be in R4 if it exists
|
||||
length = outreg.r[4];
|
||||
|
||||
if(length > sizeof(audiobuffer))
|
||||
{
|
||||
screen_nobuffer();
|
||||
while (1)
|
||||
printf("Sample exceeds %d bytes (%d bytes) object type is %d\n",sizeof(audiobuffer),length,outreg.r[0]);
|
||||
}
|
||||
|
||||
// Attempt to get file info
|
||||
inreg.r[0] = 16;
|
||||
inreg.r[1] = (int) filename;
|
||||
inreg.r[2] = (int) audiobuffer;
|
||||
inreg.r[3] = 0;
|
||||
|
||||
_kernel_swi(OS_File,&inreg,&outreg);
|
||||
|
||||
// Fill remainder of array with final byte
|
||||
memset(audiobuffer + length,audiobuffer[length-1],sizeof(audiobuffer)-length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user