tools/packsound/source/packsound.cpp
/***************************************

	Process a sound file into 4 bits per sample

***************************************/
Process a sound file into 4 bits per sample
Process a sound file into 4 bits per sample
static Word ExtractSound(OutputMemoryStream *pOutput,const Word8 *pInput,WordPtr uInputLength)
{
	if (uInputLength<4) {
		printf("Input is too small\n");
		return 1;
	}
	if (MemoryCompare("RIFF",pInput,4)) {
		printf("Not a sound file\n");
		return 1;
	}
	Word32 uFileLength = LittleEndian::Load(reinterpret_cast<const Word32 *>(pInput+4));
	if (uFileLength!=uInputLength) {
		printf("Sound file length mismatch\n");
		return 1;
	}
	int iSampleRate = LittleEndian::Load(reinterpret_cast<const Word32 *>(pInput+24));
	int iDOCRate = static_cast<int>(((static_cast<float>(iSampleRate)*512.0f)/SCAN_RATE)+0.5f);
	pOutput->Append(static_cast<Word16>(iDOCRate));
	pOutput->Append(static_cast<Word16>((iSampleRate+59)/60));
	Word uSoundLength = LittleEndian::Load(reinterpret_cast<const Word32 *>(pInput+40));
	uSoundLength>>=1U;
	if (uSoundLength) {
		const Word8 *pTemp = pInput+44;
		do {
			pOutput->Append(static_cast<Word8>((pTemp[0]&0xF0U)+(pTemp[1]>>4U)));
			pTemp+=2;
		} while (--uSoundLength);
	}
	return 0;
}
static Word ExtractSound ( OutputMemoryStream * pOutput , const Word8 * pInput , WordPtr uInputLength ) { if ( uInputLength < 4 ) { printf ( " \n " ) ; return 1 ; } if ( MemoryCompare ( " " , pInput , 4 ) ) { printf ( " \n " ) ; return 1 ; } Word32 uFileLength = LittleEndian :: Load ( reinterpret_cast < const Word32 * > ( pInput + 4 ) ) ; if ( uFileLength != uInputLength ) { printf ( " \n " ) ; return 1 ; } int iSampleRate = LittleEndian :: Load ( reinterpret_cast < const Word32 * > ( pInput + 24 ) ) ; int iDOCRate = static_cast < int > ( ( ( static_cast < float > ( iSampleRate ) * 512.0f ) / SCAN_RATE ) + 0.5f ) ; pOutput -> Append ( static_cast < Word16 > ( iDOCRate ) ) ; pOutput -> Append ( static_cast < Word16 > ( ( iSampleRate + 59 ) / 60 ) ) ; Word uSoundLength = LittleEndian :: Load ( reinterpret_cast < const Word32 * > ( pInput + 40 ) ) ; uSoundLength >>= 1U ; if ( uSoundLength ) { const Word8 * pTemp = pInput + 44 ; do { pOutput -> Append ( static_cast < Word8 > ( ( pTemp [ 0 ] & 0xF0U ) + ( pTemp [ 1 ] >> 4U ) ) ) ; pTemp += 2 ; } while ( -- uSoundLength ) ; } return 0 ; }
Process a sound file into 4 bits per sample
Process a sound file into 4 bits per sample
// Calculate the DOC rate // Convert from a IIgs step rate to a samples per second rate // Output the Space Ace audio header // WGet the number of samples // Convert to 4 bits per sample audio