chuck@richsun.UUCP (Chuck Menard) (10/03/89)
Many thanks to Johnie W. Wardlaw @usrmath.ucr.edu and all of the rest of the replies to my request. Now - for John Stanley @dynasoft and Joe Rohde at ohio-state and anyone else who is interested: I have modified Johnie Wardlaw's ST Replay 'C' code for the Mark Williams C Compiler and Replay4 sound files. I now have another question: I am not able to play sound files larger than 32K bytes. I'm wondering if it's a matter of allocating memory or if 'bascode.exe' can't handle larger than 32K files???? Here's the code: --------------------------- Cut Here ----------------------------------------- X[2-Oct-89] X X Here is the source for my ST Replay "player" code by Johnie Wardlaw and X modified by me for the Mark Williams C Compiler. X X/* X** sound.c Routines to load and play ST-Replay sound files. X** (Requires BASCODE.EXE Replay file to play it) X** Also - the sound sample Replay file replay.spl is needed. X** X** Written by Johnie W. Wardlaw (wardlaw@ucrmath.ucr.edu) X** Use this code however you wish. X** X** Modified by (me) Chuck Menard (chuck@richsun) for the Mark Williams C X** Compiler and the 'as' assembler used with MWC. X** X*/ X X#include <stdio.h> X#include <osbind.h> X Xchar player[3000]; /* Buffer for player object code */ X Xsound_init () X{ X register FILE fd; /* File descriptor for BASCODE.EXE file */ X X/* X** Open file for read only access and binary mode. X*/ X X if ((fd = fopen ("bascode.exe", "rb")) == NULL) X return( 1 ); X X/* X** Read object code into player buffer. My bascode.exe file is 2794 bytes long. X*/ X X if (fread (player, 2794, 1, fd) != 2794) { X close (fd); X return (1); X } X X/* X** Close file and return successfully. X*/ X X close (fd); X return (0); X} X X/* X** Call player code to play sound. X*/ X Xint sound_play (addr, len, freq) X Xlong addr; /* Address of Replay sample */ Xlong len; /* Length of Replay sample */ Xlong freq; /* Frequency of Replay sample */ X X{ X register long *where; /* Address of player code */ X X/* X** Initialize player code with appropriate sample information. X*/ X X *((long *) &player[30]) = addr; X *((long *) &player[34]) = len; X *((long *) &player[38]) = freq; X X/* X** Set address of player code. X*/ X X where = (long *) player; X X/* X**Jump to player code and execute it. I used a seperate assembly file - doit.s. X*/ X X doit(where); /* Go to assembly file */ X X X X X/* X** Return successfully. X*/ X X return (0); X} X X/* X** End of sound.c X*/ X/* X** stest.c Test program for sound.c source code. X** X*/ X X#include <stdio.h> X#include <osbind.h> X Xchar *sample; X Xmain () X{ X char str[128]; /* Temporary input string */ X char *malloc (); /* Allocate memory */ X long freq; /* Frequency to play at */ X long atol (); /* ASCII to LONG conversion */ X register FILE fd; /* File descriptor for sample */ X X/* X** Allocate memory for sample and load it in. X*/ X X sample = malloc( 7000 ); X if ((fd = fopen ("replay.spl", "rb")) == NULL) X exit (1); X fread (sample, 6960, 1, fd); X close (fd); X puts ("Sound file loaded"); X X/* X** Initialize sound player. X*/ X X sound_init(); X puts ("Player code loaded"); X X/* X** Play sample for user at difference frequencies depending on input X** until an empty line is entered. X*/ X X do { X printf ("Speed? [0-5] "); X fflush (stdout); X gets (str); X if (*str) { X freq = atol (str); X sound_play (sample, 6960L, freq); X } X } while (*str); X X/* X** Free memory and exit gracefully. X*/ X X free (sample); X exit (0); X} X X X /* here's doit.s */ X X .globl doit_ X X doit_: X link a6,$0 X movea.l 8(a6),a0 X jsr (a0) X unlk a6 X rts That's it - Have Fun!!!